Merge pull request #223 from qitechgmbh/fix/222

Only Process IO of `EthercatDevice`s If They are Used by a Machine
This commit is contained in:
Icedsoda authored and GitHub committed 2025-05-27 16:25:11 +02:00
commit a64a2b812c
25 files changed
+187 -51

No files matched your search

+3 -1
View File
@@ -2,7 +2,9 @@ use crate::serial::SerialDevice;
use super::identification::DeviceIdentificationIdentified;
use anyhow::Error;
use ethercat_hal::{devices::EthercatDevice, helpers::ethercrab_types::EthercrabSubDevicePreoperational};
use ethercat_hal::{
devices::EthercatDevice, helpers::ethercrab_types::EthercrabSubDevicePreoperational,
};
use ethercrab::{SubDevice, SubDeviceRef};
use smol::lock::RwLock;
use std::sync::Arc;
+12
View File
@@ -254,6 +254,18 @@ pub fn ethercat_device_derive(input: TokenStream) -> TokenStream {
self
}
}
impl crate::devices::EthercatDeviceUsed for #name {
#[doc="Implemented by the ethercat_hal_derive::EthercatDevice derive macro"]
fn is_used(&self) -> bool {
self.is_used
}
#[doc="Implemented by the ethercat_hal_derive::EthercatDevice derive macro"]
fn set_used(&mut self, used: bool) {
self.is_used = used;
}
}
};
TokenStream::from(expanded)
+4 -8
View File
@@ -3,13 +3,15 @@ use ethercat_hal_derive::EthercatDevice;
/// EK1100 bus coupler
#[derive(Clone, EthercatDevice)]
pub struct EK1100 {}
pub struct EK1100 {
is_used: bool,
}
impl EthercatDeviceProcessing for EK1100 {}
impl NewEthercatDevice for EK1100 {
fn new() -> Self {
Self {}
Self { is_used: false }
}
}
@@ -19,12 +21,6 @@ impl std::fmt::Debug for EK1100 {
}
}
impl EK1100 {
pub fn new() -> Self {
Self {}
}
}
pub const EK1100_VENDOR_ID: u32 = 0x2;
pub const EK1100_PRODUCT_ID: u32 = 0x044c2c52;
pub const EK1100_REVISION_A: u32 = 0x00120000;
+2
View File
@@ -9,6 +9,7 @@ use ethercat_hal_derive::{EthercatDevice, TxPdo};
#[derive(Clone, EthercatDevice)]
pub struct EL1002 {
pub txpdo: EL1002TxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL1002 {}
@@ -23,6 +24,7 @@ impl NewEthercatDevice for EL1002 {
fn new() -> Self {
Self {
txpdo: EL1002TxPdo::default(),
is_used: false,
}
}
}
+3 -1
View File
@@ -1,7 +1,7 @@
use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use crate::io::digital_input::{DigitalInputDevice, DigitalInputInput, DigitalInputState};
use crate::pdo::{PredefinedPdoAssignment, TxPdo, basic::BoolPdoObject};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use ethercat_hal_derive::{EthercatDevice, TxPdo};
/// EL1008 8-channel digital input device
@@ -10,6 +10,7 @@ use ethercat_hal_derive::{EthercatDevice, TxPdo};
#[derive(Clone, EthercatDevice)]
pub struct EL1008 {
pub txpdo: EL1008TxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL1008 {}
@@ -24,6 +25,7 @@ impl NewEthercatDevice for EL1008 {
fn new() -> Self {
Self {
txpdo: EL1008TxPdo::default(),
is_used: false,
}
}
}
+2
View File
@@ -10,6 +10,7 @@ use ethercat_hal_derive::{EthercatDevice, RxPdo};
#[derive(EthercatDevice)]
pub struct EL2002 {
pub rxpdo: EL2002RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2002 {}
@@ -24,6 +25,7 @@ impl NewEthercatDevice for EL2002 {
fn new() -> Self {
Self {
rxpdo: EL2002RxPdo::default(),
is_used: false,
}
}
}
+2
View File
@@ -8,6 +8,7 @@ use ethercat_hal_derive::{EthercatDevice, RxPdo};
#[derive(EthercatDevice)]
pub struct EL2004 {
pub rxpdo: EL2004RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2004 {}
@@ -22,6 +23,7 @@ impl NewEthercatDevice for EL2004 {
fn new() -> Self {
Self {
rxpdo: EL2004RxPdo::default(),
is_used: false,
}
}
}
+3 -1
View File
@@ -1,7 +1,7 @@
use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use crate::io::digital_output::{DigitalOutputDevice, DigitalOutputOutput, DigitalOutputState};
use crate::pdo::{RxPdo, basic::BoolPdoObject};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use ethercat_hal_derive::{EthercatDevice, RxPdo};
/// EL2008 8-channel digital output device
@@ -10,6 +10,7 @@ use ethercat_hal_derive::{EthercatDevice, RxPdo};
#[derive(EthercatDevice)]
pub struct EL2008 {
pub rxpdo: EL2008RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2008 {}
@@ -24,6 +25,7 @@ impl NewEthercatDevice for EL2008 {
fn new() -> Self {
Self {
rxpdo: EL2008RxPdo::default(),
is_used: false,
}
}
}
+3 -1
View File
@@ -1,6 +1,6 @@
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use crate::io::digital_output::{DigitalOutputDevice, DigitalOutputOutput, DigitalOutputState};
use crate::pdo::{RxPdo, basic::BoolPdoObject};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use ethercat_hal_derive::{EthercatDevice, RxPdo};
use super::{EthercatDeviceProcessing, NewEthercatDevice};
@@ -11,6 +11,7 @@ use super::{EthercatDeviceProcessing, NewEthercatDevice};
#[derive(EthercatDevice)]
pub struct EL2024 {
pub rxpdo: EL2024RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2024 {}
@@ -25,6 +26,7 @@ impl NewEthercatDevice for EL2024 {
fn new() -> Self {
Self {
rxpdo: EL2024RxPdo::default(),
is_used: false,
}
}
}
+4 -2
View File
@@ -1,15 +1,15 @@
use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple};
use crate::{
coe::{ConfigurableDevice, Configuration},
helpers::ethercrab_types::EthercrabSubDevicePreoperational,
io::pulse_train_output::{
PulseTrainOutputDevice, PulseTrainOutputInput, PulseTrainOutputOutput,
PulseTrainOutputState,
},
pdo::{
el252x::{EncControl, EncStatus, PtoControl, PtoStatus, PtoTarget},
PredefinedPdoAssignment, RxPdo, TxPdo,
el252x::{EncControl, EncStatus, PtoControl, PtoStatus, PtoTarget},
},
helpers::ethercrab_types::EthercrabSubDevicePreoperational,
};
use anyhow::Ok;
use ethercat_hal_derive::{EthercatDevice, RxPdo, TxPdo};
@@ -20,6 +20,7 @@ pub struct EL2521 {
pub configuration: EL2521Configuration,
pub txpdo: EL2521TxPdo,
pub rxpdo: EL2521RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2521 {}
@@ -40,6 +41,7 @@ impl NewEthercatDevice for EL2521 {
configuration: configuration,
txpdo,
rxpdo,
is_used: false,
}
}
}
+3 -1
View File
@@ -1,6 +1,7 @@
use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple};
use crate::{
coe::{ConfigurableDevice, Configuration},
helpers::ethercrab_types::EthercrabSubDevicePreoperational,
io::pulse_train_output::{
PulseTrainOutputDevice, PulseTrainOutputInput, PulseTrainOutputOutput,
PulseTrainOutputState,
@@ -9,7 +10,6 @@ use crate::{
PredefinedPdoAssignment, RxPdo, TxPdo,
el252x::{EncControl, EncStatus, PtoControl, PtoStatus, PtoTarget},
},
helpers::ethercrab_types::EthercrabSubDevicePreoperational,
};
use anyhow::Ok;
use ethercat_hal_derive::{EthercatDevice, RxPdo, TxPdo};
@@ -20,6 +20,7 @@ pub struct EL2522 {
pub configuration: EL2522Configuration,
pub txpdo: EL2522TxPdo,
pub rxpdo: EL2522RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2522 {}
@@ -40,6 +41,7 @@ impl NewEthercatDevice for EL2522 {
configuration: configuration,
txpdo,
rxpdo,
is_used: false,
}
}
}
+3 -1
View File
@@ -1,6 +1,6 @@
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use crate::io::digital_output::{DigitalOutputDevice, DigitalOutputOutput, DigitalOutputState};
use crate::pdo::{RxPdo, basic::BoolPdoObject};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use ethercat_hal_derive::{EthercatDevice, RxPdo};
use super::{EthercatDeviceProcessing, NewEthercatDevice};
@@ -11,6 +11,7 @@ use super::{EthercatDeviceProcessing, NewEthercatDevice};
#[derive(EthercatDevice)]
pub struct EL2634 {
pub rxpdo: EL2634RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2634 {}
@@ -25,6 +26,7 @@ impl NewEthercatDevice for EL2634 {
fn new() -> Self {
Self {
rxpdo: EL2634RxPdo::default(),
is_used: false,
}
}
}
+3 -1
View File
@@ -1,6 +1,6 @@
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use crate::io::digital_output::{DigitalOutputDevice, DigitalOutputOutput, DigitalOutputState};
use crate::pdo::{RxPdo, basic::BoolPdoObject};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use ethercat_hal_derive::{EthercatDevice, RxPdo};
use super::{EthercatDeviceProcessing, NewEthercatDevice};
@@ -11,6 +11,7 @@ use super::{EthercatDeviceProcessing, NewEthercatDevice};
#[derive(EthercatDevice)]
pub struct EL2809 {
pub rxpdo: EL2809RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL2809 {}
@@ -25,6 +26,7 @@ impl NewEthercatDevice for EL2809 {
fn new() -> Self {
Self {
rxpdo: EL2809RxPdo::default(),
is_used: false,
}
}
}
+2
View File
@@ -20,6 +20,7 @@ use uom::si::{electric_potential::volt, f64::ElectricPotential};
pub struct EL3001 {
pub txpdo: EL3001TxPdo,
pub configuration: EL3001Configuration,
is_used: bool,
}
impl EthercatDeviceProcessing for EL3001 {}
@@ -42,6 +43,7 @@ impl NewEthercatDevice for EL3001 {
Self {
txpdo: configuration.pdo_assignment.txpdo_assignment(),
configuration,
is_used: false,
}
}
}
+2
View File
@@ -32,6 +32,7 @@ pub struct EL3021 {
pub configuration: EL3021Configuration,
pub txpdo: EL3021TxPdo,
pub rxpdo: EL3021RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL3021 {}
@@ -64,6 +65,7 @@ impl NewEthercatDevice for EL3021 {
configuration: configuration.clone(),
txpdo: configuration.pdo_assignment.txpdo_assignment(),
rxpdo: configuration.pdo_assignment.rxpdo_assignment(),
is_used: false,
}
}
}
+4 -2
View File
@@ -5,16 +5,16 @@ use crate::pdo::RxPdo;
use crate::pdo::TxPdo;
use crate::{
coe::{ConfigurableDevice, Configuration},
helpers::signing_converter_u16::U16SigningConverter,
pdo::{
PredefinedPdoAssignment,
analog_input::{AiCompact, AiStandard},
},
shared_config::el30xx::{EL30XXChannelConfiguration, EL30XXPresentation},
helpers::signing_converter_u16::U16SigningConverter,
};
use crate::{
io::analog_input::{AnalogInputDevice, AnalogInputInput, AnalogInputState},
helpers::ethercrab_types::EthercrabSubDevicePreoperational,
io::analog_input::{AnalogInputDevice, AnalogInputInput, AnalogInputState},
};
use ethercat_hal_derive::{EthercatDevice, RxPdo, TxPdo};
use uom::si::electric_current::milliampere;
@@ -38,6 +38,7 @@ pub struct EL3024 {
pub configuration: EL3024Configuration,
pub txpdo: EL3024TxPdo,
pub rxpdo: EL3024RxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL3024 {}
@@ -73,6 +74,7 @@ impl NewEthercatDevice for EL3024 {
configuration: configuration.clone(),
txpdo: configuration.pdo_assignment.txpdo_assignment(),
rxpdo: configuration.pdo_assignment.rxpdo_assignment(),
is_used: false,
}
}
}
+2
View File
@@ -14,6 +14,7 @@ use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple}
#[derive(EthercatDevice)]
pub struct EL3204 {
pub txpdo: EL3204TxPdo,
is_used: bool,
}
impl EthercatDeviceProcessing for EL3204 {}
@@ -28,6 +29,7 @@ impl NewEthercatDevice for EL3204 {
fn new() -> Self {
Self {
txpdo: EL3204TxPdo::default(),
is_used: false,
}
}
}
+3 -1
View File
@@ -1,8 +1,8 @@
use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple};
use crate::coe::{ConfigurableDevice, Configuration};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use crate::io::serial_interface::{SerialEncoding, SerialInterfaceDevice};
use crate::pdo::{PredefinedPdoAssignment, RxPdo, RxPdoObject, TxPdo, TxPdoObject};
use crate::helpers::ethercrab_types::EthercrabSubDevicePreoperational;
use anyhow::{Error, anyhow};
use bitvec::field::BitField;
use bitvec::order::Lsb0;
@@ -369,6 +369,7 @@ pub struct EL6021 {
pub configuration: EL6021Configuration,
pub txpdo: EL6021TxPdo,
pub rxpdo: EL6021RxPdo,
is_used: bool,
pub output_ts: u64,
pub input_ts: u64,
pub has_messages_last_toggle: bool,
@@ -404,6 +405,7 @@ impl NewEthercatDevice for EL6021 {
configuration: configuration.clone(),
txpdo: configuration.pdo_assignment.txpdo_assignment(),
rxpdo: configuration.pdo_assignment.rxpdo_assignment(),
is_used: false,
output_ts: 0,
input_ts: 0,
has_messages_last_toggle: false,
+2
View File
@@ -25,6 +25,7 @@ use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple}
pub struct EL7031 {
pub txpdo: EL7031TxPdo,
pub rxpdo: EL7031RxPdo,
is_used: bool,
pub configuration: EL7031Configuration,
pub counter_wrapper: CounterWrapperU16U128,
}
@@ -100,6 +101,7 @@ impl NewEthercatDevice for EL7031 {
Self {
txpdo: configuration.pdo_assignment.txpdo_assignment(),
rxpdo: configuration.pdo_assignment.rxpdo_assignment(),
is_used: false,
configuration,
counter_wrapper: CounterWrapperU16U128::new(),
}
@@ -31,6 +31,7 @@ use super::{EthercatDeviceProcessing, NewEthercatDevice, SubDeviceIdentityTuple}
pub struct EL7031_0030 {
pub txpdo: EL7031_0030TxPdo,
pub rxpdo: EL7031_0030RxPdo,
is_used: bool,
pub configuration: EL7031_0030Configuration,
pub counter_wrapper: CounterWrapperU16U128,
}
@@ -106,6 +107,7 @@ impl NewEthercatDevice for EL7031_0030 {
Self {
txpdo: configuration.pdo_assignment.txpdo_assignment(),
rxpdo: configuration.pdo_assignment.rxpdo_assignment(),
is_used: false,
configuration,
counter_wrapper: CounterWrapperU16U128::new(),
}
@@ -23,6 +23,7 @@ pub mod pdo;
pub struct EL7041_0052 {
pub txpdo: pdo::EL7041_0052TxPdo,
pub rxpdo: pdo::EL7041_0052RxPdo,
is_used: bool,
pub configuration: EL7041_0052Configuration,
// encoder wrapping
@@ -35,6 +36,7 @@ impl NewEthercatDevice for EL7041_0052 {
EL7041_0052 {
txpdo: configuration.pdo_assignment.txpdo_assignment(),
rxpdo: configuration.pdo_assignment.rxpdo_assignment(),
is_used: false,
configuration,
counter_wrapper: CounterWrapperU16U128::new(),
}
+16 -1
View File
@@ -52,7 +52,13 @@ use std::{any::Any, fmt::Debug, sync::Arc};
/// provides interface to read and write the PDO data
pub trait EthercatDevice
where
Self: NewEthercatDevice + EthercatDeviceProcessing + Any + Send + Sync + Debug,
Self: NewEthercatDevice
+ EthercatDeviceProcessing
+ EthercatDeviceUsed
+ Any
+ Send
+ Sync
+ Debug,
{
/// Input data from the last cycle
/// `ts` is the timestamp when the input data was sent by the device
@@ -134,6 +140,15 @@ pub trait NewEthercatDevice {
Self: Sized;
}
/// A trait to ensure a divice can ony be used once
pub trait EthercatDeviceUsed {
/// Returns true if the device is used
fn is_used(&self) -> bool;
/// Sets the device as used
fn set_used(&mut self, used: bool);
}
/// Casts a `dyn Device` to a specific device type
pub async fn downcast_device<T: EthercatDevice>(
device: Arc<RwLock<dyn EthercatDevice>>,
+12
View File
@@ -65,6 +65,12 @@ pub async fn loop_once<'maindevice>(app_state: Arc<AppState>) -> Result<(), anyh
// get device
let mut device = ethercat_setup.devices[i].1.as_ref().write().await;
// check if the device is used
if !device.is_used() {
// if the device is not used, we skip it
continue;
}
// put inputs into device
device.input_checked(input_bits).or_else(|e| {
Err(anyhow::anyhow!(
@@ -121,6 +127,12 @@ pub async fn loop_once<'maindevice>(app_state: Arc<AppState>) -> Result<(), anyh
// get device
let mut device = ethercat_setup.devices[i].1.as_ref().write().await;
// check if the device is used
if !device.is_used() {
// if the device is not used, we skip it
continue;
}
// pre process outputs
device.output_pre_process().or_else(|e| {
Err(anyhow::anyhow!(
+46 -11
View File
@@ -23,8 +23,8 @@ use control_core::{
use ethercat_hal::{
coe::ConfigurableDevice,
devices::{
downcast_device,
ek1100::EK1100_IDENTITY_A,
EthercatDeviceUsed, downcast_device,
ek1100::{EK1100, EK1100_IDENTITY_A},
el1002::{EL1002, EL1002_IDENTITY_A},
el2004::{EL2004, EL2004_IDENTITY_A, EL2004Port},
el3021::{EL3021, EL3021_IDENTITY_A, EL3021Port},
@@ -92,8 +92,14 @@ impl MachineNewTrait for ExtruderV2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
match subdevice_identity_to_tuple(&subdevice_identity) {
EK1100_IDENTITY_A => (),
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EK1100_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
subdevice_index,
)?;
downcast_device::<EK1100>(ethercat_device).await?
}
_ => {
return Err(anyhow::anyhow!(
"[{}::MachineNewTrait/Winder2::new] Device with role 0 is not an EK1100",
@@ -101,7 +107,12 @@ impl MachineNewTrait for ExtruderV2 {
));
}
};
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
}
// What is its use ?
let _el1002 = {
let device_identification =
@@ -119,7 +130,7 @@ impl MachineNewTrait for ExtruderV2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL1002_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -133,7 +144,12 @@ impl MachineNewTrait for ExtruderV2 {
module_path!()
));
}
};
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
device
};
let el6021 = {
@@ -152,7 +168,7 @@ impl MachineNewTrait for ExtruderV2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
let el6021 = match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL6021_IDENTITY_A | EL6021_IDENTITY_B | EL6021_IDENTITY_C => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -167,12 +183,16 @@ impl MachineNewTrait for ExtruderV2 {
));
}
};
el6021
device
.write()
.await
.write_config(&subdevice, &EL6021Configuration::default())
.await?;
el6021
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
device
};
let el2004 = {
@@ -191,7 +211,7 @@ impl MachineNewTrait for ExtruderV2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL2004_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -205,7 +225,12 @@ impl MachineNewTrait for ExtruderV2 {
module_path!()
));
}
};
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
device
};
let el3021 = {
@@ -224,7 +249,7 @@ impl MachineNewTrait for ExtruderV2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL3021_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -238,7 +263,12 @@ impl MachineNewTrait for ExtruderV2 {
module_path!()
));
}
};
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
device
};
let el3204 = {
@@ -257,7 +287,7 @@ impl MachineNewTrait for ExtruderV2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL3204_IDENTITY_A | EL3204_IDENTITY_B => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -271,7 +301,12 @@ impl MachineNewTrait for ExtruderV2 {
module_path!()
));
}
};
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
device
};
let t1 = TemperatureInput::new(el3204.clone(), EL3204Port::T1);
+47 -19
View File
@@ -22,6 +22,7 @@ use control_core::machines::new::{
};
use control_core::uom_extensions::velocity::meter_per_minute;
use ethercat_hal::coe::ConfigurableDevice;
use ethercat_hal::devices::ek1100::EK1100;
use ethercat_hal::devices::el2002::{EL2002, EL2002Port};
use ethercat_hal::devices::el7031::coe::EL7031Configuration;
use ethercat_hal::devices::el7031::pdo::EL7031PredefinedPdoAssignment;
@@ -35,7 +36,7 @@ use ethercat_hal::devices::el7031_0030::{
};
use ethercat_hal::devices::el7041_0052::coe::EL7041_0052Configuration;
use ethercat_hal::devices::el7041_0052::{EL7041_0052, EL7041_0052_IDENTITY_A, EL7041_0052Port};
use ethercat_hal::devices::{downcast_device, subdevice_identity_to_tuple};
use ethercat_hal::devices::{EthercatDeviceUsed, downcast_device, subdevice_identity_to_tuple};
use ethercat_hal::devices::{ek1100::EK1100_IDENTITY_A, el2002::EL2002_IDENTITY_A};
use ethercat_hal::io::analog_input::AnalogInput;
use ethercat_hal::io::digital_input::DigitalInput;
@@ -98,8 +99,14 @@ impl MachineNewTrait for Winder2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
match subdevice_identity_to_tuple(&subdevice_identity) {
EK1100_IDENTITY_A => (),
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EK1100_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
subdevice_index,
)?;
downcast_device::<EK1100>(ethercat_device).await?
}
_ => {
return Err(anyhow::anyhow!(
"[{}::MachineNewTrait/Winder2::new] Device with role 0 is not an EK1100",
@@ -107,6 +114,10 @@ impl MachineNewTrait for Winder2 {
));
}
};
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
}
// Role 1
@@ -128,7 +139,7 @@ impl MachineNewTrait for Winder2 {
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice = get_subdevice_by_index(hardware.subdevices, subdevice_index)?;
let subdevice_identity = subdevice.identity();
match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL2002_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -140,7 +151,12 @@ impl MachineNewTrait for Winder2 {
"[{}::MachineNewTrait/Winder2::new] Device with role 1 is not an EL2002",
module_path!()
))?,
};
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
device
};
// Role 2
@@ -165,7 +181,7 @@ impl MachineNewTrait for Winder2 {
)?;
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice_identity = subdevice.identity();
let el7041 = match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL7041_0052_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -178,7 +194,7 @@ impl MachineNewTrait for Winder2 {
module_path!()
))?,
};
let el7041_config = EL7041_0052Configuration {
let config = EL7041_0052Configuration {
stm_features: shared_config::el70x1::StmFeatures {
operation_mode: EL70x1OperationMode::DirectVelocity,
..Default::default()
@@ -189,12 +205,16 @@ impl MachineNewTrait for Winder2 {
},
..Default::default()
};
el7041
device
.write()
.await
.write_config(&subdevice, &el7041_config)
.write_config(&subdevice, &config)
.await?;
(el7041, el7041_config)
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
(device, config)
};
// Role 3
@@ -219,7 +239,7 @@ impl MachineNewTrait for Winder2 {
)?;
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice_identity = subdevice.identity();
let el7031 = match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL7031_IDENTITY_A | EL7031_IDENTITY_B => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -232,7 +252,7 @@ impl MachineNewTrait for Winder2 {
module_path!()
))?,
};
let el7031_config = EL7031Configuration {
let config = EL7031Configuration {
stm_features: shared_config::el70x1::StmFeatures {
operation_mode: EL70x1OperationMode::DirectVelocity,
// Max Speed of 1000 steps/s
@@ -248,12 +268,16 @@ impl MachineNewTrait for Winder2 {
pdo_assignment: EL7031PredefinedPdoAssignment::VelocityControlCompact,
..Default::default()
};
el7031
device
.write()
.await
.write_config(&subdevice, &el7031_config)
.write_config(&subdevice, &config)
.await?;
(el7031, el7031_config)
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
(device, config)
};
// Role 4
@@ -278,7 +302,7 @@ impl MachineNewTrait for Winder2 {
)?;
let subdevice_index = device_hardware_identification_ethercat.subdevice_index;
let subdevice_identity = subdevice.identity();
let el7031_0030 = match subdevice_identity_to_tuple(&subdevice_identity) {
let device = match subdevice_identity_to_tuple(&subdevice_identity) {
EL7031_0030_IDENTITY_A => {
let ethercat_device = get_ethercat_device_by_index(
&hardware.ethercat_devices,
@@ -291,7 +315,7 @@ impl MachineNewTrait for Winder2 {
module_path!()
))?,
};
let el7031_0030_config = EL7031_0030Configuration {
let config = EL7031_0030Configuration {
stm_features: el7031_0030::coe::StmFeatures {
operation_mode: EL70x1OperationMode::DirectVelocity,
// Max Speed of 1000 steps/s
@@ -306,12 +330,16 @@ impl MachineNewTrait for Winder2 {
pdo_assignment: EL7031_0030PredefinedPdoAssignment::VelocityControlCompact,
..Default::default()
};
el7031_0030
device
.write()
.await
.write_config(&subdevice, &el7031_0030_config)
.write_config(&subdevice, &config)
.await?;
(el7031_0030, el7031_0030_config)
{
let mut device_guard = device.write().await;
device_guard.set_used(true);
}
(device, config)
};
let mode = Winder2Mode::Standby;