SVHController.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 SVH 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 2014 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
12 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
13 //
14 // -- END LICENSE BLOCK ------------------------------------------------
15 
16 //----------------------------------------------------------------------
38 //----------------------------------------------------------------------
40 
41 #include <driver_svh/Logging.h>
42 #include <icl_comm/ByteOrderConversion.h>
43 #include <boost/bind/bind.hpp>
44 
45 using icl_comm::ArrayBuilder;
46 
47 namespace driver_svh {
48 
49 
52  "Thumb_Flexion",
53  "Thumb_Opposition", // wrist
54  "Index_Finger_Distal",
55  "Index_Finger_Proximal",
56  "Middle_Finger_Distal",
57  "Middle_Finger_Proximal",
58  "Ring_Finger",
59  "Pinky",
60  "Finger_Spread",
61  NULL
62 };
63 
66  0.0000232, //Thumb Flexion
67  0.0000232, // Thumb Opposition
68  0.000009, // Index Finger Distal
69  0.000016, // Index Finger Proximal
70  0.000009, // Middle Finger Distal
71  0.000016, // Middle Finger Proximal
72  0.000009, // Ring Finger
73  0.000009, // Pinky
74  0.000016 // Finger Spread
75 };
76 
78  m_current_settings(eSVH_DIMENSION), // Vectors have to be filled with objects for correct deserialization
79  m_position_settings(eSVH_DIMENSION),
80  m_controller_feedback(eSVH_DIMENSION),
81  m_serial_interface(new SVHSerialInterface(boost::bind(&SVHController::receivedPacketCallback,this,_1,_2))),
82  m_enable_mask(0),
83  m_received_package_count(0)
84 {
85  LOGGING_TRACE_C(DriverSVH, SVHController, "SVH Controller started"<< endl);
86 }
87 
89 {
90  if (m_serial_interface != NULL)
91  {
92  disconnect();
93  delete m_serial_interface;
94  m_serial_interface = NULL;
95  }
96 
97  LOGGING_DEBUG_C(DriverSVH, SVHController, "SVH Controller terminated" << endl);
98 }
99 
100 bool SVHController::connect(const std::string &dev_name)
101 {
102  LOGGING_DEBUG_C(DriverSVH, SVHController, "Connect was called, starting the serial interface..." << endl);
103  if (m_serial_interface != NULL)
104  {
105  bool success = m_serial_interface->connect(dev_name);
106  LOGGING_DEBUG_C(DriverSVH, SVHController, "Connect finished " << ((success)?"succesfully":"with an error") << endl);
107  return success ;
108  }
109  else
110  {
111  LOGGING_DEBUG_C(DriverSVH, SVHController, "Connect failed" << endl);
112  return false;
113  }
114 }
115 
117 {
118  LOGGING_TRACE_C(DriverSVH, SVHController, "Disconnect called, disabling all channels and closing interface..."<< endl);
120  {
121  // Disable all channels
124  }
125  LOGGING_TRACE_C(DriverSVH, SVHController, "Disconnect finished"<< endl);
126 }
127 
128 void SVHController::setControllerTarget(const SVHChannel& channel, const int32_t& position)
129 {
130  // No Sanity Checks for out of bounds positions at this point as the finger manager has already handled these
131  if ((channel != eSVH_ALL) && (channel >=0 && channel < eSVH_DIMENSION))
132  {
133  // The channel is encoded in the index byte
134  SVHSerialPacket serial_packet(0,SVH_SET_CONTROL_COMMAND|static_cast<uint8_t>(channel << 4));
135  SVHControlCommand control_command(position);
136  // Note the 40 byte ArrayBuilder initialization -> this is needed to get a zero padding in the serialpacket. Otherwise it would be shorter
137  ArrayBuilder ab(40);
138  ab << control_command;
139  serial_packet.data = ab.array;
140  m_serial_interface ->sendPacket(serial_packet);
141 
142  // Debug Disabled as it is way to noisy
143  //LOGGING_TRACE_C(DriverSVH, SVHController, "Control command was given for channel: "<< channel << "Driving motor to position: "<< position << endl);
144  }
145  else
146  {
147  LOGGING_WARNING_C(DriverSVH, SVHController, "Control command was given for unknown (or all) channel: "<< channel << "- ignoring request"<< endl);
148  }
149 }
150 
151 void SVHController::setControllerTargetAllChannels(const std::vector<int32_t> &positions)
152 {
153  if (positions.size() >= eSVH_DIMENSION)
154  {
156  SVHControlCommandAllChannels control_command(positions);
157  ArrayBuilder ab(40);
158  ab << control_command;
159  serial_packet.data = ab.array;
160  m_serial_interface ->sendPacket(serial_packet);
161 
162  // Debug Disabled as it is way to noisy
163  //LOGGING_TRACE_C(DriverSVH, SVHController, "Control command was given for all channels: Driving motors to positions: "<< positions[0] << " , " << positions[1] << " , " << positions[2] << " , " << positions[3] << " , " << positions[4] << " , " << positions[5] << " , " << positions[6] << " , " << positions[7] << " , " << positions[8] << " , " << endl);
164  }
165  // We could theoretically allow fewer channels but this leaves some questions. Are the given channels in right order?
166  // was it realy intented to just give fewer positions? What to do witht the ones that did not get anything?
167  // Just disallowing it seems to be the most understandable decission.
168  else
169  {
170  LOGGING_WARNING_C(DriverSVH, SVHController, "Control command was given for all channels but with to few points. Expected at least "<< eSVH_DIMENSION << " values but only got " << positions.size() << "use the individual setTarget function for this" << endl);
171  }
172 }
173 
175 {
176  SVHSerialPacket serial_packet(0,SVH_SET_CONTROLLER_STATE);
177  SVHControllerState controller_state;
178  ArrayBuilder ab(40);
179 
180  LOGGING_TRACE_C(DriverSVH, SVHController, "Enable of channel " << channel << " requested."<< endl);
181 
182  // In case no channel was enabled we need to enable the 12V dc drivers first
183  if (m_enable_mask == 0)
184  {
185  LOGGING_TRACE_C(DriverSVH, SVHController, "Enable was called and no channel was previously activated, commands are sent individually......" << endl);
186  LOGGING_TRACE_C(DriverSVH, SVHController, "Sending pwm_fault and pwm_otw...(0x001F) to reset software warnings" << endl);
187  // Reset faults and overtemperature warnings saved in the controller
188  controller_state.pwm_fault = 0x001F;
189  controller_state.pwm_otw = 0x001F;
190  ab << controller_state;
191  serial_packet.data = ab.array;
192  m_serial_interface ->sendPacket(serial_packet);
193  ab.reset(40);
194 
195  // Small delays seem to make communication at this point more reliable although they SHOULD NOT be necessary
196  icl_core::os::usleep(2000);
197 
198  LOGGING_TRACE_C(DriverSVH, SVHController, "Enabling 12V Driver (pwm_reset and pwm_active = =0x0200)..." << endl);
199  // enable +12v supply driver
200  controller_state.pwm_reset = 0x0200;
201  controller_state.pwm_active = 0x0200;
202  ab << controller_state;
203  serial_packet.data = ab.array;
204  m_serial_interface ->sendPacket(serial_packet);
205  ab.reset(40);
206 
207  icl_core::os::usleep(2000);
208 
209  LOGGING_TRACE_C(DriverSVH, SVHController, "Enabling pos_ctrl and cur_ctrl..." << endl);
210  // enable controller
211  controller_state.pos_ctrl = 0x0001;
212  controller_state.cur_ctrl = 0x0001;
213  ab << controller_state;
214  serial_packet.data = ab.array;
215  m_serial_interface ->sendPacket(serial_packet);
216  ab.reset(40);
217 
218  icl_core::os::usleep(2000);
219 
220  LOGGING_TRACE_C(DriverSVH, SVHController, "...Done" << endl);
221  }
222 
223  // enable actual channels (again we only accept individual channels for safety)
224  if (channel >=0 && channel < eSVH_DIMENSION)
225  {
226  LOGGING_TRACE_C(DriverSVH, SVHController, "Enabling motor: "<< channel << endl);
227  // oring all channels to create the activation mask-> high = channel active
228  m_enable_mask |= (1<<channel);
229 
230  // SENDING EVERYTHING AT ONCE WILL LEAD TO "Jumping" behaviour of the controller on faster Systems ---> this has to
231  // do with the initialization of the hardware controllers. If we split it in two calls we will reset them first and then activate
232  // making sure that all values are initialized properly effectively preventing any jumping behaviour
233  ab.reset(40);
234  controller_state.pwm_fault = 0x001F;
235  controller_state.pwm_otw = 0x001F;
236  controller_state.pwm_reset = (0x0200 | (m_enable_mask & 0x01FF));
237  controller_state.pwm_active =(0x0200 | (m_enable_mask & 0x01FF));
238  ab << controller_state;
239  serial_packet.data = ab.array;
240  m_serial_interface ->sendPacket(serial_packet);
241  ab.reset(40);
242 
243  // WARNING: DO NOT ! REMOVE THESE DELAYS OR THE HARDWARE WILL! FREAK OUT! (see reason above)
245 
246  controller_state.pos_ctrl = 0x0001;
247  controller_state.cur_ctrl = 0x0001;
248  ab << controller_state;
249  serial_packet.data = ab.array;
250  m_serial_interface ->sendPacket(serial_packet);
251  ab.reset(40);
252 
253  LOGGING_DEBUG_C(DriverSVH, SVHController, "Enabled channel: " << channel << endl);
254  }
255  else
256  {
257  LOGGING_ERROR_C(DriverSVH, SVHController, "Activation request for ALL or unknown channel: "<< channel << "- ignoring request"<< endl);
258  }
259 
260 }
261 
263 {
264  LOGGING_TRACE_C(DriverSVH, SVHController, "Disable of channel " << channel << " requested."<< endl);
265 
267  {
268  // prepare general packet
269  SVHSerialPacket serial_packet(0,SVH_SET_CONTROLLER_STATE);
270  SVHControllerState controller_state;
271  ArrayBuilder ab(40);
272 
273  // we just accept it at this point because it makes no difference in the calls
274  if (channel == eSVH_ALL)
275  {
276  m_enable_mask = 0;
277  controller_state.pwm_fault = 0x001F;
278  controller_state.pwm_otw = 0x001F;
279 
280  // default initialization to zero -> controllers are deactivated
281  ab << controller_state;
282  serial_packet.data = ab.array;
283  m_serial_interface->sendPacket(serial_packet);
284 
285  LOGGING_DEBUG_C(DriverSVH, SVHController, "Disabled all channels"<< endl);
286  }
287  else if (channel >=0 && channel < eSVH_DIMENSION)
288  {
289  controller_state.pwm_fault = 0x001F;
290  controller_state.pwm_otw = 0x001F;
291  //Disable the finger in the bitmask
292  m_enable_mask &= ~(1<<channel);
293 
294  if (m_enable_mask != 0) // pos and current control stay on then
295  {
296  controller_state.pwm_reset = (0x0200 | (m_enable_mask & 0x01FF));
297  controller_state.pwm_active = (0x0200 | (m_enable_mask & 0x01FF));
298  controller_state.pos_ctrl = 0x0001;
299  controller_state.cur_ctrl = 0x0001;
300  }
301 
302  ab << controller_state;
303  serial_packet.data = ab.array;
304  m_serial_interface->sendPacket(serial_packet);
305 
306  LOGGING_DEBUG_C(DriverSVH, SVHController, "Disabled channel: " << channel << endl);
307  }
308  else
309  {
310  LOGGING_WARNING_C(DriverSVH, SVHController, "Disable was requestet for unknown channel: "<< channel << "- ignoring request" << endl);
311  }
312  }
313  else
314  {
315  LOGGING_ERROR_C(DriverSVH, SVHController, "Disabling Channel not possible. Serial interface is not connected!" << endl);
316  }
317 }
318 
320 {
321  LOGGING_TRACE_C(DriverSVH, SVHController, "Requesting ControllerStatefrom Hardware"<< endl);
322  SVHSerialPacket serial_packet(40,SVH_GET_CONTROLLER_STATE);
323  m_serial_interface ->sendPacket(serial_packet);
324 }
325 
327 {
328  if ((channel != eSVH_ALL) && (channel >=0 && channel < eSVH_DIMENSION))
329  {
330  SVHSerialPacket serial_packet(40,SVH_GET_CONTROL_FEEDBACK|static_cast<uint8_t>(channel << 4));
331  m_serial_interface ->sendPacket(serial_packet);
332 
333  // Disabled as it spams the output to much
334  //LOGGING_TRACE_C(DriverSVH, SVHController, "Controller feedback was requested for channel: "<< channel << endl);
335 
336  }
337  else if (channel == eSVH_ALL)
338  {
340  m_serial_interface ->sendPacket(serial_packet);
341 
342  // Disabled as it spams the output to much
343  //LOGGING_TRACE_C(DriverSVH, SVHController, "Controller feedback was requested for all channels " << endl);
344  }
345  else
346  {
347  LOGGING_WARNING_C(DriverSVH, SVHController, "Controller feedback was requestet for unknown channel: "<< channel << "- ignoring request"<< endl);
348  }
349 }
350 
352 {
353  LOGGING_TRACE_C(DriverSVH, SVHController, "Requesting PositionSettings from Hardware for channel: " << channel << endl);
354  SVHSerialPacket serial_packet(40,(SVH_GET_POSITION_SETTINGS| static_cast<uint8_t>(channel << 4)));
355  m_serial_interface ->sendPacket(serial_packet);
356 }
357 
358 void SVHController::setPositionSettings(const SVHChannel& channel,const SVHPositionSettings& position_settings)
359 {
360  if ((channel != eSVH_ALL) && (channel >=0 && channel < eSVH_DIMENSION))
361  {
362  SVHSerialPacket serial_packet(0,SVH_SET_POSITION_SETTINGS|static_cast<uint8_t>(channel << 4));
363  ArrayBuilder ab;
364  ab << position_settings;
365  serial_packet.data = ab.array;
366  m_serial_interface ->sendPacket(serial_packet);
367 
368  // Save already in case we dont get immediate response
369  m_position_settings[channel] = position_settings;
370 
371  LOGGING_DEBUG_C(DriverSVH, SVHController, "Position controller settings where send to change channel: "<< channel << " : ");
372  LOGGING_DEBUG_C(DriverSVH, SVHController, "wmn " << position_settings.wmn << " " << "wmx " << position_settings.wmx << " " << "dwmx "<< position_settings.dwmx << " "
373  << "ky " << position_settings.ky << " " << "dt " << position_settings.dt << " " << "imn " << position_settings.imn << " "
374  << "imx " << position_settings.imx << " " << "kp " << position_settings.kp << " " << "ki " << position_settings.ki << " "
375  << "kd " << position_settings.kd << " " << endl );
376 
377  }
378  else
379  {
380  LOGGING_WARNING_C(DriverSVH, SVHController, "Position controller settings where given for unknown channel: "<< channel << "- ignoring request"<< endl);
381  }
382 }
383 
385 {
386  LOGGING_TRACE_C(DriverSVH, SVHController, "Requesting CurrentSettings for channel: " << channel << endl);
387 
388  if ((channel != eSVH_ALL) && (channel >=0 && channel < eSVH_DIMENSION))
389  {
390  SVHSerialPacket serial_packet(40,(SVH_GET_CURRENT_SETTINGS|static_cast<uint8_t>(channel << 4)));
391  m_serial_interface ->sendPacket(serial_packet);
392  }
393  else
394  {
395  LOGGING_WARNING_C(DriverSVH, SVHController, "Get Current Settings can only be requested with a specific channel, ALL or unknown channel:" << channel << "was selected " << endl);
396  }
397 }
398 
399 void SVHController::setCurrentSettings(const SVHChannel& channel,const SVHCurrentSettings& current_settings)
400 {
401  if ((channel != eSVH_ALL) && (channel >=0 && channel < eSVH_DIMENSION))
402  {
403  SVHSerialPacket serial_packet(0,SVH_SET_CURRENT_SETTINGS|static_cast<uint8_t>(channel << 4));
404  ArrayBuilder ab;
405  ab << current_settings;
406  serial_packet.data = ab.array;
407  m_serial_interface ->sendPacket(serial_packet);
408 
409  // Save already in case we dont get immediate response
410  m_current_settings[channel] = current_settings;
411 
412  LOGGING_DEBUG_C(DriverSVH, SVHController, "Current controller settings where send to change channel: "<< channel << " : ");
413  LOGGING_DEBUG_C(DriverSVH, SVHController, "wmn "<< current_settings.wmn << " " << "wmx "<< current_settings.wmx << " " << "ky " << current_settings.ky << " "
414  << "dt " << current_settings.dt << " " << "imn "<< current_settings.imn << " " << "imx "<< current_settings.imx << " "
415  << "kp " << current_settings.kp << " " << "ki " << current_settings.ki << " " << "umn "<< current_settings.umn << " "
416  << "umx "<< current_settings.umx << endl);
417 
418  }
419  else
420  {
421  LOGGING_WARNING_C(DriverSVH, SVHController, "Current controller settings where given for unknown channel: "<< channel << "- ignoring request"<< endl);
422  }
423 }
424 
426 {
427  LOGGING_TRACE_C(DriverSVH, SVHController, "Requesting EncoderValues from hardware"<< endl);
428  SVHSerialPacket serial_packet(40,SVH_GET_ENCODER_VALUES);
429  m_serial_interface ->sendPacket(serial_packet);
430 }
431 
433 {
434  LOGGING_TRACE_C(DriverSVH, SVHController, "Setting new Encoder values : ");
435  for (size_t i = 0; i < encoder_settings.scalings.size(); i++)
436  {
437  // log stream unfortunately does not support the standard to stream operators yet
438  LOGGING_TRACE_C(DriverSVH, SVHController, "[" << (int)i << "] " << ": " <<encoder_settings.scalings[i] << " " );
439  }
440  LOGGING_TRACE_C(DriverSVH, SVHController, endl);
441 
442  SVHSerialPacket serial_packet(0,SVH_SET_ENCODER_VALUES);
443  ArrayBuilder ab;
444  ab << encoder_settings;
445  serial_packet.data = ab.array;
446  m_serial_interface ->sendPacket(serial_packet);
447 
448  // Save already in case we dont get imediate response
449  m_encoder_settings = encoder_settings;
450 }
451 
453 {
454  LOGGING_TRACE_C(DriverSVH, SVHController, "Requesting firmware Information from hardware" << endl);
455 
456  SVHSerialPacket serial_packet(40,SVH_GET_FIRMWARE_INFO);
457  m_serial_interface->sendPacket(serial_packet);
458 }
459 
460 void SVHController::receivedPacketCallback(const SVHSerialPacket& packet, unsigned int packet_count)
461 {
462  // Extract Channel
463  uint8_t channel = (packet.address >> 4 ) & 0x0F;
464  // Prepare Data for conversion
465  ArrayBuilder ab;
466  ab.appendWithoutConversion(packet.data);
467 
469 
470  m_received_package_count = packet_count;
471 
472  // Packet meaning is encoded in the lower nibble of the adress byte
473  switch (packet.address & 0x0F)
474  {
477  if (channel >=0 && channel < eSVH_DIMENSION)
478  {
479  //std::cout << "Recieved: Controllerfeedback RAW Data: " << ab;
480  ab >> m_controller_feedback[channel];
481  // Disabled as this is spamming the output to much
482  //LOGGING_TRACE_C(DriverSVH, SVHController, "Received a Control Feedback/Control Command packet for channel "<< channel << " Position: "<< (int)m_controller_feedback[channel].position << " Current: "<< (int)m_controller_feedback[channel].current << endl);
483  }
484  else
485  {
486  LOGGING_ERROR_C(DriverSVH, SVHController, "Received a Control Feedback/Control Command packet for ILLEGAL channel "<< channel << "- packet ignored!" << endl);
487  }
488  break;
491  // We cannot just read them all into the vector (which would have been nice) because the feedback of all channels is structured
492  // different from the feedback of one channel. So the SVHControllerFeedbackAllChannels is used as an intermediary ( handles the deserialization)
493  ab >> feedback_all;
494  m_controller_feedback = feedback_all.feedbacks;
495  // Disabled as this is spannimg the output to much
496  //LOGGING_TRACE_C(DriverSVH, SVHController, "Received a Control Feedback/Control Command packet for channel all channels "<< endl);
497  break;
500  if (channel >=0 && channel < eSVH_DIMENSION)
501  {
502  //std::cout << "Recieved: Postitionsettings RAW Data: " << ab; // for really intensive debugging
503  ab >> m_position_settings[channel];
504  LOGGING_TRACE_C(DriverSVH, SVHController, "Received a get/set position setting packet for channel "<< channel << endl);
505  LOGGING_TRACE_C(DriverSVH, SVHController, "wmn " << m_position_settings[channel].wmn << " "<< "wmx " << m_position_settings[channel].wmx << " "<< "dwmx "<< m_position_settings[channel].dwmx << " "<< "ky " << m_position_settings[channel].ky << " "<< "dt " << m_position_settings[channel].dt << " "<< "imn " << m_position_settings[channel].imn << " "<< "imx " << m_position_settings[channel].imx << " " << "kp " << m_position_settings[channel].kp << " " << "ki " << m_position_settings[channel].ki << " " << "kd " << m_position_settings[channel].kd << endl);
506 
507  }
508  else
509  {
510  LOGGING_ERROR_C(DriverSVH, SVHController, "Received a get/set position setting packet for ILLEGAL channel "<< channel << "- packet ignored!" << endl);
511  }
512  break;
515  if (channel >=0 && channel < eSVH_DIMENSION)
516  {
517  //std::cout << "Recieved: Current Settings RAW Data: " << ab; // for really intensive debugging
518  ab >> m_current_settings[channel];
519  LOGGING_TRACE_C(DriverSVH, SVHController, "Received a get/set current setting packet for channel "<< channel << endl);
520  LOGGING_TRACE_C(DriverSVH, SVHController, "wmn "<< m_current_settings[channel].wmn << " " << "wmx "<< m_current_settings[channel].wmx << " " << "ky " << m_current_settings[channel].ky << " " << "dt " << m_current_settings[channel].dt << " " << "imn "<< m_current_settings[channel].imn << " " << "imx "<< m_current_settings[channel].imx << " " << "kp " << m_current_settings[channel].kp << " " << "ki " << m_current_settings[channel].ki << " " << "umn "<< m_current_settings[channel].umn << " " << "umx "<< m_current_settings[channel].umx << " "<< endl);
521  }
522  else
523  {
524  LOGGING_ERROR_C(DriverSVH, SVHController, "Received a get/set current setting packet for ILLEGAL channel "<< channel << "- packet ignored!" << endl);
525  }
526  break;
529  //std::cout << "Recieved: Controller State RAW Data: " << ab; // for really intensive debugging
530  ab >> m_controller_state;
531  //std::cout << "Received controllerState interpreded data: "<< m_controller_state << std::endl; // for really intensive debugging
532  LOGGING_TRACE_C(DriverSVH, SVHController, "Received a get/set controler state packet " << endl);
533  LOGGING_TRACE_C(DriverSVH, SVHController, "Controllerstate (NO HEX):" << "pwm_fault " << "0x" << static_cast<int>(m_controller_state.pwm_fault) << " " << "pwm_otw " << "0x" << static_cast<int>(m_controller_state.pwm_otw) << " " << "pwm_reset " << "0x" << static_cast<int>(m_controller_state.pwm_reset) << " " << "pwm_active " << "0x" << static_cast<int>(m_controller_state.pwm_active) << " " << "pos_ctr " << "0x" << static_cast<int>(m_controller_state.pos_ctrl) << " " << "cur_ctrl " << "0x" << static_cast<int>(m_controller_state.cur_ctrl) << endl);
534  break;
537  LOGGING_TRACE_C(DriverSVH, SVHController, "Received a get/set encoder settings packet " << endl);
538  ab >> m_encoder_settings;
539  break;
541  //std::cout << "Recieved: Firmware Settings RAW Data: " << ab; // for really intensive debugging
542  ab >> m_firmware_info;
543  LOGGING_INFO(DriverSVH, "Hardware is using the following Firmware: " );
544  LOGGING_INFO(DriverSVH, m_firmware_info.svh << " Version: " << m_firmware_info.version_major << "." << m_firmware_info.version_minor << " : " << m_firmware_info.text << endl);
545  break;
546  default:
547  LOGGING_ERROR_C(DriverSVH, SVHController, "Received a Packet with unknown address: "<< (packet.address & 0x0F) << " - ignoring packet" << endl);
548  break;
549  }
550 
551 }
552 
554 {
555  if(channel >= 0 && static_cast<uint8_t>(channel) < m_controller_feedback.size())
556  {
557  controller_feedback = m_controller_feedback[channel];
558  return true;
559  }
560  else
561  {
562  LOGGING_WARNING_C(DriverSVH, SVHController, "GetFeedback was requested for unknown channel: "<< channel<< "- ignoring request" << endl);
563  return false;
564  }
565 }
566 
568 {
569  controller_feedback.feedbacks = m_controller_feedback;
570 }
571 
572 bool SVHController::getPositionSettings(const SVHChannel &channel, SVHPositionSettings &position_settings)
573 {
574  if(channel >= 0 && static_cast<uint8_t>(channel) < m_position_settings.size())
575  {
576  position_settings = m_position_settings[channel];
577  return true;
578  }
579  else
580  {
581  LOGGING_WARNING_C(DriverSVH, SVHController, "GetPositionSettings was requested for unknown channel: "<< channel<< "- ignoring request" << endl);
582  return false;
583  }
584 }
585 
586 bool SVHController::getCurrentSettings(const SVHChannel &channel, SVHCurrentSettings &current_settings)
587 {
588  if(channel >= 0 && static_cast<uint8_t>(channel) < m_current_settings.size())
589  {
590  current_settings = m_current_settings[channel];
591  return true;
592  }
593  else
594  {
595  LOGGING_WARNING_C(DriverSVH, SVHController, "GetCurrentSettings was requested for unknown channel: "<< channel<< "- ignoring request" << endl);
596  return false;
597  }
598 }
599 
601 {
602  return m_firmware_info;
603 }
604 
606 {
608  // The serial interface also keeps track about these counts
610  LOGGING_TRACE_C(DriverSVH, SVHController, "Received package count resetted" << endl);
611 }
612 
614 {
615  if (m_serial_interface != NULL)
616  {
618  }
619  else
620  {
621  LOGGING_WARNING_C(DriverSVH, SVHController, "Request for transmit packet count could not be answered as the device is not connected - ignoring request" << endl);
622  return 0;
623  }
624 }
625 
627 {
629 }
630 
632 {
633  return ((1 << channel & m_enable_mask) > 0);
634 }
635 
636 
637 
638 
639 }
SVHFirmwareInfo getFirmwareInfo()
get the latest stored Firmware information from the controller (NOT THE HARDWARE) ...
void requestPositionSettings(const SVHChannel &channel)
request the settings of the position controller for a specific channel
signed int int32_t
const uint8_t SVH_GET_POSITION_SETTINGS
Requests the active settings of the position controller.
uint16_t pos_ctrl
Enable/Disable of position controller (0x0001 to Activate )
void disableChannel(const SVHChannel &channel)
Disable one or all motor channels.
SVHFirmwareInfo m_firmware_info
Latest firmware info.
Structure for transmitting all controllcommands at once.
std::vector< SVHCurrentSettings > m_current_settings
vector of current controller parameters for each finger
SVHEncoderSettings m_encoder_settings
Currently active encoder settings.
void resetPackageCounts()
resetPackageCounts sets the sent and reveived package counts to zero
void setPositionSettings(const SVHChannel &channel, const SVHPositionSettings &position_settings)
activate a new set of position controller settings for a specific channel
const uint8_t SVH_GET_CONTROL_FEEDBACK
Request the position and current of a channel to be sent.
unsigned int transmittedPacketCount()
get number of transmitted packets
unsigned int getSentPackageCount()
requests the number of sent packages. Request ist transferred to the serial interface that knows abou...
#define LOGGING_INFO(streamname, arg)
void receivedPacketCallback(const SVHSerialPacket &packet, unsigned int packet_count)
callback function for interpretation of packages
void getControllerFeedbackAllChannels(SVHControllerFeedbackAllChannels &controller_feedback)
Get all currently available controllerfeedbacks.
The SVHCurrentSettings save the current controller paramters for a single motor.
const uint8_t SVH_SET_CONTROL_COMMAND
Sets the target position of a channel.
const uint8_t SVH_SET_ENCODER_VALUES
Set new encoder scalings.
uint8_t address
Adress denotes the actual function of the package.
void close()
canceling receive thread and closing connection to serial port
bool getControllerFeedback(const SVHChannel &channel, SVHControllerFeedback &controller_feedback)
request the latest stored controllerfeedback (current, position) from the controller.
bool connect(const std::string &dev_name)
Open serial device connection.
const uint8_t SVH_GET_CONTROLLER_STATE
Requests the state of the controller (active,faults,enabled channels)
unsigned int getReceivedPackageCount()
request the number of correctly received packages. This number is refreshed every time the serialinte...
std::vector< uint32_t > scalings
encoderSettings consist of multipliers for each encoder
void requestControllerState()
Request current controller state (mainly usefull for debug purposes)
#define LOGGING_WARNING_C(streamname, classname, arg)
int usleep(unsigned long useconds)
std::vector< SVHControllerFeedback > feedbacks
Vector holding multiple channels.
bool sendPacket(SVHSerialPacket &packet)
function for sending packets via serial device to the SVH
unsigned int m_received_package_count
store how many packages where actually received. Updated every time the receivepacket callback is cal...
std::vector< uint8_t > data
Payload of the package.
void setControllerTarget(const SVHChannel &channel, const int32_t &position)
Set new position target for finger index.
unsigned char uint8_t
bool connect(const std::string &dev_name)
connecting to serial device and starting receive thread
#define LOGGING_DEBUG_C(streamname, classname, arg)
std::vector< SVHControllerFeedback > m_controller_feedback
ControllerFeedback indicates current position and current per finger.
ThreadStream & endl(ThreadStream &stream)
const uint8_t SVH_SET_CONTROLLER_STATE
Sets new controller states (enable channels, clear faults)
bool isEnabled(const SVHChannel &channel)
Check if a channel was enabled.
const uint8_t SVH_GET_ENCODER_VALUES
Request the current encoder scalings.
void requestControllerFeedback(const SVHChannel &channel)
request feedback (position and current) to a specific channel
void setCurrentSettings(const SVHChannel &channel, const SVHCurrentSettings &current_settings)
activate a new set of current controller settings for a specific channel
The SVHFirmwareInfo holds the data of a firmware response from the hardware.
The SVHControllerFeedback saves the feedback of a single motor.
const uint8_t SVH_SET_CURRENT_SETTINGS
Sets new settings for the current controller.
void disconnect()
disconnect serial device
ControlCommands are given as a single target position for the position controller (given in ticks) ...
bool getPositionSettings(const SVHChannel &channel, SVHPositionSettings &position_settings)
request the latest stored positionsettings from the controller
uint16_t cur_ctrl
Enable/Disbale of current controller (0x0001 to Activate)
const uint8_t SVH_SET_POSITION_SETTINGS
Sets new settings for the position controller.
static const char * m_channel_description[]
Description values to get the corresponding string value to a channel enum.
std::vector< SVHPositionSettings > m_position_settings
vector of position controller parameters for each finger
const uint8_t SVH_GET_CURRENT_SETTINGS
Requests the active settings of the current controller.
SVHController()
Constructs a controller class for the SCHUNK five finger hand.
bool getCurrentSettings(const SVHChannel &channel, SVHCurrentSettings &current_settings)
request the latest stored currentsettings from the controller
This class controls the the SCHUNK five finger hand.
Definition: SVHController.h:77
void setControllerTargetAllChannels(const std::vector< int32_t > &positions)
Setting new position controller target for all fingers.
SVHControllerState m_controller_state
Currently active controllerstate on the HW Controller (indicates if PWM active etc.)
The SVHPositionSettings save the position controller paramters for a single motor.
static const float channel_effort_constants[9]
Effort multipliers to calculate the torque of the motors for the individual channels.
SVHSerialInterface * m_serial_interface
Serial interface for transmission and reveibing of data packets.
The SVHControllerState indicates the current state of the MeCoVis controller IC which is used in the ...
const uint8_t SVH_GET_CONTROL_FEEDBACK_ALL
Requests the positions and currents of ALL channels.
const uint8_t SVH_SET_CONTROL_COMMAND_ALL
Sends the target position to ALL the channels.
uint16_t m_enable_mask
Bitmask to tell which fingers are enabled.
The SVHControllerFeedbackAllChannes saves the feedback of a all motors.
const uint8_t SVH_GET_FIRMWARE_INFO
Request the firmware info to be transmitted.
Basic communication handler for the SCHUNK five finger hand.
void resetTransmitPackageCount()
resetTransmitPackageCount Resets the transmitpackage count to zero
#define LOGGING_TRACE_C(streamname, classname, arg)
void requestEncoderValues()
read out the mutipliers for the encoders from the hardware
void requestCurrentSettings(const SVHChannel &channel)
request the settings of the current controller for a specific channel
bool isConnected()
returns connected state of serial device
The SVHEncoderSettings hold the settings for the encoder scaling of each channel. ...
SVHChannel
Channel indicates which motor to use in command calls. WARNING: DO NOT CHANGE THE ORDER OF THESE as i...
Definition: SVHController.h:56
#define LOGGING_ERROR_C(streamname, classname, arg)
void setEncoderValues(const SVHEncoderSettings &encoder_settings)
sends a new set of encodervalues to the hardware
The SerialPacket holds the (non generated) header and data of one message to the SVH-Hardware.
uint16_t pwm_reset
Bitmask for low-active resets of the channels (0-8). Channel 9 (0x0200) is a special channel that act...
void requestFirmwareInfo()
request a transmission of formware information
void enableChannel(const SVHChannel &channel)
Enable one or all motor channels.


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Mon Jun 10 2019 15:04:59