test_glove_fob.cpp
Go to the documentation of this file.
1 
18 #include "ros/ros.h"
19 #include "asr_msgs/AsrGlove.h"
20 #include "asr_msgs/AsrObject.h"
21 #include <sensor_msgs/JointState.h>
23 
26 sensor_msgs::JointState joint_state;
27 
30 geometry_msgs::TransformStamped odom_trans;
31 
36 void callback(const asr_msgs::AsrGloveConstPtr& msg)
37 {
38  joint_state.header.stamp = ros::Time::now();
39 
40  // wrist: not needed because used in combination with asr_flock_of_birds
41  joint_state.position[0] = 0;
42  joint_state.position[1] = 0;
43 
44  // some values are manually adjusted since its difficult to calibrate
45  // TODO: correct mapping of thumb joints
46  joint_state.position[2] = 0.17;
47  joint_state.position[3] = 0.02;
48  joint_state.position[4] = 0.17;
49  joint_state.position[5] = msg->data[5];
50 
51  joint_state.position[6] = msg->data[6];
52  joint_state.position[7] = msg->data[7];
53  joint_state.position[8] = msg->data[8];
54  joint_state.position[9] = msg->data[9] * (-1);
55 
56  joint_state.position[10] = msg->data[10] - 0.1;
57  joint_state.position[11] = msg->data[11];
58  joint_state.position[12] = msg->data[12];
59  joint_state.position[13] = msg->data[13] - 0.5;
60 
61  joint_state.position[14] = msg->data[14];
62  joint_state.position[15] = msg->data[15] - 0.15;
63  joint_state.position[16] = msg->data[16];
64  joint_state.position[17] = msg->data[17] - 0.5;
65 
66  joint_state.position[18] = msg->data[18] - 0.3;
67  joint_state.position[19] = msg->data[19] - 0.3;
68  joint_state.position[20] = msg->data[20];
69  joint_state.position[21] = msg->data[21] * (-1) + 0.1;
70 
71  pub_states.publish(joint_state);
72 }
73 
78 void callback_tf(const asr_msgs::AsrObjectConstPtr& msg)
79 {
80  if (msg->identifier == "tracker_right")
81  {
82  odom_trans.header.stamp = ros::Time::now();
83 
84  if(!msg->sampledPoses.size())
85  {
86  std::cerr << "Got a AsrObject without poses." << std::endl;
87  std::exit(1);
88  }
89 
90  geometry_msgs::Pose current_pose = msg->sampledPoses.front().pose;
91  geometry_msgs::Point position = current_pose.position;
92 
93  odom_trans.transform.translation.x = position.x;
94  odom_trans.transform.translation.y = position.y;
95  odom_trans.transform.translation.z = position.z;
96  odom_trans.transform.rotation = current_pose.orientation;
97 
98  pub_tf->sendTransform(odom_trans);
99  }
100 }
101 
102 int main(int argc, char **argv)
103 {
104  ros::init(argc, argv, "test_glove_fob");
105  ros::NodeHandle node;
106 
107  sub_states = node.subscribe("rightGloveData_radian", 1, callback);
108  pub_states = node.advertise<sensor_msgs::JointState>("joint_states", 1);
109 
110  sub_tf = node.subscribe("fob_objects", 1, callback_tf);
111  pub_tf = new tf::TransformBroadcaster();
112 
113  joint_state.name.resize(22);
114  joint_state.position.resize(22);
115 
116  // the names are set accordingly to the names used in the xml model
117  joint_state.name[0] ="wr_j0";
118  joint_state.name[1] ="wr_j1";
119 
120  joint_state.name[2] ="th_j0";
121  joint_state.name[3] ="th_j1";
122  joint_state.name[4] ="th_j2";
123  joint_state.name[5] ="th_j3";
124 
125  joint_state.name[6] ="in_j1";
126  joint_state.name[7] ="in_j0";
127  joint_state.name[8] ="in_j2";
128  joint_state.name[9] ="in_j3";
129 
130  joint_state.name[10] ="mi_j1";
131  joint_state.name[11] ="mi_j0";
132  joint_state.name[12] ="mi_j2";
133  joint_state.name[13] ="mi_j3";
134 
135  joint_state.name[14] ="ri_j1";
136  joint_state.name[15] ="ri_j0";
137  joint_state.name[16] ="ri_j2";
138  joint_state.name[17] ="ri_j3";
139 
140  joint_state.name[18] ="pi_j1";
141  joint_state.name[19] ="pi_j0";
142  joint_state.name[20] ="pi_j2";
143  joint_state.name[21] ="pi_j3";
144 
145  odom_trans.header.frame_id = "odom";
146  odom_trans.child_frame_id = "fob_sensor";
147 
148  ros::spin();
149 
150  return 0;
151 }
void publish(const boost::shared_ptr< M > &message) const
sensor_msgs::JointState joint_state
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL void spin(Spinner &spinner)
ros::Subscriber sub_states
void sendTransform(const StampedTransform &transform)
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ros::Subscriber sub_tf
ros::Publisher pub_states
static Time now()
tf::TransformBroadcaster * pub_tf
void callback(const asr_msgs::AsrGloveConstPtr &msg)
geometry_msgs::TransformStamped odom_trans
void callback_tf(const asr_msgs::AsrObjectConstPtr &msg)


asr_cyberglove_visualization
Author(s): Heller Florian, Jäkel Rainer, Kasper Alexander, Meißner Pascal, Nguyen Trung, Yi Xie
autogenerated on Mon Jun 10 2019 12:43:22