ati_force_torque_hw_can.cpp
Go to the documentation of this file.
1 /****************************************************************
2  *
3  * Copyright 2016 Intelligent Industrial Robotics (IIROB) Group,
4  * Institute for Anthropomatics and Robotics (IAR) -
5  * Intelligent Process Control and Robotics (IPR),
6  * Karlsruhe Institute of Technology
7  *
8  * Maintainer: Denis Štogl, email: denis.stogl@kit.edu
9  *
10  * Date of update: 2014-2016
11  *
12  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13  *
14  * Copyright (c) 2010
15  *
16  * Fraunhofer Institute for Manufacturing Engineering
17  * and Automation (IPA)
18  *
19  * Date of creation: June 2010
20  *
21  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions are met:
25  *
26  * * Redistributions of source code must retain the above copyright
27  * notice, this list of conditions and the following disclaimer.
28  * * Redistributions in binary form must reproduce the above copyright
29  * notice, this list of conditions and the following disclaimer in the
30  * documentation and/or other materials provided with the distribution.
31  * * Neither the name of the copyright holder nor the names of its
32  * contributors may be used to endorse or promote products derived from
33  * this software without specific prior written permission.
34  *
35  * This program is free software: you can redistribute it and/or modify
36  * it under the terms of the GNU Lesser General Public License LGPL as
37  * published by the Free Software Foundation, either version 3 of the
38  * License, or (at your option) any later version.
39  *
40  * This program is distributed in the hope that it will be useful,
41  * but WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43  * GNU Lesser General Public License LGPL for more details.
44  *
45  * You should have received a copy of the GNU Lesser General Public
46  * License LGPL along with this program.
47  * If not, see <http://www.gnu.org/licenses/>.
48  *
49  ****************************************************************/
50 #define DEBUG 0
51 
52 // general includes
54 
56 
57 // Headrs provided by cob-packages
58 //#include <cob_generic_can/CanESD.h>
59 //#include <cob_generic_can/CanPeakSys.h>
62 
64 {
65  m_pCanCtrl = NULL;
66 
67  // for types and baudrates see:
68  // https://github.com/ipa320/cob_robots/blob/hydro_dev/cob_hardware_config/raw3-5/config/base/CanCtrl.ini
70  m_CanDevice = "/dev/pcan32";
72  m_CanBaseIdentifier = 0x20 << 4;
73 }
74 
75 ATIForceTorqueSensorHWCan::ATIForceTorqueSensorHWCan(int can_type, std::string can_path, int can_baudrate, int base_identifier)
76 {
77  m_pCanCtrl = NULL;
78 
79  // for types and baudrates see:
80  // https://github.com/ipa320/cob_robots/blob/hydro_dev/cob_hardware_config/raw3-5/config/base/CanCtrl.ini
81  m_CanType = can_type;
82  m_CanDevice = can_path;
83  m_CanBaudrate = can_baudrate;
84  m_CanBaseIdentifier = base_identifier << 4;
85 }
86 
88 {
89  if (m_pCanCtrl != NULL)
90  {
91  delete m_pCanCtrl;
92  }
93 }
94 
95 bool ATIForceTorqueSensorHWCan::initCommunication(int can_type, std::string can_path, int can_baudrate, int base_identifier)
96 {
97  m_pCanCtrl = NULL;
98 
99  // for types and baudrates see:
100  // https://github.com/ipa320/cob_robots/blob/hydro_dev/cob_hardware_config/raw3-5/config/base/CanCtrl.ini
101  m_CanType = can_type;
102  m_CanDevice = can_path;
103  m_CanBaudrate = can_baudrate;
104  m_CanBaseIdentifier = base_identifier << 4;
105 }
106 
108 {
109  bool ret = true;
110 
111  if (initCan())
112  {
113  // This is way of testig if communication is also successful
114  if (!ReadFTSerialNumber())
115  {
116  std::cout << "Can not read Serial Number from FTS!" << std::endl;
117  ret = false;
118  }
119  if (!ReadFirmwareVersion())
120  {
121  std::cout << "Can not read Firmware version from FTS!" << std::endl;
122  ret = false;
123  }
124  if (!ReadCountsPerUnit())
125  {
126  std::cout << "Can not read Counts Per Unit from FTS!" << std::endl;
127  ret = false;
128  }
129  if (!ReadUnitCodes())
130  {
131  std::cout << "Can not read Unit Codes from FTS!" << std::endl;
132  ret = false;
133  }
134  // Add return values and checking
137  }
138  else
139  {
140  std::cout << "CAN initialisation unsuccessful!" << std::endl;
141  ret = false;
142  }
143 
144  return ret;
145 }
146 
148 {
149  bool ret = true;
150 
151  // current implementation only for CanPeakSysUSB and SocketCan
152  switch (m_CanType)
153  {
156  ret = m_pCanCtrl->init_ret();
157  break;
158 
160  m_pCanCtrl = new SocketCan(m_CanDevice.c_str());
161  ret = m_pCanCtrl->init_ret();
162  break;
163  }
164  return ret;
165 }
166 
168 {
169 #if DEBUG
170  std::cout << "\n\n*********FTSerialNumber**********" << std::endl;
171 #endif
172  bool ret = true;
173  CanMsg CMsg;
175  CMsg.setLength(0);
176  ret = m_pCanCtrl->transmitMsg(CMsg, true);
177  if (ret)
178  {
179  CanMsg replyMsg;
180  replyMsg.set(0, 0, 0, 0, 0, 0, 0, 0);
181  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
182 
183  if (ret)
184  {
185 #if DEBUG
186  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
187  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
188 #endif
189  if (replyMsg.getID() == (m_CanBaseIdentifier | READ_SERIALNR))
190  {
191 #if DEBUG
192  std::cout << "Reading Serial Number Succeeded!" << std::endl;
193  std::cout << "reply Data: \t" << (char)replyMsg.getAt(0) << " " << (char)replyMsg.getAt(1) << " "
194  << (char)replyMsg.getAt(2) << " " << (char)replyMsg.getAt(3) << " " << (char)replyMsg.getAt(4) << " "
195  << (char)replyMsg.getAt(5) << " " << (char)replyMsg.getAt(6) << " " << (char)replyMsg.getAt(7)
196  << std::endl;
197 #endif
198  }
199  else
200  {
201 #if DEBUG
202  std::cout << "Error: Received wrong opcode!" << std::endl;
203 #endif
204  ret = false;
205  }
206  }
207  else
208  {
209 #if DEBUG
210  std::cout << "ATIForceTorqueSensorHWCan::ReadFTSerialNumber(): Can not read message!" << std::endl;
211 #endif
212  }
213  }
214  else
215  {
216 #if DEBUG
217  std::cout << "ATIForceTorqueSensorHWCan::ReadFTSerialNumber(): Can not transmit message!" << std::endl;
218 #endif
219  }
220 
221  return ret;
222 }
223 
225 {
226 #if DEBUG
227  std::cout << "\n\n*********Read Counts Per Unit**********" << std::endl;
228 #endif
229  bool ret = true;
230  float countsPerForce = 0, countsPerTorque = 0;
231  CanMsg CMsg;
233  CMsg.setLength(0);
234 
235  ret = m_pCanCtrl->transmitMsg(CMsg, true);
236 
237  if (ret)
238  {
239  CanMsg replyMsg;
240  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
241 
242  if (ret)
243  {
244 #if DEBUG
245  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
246  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
247 #endif
248  if (replyMsg.getID() == (m_CanBaseIdentifier | READ_COUNTSPERU))
249  {
250 #if DEBUG
251  std::cout << "Reading Counts Per Unit Succeeded!" << std::endl;
252  std::cout << "reply Data: \t" << (char)replyMsg.getAt(0) << " " << (char)replyMsg.getAt(1) << " "
253  << (char)replyMsg.getAt(2) << " " << (char)replyMsg.getAt(3) << " " << (char)replyMsg.getAt(4) << " "
254  << (char)replyMsg.getAt(5) << " " << (char)replyMsg.getAt(6) << " " << (char)replyMsg.getAt(7)
255  << std::endl;
256 #endif
257  }
258  else
259  {
260 #if DEBUG
261  std::cout << "Error: Received wrong opcode!" << std::endl;
262 #endif
263  ret = false;
264  }
265 
266  intbBuf.bytes[0] = replyMsg.getAt(3);
267  intbBuf.bytes[1] = replyMsg.getAt(2);
268  intbBuf.bytes[2] = replyMsg.getAt(1);
269  intbBuf.bytes[3] = replyMsg.getAt(0);
270  countsPerForce = intbBuf.value;
271 
272  intbBuf.bytes[0] = replyMsg.getAt(7);
273  intbBuf.bytes[1] = replyMsg.getAt(6);
274  intbBuf.bytes[2] = replyMsg.getAt(5);
275  intbBuf.bytes[3] = replyMsg.getAt(4);
276  countsPerTorque = intbBuf.value;
277  }
278  else
279  {
280  std::cout << "ATIForceTorqueSensorHWCan::ReadCountsPerUnit(): Can not read message!" << std::endl;
281  }
282  }
283  else
284  {
285  std::cout << "ATIForceTorqueSensorHWCan::ReadCountsPerUnit(): Can not transmit message!" << std::endl;
286  }
287 #if DEBUG
288  std::cout << "CountsPerforce: " << countsPerForce << " CountsPerTorque: " << countsPerTorque << std::endl;
289 #endif
290  return ret;
291 }
292 
294 {
295 #if DEBUG
296  std::cout << "\n\n*********Read Unit Codes**********" << std::endl;
297 #endif
298  bool ret = true;
299  CanMsg CMsg;
301  CMsg.setLength(0);
302 
303  ret = m_pCanCtrl->transmitMsg(CMsg, true);
304 
305  if (ret)
306  {
307  CanMsg replyMsg;
308  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
309 
310  if (ret)
311  {
312 #if DEBUG
313  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
314  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
315 #endif
316  if (replyMsg.getID() == (m_CanBaseIdentifier | READ_UNITCODE))
317  {
318 #if DEBUG
319  std::cout << "Reading Unit codes Succeed!" << std::endl;
320  std::cout << "reply Data: \t" << replyMsg.getAt(0) << " " << replyMsg.getAt(1) << std::endl;
321 #endif
322  }
323  }
324  else
325  {
326  std::cout << "ATIForceTorqueSensorHWCan::ReadUnitCodes(): Can not read message!" << std::endl;
327  }
328  }
329  else
330  {
331  std::cout << "ATIForceTorqueSensorHWCan::ReadUnitCodes(): Can not transmit message!" << std::endl;
332  }
333 
334  return ret;
335 }
336 
338 {
339  // TODO: Check for Init
340 #if DEBUG
341  std::cout << "\n\n*******Read Diagnostic ADC Voltages on index: " << index << "********" << std::endl;
342 #endif
343  bool ret = true;
344  CanMsg CMsg;
346  CMsg.setLength(1);
347  // TODO: offset or typecast index
348  CMsg.setAt(index, 0);
349 
350  ret = m_pCanCtrl->transmitMsg(CMsg, true);
351 
352  if (ret)
353  {
354  CanMsg replyMsg;
355  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
356  if (ret)
357  {
358 #if DEBUG
359  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
360  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
361 #endif
362  if (replyMsg.getID() == (m_CanBaseIdentifier | READ_DIAGNOV))
363  {
364 #if DEBUG
365  std::cout << "Reading Diagnostic ADC Voltage succeed!" << std::endl;
366  std::cout << "ADC Voltage of diagnostic value " << index << " : " << replyMsg.getAt(0) << " "
367  << replyMsg.getAt(1) << std::endl;
368 #endif
369 
370  ibBuf.bytes[0] = replyMsg.getAt(1);
371  ibBuf.bytes[1] = replyMsg.getAt(0);
372  value = ibBuf.value;
373  }
374  else
375  std::cout << "Error: Received wrong opcode!" << std::endl;
376  }
377  else
378  std::cout << "Error: Receiving Message failed!" << std::endl;
379  }
380  else
381  {
382  std::cout << "ATIForceTorqueSensorHWCan::readDiagnosticADCVoltages(byte index): Can not transmit message!" << std::endl;
383  }
384 
385  return ret;
386 }
387 
389 {
390 #if DEBUG
391  std::cout << "\n\n*******Setting Active Calibration Matrix Num to: " << num << "********" << std::endl;
392 #endif
393  bool ret = true;
394  CanMsg CMsg;
396  CMsg.setLength(1);
397  CMsg.setAt(num, 0);
398 
399  ret = m_pCanCtrl->transmitMsg(CMsg, true);
400 
401  if (ret)
402  {
403  CanMsg replyMsg;
404  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
405  if (ret)
406  {
407 #if DEBUG
408  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
409  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
410 #endif
411  if (replyMsg.getID() == (m_CanBaseIdentifier | SET_CALIB))
412  {
413 #if DEBUG
414  std::cout << "Setting Calibration Matrix succeed!" << std::endl;
415  std::cout << "Calibration Matrix: " << replyMsg.getAt(0) << " is Activ!" << std::endl;
416 #endif
417  }
418  else
419  {
420 #if DEBUG
421  std::cout << "Error: Received wrong opcode!" << std::endl;
422 #endif
423  ret = false;
424  }
425  }
426  else
427  {
428  std::cout << "Error: Receiving Message failed!" << std::endl;
429  ret = false;
430  }
431  }
432  else
433  {
434  std::cout << "ATIForceTorqueSensorHWCan::SetActiveCalibrationMatrix(int num): Can not transmit message!" << std::endl;
435  ret = false;
436  }
437 
438  return ret;
439 }
440 
442 {
443 #if DEBUG
444  std::cout << "\n\n*******Setting Baud Rate value to: " << value << "********" << std::endl;
445 #endif
446  bool ret = true;
447  CanMsg CMsg;
449  CMsg.setLength(1);
450  CMsg.setAt(value, 0);
451 
452  ret = m_pCanCtrl->transmitMsg(CMsg, true);
453 
454  if (ret)
455  {
456  CanMsg replyMsg;
457  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
458  if (ret)
459  {
460 #if DEBUG
461  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
462  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
463 #endif
464  if (replyMsg.getID() == (m_CanBaseIdentifier | SET_BAUD))
465  {
466 #if DEBUG
467  std::cout << "Send Baud Rate value: " << CMsg.getAt(0) << "!" << std::endl;
468  std::cout << "Setting Baud Rate succeed!" << std::endl;
469 #endif
470  }
471  else
472  {
473  std::cout << "Error: Received wrong opcode!" << std::endl;
474  ret = false;
475  }
476  }
477  else
478  {
479  std::cout << "Error: Receiving Message failed!" << std::endl;
480  ret = false;
481  }
482  }
483  else
484  {
485  std::cout << "ATIForceTorqueSensorHWCan::SetBaudRate(int value): Can not transmit message!" << std::endl;
486  ret = false;
487  }
488 
489  return ret;
490 }
491 
493 {
494  std::cout << "\n\n******* Reseting the NETCANOEM ********" << std::endl;
495  bool ret = true;
496  CanMsg CMsg;
498  CMsg.setLength(0);
499 
500  ret = m_pCanCtrl->transmitMsg(CMsg, true);
501 
502  if (!ret)
503  {
504  std::cout << "ATIForceTorqueSensorHWCan::Reset(): Can not transmit message!" << std::endl;
505  ret = false;
506  }
507 
508  usleep(10000);
509 
510  return ret;
511 }
512 
514 {
515 #if DEBUG
516  std::cout << "\n\n*******Setting Base Identifier value to HEX : " << std::hex << identifier << " ********"
517  << std::endl;
518 #endif
519  bool ret = true;
520  CanMsg CMsg;
522  CMsg.setLength(1);
523  CMsg.setAt(identifier, 0);
524 
525  ret = m_pCanCtrl->transmitMsg(CMsg, true);
526 
527  if (ret)
528  {
529  CanMsg replyMsg;
530  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
531  if (ret)
532  {
533 #if DEBUG
534  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
535  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
536 #endif
537  if (replyMsg.getID() == (m_CanBaseIdentifier | SET_BASEID))
538  {
539 #if DEBUG
540  std::cout << "Setting Base Identifier succeed!" << std::endl;
541  std::cout << "Send Base Identifier value: " << std::hex << CMsg.getAt(0) << "!" << std::endl;
542 #endif
543  ret = true;
544  }
545  else
546  {
547  std::cout << "Error: Received wrong opcode!" << std::endl;
548  ret = false;
549  }
550  }
551  else
552  {
553  std::cout << "Error: Receiving Message failed!" << std::endl;
554  ret = false;
555  }
556  }
557  else
558  {
559  std::cout << "ATIForceTorqueSensorHWCan::SetBaseIdentifier(int identifier): Can not transmit message!" << std::endl;
560  ret = false;
561  }
562 
563  return ret;
564 }
565 
567 {
568  Eigen::VectorXf vCoef(6);
569 
570  // Read Fx coefficients
571  ReadMatrix(0, vCoef);
572  m_v3FXGain = vCoef;
573 
574  // Read Fy coefficients
575  ReadMatrix(1, vCoef);
576  m_v3FYGain = vCoef;
577 
578  // Read Fz coefficients
579  ReadMatrix(2, vCoef);
580  m_v3FZGain = vCoef;
581 
582  // Read Tx coefficients
583  ReadMatrix(3, vCoef);
584  m_v3TXGain = vCoef;
585 
586  // Read Ty coefficients
587  ReadMatrix(4, vCoef);
588  m_v3TYGain = vCoef;
589 
590  // Read Tz coefficients
591  ReadMatrix(5, vCoef);
592  m_v3TZGain = vCoef;
593  SetCalibMatrix();
594 }
595 
596 void ATIForceTorqueSensorHWCan::ReadMatrix(int axis, Eigen::VectorXf &vec)
597 {
598 #if DEBUG
599  std::cout << "\n\n*******Read Matrix**********" << std::endl;
600 #endif
601  float statusCode = 0, sg0 = 0.0, sg1 = 0.0, sg2 = 0.0, sg3 = 0.0, sg4 = 0.0, sg5 = 0.0;
602 
603  CanMsg CMsg;
605  CMsg.setLength(1);
606  CMsg.setAt(axis, 0);
607 
608  bool ret = m_pCanCtrl->transmitMsg(CMsg, true);
609  if (!ret)
610  {
611  std::cout << "Error: Requesting Calibration Matrix!" << std::endl;
612  return;
613  }
614 
615  CanMsg replyMsg;
616  bool ret2 = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
617  if (ret2)
618  {
619 #if DEBUG
620  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
621  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
622 #endif
623  if (replyMsg.getID() == (m_CanBaseIdentifier | READ_MATRIX))
624  {
625 #if DEBUG
626  std::cout << "Reading Matrix Succeeded!" << std::endl;
627  std::cout << "reply Data: \t" << replyMsg.getAt(0) << " " << replyMsg.getAt(1) << " " << replyMsg.getAt(2) << " "
628  << replyMsg.getAt(3) << " " << replyMsg.getAt(4) << " " << replyMsg.getAt(5) << " " << replyMsg.getAt(6)
629  << " " << replyMsg.getAt(7) << std::endl;
630 #endif
631  }
632  else
633  {
634  std::cout << "Error: Received wrong opcode!" << std::endl;
635  ret = false;
636  }
637 
638  fbBuf.bytes[0] = replyMsg.getAt(3);
639  fbBuf.bytes[1] = replyMsg.getAt(2);
640  fbBuf.bytes[2] = replyMsg.getAt(1);
641  fbBuf.bytes[3] = replyMsg.getAt(0);
642  sg0 = fbBuf.value;
643 
644  fbBuf.bytes[0] = replyMsg.getAt(7);
645  fbBuf.bytes[1] = replyMsg.getAt(6);
646  fbBuf.bytes[2] = replyMsg.getAt(5);
647  fbBuf.bytes[3] = replyMsg.getAt(4);
648  sg1 = fbBuf.value;
649  }
650  else
651  return;
652 
653  ret2 = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
654  if (ret2)
655  {
656 #if DEBUG
657  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
658  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
659  std::cout << "reply Data: \t" << replyMsg.getAt(0) << " " << replyMsg.getAt(1) << " " << replyMsg.getAt(2) << " "
660  << replyMsg.getAt(3) << " " << replyMsg.getAt(4) << " " << replyMsg.getAt(5) << " " << replyMsg.getAt(6)
661  << " " << replyMsg.getAt(7) << std::endl;
662 #endif
663 
664  fbBuf.bytes[0] = replyMsg.getAt(3);
665  fbBuf.bytes[1] = replyMsg.getAt(2);
666  fbBuf.bytes[2] = replyMsg.getAt(1);
667  fbBuf.bytes[3] = replyMsg.getAt(0);
668  sg2 = fbBuf.value;
669 
670  fbBuf.bytes[0] = replyMsg.getAt(7);
671  fbBuf.bytes[1] = replyMsg.getAt(6);
672  fbBuf.bytes[2] = replyMsg.getAt(5);
673  fbBuf.bytes[3] = replyMsg.getAt(4);
674  sg3 = fbBuf.value;
675  }
676  else
677  return;
678 
679  ret2 = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
680  if (ret2)
681  {
682 #if DEBUG
683  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
684  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
685  std::cout << "reply Data: \t" << replyMsg.getAt(0) << " " << replyMsg.getAt(1) << " " << replyMsg.getAt(2) << " "
686  << replyMsg.getAt(3) << " " << replyMsg.getAt(4) << " " << replyMsg.getAt(5) << " " << replyMsg.getAt(6)
687  << " " << replyMsg.getAt(7) << std::endl;
688 #endif
689 
690  fbBuf.bytes[0] = replyMsg.getAt(3);
691  fbBuf.bytes[1] = replyMsg.getAt(2);
692  fbBuf.bytes[2] = replyMsg.getAt(1);
693  fbBuf.bytes[3] = replyMsg.getAt(0);
694  sg4 = fbBuf.value;
695 
696  fbBuf.bytes[0] = replyMsg.getAt(7);
697  fbBuf.bytes[1] = replyMsg.getAt(6);
698  fbBuf.bytes[2] = replyMsg.getAt(5);
699  fbBuf.bytes[3] = replyMsg.getAt(4);
700  sg5 = fbBuf.value;
701  }
702  else
703  return;
704 
705  vec[0] = sg0;
706  vec[1] = sg1;
707  vec[2] = sg2;
708  vec[3] = sg3;
709  vec[4] = sg4;
710  vec[5] = sg5;
711 #if DEBUG
712  std::cout << "Matix: SG0: " << sg0 << " SG1: " << sg1 << " SG2: " << sg2 << " SG3: " << sg3 << " SG4: " << sg4
713  << " SG5: " << sg5 << std::endl;
714 #endif
715 }
716 
718 {
719 #if DEBUG
720  std::cout << "\n\n*******Reading Firmware Version*******" << std::endl;
721 #endif
722  bool ret = true;
723  CanMsg CMsg;
725  CMsg.setLength(0);
726 
727  ret = m_pCanCtrl->transmitMsg(CMsg, true);
728 
729  if (ret)
730  {
731  CanMsg replyMsg;
732  ret = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
733  if (ret)
734  {
735 #if DEBUG
736  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
737  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
738 #endif
739  if (replyMsg.getID() == (m_CanBaseIdentifier | READ_FIRMWARE))
740  {
741 #if DEBUG
742  std::cout << "Reading Firmware Succeed!" << std::endl;
743  std::cout << "reply Data: \t" << replyMsg.getAt(0) << " " << replyMsg.getAt(1) << " " << replyMsg.getAt(2)
744  << " " << replyMsg.getAt(3) << std::endl;
745 #endif
746  }
747  else
748  {
749  std::cout << "Error: Received wrong opcode!" << std::endl;
750  ret = false;
751  }
752  }
753  else
754  {
755  std::cout << "Error: Receiving Message failed!" << std::endl;
756  ret = false;
757  }
758  }
759  else
760  {
761  std::cout << "Error: Transmiting Message failed!" << std::endl;
762  ret = false;
763  }
764 
765  return ret;
766 }
767 
768 bool ATIForceTorqueSensorHWCan::readFTData(int statusCode, double &Fx, double &Fy, double &Fz, double &Tx, double &Ty, double &Tz)
769 {
770  int sg0 = 0, sg1 = 0, sg2 = 0, sg3 = 0, sg4 = 0, sg5 = 0;
771 
772  CanMsg CMsg;
774  CMsg.setLength(0);
775  bool ret = m_pCanCtrl->transmitMsg(CMsg, true);
776 
777  if (!ret)
778  {
779  std::cout << "ATIForceTorqueSensorHWCan::ReadSGData: Error: Transmiting message failed!" << std::endl;
780  return false;
781  }
782 
783  CanMsg replyMsg;
784  bool ret2 = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
785  unsigned char c[2];
786  if (ret2)
787  {
788  if (replyMsg.getID() != (m_CanBaseIdentifier | 0x0))
789  {
790  std::cout << "ATIForceTorqueSensorHWCan::ReadSGData: Error: Received wrong opcode (Should be 0x200)!" << std::endl;
791  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
792  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
793  std::cout << "reply Data: \t" << replyMsg.getAt(0) << " " << replyMsg.getAt(1) << " " << replyMsg.getAt(2) << " "
794  << replyMsg.getAt(3) << " " << replyMsg.getAt(4) << " " << replyMsg.getAt(5) << " " << replyMsg.getAt(6)
795  << " " << replyMsg.getAt(7) << std::endl;
796  return false ;
797  }
798 
799  c[0] = replyMsg.getAt(0); // status code
800  c[1] = replyMsg.getAt(1);
801  statusCode = (short)((c[0] << 8) | c[1]);
802 
803  if (statusCode != 0)
804  {
805  if (statusCode & 0x4000)
806  {
807  std::cout << "ATIForceTorqueSensorHWCan::ReadSGData: CAN bus error detected!" << std::endl;
808  Reset();
809  std::cout << "ATIForceTorqueSensorHWCan::ReadSGData: FTS reseted!" << std::endl;
810  }
811  else
812  {
813  std::cout << "ATIForceTorqueSensorHWCan::ReadSGData: Error: Something is wrong with sensor!" << std::endl;
814  std::cout << std::hex << statusCode << std::endl;
815  }
816  }
817 
818  c[0] = replyMsg.getAt(2); // sg0
819  c[1] = replyMsg.getAt(3);
820  sg0 = (short)((c[0] << 8) | c[1]);
821 
822  c[0] = replyMsg.getAt(4); // sg2
823  c[1] = replyMsg.getAt(5);
824  sg2 = (short)((c[0] << 8) | c[1]);
825 
826  c[0] = replyMsg.getAt(6); // sg4
827  c[1] = replyMsg.getAt(7);
828  sg4 = (short)((c[0] << 8) | c[1]);
829  }
830  else
831  return false;
832 
833  ret2 = m_pCanCtrl->receiveMsgRetry(&replyMsg, 10);
834  if (ret2)
835  {
836  if (replyMsg.getID() != (m_CanBaseIdentifier | 0x1))
837  {
838  std::cout << "ATIForceTorqueSensorHWCan::ReadSGData: Error: Received wrong opcode (Should be 0x201)!" << std::endl;
839  std::cout << "reply ID: \t" << std::hex << replyMsg.getID() << std::endl;
840  std::cout << "reply Length: \t" << replyMsg.getLength() << std::endl;
841  std::cout << "reply Data: \t" << replyMsg.getAt(0) << " " << replyMsg.getAt(1) << " " << replyMsg.getAt(2) << " "
842  << replyMsg.getAt(3) << " " << replyMsg.getAt(4) << " " << replyMsg.getAt(5) << " " << replyMsg.getAt(6)
843  << " " << replyMsg.getAt(7) << std::endl;
844  return false ;
845  }
846 
847  c[0] = replyMsg.getAt(0); // sg1
848  c[1] = replyMsg.getAt(1);
849  sg1 = (short)((c[0] << 8) | c[1]);
850 
851  c[0] = replyMsg.getAt(2); // sg3
852  c[1] = replyMsg.getAt(3);
853  sg3 = (short)((c[0] << 8) | c[1]);
854 
855  c[0] = replyMsg.getAt(4); // sg5
856  c[1] = replyMsg.getAt(5);
857  sg5 = (short)((c[0] << 8) | c[1]);
858  }
859  else
860  return false;
861 
862  StrainGaugeToForce(sg0, sg1, sg2, sg3, sg4, sg5);
863  Fx = m_vForceData(0);
864  Fy = m_vForceData(1);
865  Fz = m_vForceData(2);
866  Tx = m_vForceData(3);
867  Ty = m_vForceData(4);
868  Tz = m_vForceData(5);
869  return true;
870 }
871 
872 void ATIForceTorqueSensorHWCan::StrainGaugeToForce(int &sg0, int &sg1, int &sg2, int &sg3, int &sg4, int &sg5)
873 {
874  Eigen::VectorXf v6SG(6);
875  Eigen::VectorXf v6tmp(6);
876  Eigen::VectorXf test(6);
877 
878  v6SG[0] = sg0;
879  v6SG[1] = sg1;
880  v6SG[2] = sg2;
881  v6SG[3] = sg3;
882  v6SG[4] = sg4;
883  v6SG[5] = sg5;
884  test = m_mXCalibMatrix * v6SG;
885  m_vForceData = test * 0.000001;
886 }
887 
888 void ATIForceTorqueSensorHWCan::SetGaugeOffset(float sg0Off, float sg1Off, float sg2Off, float sg3Off, float sg4Off, float sg5Off)
889 {
890  Eigen::VectorXf tmp(6);
891  tmp[0] = sg0Off;
892  tmp[1] = sg1Off;
893  tmp[2] = sg2Off;
894  tmp[3] = sg3Off;
895  tmp[4] = sg4Off;
896  tmp[5] = sg5Off;
897  m_v3StrainGaigeOffset = tmp;
898 }
899 void ATIForceTorqueSensorHWCan::SetGaugeGain(float gg0, float gg1, float gg2, float gg3, float gg4, float gg5)
900 {
901  Eigen::VectorXf tmp(6);
902  tmp[0] = gg0;
903  tmp[1] = gg1;
904  tmp[2] = gg2;
905  tmp[3] = gg3;
906  tmp[4] = gg4;
907  tmp[5] = gg5;
908  m_v3GaugeGain = tmp;
909  // std::cout<<"GaugeGain: \n"<<m_v3GaugeGain<<"\n\n";
910 }
911 
912 void ATIForceTorqueSensorHWCan::SetFXGain(float fxg0, float fxg1, float fxg2, float fxg3, float fxg4, float fxg5)
913 {
914  Eigen::VectorXf tmp(6);
915  tmp[0] = fxg0;
916  tmp[1] = fxg1;
917  tmp[2] = fxg2;
918  tmp[3] = fxg3;
919  tmp[4] = fxg4;
920  tmp[5] = fxg5;
921  m_v3FXGain = tmp;
922  // std::cout<<"FXGain: \n"<<m_v3FXGain<<"\n\n";
923 }
924 void ATIForceTorqueSensorHWCan::SetFYGain(float fyg0, float fyg1, float fyg2, float fyg3, float fyg4, float fyg5)
925 {
926  Eigen::VectorXf tmp(6);
927  tmp[0] = fyg0;
928  tmp[1] = fyg1;
929  tmp[2] = fyg2;
930  tmp[3] = fyg3;
931  tmp[4] = fyg4;
932  tmp[5] = fyg5;
933  m_v3FYGain = tmp;
934  // std::cout<<"FYGain: \n"<<m_v3FYGain<<"\n\n";
935 }
936 void ATIForceTorqueSensorHWCan::SetFZGain(float fzg0, float fzg1, float fzg2, float fzg3, float fzg4, float fzg5)
937 {
938  Eigen::VectorXf tmp(6);
939  tmp[0] = fzg0;
940  tmp[1] = fzg1;
941  tmp[2] = fzg2;
942  tmp[3] = fzg3;
943  tmp[4] = fzg4;
944  tmp[5] = fzg5;
945  m_v3FZGain = tmp;
946  // std::cout<<"FZGain: \n"<<m_v3FZGain<<"\n\n";
947 }
948 void ATIForceTorqueSensorHWCan::SetTXGain(float txg0, float txg1, float txg2, float txg3, float txg4, float txg5)
949 {
950  Eigen::VectorXf tmp(6);
951  tmp[0] = txg0;
952  tmp[1] = txg1;
953  tmp[2] = txg2;
954  tmp[3] = txg3;
955  tmp[4] = txg4;
956  tmp[5] = txg5;
957  m_v3TXGain = tmp;
958  // std::cout<<"TXGain: \n"<<m_v3TXGain<<"\n\n";
959 }
960 void ATIForceTorqueSensorHWCan::SetTYGain(float tyg0, float tyg1, float tyg2, float tyg3, float tyg4, float tyg5)
961 {
962  Eigen::VectorXf tmp(6);
963  tmp[0] = tyg0;
964  tmp[1] = tyg1;
965  tmp[2] = tyg2;
966  tmp[3] = tyg3;
967  tmp[4] = tyg4;
968  tmp[5] = tyg5;
969  m_v3TYGain = tmp;
970  // std::cout<<"TYGain: \n"<<m_v3TYGain<<"\n\n";
971 }
972 void ATIForceTorqueSensorHWCan::SetTZGain(float tzg0, float tzg1, float tzg2, float tzg3, float tzg4, float tzg5)
973 {
974  Eigen::VectorXf tmp(6);
975  tmp[0] = tzg0;
976  tmp[1] = tzg1;
977  tmp[2] = tzg2;
978  tmp[3] = tzg3;
979  tmp[4] = tzg4;
980  tmp[5] = tzg5;
981  m_v3TZGain = tmp;
982  // std::cout<<"TZGain: \n"<<m_v3TZGain<<"\n\n";
983 }
984 
986 {
987  Eigen::MatrixXf tmp(6, 6);
988  tmp(0) = m_v3FXGain[0] / m_v3GaugeGain[0];
989  tmp(1) = m_v3FXGain[1] / m_v3GaugeGain[1];
990  tmp(2) = m_v3FXGain[2] / m_v3GaugeGain[2];
991  tmp(3) = m_v3FXGain[3] / m_v3GaugeGain[3];
992  tmp(4) = m_v3FXGain[4] / m_v3GaugeGain[4];
993  tmp(5) = m_v3FXGain[5] / m_v3GaugeGain[5];
994 
995  tmp(6) = m_v3FYGain[0] / m_v3GaugeGain[0];
996  tmp(7) = m_v3FYGain[1] / m_v3GaugeGain[1];
997  tmp(8) = m_v3FYGain[2] / m_v3GaugeGain[2];
998  tmp(9) = m_v3FYGain[3] / m_v3GaugeGain[3];
999  tmp(10) = m_v3FYGain[4] / m_v3GaugeGain[4];
1000  tmp(11) = m_v3FYGain[5] / m_v3GaugeGain[5];
1001 
1002  tmp(12) = m_v3FZGain[0] / m_v3GaugeGain[0];
1003  tmp(13) = m_v3FZGain[1] / m_v3GaugeGain[1];
1004  tmp(14) = m_v3FZGain[2] / m_v3GaugeGain[2];
1005  tmp(15) = m_v3FZGain[3] / m_v3GaugeGain[3];
1006  tmp(16) = m_v3FZGain[4] / m_v3GaugeGain[4];
1007  tmp(17) = m_v3FZGain[5] / m_v3GaugeGain[5];
1008 
1009  tmp(18) = m_v3TXGain[0] / m_v3GaugeGain[0];
1010  tmp(19) = m_v3TXGain[1] / m_v3GaugeGain[1];
1011  tmp(20) = m_v3TXGain[2] / m_v3GaugeGain[2];
1012  tmp(21) = m_v3TXGain[3] / m_v3GaugeGain[3];
1013  tmp(22) = m_v3TXGain[4] / m_v3GaugeGain[4];
1014  tmp(23) = m_v3TXGain[5] / m_v3GaugeGain[5];
1015 
1016  tmp(24) = m_v3TYGain[0] / m_v3GaugeGain[0];
1017  tmp(25) = m_v3TYGain[1] / m_v3GaugeGain[1];
1018  tmp(26) = m_v3TYGain[2] / m_v3GaugeGain[2];
1019  tmp(27) = m_v3TYGain[3] / m_v3GaugeGain[3];
1020  tmp(28) = m_v3TYGain[4] / m_v3GaugeGain[4];
1021  tmp(29) = m_v3TYGain[5] / m_v3GaugeGain[5];
1022 
1023  tmp(30) = m_v3TZGain[0] / m_v3GaugeGain[0];
1024  tmp(31) = m_v3TZGain[1] / m_v3GaugeGain[1];
1025  tmp(32) = m_v3TZGain[2] / m_v3GaugeGain[2];
1026  tmp(33) = m_v3TZGain[3] / m_v3GaugeGain[3];
1027  tmp(34) = m_v3TZGain[4] / m_v3GaugeGain[4];
1028  tmp(35) = m_v3TZGain[5] / m_v3GaugeGain[5];
1029 
1030  m_mXCalibMatrix = tmp;
1031 }
1032 
1034 {
1035  Eigen::MatrixXf tmp(6, 6);
1036  tmp(0) = m_v3FXGain[0];
1037  tmp(1) = m_v3FXGain[1];
1038  tmp(2) = m_v3FXGain[2];
1039  tmp(3) = m_v3FXGain[3];
1040  tmp(4) = m_v3FXGain[4];
1041  tmp(5) = m_v3FXGain[5];
1042 
1043  tmp(6) = m_v3FYGain[0];
1044  tmp(7) = m_v3FYGain[1];
1045  tmp(8) = m_v3FYGain[2];
1046  tmp(9) = m_v3FYGain[3];
1047  tmp(10) = m_v3FYGain[4];
1048  tmp(11) = m_v3FYGain[5];
1049 
1050  tmp(12) = m_v3FZGain[0];
1051  tmp(13) = m_v3FZGain[1];
1052  tmp(14) = m_v3FZGain[2];
1053  tmp(15) = m_v3FZGain[3];
1054  tmp(16) = m_v3FZGain[4];
1055  tmp(17) = m_v3FZGain[5];
1056 
1057  tmp(18) = m_v3TXGain[0];
1058  tmp(19) = m_v3TXGain[1];
1059  tmp(20) = m_v3TXGain[2];
1060  tmp(21) = m_v3TXGain[3];
1061  tmp(22) = m_v3TXGain[4];
1062  tmp(23) = m_v3TXGain[5];
1063 
1064  tmp(24) = m_v3TYGain[0];
1065  tmp(25) = m_v3TYGain[1];
1066  tmp(26) = m_v3TYGain[2];
1067  tmp(27) = m_v3TYGain[3];
1068  tmp(28) = m_v3TYGain[4];
1069  tmp(29) = m_v3TYGain[5];
1070 
1071  tmp(30) = m_v3TZGain[0];
1072  tmp(31) = m_v3TZGain[1];
1073  tmp(32) = m_v3TZGain[2];
1074  tmp(33) = m_v3TZGain[3];
1075  tmp(34) = m_v3TZGain[4];
1076  tmp(35) = m_v3TZGain[5];
1077 
1078  m_mXCalibMatrix = tmp.transpose();
1079 }
1080 
#define READ_SERIALNR
void StrainGaugeToForce(int &sg0, int &sg1, int &sg2, int &sg3, int &sg4, int &sg5)
void setLength(int len)
#define READ_COUNTSPERU
union ATIForceTorqueSensorHWCan::@1 intbBuf
bool SetBaseIdentifier(int identifier)
int getID()
void SetFYGain(float fyg0, float fyg1, float fyg2, float fyg3, float fyg4, float fyg5)
bool readFTData(int statusCode, double &Fx, double &Fy, double &Fz, double &Tx, double &Ty, double &Tz)
void SetTXGain(float txg0, float txg1, float txg2, float txg3, float txg4, float txg5)
void SetFXGain(float fxg0, float fxg1, float fxg2, float fxg3, float fxg4, float fxg5)
#define READ_MATRIX
void setAt(BYTE data, int iNr)
union ATIForceTorqueSensorHWCan::@2 fbBuf
#define CANITFBAUD_250K
void SetGaugeGain(float gg0, float gg1, float gg2, float gg3, float gg4, float gg5)
#define READ_DIAGNOV
#define READ_UNITCODE
bool readDiagnosticADCVoltages(int index, short int &value)
void SetGaugeOffset(float sg0Off, float sg1Off, float sg2Off, float sg3Off, float sg4Off, float sg5Off)
void SetTYGain(float tyg0, float tyg1, float tyg2, float tyg3, float tyg4, float tyg5)
union ATIForceTorqueSensorHWCan::@0 ibBuf
virtual bool init_ret()=0
void setID(int id)
virtual bool receiveMsgRetry(CanMsg *pCMsg, int iNrOfRetry)=0
bool initCommunication(int can_type, std::string can_path, int can_baudrate, int base_identifier)
void SetFZGain(float fzg0, float fzg1, float fzg2, float fzg3, float fzg4, float fzg5)
void set(BYTE Data0=0, BYTE Data1=0, BYTE Data2=0, BYTE Data3=0, BYTE Data4=0, BYTE Data5=0, BYTE Data6=0, BYTE Data7=0)
#define CANITFTYPE_SOCKET_CAN
#define SET_BAUD
#define RESET
int getLength()
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define READ_FIRMWARE
void ReadMatrix(int axis, Eigen::VectorXf &vec)
#define SET_BASEID
#define READ_SG
virtual bool transmitMsg(CanMsg CMsg, bool bBlocking=true)=0
int getAt(int iNr)
void SetTZGain(float tzg0, float tzg1, float tzg2, float tzg3, float tzg4, float tzg5)
#define CANITFTYPE_CAN_PEAK_USB
#define SET_CALIB


ati_force_torque
Author(s): Denis Štogl, Alexander Bubeck
autogenerated on Thu Sep 17 2020 03:18:35