Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00043 #include <string.h>
00044 #include <stdio.h>
00045
00046 #include "ros/ros.h"
00047 #include "std_msgs/String.h"
00048 #include "robotiq_force_torque_sensor/rq_sensor_state.h"
00049 #include "robotiq_force_torque_sensor/ft_sensor.h"
00050 #include "robotiq_force_torque_sensor/sensor_accessor.h"
00051
00052 static void decode_message_and_do(INT_8 const * const buff, INT_8 * const ret);
00053 static void wait_for_other_connection(void);
00054
00055 ros::Publisher sensor_pub_acc;
00056
00062 static void decode_message_and_do(INT_8 const * const buff, INT_8 * const ret)
00063 {
00064 INT_8 get_or_set[3];
00065 INT_8 nom_var[4];
00066
00067 if(buff == NULL || strlen(buff) != 7)
00068 {
00069 return;
00070 }
00071
00072 strncpy(get_or_set, &buff[0], 3);
00073 strncpy(nom_var, &buff[4], strlen(buff) -3);
00074
00075 if(strstr(get_or_set, "GET"))
00076 {
00077 rq_state_get_command(nom_var, ret);
00078 }
00079 else if(strstr(get_or_set, "SET"))
00080 {
00081 if(strstr(nom_var, "ZRO"))
00082 {
00083 rq_state_do_zero_force_flag();
00084 strcpy(ret,"Done");
00085 }
00086 }
00087 }
00088
00089 bool receiverCallback(robotiq_force_torque_sensor::sensor_accessor::Request& req,
00090 robotiq_force_torque_sensor::sensor_accessor::Response& res)
00091 {
00092 ROS_INFO("I heard: [%s]",req.command.c_str());
00093 INT_8 buffer[512];
00094 decode_message_and_do((char*)req.command.c_str(), buffer);
00095 res.res = buffer;
00096 ROS_INFO("I send: [%s]", res.res.c_str());
00097 return true;
00098 }
00099
00104 static void wait_for_other_connection(void)
00105 {
00106 INT_8 ret;
00107
00108 while(1)
00109 {
00110 usleep(1000000);
00111 ret = rq_sensor_state();
00112
00113 if(ret == 0)
00114 {
00115 break;
00116 }
00117 ros::spinOnce();
00118 }
00119 }
00120
00126 static robotiq_force_torque_sensor::ft_sensor get_data(void)
00127 {
00128 robotiq_force_torque_sensor::ft_sensor msgStream;
00129
00130 msgStream.Fx = rq_state_get_received_data(0);
00131 msgStream.Fy = rq_state_get_received_data(1);
00132 msgStream.Fz = rq_state_get_received_data(2);
00133 msgStream.Mx = rq_state_get_received_data(3);
00134 msgStream.My = rq_state_get_received_data(4);
00135 msgStream.Mz = rq_state_get_received_data(5);
00136
00137 return msgStream;
00138 }
00139
00140 int main(int argc, char **argv)
00141 {
00142 ros::init(argc, argv, "robotiq_force_torque_sensor");
00143
00144 INT_8 bufStream[512];
00145 robotiq_force_torque_sensor::ft_sensor msgStream;
00146 ros::NodeHandle n;
00147 INT_8 ret;
00148
00149
00150
00151 ret = rq_sensor_state();
00152 if(ret == -1)
00153 {
00154 wait_for_other_connection();
00155 }
00156
00157
00158 ret = rq_sensor_state();
00159 if(ret == -1)
00160 {
00161 wait_for_other_connection();
00162 }
00163
00164
00165 ret = rq_sensor_state();
00166 if(ret == -1)
00167 {
00168 wait_for_other_connection();
00169 }
00170
00171 ros::Publisher sensor_pub = n.advertise<robotiq_force_torque_sensor::ft_sensor>("robotiq_force_torque_sensor", 512);
00172 ros::ServiceServer service = n.advertiseService("robotiq_force_torque_sensor_acc", receiverCallback);
00173
00174
00175
00176 while(1)
00177 {
00178 ret = rq_sensor_state();
00179
00180 if(ret == -1)
00181 {
00182 wait_for_other_connection();
00183 }
00184
00185 if(rq_sensor_get_current_state() == RQ_STATE_RUN)
00186 {
00187 strcpy(bufStream,"");
00188 msgStream = get_data();
00189
00190 if(rq_state_got_new_message())
00191 {
00192 sensor_pub.publish(msgStream);
00193 }
00194 }
00195
00196 ros::spinOnce();
00197 }
00198 return 0;
00199 }