33 namespace canopen_schunk {
36 DS301Node(node_id,can_device, heartbeat_monitor),
37 m_interpolation_cycle_time_ms(20),
38 m_max_number_of_state_transitions(10),
40 m_transmission_factor(1)
104 success =
setRPDOValue(
"target_position", static_cast<int32_t>(target_ticks));
109 success =
setRPDOValue(
"vl_target_velocity", static_cast<int16_t>(target_ticks));
114 success =
setRPDOValue(
"target_velocity", static_cast<int32_t>(target_ticks));
119 success =
setRPDOValue(
"target_torque", static_cast<int16_t>(target_ticks));
130 success =
setRPDOValue(
"interpolation_buffer", static_cast<int32_t>(target_ticks));
168 word.
all = getRPDOValue<uint16_t> (
"control_word");
178 word.
all = getRPDOValue<uint16_t> (
"control_word");
192 feedback = getTPDOValue<int32_t>(
"measured_position");
198 LOGGING_ERROR (CanOpen,
"GetTargetFeature is not yet implemented for velocity mode." <<
endl);
204 LOGGING_ERROR (CanOpen,
"GetTargetFeature is not yet implemented for profile velocity mode." <<
endl);
210 LOGGING_ERROR (CanOpen,
"GetTargetFeature is not yet implemented for profile torque mode." <<
endl);
221 feedback = getTPDOValue<int32_t>(
"measured_position");
227 LOGGING_ERROR (CanOpen,
"GetTargetFeature is not yet implemented for cyclic sync position mode." <<
endl);
233 LOGGING_ERROR (CanOpen,
"GetTargetFeature is not yet implemented for cyclic sync velocity mode." <<
endl);
239 LOGGING_ERROR (CanOpen,
"GetTargetFeature is not yet implemented for cyclic sync torque mode." <<
endl);
249 #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_ 254 #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_ 271 std::string identifier =
"control_word";
275 word.
all = getRPDOValue<uint16_t> (identifier);
317 status_word.
all = getTPDOValue<uint16_t>(
"status_word");
323 bool reset_fault_successful =
false;
324 for (
size_t i = 0; i < 5; ++i)
327 if (reset_fault_successful)
333 if (!reset_fault_successful)
335 LOGGING_INFO (CanOpen,
"Unable to reset from fault state after 5 tries. " <<
336 "Trying to do a hard reset on the device." <<
endl);
343 std::stringstream ss;
344 ss <<
"Could not perform fault reset for node " 346 <<
" after multiple tries. " 347 <<
"Is the device hard-disabled?" 348 <<
"\nOtherwise: Have you tried turning it off and on again?";
358 size_t num_transitions = 0;
364 switch (current_state)
436 int16_t quick_stop_option_code = 0;
443 LOGGING_WARNING (CanOpen,
"Caught error while downloading quick-stop-option code. " 444 <<
"Probably it is not implemented, as it is optional. " 445 <<
"Will carry on assuming quick-stop-option-code = 0.\n" 446 <<
"Error was: " << e.
what() <<
endl 449 if (quick_stop_option_code >=5 && quick_stop_option_code <=8 &&
466 ". Starting all over again..." <<
endl);
481 ". Aborting state transition." <<
endl);
507 " is not set. Aborting homing now." <<
endl);
518 controlword.
all = getRPDOValue<uint16_t>(
"control_word");
528 bool homing_attained =
false;
529 bool homing_error =
false;
530 while (!homing_attained)
538 std::stringstream ss;
539 ss <<
"Homing of node " <<
static_cast<int>(
m_node_id) <<
" failed.";
557 statusword.
all = getTPDOValue<uint16_t> (
"status_word");
559 std::stringstream ss;
560 ss <<
"Device " <<
static_cast<int>(
m_node_id) <<
" status: " <<
563 ss <<
"Fault: " << statusword.
bit.
fault << std::endl;
567 ss <<
"Quick stop active: " << statusword.
bit.
quick_stop << std::endl;
578 std::stringstream ss;
653 int8_t mode_int = op_mode;
654 uint32_t bitmask_mode = 0x01 << (mode_int-1);
666 std::stringstream ss;
667 ss <<
"Modes of operation supported by device " <<
static_cast<int>(
m_node_id) << std::endl;
670 ss <<
"Profile position mode" << std::endl;
674 ss <<
"Velocity mode" << std::endl;
678 ss <<
"Profile velocity mode" << std::endl;
682 ss <<
"Profile torque mode" << std::endl;
686 ss <<
"Homing mode" << std::endl;
690 ss <<
"Interpolated position mode" << std::endl;
694 ss <<
"Cyclic sync position mode" << std::endl;
698 ss <<
"Cyclic sync velocity mode" << std::endl;
702 ss <<
"Cyclic sync torque mode" << std::endl;
724 static_cast<int>(
m_node_id) <<
", which is currently not supported." <<
endl);
732 " is not supported by the device " <<
745 int8_t mode_int = op_mode;
750 catch (
const std::exception& e)
766 if (interpolation_cycle_time_ms != 0)
796 " Some devices do not support setting this, but use the acceleration value for deceleration, as well. So you might want to ignore this message. " <<
797 "The error was: " << e.
what() <<
endl 831 status_word.
all = getTPDOValue<uint16_t>(
"status_word");
837 "not in state FAULT. Instead it is in state " <<
deviceStatusString (current_state) <<
838 ". Not doing anything here." <<
endl);
849 status_word.
all = getTPDOValue<uint16_t>(
"status_word");
855 m_node_id <<
". Possibly the reason for entering the fault state still exists." <<
881 velocity <<
"." <<
endl);
889 acceleration <<
"." <<
endl);
901 deceleration <<
"." <<
endl);
908 motion_type <<
"." <<
endl);
953 const int16_t interpolation_type,
954 const uint8_t size_of_data_record)
978 std::string identifier =
"control_word";
980 word.
all = getRPDOValue<uint16_t> (identifier);
1035 std::stringstream ss;
1036 ss <<
"Illegal DS402 state transition requested: " << transition;
1084 controlword.
all = getRPDOValue<uint16_t>(
"control_word");
1111 LOGGING_ERROR (CanOpen,
"OpenBrakes called while not in OPERATION_ENABLE state. Will do nothing" <<
endl);
1132 LOGGING_ERROR (CanOpen,
"CloseBrakes called while not in OPERATION_ENABLE state. Will do nothing" <<
endl);
1139 statusword.
all = getTPDOValue<uint16_t>(
"status_word");
1149 " has switched to state " <<
1151 " without host request. " <<
1152 "The controller will adapt the device's status." <<
endl 1162 statusword.
all = getTPDOValue<uint16_t>(
"status_word");
1170 word.
all = getTPDOValue<uint16_t>(
"status_word");
virtual void configureInterpolationData(const uint8_t buffer_organization=0, const int16_t interpolation_type=0, const uint8_t size_of_data_record=4)
Configure the buffer for the interpolated position mode.
uint32_t cyclic_sync_velocity_mode
virtual void configureInterpolationCycleTime(const uint8_t interpolation_cycle_time_ms=8)
Set the interpolation cycle time in milliseconds. If no time is given the default will be used...
#define LOGGING_INFO_C(streamname, classname, arg)
void configureMotionProfileType(const int16_t motion_type)
Set the device's motion profile type through an SDO (OD 0x6086)
double m_transmission_factor
uint32_t homing_speed_low
Configuration parameters for a Profile_Position_Mode according to CiA DSP-402 V1.1 section 12...
std::string operationModeSpecificStatus(const ds402::Statusword &statusword)
This function queries the two operation mode specific bits and turns them to a human-readable string...
virtual bool isTargetReached()
Returns whether the device has reached it's recent target.
std::vector< MappingConfiguration > MappingConfigurationList
The MappingConfigurationList holds multiple Mapping configurations. The Mapping of a single PDO is de...
virtual void setupProfileTorqueMode(const ds402::ProfileTorqueModeConfiguration &config)
Configure the mandatory parameters for a profile torque mode.
virtual void initPDOMappingSingle(const PDO::MappingConfigurationList &config, const uint16_t pdo_nr, const PDO::eTransmissionType &transmission_type, const ePDO_TYPE &pdo_type, const bool dummy_mapping=false, const uint8_t cyclic_timeout_cycles=0)
Init PDO mapping with a given mapping configuration for a given pdo nr.
virtual void enableNode(const ds402::eModeOfOperation operation_mode=ds402::MOO_RESERVED_0)
Switches on the device and enters Operation Enabled mode with the given mode. If the requested mode i...
void doDS402StateTransition(const ds402::eStateTransission transition)
Performs a state transition in the DS402 state machine.
virtual void closeBrakes()
When the device is in OperationEnabled mode, this function disable the drive motion.
virtual void initNode()
Initializes the node. Tries to query all required data from the device.
#define LOGGING_INFO(streamname, arg)
Basic CanOpen exception that contains the Object dictionary index and subindex.
void configureTorqueSlope(const uint32_t torque_slope)
Set the device's torque slope through an SDO (OD 0x6087)
SDO m_sdo
SDO object for specific calls.
void configureProfileAcceleration(const uint32_t acceleration)
Set the device's profile acceleration through an SDO (OD 0x6083)
virtual bool resetFault()
This function is used to recover from a fault state.
data union for access to DSP 402 6041 statusword,
uint32_t profile_velocity_mode
boost::shared_ptr< icl_comm::websocket::WsBroadcaster > m_ws_broadcaster
Interface to send out diagnostics data. Only available if compiled with IC_BUILDER_ICL_COMM_WEBSOCKET...
#define LOGGING_DEBUG(streamname, arg)
uint16_t operation_mode_specific_0
eNMT_SubState
The NMT Substate is only used during initialization of a device. Meaning the substates are only usefu...
bool download(const bool normal_transfer, const uint16_t index, const uint8_t subindex, const std::vector< uint8_t > &usrdata)
Downloads SDO data from the master to the slave (From PC to node).
uint8_t m_interpolation_cycle_time_ms
Cycle time of interpolation mode.
uint32_t cyclic_sync_position_mode
Configuration parameters for a Profile_Velocity_Mode according to CiA DSP-402 V1.1 section 16...
eState stateFromStatusword(const ds402::Statusword &statusword)
uint16_t operation_enabled
std::string deviceStatusString(const eState state)
Turns a status word into a status string according to the elmo DS-402 implementation guide chapter 6...
void configureHomingAcceleration(const uint32_t acceleration)
Set the device's homing acceleration through an SDO (OD 0x609A)
bool use_blending
If set to true, the device will blend over to a new setpoint. Defaults to true.
virtual void querySupportedDeviceModes()
Uploads all supported modes of operation from the device. and stores them in the m_supported_modes me...
virtual void initDS402State(const icl_hardware::canopen_schunk::ds402::eState &requested_state)
Initializes a state of the DS402 state machine. Performs all necessary state transitions until the ta...
PDO related exceptions go here.
int16_t motion_profile_type
Type of ramp used for accelerating and decelerating. Defaults to linear.
void printSupportedModesOfOperation()
Prints out all Modes on which the device claims to be able to operate on.
virtual void initNode()
Initializes the node.
void configureProfileVelocity(const uint32_t velocity)
Set the device's profile velocity through an SDO (OD 0x6081)
#define LOGGING_WARNING_C(streamname, classname, arg)
ds402::ProfilePositionModeConfiguration m_ppm_config
#define LOGGING_ERROR(streamname, arg)
virtual void startPPMovement()
This sets the RPDO communication for enabling the movement after a target has been set...
static const uint16_t ID_CONTROL_WORD
uint8_t m_node_id
CANOPEN ID of the node.
void configureSensorSelectionCode(const int16_t sensor_selection_code)
Set the device's sensor selection code through an SDO (OD 0x606a)
void stop()
stop Stops the device by setting the NMT state to stopped
virtual void configureHomingSpeeds(const uint32_t low_speed, const uint32_t high_speed=0)
Set the speeds for homing through SDO 6099. Typically, a high speed is used when searching for a home...
virtual void home()
Perform homing for this node.
bool use_relative_targets
This parameter influences the interpretation of new set points. If set to true, new set point positio...
virtual void openBrakes()
When the device is in OperationEnabled mode, this function enables the drive motion.
#define LOGGING_DEBUG_C(streamname, classname, arg)
float profile_acceleration
This will be used for both acceleration ramps.
void configureMaxDeceleration(const uint32_t deceleration)
Set the device's maximum deceleration through an SDO (OD 0x60c6)
ThreadStream & endl(ThreadStream &stream)
virtual bool isModeSupported(const ds402::eModeOfOperation op_mode)
Tests whether a given mode of operation is supported by the device.
DS402Node(const uint8_t node_id, const icl_hardware::canopen_schunk::CanDevPtr &can_device, HeartBeatMonitor::Ptr heartbeat_monitor)
ds402::SupportedDriveModes m_supported_modes
supported modes of operation
static const uint16_t ID_STATUS_WORD
virtual void disableNode()
Puts the device into STATE_SWITCHED_ON mode. If the device was in InterpolatedPositionMode, interpolation will be stopped here, as well.
void configureQuickStopDeceleration(const uint32_t deceleration)
Set the device's quick stop deceleration through an SDO (OD 0x6085)
uint32_t cyclic_sync_torque_mode
int16_t torque_profile_type
bool setRPDOValue(const std::string &identifier, const T value)
Set the value of a PDO which is mapped to a given identifier.
virtual void setDefaultPDOMapping(const eDefaultPDOMapping mapping)
Choose one of the predefined default mappings. Please see the enum eDefaultPDOMapping for a list of a...
std::string operationModeString(const eModeOfOperation mode)
If something goes wrong with the host's CAN controller, this exception will be used.
virtual void onStatusWordUpdate()
This will be called when a new statusword PDO comes in. If the device's state differs from the one ex...
virtual void printStatus()
Prints a stringified version of the statusword to the logging system.
uint32_t profile_torque_mode
virtual void configureHomingMethod(const int8_t homing_method)
Set the device's homing method through an SDO (OD 0x6098)
#define LOGGING_WARNING(streamname, arg)
bool upload(const bool normal_transfer, const uint16_t index, const uint8_t subindex, std::vector< uint8_t > &uploaded_data)
Uploads data from a slave (node) to a master (PC).
uint16_t operation_mode_specific_1
bool setTPDOValue(const std::string &identifier, const T value)
Set the value of a PDO which is mapped to a given identifier.
virtual void stopNode()
This redefines the basic stopNode function.
Configuration parameters for a Profile_Torque_Mode according to CiA DSP-402 V1.1 section 17...
void configureTorqueProfileType(const int16_t torque_profile_type)
Set the device's torque profile type through an SDO (OD 0x6088)
uint16_t operation_mode_specific_0
float profile_velocity
Final velocity.
uint16_t operation_mode_specific_1
uint32_t interpolated_position_mode
virtual void acceptPPTargets()
After enabling PP movement, this enables accepting new targets again. Remember to sync all nodes and ...
uint32_t homing_speed_high
std::string binaryString(const uint64_t num)
EMCY::Ptr m_emcy
EMCY object to handle spontaneous callbacks with emergency messages.
virtual void setupHomingMode(const ds402::HomingModeConfiguration &config)
Configure the mandatory parameters for a homing mode.
void configureProfileDeceleration(const uint32_t deceleration)
Set the device's profile deceleration through an SDO (OD 0x6084)
eState
DS402 states as described in Figure 6.3 in ELMO DS402 implementation guide V1.000.
virtual void setupProfileVelocityMode(const ds402::ProfileVelocityModeConfiguration &config)
Configure the mandatory parameters for a profile velocity mode.
virtual const char * what() const _GLIBCXX_USE_NOEXCEPT
void start()
start Starts the device by setting the NMT state to operational
virtual bool setModeOfOperation(const ds402::eModeOfOperation op_mode)
Sets and initializes a mode of operation. First it will check whether the device supports the request...
virtual void quickStop()
This sends the controlword for performing a quick_stop.
ds402::eModeOfOperation m_op_mode
The mode of operation of this device.
virtual void setNMTState(const NMT::eNMT_State state, const NMT::eNMT_SubState sub_state)
bool change_set_immediately
If this is set to true the device will not ramp down at a setpoint if a following one is given...
data union for access to DSP 402 6040 controlword,
uint32_t profile_position_mode
eNMT_State
The NMT state indicates the behavior of the communication of a device, everything else is device spec...
size_t m_max_number_of_state_transitions
uint16_t operation_mode_specific_2
void configureMaxAcceleration(const uint32_t acceleration)
Set the device's maximum acceleration through an SDO (OD 0x60c5)
virtual ds402::Statusword getStatus()
Mapping of a PDO. This is basically a description that says where to look in the object dictionary an...
ds402::eState m_expected_ds402_state
float profile_deceleration
This will be used for both acceleration ramps.
#define LOGGING_ERROR_C(streamname, classname, arg)
virtual void setupProfilePositionMode(const ds402::ProfilePositionModeConfiguration &config)
Configure the mandatory parameters for a profile position mode.
Class that holds devices according to the DS402 (drives and motion control) specification.
uint16_t enable_operation
virtual double getTargetFeedback()
Depending on the mode of operation, this will return the current position, velocity or torque...
The DS301Node class Is the base class representation of canOpen devices. It is the access point to th...
ds402::eState m_current_ds402_state
int16_t sensor_selection_code
virtual bool setTarget(const float target)
Sets the target for the motor. What that target is, depends on the selected mode of operation...
NMT m_nmt
Object to handle NMT calls and status.
int usleep(unsigned long useconds)
void registerPDONotifyCallback(const std::string &identifier, const boost::function< void()> &f)
This function maps a callback to a specific mapped PDO entry. This callback will be called by the PDO...
Configuration parameters for a Homing_Mode according to CiA DSP-402 V1.1 section 13.2.1.