├── include
├── .gitignore
├── ati-force-torque-sensor
│ └── ati_ft_sensor_hw.h
└── FTSensor
│ └── FTSensor.h
├── model
├── meshes
│ └── nano17.stl
├── ft_sensor.gazebo.xacro
├── ft_sensor.urdf.xacro
└── models.urdf.xacro
├── .gitmodules
├── worlds
└── simple_environment.world
├── .gitignore
├── robot
└── nano17.urdf.xacro
├── README.md
├── launch
├── display.launch
├── display_simulation.launch
└── ft_sensor_hw.launch.xml
├── package.xml
├── test
└── simple_reader.cpp
├── CMakeLists.txt
├── src
├── ati_ft_sensor_hw.cpp
├── ati_sensor_node.cpp
├── ft_sensor_hw.cpp
└── FTSensor.cpp
└── LICENSE.txt
/include/.gitignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/model/meshes/nano17.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CentroEPiaggio/force-torque-sensor/HEAD/model/meshes/nano17.stl
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "ATI_FTSensors"]
2 | path = ATI_FTSensors
3 | url = https://github.com/CentroEPiaggio/ATI_FTSensors.git
4 |
--------------------------------------------------------------------------------
/worlds/simple_environment.world:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | model://ground_plane
6 |
7 |
8 | model://sun
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 |
6 | # Compiled Dynamic libraries
7 | *.so
8 | *.dylib
9 |
10 | # Compiled Static libraries
11 | *.lai
12 | *.la
13 | *.a
14 |
15 | # Binary folders
16 | build
17 | Build
18 | BUILD
19 |
20 | # Kdev and QTcreator files
21 | *.kdev_include_paths
22 | *.kdev4
23 | *.user
24 |
--------------------------------------------------------------------------------
/robot/nano17.urdf.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | force-torque-sensor
2 | ===================
3 |
4 | A catkin package to read measurements from any ATI FT sensor via XML.
5 |
6 | To clone the repository:
7 | ```
8 | cd ~/catkin_ws/src
9 | git clone --recursive https://github.com/CentroEPiaggio/force-torque-sensor.git
10 | ```
11 |
12 |
13 | ToDO:
14 | - [ ] Use force-torque-sensor controller from ros_control
15 | - [x] Create an URDF of the sensor to visualize the forces and frames
16 | - [ ] Create plugin to be used in simulation
17 |
--------------------------------------------------------------------------------
/launch/display.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | force_torque_sensor
4 | 0.0.0
5 | The package for FT sensors using the ATInetbox
6 |
7 | Carlos Rosales
8 |
9 | GPLv2
10 |
11 | catkin
12 |
13 | cmake_modules
14 |
15 | roscpp
16 | message_generation
17 | std_msgs
18 | geometry_msgs
19 | hardware_interface
20 | force_torque_sensor_controller
21 |
22 | roscpp
23 | message_generation
24 | std_msgs
25 | geometry_msgs
26 | hardware_interface
27 | force_torque_sensor_controller
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/model/ft_sensor.gazebo.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | true
8 |
9 |
10 |
11 | true
12 |
13 |
14 |
15 | true
16 |
17 |
18 |
19 |
20 |
21 | 1000.0
22 | ${parent}_${name}/ft_sensor_topic
23 | ${parent}_${name}_measure_joint
24 |
25 | gaussian
26 | 0.0
27 | 0.003
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/launch/display_simulation.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/include/ati-force-torque-sensor/ati_ft_sensor_hw.h:
--------------------------------------------------------------------------------
1 | #ifndef ATI_FT_SENSOR_HW_H_
2 | #define ATI_FT_SENSOR_HW_H_
3 |
4 | // ROS headers
5 | #include
6 | #include
7 | #include
8 |
9 |
10 | // ROS controls
11 | #include
12 | #include
13 |
14 | namespace ati_hw
15 | {
16 |
17 | class ATIHW : public hardware_interface::ForceTorqueSensorInterface
18 | {
19 | public:
20 |
21 | ATIHW() {}
22 | virtual ~ATIHW() {}
23 |
24 | // void create(std::string name, std::string urdf_string);
25 | bool init(ros::NodeHandle n, std::string sensor_name, std::string frame_id, std::string ip, bool startDataStream=false);
26 | void updateReadings();
27 | double getNormalizeWrench();
28 | // Strings
29 | std::string robot_namespace_;
30 |
31 | private:
32 | FTSensors::ATI::NetFT ati_sensor;
33 | double ati_force_[3];
34 | double ati_torque_[3];
35 | double max_force[3];
36 | double max_torque[3];
37 | bool calibrate(std_srvs::Empty::Request& req, std_srvs::Empty::Response& res);
38 | ros::ServiceServer srv_calibrate;
39 |
40 | }; // class
41 |
42 | } // namespace
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/test/simple_reader.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // FTSensor class definition
5 | #include "FTSensor/FTSensor.h"
6 |
7 | int main(int argc, char **argv)
8 | {
9 | // The sensor object
10 | FTSensor* ftsensor;
11 |
12 | // Create a new sensor
13 | ftsensor = new FTSensor();
14 |
15 | // ip of the FT sensor, change if necessary
16 | // TODO make the ip an argument
17 | std::string ip = "192.168.0.201";
18 | char* IP = new char[ip.size() + 1];
19 | std::copy(ip.begin(), ip.end(), IP);
20 | IP[ip.size()] = '\0'; // don't forget the terminating 0
21 |
22 | // Set ip of FT Sensor
23 | ftsensor->setIP( IP );
24 |
25 | // don't forget to free the char after finished using it
26 | delete[] IP;
27 |
28 | // Init FT Sensor
29 | ftsensor->init();
30 |
31 | // Set bias
32 | ftsensor->setBias();
33 |
34 | // The variable where the measurements are saved
35 | float measurements[6];
36 |
37 | // Loop to read and printout the values
38 | while(1)
39 | {
40 | ftsensor->getMeasurements(measurements);
41 | cout << "Fx: " << measurements[0] << "Fy: " << measurements[1] << "Fz: " << measurements[2]
42 | << "Tx: " << measurements[3] << "Ty: " << measurements[4] << "Tz: " << measurements[5]
43 | << endl;
44 | }
45 | return 0;
46 | }
--------------------------------------------------------------------------------
/model/ft_sensor.urdf.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.8.3)
2 | project(force_torque_sensor)
3 |
4 | if (CMAKE_VERSION VERSION_LESS "3.1")
5 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
6 | else()
7 | set(CMAKE_CXX_STANDARD 11)
8 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
9 | endif()
10 |
11 | find_package(cmake_modules REQUIRED)
12 |
13 | find_package(LibXml2 REQUIRED)
14 | find_package(Eigen REQUIRED)
15 | find_package(catkin REQUIRED COMPONENTS
16 | roscpp
17 | message_generation
18 | std_msgs
19 | geometry_msgs
20 | hardware_interface
21 | force_torque_sensor_controller
22 | cmake_modules
23 | )
24 |
25 | catkin_package()
26 |
27 |
28 | include_directories(include
29 | ${LIBXML2_INCLUDE_DIR}
30 | ${catkin_INCLUDE_DIRS}
31 | ${EIGEN_INCLUDE_DIR}
32 | ATI_FTSensors/include
33 | )
34 |
35 | add_library(FTSensor
36 | src/FTSensor.cpp
37 | )
38 |
39 | add_executable(ft_sensor_hw
40 | src/ft_sensor_hw.cpp
41 | )
42 |
43 | add_dependencies(ft_sensor_hw
44 | FTSensor
45 | )
46 |
47 | target_link_libraries(ft_sensor_hw
48 | FTSensor
49 | ${LIBXML2_LIBRARIES}
50 | ${catkin_LIBRARIES}
51 | ${EIGEN_LIBRARIES}
52 | )
53 |
54 | add_subdirectory(ATI_FTSensors)
55 |
56 | add_executable(ati_sensor_node src/ati_sensor_node.cpp src/ati_ft_sensor_hw.cpp)
57 | add_dependencies(ati_sensor_node FTSensors)
58 | target_link_libraries(ati_sensor_node FTSensors ${catkin_LIBRARIES} ${EIGEN_LIBRARIES})
59 | # target_link_libraries(ati_sensor_node /home/manuelb/manuelb_ws/devel/lib/libFTSensors.so ${catkin_LIBRARIES})
60 |
--------------------------------------------------------------------------------
/launch/ft_sensor_hw.launch.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/include/FTSensor/FTSensor.h:
--------------------------------------------------------------------------------
1 | // standard and socket related libraries
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | // XML related libraries
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | using namespace std;
19 |
20 | #define PORT 49152
21 | #define COMMAND 1 // 0 for check comm, doesn't send any request, 1 to ask for the values
22 | #define NUM_SAMPLES 1
23 | #define PI 3.141592653589793
24 |
25 | // Structure for the sensor response
26 | typedef struct response_struct {
27 | unsigned int rdt_sequence;
28 | unsigned int ft_sequence;
29 | unsigned int status;
30 | int FTData[6];
31 | } RESPONSE;
32 |
33 |
34 | class FTSensor{
35 | public:
36 | // Socket info
37 | char ip_[15];
38 | int socketHandle_;
39 | struct sockaddr_in addr_;
40 | struct hostent *hePtr_;
41 |
42 | // Sensor parameters
43 | double counts_per_force_ ;
44 | double counts_per_torque_;
45 |
46 | // Communication protocol
47 | RESPONSE resp_;
48 | char request_[8];
49 | char response_[36];
50 |
51 | // Constructor
52 | FTSensor();
53 | ~FTSensor();
54 |
55 | // Initialization, reading parameters from XML files, etc..
56 | void init();
57 |
58 | // GET functions
59 | // Read elements from XML file
60 | void getElementNames(xmlNode * a_node);
61 | // Read parameters
62 | double getCountsperForce(){return counts_per_force_;};
63 | double getCountsperTorque(){return counts_per_torque_;};
64 | // Read sensor values
65 | void getMeasurements(float measurements[6]);
66 |
67 | // SET functions
68 | // Write the ip of the sensor
69 | void setIP(char *ip_in);
70 | // Set the zero of the sensor
71 | void setBias();
72 | };
73 |
--------------------------------------------------------------------------------
/model/models.urdf.xacro:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/src/ati_ft_sensor_hw.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #define DEBUG 2
4 |
5 | namespace ati_hw {
6 |
7 | bool ATIHW::init(ros::NodeHandle n, std::string sensor_name, std::string frame_id, std::string ip, bool startDataStream)
8 | {
9 | bool is_ok = true;
10 | this->registerHandle(hardware_interface::ForceTorqueSensorHandle(sensor_name, frame_id, ati_force_, ati_torque_));
11 | is_ok &= ati_sensor.setIP(ip);
12 | is_ok &= ati_sensor.setFilterFrequency(FTSensors::ATI::FilterFrequency::FILTER_838_HZ);
13 | is_ok &= ati_sensor.setForceUnit(FTSensors::ATI::ForceUnit::N);
14 | is_ok &= ati_sensor.setTorqueUnit(FTSensors::ATI::TorqueUnit::Nm);
15 | is_ok &= ati_sensor.setDataRate(1000);
16 | is_ok &= ati_sensor.startDataStream(startDataStream); //Originally was true<
17 | is_ok &= ati_sensor.getForceSensingRange(max_force[0], max_force[1], max_force[2]);
18 | is_ok &= ati_sensor.getTorqueSensingRange(max_torque[0], max_torque[1], max_torque[2]);
19 |
20 | srv_calibrate = n.advertiseService("calibrate",\
21 | &ATIHW::calibrate, \
22 | this);
23 |
24 | #if DEBUG>1
25 | std::cout << "Sensing Range Fx: " << max_force[0] << ". Fy: " << max_force[1] << ". Fz: "<< max_force[2]
26 | << " Tx: " << max_torque[0] << ". Ty: " << max_torque[1] << ". Tz: "<< max_torque[2] << std::endl;
27 | #endif
28 |
29 | return is_ok;
30 |
31 | }
32 |
33 | void ATIHW::updateReadings()
34 | {
35 | double fx, fy, fz, tx, ty, tz;
36 | if(ati_sensor.getData(fx, fy, fz, tx, ty, tz))
37 | {
38 | ati_force_[0] = fx;
39 | ati_force_[1] = fy;
40 | ati_force_[2] = fz;
41 | ati_torque_[0] = tx;
42 | ati_torque_[1] = ty;
43 | ati_torque_[2] = tz;
44 | }
45 | }
46 |
47 | double ATIHW::getNormalizeWrench()
48 | {
49 | double norm = 0;
50 | norm = std::sqrt(ati_force_[0]*ati_force_[0]/(max_force[0]*max_force[0]) +
51 | ati_force_[1]*ati_force_[1]/(max_force[1]*max_force[1]) +
52 | ati_force_[2]*ati_force_[2]/(max_force[2]*max_force[2]) +
53 | ati_torque_[0]*ati_torque_[0]/(max_torque[0]*max_torque[0]) +
54 | ati_torque_[1]*ati_torque_[1]/(max_torque[1]*max_torque[1]) +
55 | ati_torque_[2]*ati_torque_[2]/(max_torque[2]*max_torque[2]));
56 | return norm;
57 |
58 | }
59 |
60 | bool ATIHW::calibrate(std_srvs::Empty::Request& req,\
61 | std_srvs::Empty::Response& res)
62 | {
63 | ati_sensor.calibration();
64 | return true;
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/ati_sensor_node.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | // ROS headers
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #define CLASS_LOGNAME "ati_sensor_node"
11 |
12 | int main( int argc, char** argv )
13 | {
14 | // initialize ROS
15 | ros::init(argc, argv, "ati_ft_sensor_hw_interface");
16 |
17 | // ros spinner
18 | ros::AsyncSpinner spinner(1);
19 | spinner.start();
20 |
21 | // create a node
22 | ros::NodeHandle ati_sensor_nh("~");
23 | ati_hw::ATIHW ati_sensor_hw;
24 |
25 | // get params or give default values
26 | std::string name, ip, frame_id, safety_topic;
27 | double rate;
28 | double wrench_threshold;
29 | bool startDataStream(false);
30 |
31 | ati_sensor_nh.param("name", name, std::string("ati_sensor"));
32 | ati_sensor_nh.param("ip", ip, std::string("192.168.1.101") );
33 | ati_sensor_nh.param("frame_id", frame_id, std::string("sensor_frame_id"));
34 | ati_sensor_nh.param("publish_rate", rate, 500.0);
35 | ati_sensor_nh.param("safety_threshold",wrench_threshold, 0.5);
36 | ati_sensor_nh.param("safety_topic",safety_topic, std::string("emergency_event"));
37 | ati_sensor_nh.param("startDataStream",startDataStream, false);
38 |
39 | ROS_DEBUG_STREAM_NAMED(CLASS_LOGNAME, CLASS_LOGNAME << " - name: " << name);
40 | ROS_DEBUG_STREAM_NAMED(CLASS_LOGNAME, CLASS_LOGNAME << " - ip: " << ip);
41 | ROS_DEBUG_STREAM_NAMED(CLASS_LOGNAME, CLASS_LOGNAME << " - frame_id: " << frame_id);
42 | ROS_DEBUG_STREAM_NAMED(CLASS_LOGNAME, CLASS_LOGNAME << " - publish_rate: " << rate);
43 | ROS_DEBUG_STREAM_NAMED(CLASS_LOGNAME, CLASS_LOGNAME << " - safety_threshold: " <(safety_topic,1);
47 |
48 | if(!ati_sensor_hw.init(ati_sensor_nh, name, frame_id, ip, startDataStream))
49 | {
50 | ROS_FATAL_NAMED("ati_sensor_hw","Could not initialize sensor");
51 | return -1;
52 | }
53 |
54 | // timer variables
55 | struct timespec ts = {0, 0};
56 | ros::Time last(ts.tv_sec, ts.tv_nsec), now(ts.tv_sec, ts.tv_nsec);
57 | ros::Duration period(1.0), time_offset(0.0);
58 | if (!clock_gettime(CLOCK_MONOTONIC, &ts))
59 | {
60 | time_offset = ros::Time::now() - ros::Time(ts.tv_sec,ts.tv_nsec);
61 | }
62 | else
63 | {
64 | return -1;
65 | }
66 |
67 | //the controller manager
68 | force_torque_sensor_controller::ForceTorqueSensorController manager;
69 | manager.init(&ati_sensor_hw, ati_sensor_nh, ati_sensor_nh);
70 |
71 | bool started_manager(false);
72 |
73 | // run as fast as the robot interface, or as fast as possible
74 | ros::Rate ros_rate(rate);
75 | while( ros::ok() )
76 | {
77 | // get the time / period
78 | if (!clock_gettime(CLOCK_MONOTONIC, &ts))
79 | {
80 | now.sec = ts.tv_sec;
81 | now.nsec = ts.tv_nsec;
82 | now += time_offset;
83 | period = now - last;
84 | last = now;
85 | }
86 | else
87 | {
88 | ROS_FATAL_STREAM_NAMED(CLASS_LOGNAME,"Failed to poll realtime clock!");
89 | break;
90 | }
91 |
92 | if(!started_manager)
93 | {
94 | manager.starting(now);
95 | started_manager = true;
96 | }
97 |
98 | // read the state from the sensor
99 | ati_sensor_hw.updateReadings();
100 | if(ati_sensor_hw.getNormalizeWrench() > wrench_threshold)
101 | {
102 | std_msgs::Bool emergency_event_msg;
103 | emergency_event_msg.data = true;
104 | emergency_event_pub.publish(emergency_event_msg);
105 | }
106 |
107 | manager.update(now, period);
108 | ros_rate.sleep();
109 | }
110 |
111 | spinner.stop();
112 |
113 | return 0;
114 | }
115 |
--------------------------------------------------------------------------------
/src/ft_sensor_hw.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include
6 |
7 | // FTSensor class definition
8 | #include "FTSensor/FTSensor.h"
9 |
10 | namespace ftsensor {
11 |
12 | class FTSensorHW
13 | {
14 | private:
15 | //! The node handle
16 | ros::NodeHandle nh_;
17 | //! Node handle in the private namespace
18 | ros::NodeHandle priv_nh_;
19 |
20 | //! The sensor
21 | FTSensor* ftsensor_;
22 | std::string ip_;
23 | std::string name_;
24 | std::string type_;
25 |
26 | //! Publisher for sensor readings
27 | ros::Publisher pub_sensor_readings_;
28 |
29 | //! Service for setting the bias
30 | ros::ServiceServer srv_set_bias_;
31 |
32 | public:
33 | //------------------ Callbacks -------------------
34 | // Callback for setting bias
35 | bool setBiasCallback(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response);
36 |
37 | // Publish the measurements
38 | void publishMeasurements();
39 |
40 | //! Subscribes to and advertises topics
41 | FTSensorHW(ros::NodeHandle nh) : nh_(nh), priv_nh_("~")
42 | {
43 |
44 | priv_nh_.param("name", name_, "my_sensor");
45 | priv_nh_.param("type", type_, "nano17");
46 | priv_nh_.param("ip", ip_, "192.168.0.100");
47 |
48 | char* ip = new char[ip_.size() + 1];
49 | std::copy(ip_.begin(), ip_.end(), ip);
50 | ip[ip_.size()] = '\0'; // don't forget the terminating 0
51 |
52 | ROS_INFO("FT Sensor config:");
53 | ROS_INFO_STREAM("ip: " << ip);
54 | ROS_INFO_STREAM("name: " << name_);
55 | ROS_INFO_STREAM("type: " << type_);
56 |
57 | // Create a new sensor
58 | ftsensor_ = new FTSensor();
59 | // Set ip of FT Sensor
60 | ftsensor_->setIP(ip);
61 | // don't forget to free the string after finished using it
62 | delete[] ip;
63 |
64 | // Init FT Sensor
65 | ftsensor_->init();
66 | // Set bias
67 | ftsensor_->setBias();
68 |
69 | // Advertise topic where readings are published
70 | pub_sensor_readings_ = nh_.advertise(nh_.resolveName("sensor_measurements"), 10);
71 |
72 | // Advertise service for setting the bias
73 | srv_set_bias_ = nh_.advertiseService(nh_.resolveName("tare"), &FTSensorHW::setBiasCallback, this);
74 | }
75 |
76 | //! Empty stub
77 | ~FTSensorHW() {}
78 |
79 | };
80 |
81 | // ToDo: setBias and Tare are different things
82 | // setBias(A B C D E F) to set an external bias manually
83 | // Tare() it set the bias such that all sensor_measurements are zero
84 | bool FTSensorHW::setBiasCallback(std_srvs::Empty::Request &request, std_srvs::Empty::Response &response)
85 | {
86 | ftsensor_->setBias();
87 |
88 | return true;
89 | }
90 |
91 | void FTSensorHW::publishMeasurements()
92 | {
93 | geometry_msgs::WrenchStamped ftreadings;
94 | float measurements[6];
95 | ftsensor_->getMeasurements(measurements);
96 |
97 | ftreadings.wrench.force.x = measurements[0];
98 | ftreadings.wrench.force.y = measurements[1];
99 | ftreadings.wrench.force.z = measurements[2];
100 | ftreadings.wrench.torque.x = measurements[3];
101 | ftreadings.wrench.torque.y = measurements[4];
102 | ftreadings.wrench.torque.z = measurements[5];
103 |
104 | ftreadings.header.stamp = ros::Time::now();
105 | ftreadings.header.frame_id = name_ + "_" + type_ + "_" + "measure";
106 |
107 | pub_sensor_readings_.publish(ftreadings);
108 | }
109 |
110 | } // namespace ftsensor
111 |
112 | int main(int argc, char **argv)
113 | {
114 | ros::init(argc, argv, "ft_sensor_hw");
115 | ros::NodeHandle nh;
116 | ros::Rate loop(100);
117 | ftsensor::FTSensorHW node(nh);
118 |
119 | while(ros::ok())
120 | {
121 | node.publishMeasurements();
122 | ros::spinOnce();
123 |
124 | loop.sleep();
125 | }
126 | return 0;
127 | }
--------------------------------------------------------------------------------
/src/FTSensor.cpp:
--------------------------------------------------------------------------------
1 | // This program is free software; you can redistribute it and/or
2 | // modify it under the terms of the GNU General Public License
3 | // as published by the Free Software Foundation; either version 2
4 | // of the License, or (at your option) any later version.
5 |
6 | // This program is distributed in the hope that it will be useful,
7 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
8 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 | // GNU General Public License for more details.
10 |
11 | // You should have received a copy of the GNU General Public License
12 | // along with this program; if not, write to the Free Software
13 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14 | // Also add information on how to contact you by electronic and paper mail.
15 |
16 | // Research Center "E. Piaggio"
17 | // This file implements the FTSensor class usable with sensors using the ATI Netbox via xml parsing
18 | // Authors: Manuel Bonilla, Carlos Rosales
19 |
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | #include "FTSensor/FTSensor.h"
26 |
27 | // Class constructor, empty for now
28 | FTSensor::FTSensor()
29 | {
30 |
31 | }
32 |
33 | FTSensor::~FTSensor()
34 | {
35 |
36 | }
37 |
38 | // Initialization read from XML file
39 | void FTSensor::init()
40 | {
41 |
42 | // create the socket
43 | socketHandle_ = socket(AF_INET, SOCK_DGRAM, 0);
44 | if (socketHandle_ == -1) {
45 | printf("failed to ini sensor");
46 | }
47 |
48 | // parse the configuration
49 | xmlDoc *doc = NULL;
50 | xmlNode *root_element = NULL;
51 | char Filename[100];
52 | sprintf(Filename, "http://%s/netftapi2.xml?index=15", ip_);
53 |
54 | doc = xmlReadFile(Filename, NULL, 0);
55 |
56 | if (doc == NULL) {
57 | printf("error: could not parse file %s\n", Filename);
58 | }
59 | else {
60 | root_element = xmlDocGetRootElement(doc);
61 | getElementNames(root_element);
62 | xmlFreeDoc(doc);
63 | }
64 |
65 | xmlCleanupParser();
66 |
67 | // set the socket parameters
68 | hePtr_ = gethostbyname(ip_);
69 | memcpy(&addr_.sin_addr, hePtr_->h_addr_list[0], hePtr_->h_length);
70 | addr_.sin_family = AF_INET;
71 | addr_.sin_port = htons(PORT);
72 |
73 | // connect
74 | int err = connect( socketHandle_, (struct sockaddr *)&addr_, sizeof(addr_) );
75 | if (err == -1) {
76 | printf("Error to conect with sensor");
77 | return;
78 | }
79 |
80 | }
81 |
82 | void FTSensor::getElementNames(xmlNode * a_node)
83 | {
84 | xmlNode *cur_node = NULL;
85 | xmlNode *cur_node_temp = NULL;
86 | int i=0;
87 | char parameter_text[40];
88 | char parameter_comp[40];
89 | for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
90 | if (cur_node->type == XML_ELEMENT_NODE) {
91 | sprintf(parameter_comp, "%s", cur_node->name);
92 | if(!strcmp(parameter_comp, "cfgcpf")){
93 | cur_node_temp=cur_node->children;
94 | sprintf(parameter_text, "%s", cur_node_temp->content);
95 | counts_per_force_ =(double)atoi(parameter_text);
96 | //counts_per_torque_ =(double)1000000.0;
97 | continue;
98 | }
99 | if(!strcmp(parameter_comp, "cfgcpt")){
100 | cur_node_temp=cur_node->children;
101 | sprintf(parameter_text, "%s", cur_node_temp->content);
102 | counts_per_torque_ =(double)atoi(parameter_text);
103 | //counts_per_torque_ =(double)1000000000.0;
104 | continue;
105 | }
106 | }
107 | getElementNames(cur_node->children);
108 | }
109 | return ;
110 | }
111 |
112 | void FTSensor::getMeasurements(float measurements[6])
113 | {
114 | // set the standard request
115 | *(short*)&request_[0] = htons(0x1234); /* standard header. */
116 | *(short*)&request_[2] = htons(COMMAND); /* per table 9.1 in Net F/T user manual. */
117 | *(unsigned int*)&request_[4] = htonl(NUM_SAMPLES); /* see section 9.1 in Net F/T user manual. */
118 |
119 | send( socketHandle_, request_, 8, 0 );
120 | recv( socketHandle_, response_, 36, 0 );
121 |
122 | resp_.rdt_sequence = ntohl(*(unsigned int*)&response_[0]);
123 | resp_.ft_sequence = ntohl(*(unsigned int*)&response_[4]);
124 | resp_.status = ntohl(*(unsigned int*)&response_[8]);
125 | int i;
126 | for( i = 0; i < 6; i++ ) {
127 | resp_.FTData[i] = ntohl(*(unsigned int*)&response_[12 + i * 4]);
128 | if (i<3)
129 | measurements[i]=(float) resp_.FTData[i]/(float) counts_per_force_;
130 | else
131 | measurements[i]=(float) resp_.FTData[i]/(float) counts_per_torque_;
132 | }
133 |
134 | return;
135 | }
136 |
137 | void FTSensor::setIP(char *ip_in)
138 | {
139 | sprintf(ip_, "%s",ip_in);
140 | }
141 |
142 | void FTSensor::setBias()
143 | {
144 |
145 | char Filename[300];
146 |
147 | *(short*)&request_[0] = htons(0x1234);
148 | *(short*)&request_[2] = htons(0x0042);
149 | *(unsigned int*)&request_[4] = htonl(NUM_SAMPLES);
150 |
151 | hePtr_ = gethostbyname(ip_);
152 | memcpy(&addr_.sin_addr, hePtr_->h_addr_list[0], hePtr_->h_length);
153 | addr_.sin_family = AF_INET;
154 | addr_.sin_port = htons(PORT);
155 |
156 | int err = connect( socketHandle_, (struct sockaddr *)&addr_, sizeof(addr_) );
157 | if (err == -1) {
158 | printf("Error to conect with sensor");
159 | return;
160 | }
161 | send( socketHandle_, request_, 8, 0 );
162 |
163 | return;
164 | }
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 |
3 | Version 2, June 1991
4 |
5 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.
6 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
7 |
8 | Everyone is permitted to copy and distribute verbatim copies
9 | of this license document, but changing it is not allowed.
10 | Preamble
11 |
12 | The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
13 |
14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
15 |
16 | To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
17 |
18 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
19 |
20 | We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
21 |
22 | Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
23 |
24 | Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
25 |
26 | The precise terms and conditions for copying, distribution and modification follow.
27 |
28 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
29 |
30 | 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
31 |
32 | Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
33 |
34 | 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
35 |
36 | You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
37 |
38 | 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
39 |
40 | a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
41 | b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
42 | c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
43 | These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
44 |
45 | Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
46 |
47 | In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
48 |
49 | 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
50 |
51 | a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
52 | b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
53 | c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
54 | The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
55 |
56 | If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
57 |
58 | 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
59 |
60 | 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
61 |
62 | 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
63 |
64 | 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
65 |
66 | If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
67 |
68 | It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
69 |
70 | This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
71 |
72 | 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
73 |
74 | 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
75 |
76 | Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
77 |
78 | 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
79 |
80 | NO WARRANTY
81 |
82 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
83 |
84 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
85 |
86 | END OF TERMS AND CONDITIONS
--------------------------------------------------------------------------------