00001
00014
00015 #include <ros/ros.h>
00016
00017
00018 #include <std_msgs/Float64.h>
00019
00020
00021 #include <vector>
00022 #include <string>
00023 #include <sstream>
00024
00025
00026 #include <robot/robot.h>
00027 #include <robot/hand.h>
00028 #include <robot/hand_protocol.h>
00029
00030 #include "sr_hand/sr_tactile_sensor_pub.h"
00031
00032 using namespace ros;
00033 using namespace std;
00034
00035 namespace shadowrobot
00036 {
00038
00040 SRTactileSensorPublisher::SRTactileSensorPublisher() :
00041 n_tilde("~"), publish_rate(0.0)
00042 {
00043
00044 if( robot_init() < 0 )
00045 {
00046 ROS_FATAL("Robot interface broken\n");
00047 ROS_BREAK();
00048 }
00049
00050
00051 if( hand_init() < 0 )
00052 {
00053 ROS_FATAL("Hand interface broken\n");
00054 ROS_BREAK();
00055 }
00056
00057
00058 double publish_freq;
00059 n_tilde.param("publish_frequency", publish_freq, 20.0);
00060 publish_rate = Rate(publish_freq);
00061
00062
00063 std::string prefix;
00064 std::string searched_param;
00065 n_tilde.searchParam("shadowhand_prefix", searched_param);
00066 n_tilde.param(searched_param, prefix, std::string());
00067 std::string full_topic_touch = "touch/";
00068 std::string full_topic_temp = "temp/";
00069 std::vector<std::string> names;
00070 names.push_back("ff");
00071 names.push_back("mf");
00072 names.push_back("rf");
00073 names.push_back("lf");
00074 names.push_back("th");
00075
00076 sensor_touch_names.push_back("FF_Touch");
00077 sensor_touch_names.push_back("MF_Touch");
00078 sensor_touch_names.push_back("RF_Touch");
00079 sensor_touch_names.push_back("LF_Touch");
00080 sensor_touch_names.push_back("TH_Touch");
00081
00082 sensor_temp_names.push_back("FF_Touch_Temp");
00083 sensor_temp_names.push_back("MF_Touch_Temp");
00084 sensor_temp_names.push_back("RF_Touch_Temp");
00085 sensor_temp_names.push_back("LF_Touch_Temp");
00086 sensor_temp_names.push_back("TH_Touch_Temp");
00087
00088 for( unsigned int i=0; i<5; ++i)
00089 {
00090 std::string top_touch = full_topic_touch + names[i];
00091 sr_touch_pubs.push_back(n_tilde.advertise<std_msgs::Float64> (top_touch, 20));
00092
00093 std::string top_temp = full_topic_temp + names[i];
00094 sr_temp_pubs.push_back(n_tilde.advertise<std_msgs::Float64> (top_temp, 20));
00095 }
00096 }
00097
00099
00101 void SRTactileSensorPublisher::publish()
00102 {
00103 std_msgs::Float64 msg_temp;
00104 std_msgs::Float64 msg_touch;
00105
00106
00107 for( unsigned int i = 0; i < sensor_touch_names.size(); ++i )
00108 {
00109 struct sensor s1, s2;
00110 int res1 = robot_name_to_sensor(sensor_touch_names[i].c_str(), &s1);
00111 int res2 = robot_name_to_sensor(sensor_temp_names[i].c_str(), &s2);
00112
00113
00114 if( res1 )
00115 ROS_ERROR("Can't open sensor %s\n", sensor_touch_names[i].c_str());
00116 if( res2 )
00117 ROS_ERROR("Can't open sensor %s\n", sensor_temp_names[i].c_str());
00118
00119 msg_touch.data = robot_read_sensor(&s1);
00120 msg_temp.data = robot_read_sensor(&s2);
00121
00122 sr_touch_pubs[i].publish(msg_touch);
00123 sr_temp_pubs[i].publish(msg_temp);
00124 }
00125
00126 ros::spinOnce();
00127 publish_rate.sleep();
00128 }
00129
00130 }
00131
00132