DS402Group.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of the SCHUNK Canopen Driver suite.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 SCHUNK GmbH, Lauffen/Neckar Germany
12 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
23 //----------------------------------------------------------------------
24 
25 #include "DS402Group.h"
26 
27 namespace icl_hardware {
28 namespace canopen_schunk {
29 
30 DS402Group::DS402Group(const std::string& name)
31  : DS301Group(name)
32 {
33 }
34 
35 void DS402Group::initNodes(const int16_t node_id)
36 {
37  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
38  it != m_ds402_nodes.end();
39  ++it)
40  {
41  DS402Node::Ptr node = *it;
42  if (node->getNodeId() == node_id || node_id < 0)
43  {
44  node->initNode();
45  }
46  }
47 }
48 
49 
50 void DS402Group::printStatus(const int16_t node_id)
51 {
52  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
53  it != m_ds402_nodes.end();
54  ++it)
55  {
56  DS402Node::Ptr node = *it;
57  if (node->getNodeId() == node_id || node_id < 0)
58  {
59  node->printStatus();
60  }
61  }
62 }
63 
64 bool DS402Group::setTarget (const float target, const uint8_t node_id)
65 {
66  bool successful = false;
67  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
68  it != m_ds402_nodes.end();
69  ++it)
70  {
71  DS402Node::Ptr node = *it;
72  if (node->getNodeId() == node_id)
73  {
74  successful = node->setTarget(target);
75  }
76  }
77 
78  return successful;
79 }
80 
81 bool DS402Group::setTarget (const std::vector< float >& targets)
82 {
83  bool all_successful = true;
84  size_t i = 0;
85  if (targets.size() != m_ds402_nodes.size())
86  {
87  LOGGING_ERROR (CanOpen, "The given number of target points (" << targets.size() <<
88  ") does not match the " <<
89  "number of nodes registered to this group (" << m_ds402_nodes.size() << ")." << endl
90  );
91  return false;
92  }
93 
94  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
95  it != m_ds402_nodes.end();
96  ++it)
97  {
98  DS402Node::Ptr node = *it;
99  all_successful &= node->setTarget(targets[i]);
100  ++i;
101  }
102 
103  return all_successful;
104 }
105 
107 {
108  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
109  it != m_ds402_nodes.end();
110  ++it)
111  {
112  DS402Node::Ptr node = *it;
113  if (node->getNodeId() == node_id || node_id < 0)
114  {
115  node->startPPMovement();
116  }
117  }
118 }
119 
121 {
122  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
123  it != m_ds402_nodes.end();
124  ++it)
125  {
126  DS402Node::Ptr node = *it;
127  if (node->getNodeId() == node_id || node_id < 0)
128  {
129  node->acceptPPTargets();
130  }
131  }
132 }
133 
134 void DS402Group::getTargetFeedback (std::vector< double >& feedback)
135 {
136  feedback.resize(m_ds402_nodes.size());
137  size_t i = 0;
138  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
139  it != m_ds402_nodes.end();
140  ++it)
141  {
142  DS402Node::Ptr node = *it;
143  feedback[i] = node->getTargetFeedback();
144  ++i;
145  }
146 }
147 
149 {
150  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
151  it != m_ds402_nodes.end();
152  ++it)
153  {
154  DS402Node::Ptr node = *it;
155  if (node->getNodeId() == node_id || node_id < 0)
156  {
157  node->setDefaultPDOMapping(mapping);
158  }
159  }
160 }
161 
162 void DS402Group::home (const int16_t node_id)
163 {
164  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
165  it != m_ds402_nodes.end();
166  ++it)
167  {
168  DS402Node::Ptr node = *it;
169  if (node->getNodeId() == node_id || node_id < 0)
170  {
171  node->home();
172  }
173  }
174 }
175 
176 void DS402Group::getModeOfOperation (std::vector< ds402::eModeOfOperation >& modes)
177 {
178  modes.resize(m_ds402_nodes.size());
179  size_t i = 0;
180  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
181  it != m_ds402_nodes.end();
182  ++it)
183  {
184  DS402Node::Ptr node = *it;
185  modes[i] = node->getModeOfOperation();
186  ++i;
187  }
188 }
189 
191 {
192  bool all_successful = true;
193  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
194  it != m_ds402_nodes.end();
195  ++it)
196  {
197  DS402Node::Ptr node = *it;
198  if (node->getNodeId() == node_id || node_id < 0)
199  {
200  all_successful &= node->setModeOfOperation(op_mode);
201  }
202  }
203 
204  return all_successful;
205 }
206 
208 {
209  bool supported_by_all = true;
210  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
211  it != m_ds402_nodes.end();
212  ++it)
213  {
214  DS402Node::Ptr node = *it;
215  if (node->getNodeId() == node_id || node_id < 0)
216  {
217  supported_by_all &= node->isModeSupported(op_mode);
218  }
219  }
220 
221  return supported_by_all;
222 }
223 
224 void DS402Group::quickStop (const int16_t node_id)
225 {
226  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
227  it != m_ds402_nodes.end();
228  ++it)
229  {
230  DS402Node::Ptr node = *it;
231  if (node->getNodeId() == node_id || node_id < 0)
232  {
233  node->quickStop();
234  #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
235  if (m_ws_broadcaster)
236  {
237  m_ws_broadcaster->robot->setJointEnabled(false, node->getNodeId());
238  }
239  #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
240  }
241  }
242 }
243 
244 
245 
247 {
248  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
249  it != m_ds402_nodes.end();
250  ++it)
251  {
252  DS402Node::Ptr node = *it;
253  if (node->getNodeId() == node_id || node_id < 0)
254  {
255  node->setupProfilePositionMode(config);
256  }
257  }
258 }
259 
261 {
262  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
263  it != m_ds402_nodes.end();
264  ++it)
265  {
266  DS402Node::Ptr node = *it;
267  if (node->getNodeId() == node_id || node_id < 0)
268  {
269  node->setupHomingMode(config);
270  }
271  }
272 }
273 
275 {
276  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
277  it != m_ds402_nodes.end();
278  ++it)
279  {
280  DS402Node::Ptr node = *it;
281  if (node->getNodeId() == node_id || node_id < 0)
282  {
283  node->setupProfileVelocityMode(config);
284  }
285  }
286 }
287 
289 {
290  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
291  it != m_ds402_nodes.end();
292  ++it)
293  {
294  DS402Node::Ptr node = *it;
295  if (node->getNodeId() == node_id || node_id < 0)
296  {
297  node->setupProfileTorqueMode(config);
298  }
299  }
300 }
301 
302 bool DS402Group::resetFault (const int16_t node_id)
303 {
304  bool all_successful = true;
305  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
306  it != m_ds402_nodes.end();
307  ++it)
308  {
309  DS402Node::Ptr node = *it;
310  if (node->getNodeId() == node_id || node_id < 0)
311  {
312  all_successful &= node->resetFault();
313  }
314  }
315 
316  return all_successful;
317 }
318 
319 void DS402Group::configureInterpolationCycleTime (const int16_t node_id, const uint8_t interpolation_cycle_time_ms)
320 {
321  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
322  it != m_ds402_nodes.end();
323  ++it)
324  {
325  DS402Node::Ptr node = *it;
326  if (node->getNodeId() == node_id || node_id < 0)
327  {
328  node->configureInterpolationCycleTime(interpolation_cycle_time_ms);
329  }
330  }
331 }
332 
333 void DS402Group::configureHomingSpeeds (const uint32_t low_speed, const uint32_t high_speed, const int16_t node_id)
334 {
335  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
336  it != m_ds402_nodes.end();
337  ++it)
338  {
339  DS402Node::Ptr node = *it;
340  if (node->getNodeId() == node_id || node_id < 0)
341  {
342  node->configureHomingSpeeds(low_speed, high_speed);
343  }
344  }
345 }
346 
347 void DS402Group::configureHomingMethod (const int8_t homing_method, const int16_t node_id)
348 {
349  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
350  it != m_ds402_nodes.end();
351  ++it)
352  {
353  DS402Node::Ptr node = *it;
354  if (node->getNodeId() == node_id || node_id < 0)
355  {
356  node->configureHomingSpeeds(homing_method);
357  }
358  }
359 }
360 
361 void DS402Group::enableNodes (const ds402::eModeOfOperation operation_mode, const int16_t node_id)
362 {
363  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
364  it != m_ds402_nodes.end();
365  ++it)
366  {
367  DS402Node::Ptr node = *it;
368  if (node->getNodeId() == node_id || node_id < 0)
369  {
370  node->enableNode(operation_mode);
371 
372  #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
373  if (m_ws_broadcaster)
374  {
375  m_ws_broadcaster->robot->setJointEnabled(true, node->getNodeId());
376  }
377  #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
378 
379  }
380  }
381 }
382 
383 void DS402Group::disableNodes (const int16_t node_id)
384 {
385  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
386  it != m_ds402_nodes.end();
387  ++it)
388  {
389  DS402Node::Ptr node = *it;
390  if (node->getNodeId() == node_id || node_id < 0)
391  {
392  node->disableNode();
393 
394  #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
395  if (m_ws_broadcaster)
396  {
397  m_ws_broadcaster->robot->setJointEnabled(false, node->getNodeId());
398  }
399  #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
400  }
401  }
402 }
403 
404 void DS402Group::openBrakes (const int16_t node_id)
405 {
406  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
407  it != m_ds402_nodes.end();
408  ++it)
409  {
410  DS402Node::Ptr node = *it;
411  if (node->getNodeId() == node_id || node_id < 0)
412  {
413  node->openBrakes();
414  #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
415  if (m_ws_broadcaster)
416  {
417  m_ws_broadcaster->robot->setJointEnabled(true, node->getNodeId());
418  }
419  #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
420  }
421  }
422 }
423 
424 void DS402Group::closeBrakes (const int16_t node_id)
425 {
426  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
427  it != m_ds402_nodes.end();
428  ++it)
429  {
430  DS402Node::Ptr node = *it;
431  if (node->getNodeId() == node_id || node_id < 0)
432  {
433  node->closeBrakes();
434  #ifdef _IC_BUILDER_ICL_COMM_WEBSOCKET_
435  if (m_ws_broadcaster)
436  {
437  m_ws_broadcaster->robot->setJointEnabled(false, node->getNodeId());
438  }
439  #endif // _IC_BUILDER_ICL_COMM_WEBSOCKET_
440  }
441  }
442 }
443 
444 bool DS402Group::isTargetReached (std::vector< bool >& reached_single)
445 {
446  reached_single.resize(m_ds402_nodes.size());
447  bool reached_all = true;
448  size_t i = 0;
449  for (std::vector<DS402Node::Ptr>::iterator it = m_ds402_nodes.begin();
450  it != m_ds402_nodes.end();
451  ++it)
452  {
453  DS402Node::Ptr node = *it;
454  reached_single[i] = node->isTargetReached();
455  reached_all &= reached_single[i];
456  ++i;
457  }
458 
459  return reached_all;
460 }
461 
462 
463 
464 
465 
466 }} // end of NS
std::vector< DS402Node::Ptr > m_ds402_nodes
Definition: DS402Group.h:326
unsigned int uint32_t
virtual void configureHomingSpeeds(const uint32_t low_speed, const uint32_t high_speed=0, const int16_t node_id=-1)
Set the speeds for homing through SDO 6099. Typically, a high speed is used when searching for a home...
Definition: DS402Group.cpp:333
virtual void setDefaultPDOMapping(const DS402Node::eDefaultPDOMapping mapping, const int16_t node_id=-1)
Choose one of the predefined default mappings. Please see the enum eDefaultPDOMapping for a list of a...
Definition: DS402Group.cpp:148
Configuration parameters for a Profile_Position_Mode according to CiA DSP-402 V1.1 section 12...
Definition: ds402.h:169
virtual void setupHomingMode(const ds402::HomingModeConfiguration &config, const int16_t node_id=-1)
Configure the mandatory parameters for a homing mode.
Definition: DS402Group.cpp:260
signed char int8_t
virtual void getTargetFeedback(std::vector< double > &feedback)
Depending on the mode of operation, this will return the current position, velocity or torque...
Definition: DS402Group.cpp:134
Configuration parameters for a Profile_Velocity_Mode according to CiA DSP-402 V1.1 section 16...
Definition: ds402.h:246
virtual bool setTarget(const std::vector< float > &targets)
Sets the target for the motor. What that target is, depends on the selected mode of operation...
Definition: DS402Group.cpp:81
virtual void getModeOfOperation(std::vector< ds402::eModeOfOperation > &modes)
Gets a vector of the Mode of operation of all nodes within this group.
Definition: DS402Group.cpp:176
The DS301Group class is the base Class for all canOpen device groups, providing basic interfaces to t...
Definition: DS301Group.h:41
virtual void openBrakes(const int16_t node_id=-1)
When the device is in OperationEnabled mode, this function enables the drive motion.
Definition: DS402Group.cpp:404
virtual bool isModeSupported(const ds402::eModeOfOperation op_mode, const int16_t node_id=-1)
Tests whether a given mode of operation is supported by the device.
Definition: DS402Group.cpp:207
#define LOGGING_ERROR(streamname, arg)
virtual void startPPMovement(const int16_t node_id=-1)
This sets the RPDO communication for enabling the movement after a target has been set...
Definition: DS402Group.cpp:106
unsigned char uint8_t
virtual void printStatus(const int16_t node_id=-1)
Prints a stringified version of the statusword to the logging system.
Definition: DS402Group.cpp:50
virtual void enableNodes(const ds402::eModeOfOperation operation_mode=ds402::MOO_RESERVED_0, const int16_t node_id=-1)
Switches on the device and enters Operation Enabled mode with the given mode. If the requested mode i...
Definition: DS402Group.cpp:361
ThreadStream & endl(ThreadStream &stream)
virtual void setupProfilePositionMode(const ds402::ProfilePositionModeConfiguration &config, const int16_t node_id=-1)
Configure the mandatory parameters for a profile position mode.
Definition: DS402Group.cpp:246
virtual bool resetFault(const int16_t node_id=-1)
This function is used to recover from a fault state.
Definition: DS402Group.cpp:302
virtual void acceptPPTargets(const int16_t node_id=-1)
After enabling PP movement, this enables accepting new targets again. Remember to sync all nodes and ...
Definition: DS402Group.cpp:120
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: DS301Group.h:168
virtual void setupProfileVelocityMode(const ds402::ProfileVelocityModeConfiguration &config, const int16_t node_id=-1)
Configure the mandatory parameters for a profile velocity mode.
Definition: DS402Group.cpp:274
virtual void initNodes(const int16_t node_id=-1)
Initializes the node. Tries to query all required data from the device.
Definition: DS402Group.cpp:35
virtual void home(const int16_t node_id=-1)
Perform homing for nodes.
Definition: DS402Group.cpp:162
virtual bool isTargetReached(std::vector< bool > &reached_single)
Returns whether the device has reached it&#39;s recent target.
Definition: DS402Group.cpp:444
virtual bool setModeOfOperation(const ds402::eModeOfOperation op_mode, const int16_t node_id=-1)
Sets and initializes a mode of operation. First it will check whether the device supports the request...
Definition: DS402Group.cpp:190
Configuration parameters for a Profile_Torque_Mode according to CiA DSP-402 V1.1 section 17...
Definition: ds402.h:261
virtual void setupProfileTorqueMode(const ds402::ProfileTorqueModeConfiguration &config, const int16_t node_id=-1)
Configure the mandatory parameters for a profile torque mode.
Definition: DS402Group.cpp:288
signed short int16_t
virtual void closeBrakes(const int16_t node_id=-1)
When the device is in OperationEnabled mode, this function disables the drive motion.
Definition: DS402Group.cpp:424
virtual void quickStop(const int16_t node_id=-1)
This sends the controlword for performing a quick_stop.
Definition: DS402Group.cpp:224
virtual void configureInterpolationCycleTime(const int16_t node_id=-1, const uint8_t interpolation_cycle_time_ms=20)
Set the interpolation cycle time in milliseconds. If no time is given the default will be used...
Definition: DS402Group.cpp:319
virtual void configureHomingMethod(const int8_t homing_method, const int16_t node_id=-1)
Set the device&#39;s homing method through an SDO (OD 0x6098)
Definition: DS402Group.cpp:347
virtual void disableNodes(const int16_t node_id=-1)
Puts the device into STATE_SWITCHED_ON mode. If the device was in InterpolatedPositionMode, interpolation will be stopped here, as well.
Definition: DS402Group.cpp:383
DS402Group(const std::string &name="")
Definition: DS402Group.cpp:30
Configuration parameters for a Homing_Mode according to CiA DSP-402 V1.1 section 13.2.1.
Definition: ds402.h:229


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