Go to the documentation of this file.00001
00029
00030 #include <ros/ros.h>
00031
00032
00033 #include <string>
00034
00035 #include <unistd.h>
00036 #include <math.h>
00037
00038
00039 #include "sr_remappers/shadowhand_to_cybergrasp_remapper.h"
00040
00041 using namespace ros;
00042
00043 namespace shadowhand_to_cybergrasp_remapper{
00044
00045 ShadowhandToCybergraspRemapper::ShadowhandToCybergraspRemapper()
00046 : n_tilde("~"), publish_rate(0.0)
00047 {
00048 std::string searched_param;
00049
00050
00051 std::string path;
00052 n_tilde.searchParam("cybergrasp_calibration_path", searched_param);
00053 n_tilde.param(searched_param, path, std::string());
00054
00055 calibration_parser = new CalibrationParser(path);
00056
00057
00058 std::string prefix;
00059 n_tilde.searchParam("cybergrasp_prefix", searched_param);
00060 n_tilde.param(searched_param, prefix, std::string());
00061 std::string full_topic = prefix + "cybergraspforces";
00062
00063 shadowhand_cybergrasp_pub = node.advertise<cybergrasp::cybergraspforces>(full_topic, 20);
00064
00065
00066 n_tilde.searchParam("joint_states_prefix", searched_param);
00067 n_tilde.param(searched_param, prefix, std::string());
00068
00069 full_topic = prefix + "joint_states";
00070
00071 shadowhand_jointstates_sub = node.subscribe(full_topic, 10, &ShadowhandToCybergraspRemapper::jointstatesCallback, this);
00072
00073 }
00074
00075 ShadowhandToCybergraspRemapper::~ShadowhandToCybergraspRemapper()
00076 {
00077 if( calibration_parser )
00078 delete calibration_parser;
00079 }
00080
00087 void ShadowhandToCybergraspRemapper::jointstatesCallback(const sensor_msgs::JointStateConstPtr& msg)
00088 {
00089
00090 cybergrasp::cybergraspforces cybergrasp_msg;
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 double average = 0.0;
00119
00120 for( unsigned int i=0; i < msg->effort.size(); ++i)
00121 {
00122 average = msg->effort[i]*10.0;
00123 }
00124
00125 average /= msg->effort.size();
00126
00127 average /= msg->effort.size();
00128 average *= 1000.0;
00129
00130 for( unsigned int i=0; i < 5; ++i)
00131 {
00132 cybergrasp_msg.forces[i] = 0.01;
00133 }
00134
00135
00136 cybergrasp_msg.forces[1] = (average - 0.016)*2.0;
00137
00138 shadowhand_cybergrasp_pub.publish(cybergrasp_msg);
00139
00140
00141
00142 }
00143 }