ati_force_torque_hw_rs485.h
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  * Author: Florian Aumann
9  * Maintainer: Denis Štogl, email: denis.stogl@kit.edu
10  *
11  * Date of creation: October 2018
12  *
13  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are met:
17  *
18  * * Redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer.
20  * * Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in the
22  * documentation and/or other materials provided with the distribution.
23  * * Neither the name of the copyright holder nor the names of its
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * This program is free software: you can redistribute it and/or modify
28  * it under the terms of the GNU Lesser General Public License LGPL as
29  * published by the Free Software Foundation, either version 3 of the
30  * License, or (at your option) any later version.
31  *
32  * This program is distributed in the hope that it will be useful,
33  * but WITHOUT ANY WARRANTY; without even the implied warranty of
34  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35  * GNU Lesser General Public License LGPL for more details.
36  *
37  * You should have received a copy of the GNU Lesser General Public
38  * License LGPL along with this program.
39  * If not, see <http://www.gnu.org/licenses/>.
40  *
41  ****************************************************************/
42 
43 #ifndef ATIForceTorqueSensorHWRS485_INCLUDEDEF_H
44 #define ATIForceTorqueSensorHWRS485_INCLUDEDEF_H
45 // Communication Class for the ATI FT sensor over a FS485 connecting using the modbus protocol
46 // If not specified otherwise, all documentation references in this class refer to:
47 // https://www.ati-ia.com/app_content/documents/9620-05-Digital%20FT.pdf
48 
49 #include <iostream>
50 #include <fstream>
51 #include <Eigen/Core>
52 
53 #include <libmodbus/modbus-rtu.h>
54 #include <ros/time.h>
55 #include <ros/ros.h>
56 #include <mutex>
57 #include <thread>
58 #include <boost/thread.hpp>
59 
61 
62 //Available Modbus Baudrates (As specified in 8.1):
63 #define MODBUSBAUD_1250K 1250000
64 #define MODBUSBAUD_115200 115200
65 #define MODBUSBAUD_19200 19200
66 
68 {
69  FU_POUNDS = 1,
75 };
76 
78 {
85 };
86 
87 const std::string ForceUnitNames[] = {"lb", "N", "kip", "KN", "kp", "gf"};
88 const std::string TorqueUnitNames[] = {"lb-in", "lb-ft", "Nm", "Nmm", "", "KNm"};
89 
90 //Available status words (As specified in 8.4.3):
91 #define ST_WATCHDOG_RESET 1
92 #define ST_EXC_VOLTAGE_HIGH 2
93 #define ST_EXC_VOLTAGE_LOW 4
94 #define ST_ART_ANALOG_GRND_OOR 8
95 #define ST_PWR_HIGH 16
96 #define ST_PWR_LOW 32
97 //-------------------------Bit 6 not used
98 #define ST_EEPROM_ERR 128
99 #define ST_INV_CONF_DATA 256
100 #define ST_STRAIN_GAGE_SUPPLY_HIGH 512
101 #define ST_STRAIN_GAGE_SUPPLY_LOW 1024
102 #define ST_THERMISTOR_HIGH 2048
103 #define ST_THERMISTOR_LOW 4096
104 #define ST_DAC_READING_OOR 8192
105 
106 //Encapsulates all calibration data available from the sensor. Mirrors the data structure specified in 8.4.4.
108 {
109  std::string calibSerialNumber;
111  std::string calibFamilyID;
112  std::string calibTime;
113  float basicMatrix[6][6];
116  float maxRating[6];
117  int32_t countsPerForce;
119  uint16_t gageGain[6];
120  uint16_t gageOffset[6];
121 };
122 
123 //A gage vector containing the ft data from a single sensor response.
125 {
126  int16_t gageData[6];
128 };
129 
131 {
132 public:
137 
144  ATIForceTorqueSensorHWRS485(std::string device_path, int device_baudrate, int base_identifier);
145 
149  virtual ~ATIForceTorqueSensorHWRS485();
150 
156  virtual bool init();
157 
166  virtual bool initCommunication(int type, std::string path, int baudrate, int base_identifier);
167 
174  bool ReadFTCalibrationData(const unsigned int calibrationNumber = 1);
175 
182  bool ReadStatusWord() const;
183 
191  bool SetBaudRate(const int value, const bool setVolatile = true);
192 
197  bool SetSessionID(const uint16_t sessionID);
198 
204  bool ReadSessionID(uint16_t &sessionID) const;
205 
210  bool Reset();
211 
216  bool Close();
217 
221  bool StartStreaming();
222 
226  bool StopStreaming();
227 
238  virtual bool readFTData(int statusCode, double& Fx, double& Fy, double& Fz, double& Tx, double& Ty, double& Tz);
239 
249  bool SetActiveGain(const uint16_t ag0, const uint16_t ag1, const uint16_t ag2, const uint16_t ag3, const uint16_t ag4, const uint16_t ag5) const;
250 
260  bool SetActiveOffset(const uint16_t ao0, const uint16_t ao1, const uint16_t ao2, const uint16_t ao3, const uint16_t ao4, const uint16_t ao5) const;
261 
266  void SetCalibMatrix(const float (&matrix)[6][6]);
267 
278  void StrainGaugeToForce(const int &sg0, const int &sg1, const int &sg2, const int &sg3, const int &sg4, const int &sg5);
279 protected:
284  bool initRS485();
285 
292  bool SetStorageLock(const bool lock) const;
293 
299  bool ReadData();
300  void ReadDataLoop();
301 
302  bool OpenRawConnection();
303 
304  bool ValidateFTData(const uint8_t (&buf)[26]) const;
305 
306  bool SendStopSequence();
307 
308 private:
309  modbus_t* m_modbusCtrl; //Modbus handle to the rs485 port
310  int m_rs485; //Raw handle to the rs485 port
311 
312  std::string m_RS485Device; //Device path of the rs485 device
313  uint8_t m_ModbusBaseIdentifier; //ID number of the sensor, is 0xA by default
314  int m_ModbusBaudrate; //Sensor baudrate, must be set to 1250000, 115200 or 19200
315 
316  Eigen::MatrixXf m_mXCalibMatrix; //6-D Matrix Calibration Matrix, transforms the Raw Gage data into FT values
317  Eigen::MatrixXf m_vForceData; //6-D Vector: Latest Force-Torque values from the sensor
318 
319  bool m_isStreaming = false; //Indicates whether the sensor is streaming ft data and the stream reader thread is running
320 
321  long unsigned int m_bufferTimeout = 10000000;
322  long unsigned int bytesRead;
323 
324  CalibrationData m_calibrationData; //Calibration data object from the sensor. Can be set using ReadFTCalibrationData
325  ros::Time lastValidTimeStamp; //The timestamp of the last valid data package
326  uint8_t streamBuf [26]; //Stream buffer. Contains the latest streaming data from the sensor
328  unsigned int bufferSize = 0; //Contains the size of the current buffer
329 
330  GageVector m_buffer; //Contains the latest reading from the sensor
331  std::mutex m_buffer_mutex; //Mutex used to prevent external data requests from interfering with the reader thread
332  boost::thread m_readThread; //This thread runs in the background and keeps updating the buffer by reading new data from the sensor
333 
334  std::string forceUnitStr; //The current force unit's name
335  std::string torqueUnitStr; //The current torque unit's name
336 
337 };
338 
339 #endif /* ATIForceTorqueSensorHWRS485_INCLUDEDEF_H */
path
const std::string TorqueUnitNames[]
const std::string ForceUnitNames[]
unsigned char uint8_t


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