10#include <unordered_map>
21#define CIA402_STATUS_WORD_MASQ_A 0x6fu
22#define CIA402_STATUS_WORD_MASQ_B 0x4fu
23#define CIA402_STATUS_WORD_MASQ_WARN 0x80u
25#define CIA402_STATUS_NOT_READY 0x00u
26#define CIA402_STATUS_SWITCH_ON_DISABLED 0x40u
27#define CIA402_STATUS_READY_SWITCH_ON 0x21u
28#define CIA402_STATUS_SWITCHED_ON 0x23u
29#define CIA402_STATUS_OP_ENABLED 0x27u
30#define CIA402_STATUS_QUICK_STOP_ACTIVE 0x07u
31#define CIA402_STATUS_FAULT_REACTION_ACTIVE 0x0fu
32#define CIA402_STATUS_FAULT 0x08u
34#define CIA402_STATUS_INTERNAL_LIMIT_REACHED 0x0800u
36#define CIA402_CONTROL_BIT_ENABLE_OP 0x08u
37#define CIA402_CONTROL_BIT_QUICK_STOP 0x04u
38#define CIA402_CONTROL_BIT_ENABLE_VOLTAGE 0x02u
39#define CIA402_CONTROL_BIT_SWITCH_ON 0x01u
40#define CIA402_CONTROL_BIT_FAULT_RESET 0x80u
42#define FAULT_RESET_TIMEOUT_ATTEMPTS 2000
115 {{
false,
false,
false}, EncoderFunction::kDisabled},
116 {{
false,
false,
true}, EncoderFunction::kCommutationOnly},
117 {{
false,
true,
false}, EncoderFunction::kVelocity},
118 {{
false,
true,
true}, EncoderFunction::kCommutationAndVelocity},
119 {{
true,
false,
false}, EncoderFunction::kPosition},
120 {{
true,
false,
true}, EncoderFunction::kCommutationAndPosition},
121 {{
true,
true,
false}, EncoderFunction::kMotionControlFeedbackOnly},
123 EncoderFunction::kCommutationAndMotionControlFeedback}};
150 [[nodiscard]] int32_t
get_id()
const;
336 int32_t
value,
bool reload_configuration);
361 bool reload_configuration);
386 double value,
bool reload_configuration);
398 const std::string&
value);
430 [[nodiscard]] std::variant<MotionMasterError, std::list<std::string>>
440 [[nodiscard]] std::variant<MotionMasterError, std::string>
read_file(
441 const std::string& file_name)
const;
452 const std::string& content);
680 uint8_t address, uint8_t&
value);
692 uint8_t address, uint8_t
value);
709 void refresh_current_position();
716 void set_controlword(uint16_t controlword);
723 void set_op_mode(
OpMode op_mode);
732 [[nodiscard]]
Cia402State cia402_read_state(uint16_t statusword)
const;
742 static uint16_t cia402_command(
Cia402Command command, uint16_t controlword);
754 static uint16_t cia402_go_to_state(
Cia402State target_state,
756 uint16_t controlword,
757 bool skip_states =
true);
764 std::vector<VirtualParameter*> get_sensor_port_virtual_parameters();
Definition: cia402_drive.h:48
static std::map< uint8_t, uint16_t > fw_v5_encoder_feedback_map_
Definition: cia402_drive.h:96
bool get_internal_limit_reached()
Check if the internal limit reached statusword bit is active.
Definition: cia402_drive.cc:625
int32_t get_target_velocity()
Get the current target velocity.
Definition: cia402_drive.cc:237
MotionMasterError reset_fault(bool ignore_timeout_error=false)
Reset the current fault.
Definition: cia402_drive.cc:537
std::tuple< uint8_t, uint8_t, uint8_t > get_controller_encoder_sources()
Get the encoder used for each of the controllers.
Definition: cia402_drive.cc:874
MotionMasterError read_encoder_register(uint8_t encoder_ordinal, uint8_t address, uint8_t &value)
Read a value from an encoder register.
Definition: cia402_drive.cc:811
static std::map< uint8_t, uint16_t > fw_v5_encoder_configuration_map_
Definition: cia402_drive.h:91
uint16_t get_statusword()
Get the raw statusword.
Definition: cia402_drive.cc:279
EncoderFunction
Definition: cia402_drive.h:99
@ kCommutationAndMonitoring
@ kCommutationAndMotionControlFeedback
@ kMotionControlFeedbackOnly
@ kCommutationAndPosition
@ kCommutationAndVelocity
bool is_running()
Check if the device is currently running.
Definition: cia402_drive.cc:527
void set_target_torque(int32_t torque)
Set the target torque.
Definition: cia402_drive.cc:116
MotionMasterError state_machine_control(OpMode target_op_mode, Cia402State target_state)
Change the device OP mode and CiA402 state.
Definition: cia402_drive.cc:1914
MotionMasterError init_position_controller()
Initialize the position controller.
Definition: cia402_drive.cc:62
MotionMasterError init_velocity_controller()
Initialize the velocity controller.
Definition: cia402_drive.cc:88
void set_target_velocity(int32_t velocity)
Set the target velocity.
Definition: cia402_drive.cc:96
std::variant< MotionMasterError, std::list< std::string > > get_file_list() const
Get the list of available files on the flash memory.
Definition: cia402_drive.cc:739
MotionMasterError quick_stop_blocking()
Request an asynchronous quick stop on a device.
Definition: cia402_drive.cc:432
void reset_torque_target_and_offset()
Definition: cia402_drive.cc:382
static std::map< std::tuple< bool, bool, bool >, EncoderFunction > controller_to_encoder_function_map_
Definition: cia402_drive.h:114
MotionMasterError init_slave_profile_position()
Initialize the position profile on the slave.
Definition: cia402_drive.cc:69
BrakeStatus
Definition: cia402_drive.h:135
bool execute_profile_position_ramp()
Execute a position profile ramp on the slave.
Definition: cia402_drive.cc:149
uint32_t get_current_timestamp()
Get the current timestamp.
Definition: cia402_drive.cc:369
Cia402Command
Definition: cia402_drive.h:79
MotionMasterError set_parameter(uint16_t index, uint8_t subindex, int32_t value)
Set parameter value (and reload the device if requested)
Definition: cia402_drive.cc:631
EncoderType
Definition: cia402_drive.h:125
int32_t get_id() const
Get the device ID.
Definition: cia402_drive.cc:56
MotionMasterError init_slave_profile_velocity()
Initialize the velocity profile on the slave.
Definition: cia402_drive.cc:92
void set_target_position(int32_t position)
Set the target position.
Definition: cia402_drive.cc:76
MotionMasterError reload_drive(bool ignore_fault_reset_timeout=false)
Make the CiA402 drive reload (soft restart)
Definition: cia402_drive.cc:718
void set_halt_bit(bool value)
Set the halt bit (up or down) in the controlword.
Definition: cia402_drive.cc:198
VirtualParameter * get_parameter(uint16_t index, uint8_t subindex)
Get a parameter by index/subindex.
Definition: cia402_drive.cc:714
MotionMasterError engage_brake(bool value)
Apply or release the brake.
Definition: cia402_drive.cc:1602
MotionMasterError init_slave_profile_torque()
Initialize the torque profile on the slave.
Definition: cia402_drive.cc:112
int32_t get_current_torque()
Get the current torque.
Definition: cia402_drive.cc:356
int32_t get_target_torque()
Get the current target torque.
Definition: cia402_drive.cc:257
std::map< uint16_t, EncoderFunction > get_all_encoder_functions()
Get all encoder functions.
Definition: cia402_drive.cc:956
BrakeReleaseStrategy
Definition: cia402_drive.h:137
@ kClutchStyleBrakeControl
MotionMasterError deinit_current_controller()
Deinitialize a controller.
Definition: cia402_drive.cc:128
OpMode get_op_mode()
Get the current OP mode.
Definition: cia402_drive.cc:295
std::vector< int16_t > get_cogging_torque_compensation_data()
Get the cogging torque compensation values.
Definition: cia402_drive.cc:791
bool get_fault_state()
Get the current fault state.
Definition: cia402_drive.cc:531
int32_t load_configuration_from_flash()
Load the configuration from the flash memory.
Definition: cia402_drive.cc:503
bool get_warning_status()
Get the current warning status.
Definition: cia402_drive.cc:621
EncoderType get_commutation_encoder_type()
Get the type of the encoder set as the commutation encoder.
Definition: cia402_drive.cc:1190
int32_t get_target_position()
Get the current target position.
Definition: cia402_drive.cc:217
bool is_gearbox_potentially_present()
Determine if a gearbox is potentially present depending on the encoder configuration.
Definition: cia402_drive.cc:1441
MotionMasterError write_file(const std::string &name, const std::string &content)
Write the file to the flash memory.
Definition: cia402_drive.cc:754
MotionMasterError remove_file(const std::string &file_name)
Remove a file from the flash memory.
Definition: cia402_drive.cc:760
bool is_brake_engaged()
Check if the brake is currently engaged.
Definition: cia402_drive.cc:1585
Cia402State get_cia402_state()
Get the current CiA402 state.
Definition: cia402_drive.cc:291
MotionMasterError write_encoder_register(uint8_t encoder_ordinal, uint8_t address, uint8_t value)
Write a value into an encoder register.
Definition: cia402_drive.cc:839
bool is_operational()
Check if the device is operational.
Definition: cia402_drive.cc:629
bool set_encoder_function(uint16_t index, EncoderFunction encoder_function)
(Re)set an encoder function based on the get_all_encoder_functions output
Definition: cia402_drive.cc:1002
int32_t get_current_position()
Get the current position.
Definition: cia402_drive.cc:330
int32_t save_current_configuration_to_flash()
Save the current device configuration to the flash memory.
Definition: cia402_drive.cc:479
uint32_t get_position_control_encoder_resolution()
Find the resolution of the encoder used for motion feedback (function 1 or 3)
Definition: cia402_drive.cc:1358
MotionMasterError init_torque_controller()
Initialize the torque controller.
Definition: cia402_drive.cc:108
uint32_t get_commutation_encoder_resolution()
Find the resolution of the encoder used for commutation feedback.
Definition: cia402_drive.cc:1272
std::string get_log()
Get the slave log from the flash memory.
Definition: cia402_drive.cc:764
double get_feed_constant()
Get and calculate the feed constant if set.
Definition: cia402_drive.cc:1534
Cia402State
Definition: cia402_drive.h:68
void quick_stop()
Request a quick stop on a device.
Definition: cia402_drive.cc:416
uint16_t get_hardware_id() const
Get the hardware ID.
Definition: cia402_drive.cc:58
OpMode
Definition: cia402_drive.h:50
@ kCoggingCompensationRecording
std::variant< MotionMasterError, std::string > read_file(const std::string &file_name) const
Get the file content from a file from the flash memory.
Definition: cia402_drive.cc:743
double get_gear_ratio()
Get the configured gear ratio.
Definition: cia402_drive.cc:1497
int32_t get_current_velocity()
Get the current velocity.
Definition: cia402_drive.cc:343
Definition: motion_master_error.h:6
Definition: virtual_device.h:20
Definition: virtual_parameter.h:9
const char ** name
Definition: co_dictionary.h:7
uint8_t * value
Definition: co_dictionary.h:9
uint16_t index
Definition: co_dictionary.h:0
#define OD_INDEX_ENCODER_1_CONFIGURATION
Definition: dictionary_symbols.h:329
#define OD_INDEX_ENCODER_1_FEEDBACK
Definition: dictionary_symbols.h:357
#define OD_INDEX_ENCODER_2_FEEDBACK
Definition: dictionary_symbols.h:389
#define OD_INDEX_ENCODER_2_CONFIGURATION
Definition: dictionary_symbols.h:361