test_glove_fob.cpp
Go to the documentation of this file.
00001 
00018 #include "ros/ros.h"
00019 #include "asr_msgs/AsrGlove.h"
00020 #include "asr_msgs/AsrObject.h"
00021 #include <sensor_msgs/JointState.h>
00022 #include <tf/transform_broadcaster.h>
00023 
00024 ros::Subscriber sub_states;
00025 ros::Publisher pub_states;
00026 sensor_msgs::JointState joint_state;
00027 
00028 ros::Subscriber sub_tf;
00029 tf::TransformBroadcaster *pub_tf;
00030 geometry_msgs::TransformStamped odom_trans;
00031 
00036 void callback(const asr_msgs::AsrGloveConstPtr& msg)
00037 {
00038     joint_state.header.stamp = ros::Time::now();
00039 
00040     // wrist: not needed because used in combination with asr_flock_of_birds
00041     joint_state.position[0] = 0;
00042     joint_state.position[1] = 0;
00043 
00044     // some values are manually adjusted since its difficult to calibrate
00045     // TODO: correct mapping of thumb joints
00046     joint_state.position[2] = 0.17;
00047     joint_state.position[3] = 0.02;
00048     joint_state.position[4] = 0.17;
00049     joint_state.position[5] = msg->data[5];
00050 
00051     joint_state.position[6] = msg->data[6];
00052     joint_state.position[7] = msg->data[7];
00053     joint_state.position[8] = msg->data[8];
00054     joint_state.position[9] = msg->data[9] * (-1);
00055 
00056     joint_state.position[10] = msg->data[10] - 0.1;
00057     joint_state.position[11] = msg->data[11];
00058     joint_state.position[12] = msg->data[12];
00059     joint_state.position[13] = msg->data[13] - 0.5;
00060 
00061     joint_state.position[14] = msg->data[14];
00062     joint_state.position[15] = msg->data[15] - 0.15;
00063     joint_state.position[16] = msg->data[16];
00064     joint_state.position[17] = msg->data[17] - 0.5;
00065 
00066     joint_state.position[18] = msg->data[18] - 0.3;
00067     joint_state.position[19] = msg->data[19] - 0.3;
00068     joint_state.position[20] = msg->data[20];
00069     joint_state.position[21] = msg->data[21] * (-1) + 0.1;
00070 
00071     pub_states.publish(joint_state);
00072 }
00073 
00078 void callback_tf(const asr_msgs::AsrObjectConstPtr& msg)
00079 {
00080     if (msg->identifier == "tracker_right")
00081     {
00082         odom_trans.header.stamp = ros::Time::now();
00083 
00084         if(!msg->sampledPoses.size())
00085         {
00086             std::cerr << "Got a AsrObject without poses." << std::endl;
00087             std::exit(1);
00088         }
00089 
00090         geometry_msgs::Pose current_pose = msg->sampledPoses.front().pose;
00091         geometry_msgs::Point position = current_pose.position;
00092 
00093         odom_trans.transform.translation.x = position.x;
00094         odom_trans.transform.translation.y = position.y;
00095         odom_trans.transform.translation.z = position.z;
00096         odom_trans.transform.rotation = current_pose.orientation;
00097 
00098         pub_tf->sendTransform(odom_trans);
00099     }
00100 }
00101 
00102 int main(int argc, char **argv)
00103 {
00104     ros::init(argc, argv, "test_glove_fob");
00105     ros::NodeHandle node;
00106 
00107     sub_states = node.subscribe("rightGloveData_radian", 1, callback);
00108     pub_states = node.advertise<sensor_msgs::JointState>("joint_states", 1);
00109 
00110     sub_tf = node.subscribe("fob_objects", 1, callback_tf);
00111     pub_tf = new tf::TransformBroadcaster();
00112 
00113     joint_state.name.resize(22);
00114     joint_state.position.resize(22);
00115 
00116     // the names are set accordingly to the names used in the xml model
00117     joint_state.name[0] ="wr_j0";
00118     joint_state.name[1] ="wr_j1";
00119 
00120     joint_state.name[2] ="th_j0";
00121     joint_state.name[3] ="th_j1";
00122     joint_state.name[4] ="th_j2";
00123     joint_state.name[5] ="th_j3";
00124 
00125     joint_state.name[6] ="in_j1";
00126     joint_state.name[7] ="in_j0";
00127     joint_state.name[8] ="in_j2";
00128     joint_state.name[9] ="in_j3";
00129 
00130     joint_state.name[10] ="mi_j1";
00131     joint_state.name[11] ="mi_j0";
00132     joint_state.name[12] ="mi_j2";
00133     joint_state.name[13] ="mi_j3";
00134 
00135     joint_state.name[14] ="ri_j1";
00136     joint_state.name[15] ="ri_j0";
00137     joint_state.name[16] ="ri_j2";
00138     joint_state.name[17] ="ri_j3";
00139 
00140     joint_state.name[18] ="pi_j1";
00141     joint_state.name[19] ="pi_j0";
00142     joint_state.name[20] ="pi_j2";
00143     joint_state.name[21] ="pi_j3";
00144 
00145     odom_trans.header.frame_id = "odom";
00146     odom_trans.child_frame_id = "fob_sensor";
00147 
00148     ros::spin();
00149 
00150     return 0;
00151 }


asr_cyberglove_visualization
Author(s): Heller Florian, Jäkel Rainer, Kasper Alexander, Meißner Pascal, Nguyen Trung, Yi Xie
autogenerated on Thu Jun 6 2019 18:29:01