SchunkPowerBallNode.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 // -- BEGIN LICENSE BLOCK ----------------------------------------------
3 // This file is part of the SCHUNK Canopen Driver suite.
4 //
5 // This program is free software licensed under the LGPL
6 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
7 // You can find a copy of this license in LICENSE folder in the top
8 // directory of the source code.
9 //
10 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 // -- END LICENSE BLOCK ------------------------------------------------
13 //----------------------------------------------------------------------
20 //----------------------------------------------------------------------
21 
22 #include "SchunkPowerBallNode.h"
23 
24 #include "sync.h"
25 
26 #include "Logging.h"
27 #include "exceptions.h"
28 
29 namespace icl_hardware {
30 namespace canopen_schunk {
31 
32 int boolify( int v )
33 {
34  return (v!=0);
35 }
36 
37 SchunkPowerBallNode::SchunkPowerBallNode (const uint8_t node_id, const CanDevPtr& can_device, HeartBeatMonitor::Ptr heartbeat_monitor)
38  : DS402Node(node_id, can_device, heartbeat_monitor)
39 {
40  m_homing_method = 33;
42 }
43 
45 {
47  m_nmt.start();
50 }
51 
53 {
54  PDO::MappingConfigurationList rpdo_mappings;
55  PDO::MappingConfigurationList tpdo_mappings;
56  switch (mapping)
57  {
59  {
60  // Map control and status word to the first PDO (receive and transmit respectively)
61  rpdo_mappings.push_back(PDO::MappingConfiguration(0x6040, 0, 16, "control_word"));
62  tpdo_mappings.push_back(PDO::MappingConfiguration(0x6041, 0, 16, "status_word"));
65  break;
66  }
68  {
69  // Map control and status word to the first PDO (receive and transmit respectively)
70  rpdo_mappings.push_back(PDO::MappingConfiguration(0x6040, 0, 16, "control_word"));
71  rpdo_mappings.push_back(PDO::MappingConfiguration(0x60B2, 0, 16, "torque_offset"));
72  rpdo_mappings.push_back(PDO::MappingConfiguration(0x60C1, 1, 32, "interpolation_buffer"));
73 
74  tpdo_mappings.push_back(PDO::MappingConfiguration(0x6041, 0, 16, "status_word"));
75  tpdo_mappings.push_back(PDO::MappingConfiguration(0x6077, 0, 16, "measured_torque"));
76  tpdo_mappings.push_back(PDO::MappingConfiguration(0x6064, 0, 32, "measured_position"));
77 
80  break;
81  }
83  {
84  // We map the interpolated position buffer as well, as it is needed for commutation
85  rpdo_mappings.push_back(PDO::MappingConfiguration(0x6040, 0, 16, "control_word"));
86  rpdo_mappings.push_back(PDO::MappingConfiguration(0x60B2, 0, 16, "torque_offset"));
87  rpdo_mappings.push_back(PDO::MappingConfiguration(0x60C1, 1, 32, "interpolation_buffer"));
88 
89  tpdo_mappings.push_back(PDO::MappingConfiguration(0x6041, 0, 16, "status_word"));
90  tpdo_mappings.push_back(PDO::MappingConfiguration(0x6077, 0, 16, "measured_torque"));
91  tpdo_mappings.push_back(PDO::MappingConfiguration(0x6064, 0, 32, "measured_position"));
92 
95 
96  rpdo_mappings.clear();
97  rpdo_mappings.push_back(PDO::MappingConfiguration(0x607A, 0, 32, "target_position"));
99  break;
100  }
101  default:
102  {
103  break;
104  }
105  }
106 }
107 
108 
110 {
111  LOGGING_INFO (CanOpen, "Commutation search for node " << m_node_id << endl);
112 
113  bool calib_ok = CommutationCalibrated();
114 
115  // copy current position into the PDO buffer, as this will be read by the enable function
116  int32_t current_position = 0;
117  m_sdo.upload(false, 0x6064, 0x0, current_position);
118  setTPDOValue("measured_position", current_position);
119  LOGGING_INFO(CanOpen, "Initially, node is at position " << current_position << endl);
120 
121  // I'm not entirely sure why I need that, but I get an RPDO timeout error if I remove this
122 
124  bool disable_again = false;
125 
127  if (!calib_ok)
128  {
130  disable_again = true;
131  LOGGING_INFO (CanOpen, "Activated commutation search for node " << m_node_id << endl);
132  // Make sure, the node is in interpolated position mode and enabled
133  }
134 
135  size_t counter = 50;
136 
137  // Try commutation search for counter times
138  while (!calib_ok && counter--)
139  {
140  usleep(100000); // sleep for 100 ms
141  downloadPDOs();
143  uploadPDOs();
144  calib_ok = CommutationCalibrated();
145  }
146  if(!calib_ok)
147  {
148  LOGGING_ERROR (CanOpen, "Commutation of node "<< (int)(m_node_id) << " could not be ensured after 50 tries! Aborting... You probably should do a recalibration!" << endl);
149  }
150  else
151  {
152  if (disable_again)
153  {
154  disableNode();
155  }
156  LOGGING_INFO (CanOpen, "Commutation search for node " << m_node_id << " was successful!" << endl);
157  }
158 
159 
160  #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
161  if (m_ws_broadcaster)
162  {
163  m_ws_broadcaster->robot->setJointHomed(calib_ok, m_node_id);
164  m_ws_broadcaster->robot->setInputToRadFactor(1.0 / RAD_TO_STEPS_FACTOR);
165  }
166  #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
167 
168 }
169 
170 
172 {
173  uint8_t commutation_status;
174 
175  bool commutation_search_completed = true;
176 
177  // - Bit 0 (Bit-Maske 0x01) mit der Bedeutung "commutation_search_completed"
178  // - Bit 1 (Bit-Maske 0x02) mit der Bedeutung "pseudo_absolute_position_verified"
179  m_sdo.upload(false, 0x2050, 0, commutation_status);
180 // LOGGING_INFO(CanOpen, "Commutation status: " << hexToString(commutation_status) << endl);
181  commutation_search_completed = commutation_status & (1 << 0);
182 
183  return commutation_search_completed;
184 }
185 
186 
187 
189 {
190  LOGGING_ERROR (CanOpen, "configureHomingMethod called for a Schunk powerball node (id " <<
191  m_node_id << "). " <<
192  "However, the powerballs only support one homing mode so this request will be ignored." << endl
193  );
194 }
195 
196 void SchunkPowerBallNode::configureHomingSpeeds (const uint32_t low_speed, const uint32_t high_speed)
197 {
198  LOGGING_ERROR (CanOpen, "configureHomingSpeeds called for a Schunk powerball node (id " <<
199  m_node_id << "). " <<
200  "However, the powerballs do not allow that, so this request will be ignored." << endl
201  );
202 }
203 
205  const int16_t interpolation_type,
206  const uint8_t size_of_data_record)
207 {
208  DS402Node::configureInterpolationData (buffer_organization, interpolation_type, size_of_data_record);
209 
210  LOGGING_DEBUG (CanOpen, "Initializing interpolation data for Schunk power ball node with id " << m_node_id << endl);
211 
212  // Number of cycles that can be missed by the interpolator. If for more than this number of cycles
213  // no new interpolation data is sent, the node will go into quick stop.
214  // For hard realtime security use a value of 1 here.
215  // Due to still existing state machine issues, we leave this higher here, which seems reasonable
216  // as long as we're doing position control only.
217  int8_t data8 = 100;
218  m_sdo.download(false, 0x200e, 0, data8);
219 }
220 
221 
222 }} // end of NS
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.
Definition: DS402Node.cpp:952
signed int int32_t
unsigned int uint32_t
bool CommutationCalibrated()
Checks if the device is already correctly commutated by checking the value of the relevant register e...
CanDevPtr m_can_dev
Device handle for transmission of messages.
Definition: DS301Node.h:318
virtual void initNode()
Initializes the node and sets the Schunk Default PDO mapping.
void commutationSearch()
Performs a commutation search for a Schunk powerball module.
std::vector< MappingConfiguration > MappingConfigurationList
The MappingConfigurationList holds multiple Mapping configurations. The Mapping of a single PDO is de...
Definition: PDO.h:70
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.
Definition: DS301Node.cpp:66
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...
Definition: DS402Node.cpp:1049
virtual void initNode()
Initializes the node. Tries to query all required data from the device.
Definition: DS402Node.cpp:639
#define LOGGING_INFO(streamname, arg)
SDO m_sdo
SDO object for specific calls.
Definition: DS301Node.h:305
signed char int8_t
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...
Definition: DS301Node.h:331
#define LOGGING_DEBUG(streamname, arg)
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).
Definition: SDO.cpp:84
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...
Definition: DS402Node.cpp:302
virtual void configureInterpolationData(const uint8_t buffer_organization=0, const int16_t interpolation_type=0, const uint8_t size_of_data_record=4)
Additionally to the basis implementation this sets a number of cycles that are allowed to be missed b...
SchunkPowerBallNode(const uint8_t node_id, const icl_hardware::canopen_schunk::CanDevPtr &can_device, HeartBeatMonitor::Ptr heartbeat_monitor)
static void sendSync(const CanDevPtr &can_device)
sendSync sends a SYNC message which is used to ensure synchronous processing of all CanOpen nodes...
Definition: sync.h:41
#define LOGGING_ERROR(streamname, arg)
uint8_t m_node_id
CANOPEN ID of the node.
Definition: DS301Node.h:315
virtual void setDefaultPDOMapping(const DS402Node::eDefaultPDOMapping mapping)
Choose one of the predefined default mappings. Please see the enum eDefaultPDOMapping for a list of a...
unsigned char uint8_t
ThreadStream & endl(ThreadStream &stream)
virtual void disableNode()
Puts the device into STATE_SWITCHED_ON mode. If the device was in InterpolatedPositionMode, interpolation will be stopped here, as well.
Definition: DS402Node.cpp:1069
virtual void configureHomingMethod(const uint8_t homing_method)
Set the device&#39;s homing method for a Schunk PowerBall.
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).
Definition: SDO.cpp:209
bool setTPDOValue(const std::string &identifier, const T value)
Set the value of a PDO which is mapped to a given identifier.
Definition: DS301Node.h:246
virtual void configureHomingSpeeds(const uint32_t low_speed, const uint32_t high_speed=0)
Set the speeds for homing for a Schunk PowerBall.
void downloadPDOs()
Downloads all Receive-PDOs of this node to the device.
Definition: DS301Node.cpp:162
signed short int16_t
void start()
start Starts the device by setting the NMT state to operational
Definition: NMT.cpp:91
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...
Definition: DS402Node.cpp:709
void uploadPDOs()
Uploads all Transmit-PDOs of this node from the device.
Definition: DS301Node.cpp:154
Mapping of a PDO. This is basically a description that says where to look in the object dictionary an...
Definition: PDO.h:53
Class that holds devices according to the DS402 (drives and motion control) specification.
Definition: DS402Node.h:43
static const double RAD_TO_STEPS_FACTOR
This factor will be used to convert RAD numbers into encoder ticks.
NMT m_nmt
Object to handle NMT calls and status.
Definition: DS301Node.h:303
int usleep(unsigned long useconds)


schunk_canopen_driver
Author(s): Felix Mauch , Georg Heppner
autogenerated on Mon Jun 10 2019 15:07:49