test_fob.cpp
Go to the documentation of this file.
1 
18 #include "ros/ros.h"
19 #include "asr_msgs/AsrObject.h"
20 #include <sensor_msgs/JointState.h>
22 
24 sensor_msgs::JointState joint_state;
25 
28 geometry_msgs::TransformStamped odom_trans;
29 
34 void callback_tf(const asr_msgs::AsrObjectConstPtr& msg)
35 {
36  if (msg->identifier == "tracker_right")
37  {
38  odom_trans.header.stamp = ros::Time::now();
39 
40  if(!msg->sampledPoses.size())
41  {
42  std::cerr << "Got a AsrObject without poses." << std::endl;
43  std::exit(1);
44  }
45 
46  geometry_msgs::Pose current_pose = msg->sampledPoses.front().pose;
47  geometry_msgs::Point position = current_pose.position;
48 
49  odom_trans.transform.translation.x = position.x;
50  odom_trans.transform.translation.y = position.y;
51  odom_trans.transform.translation.z = position.z;
52  odom_trans.transform.rotation = current_pose.orientation;
53 
54  pub_tf->sendTransform(odom_trans);
55 
56  // send 0-pose for hand model
57  joint_state.header.stamp = ros::Time::now();
58  pub_states.publish(joint_state);
59  }
60 }
61 
62 int main(int argc, char **argv)
63 {
64  ros::init(argc, argv, "test_fob");
65  ros::NodeHandle node;
66 
67  sub_tf = node.subscribe("fob_objects", 1, callback_tf);
68  pub_tf = new tf::TransformBroadcaster();
69 
70  odom_trans.header.frame_id = "odom";
71  odom_trans.child_frame_id = "fob_sensor";
72 
73  pub_states = node.advertise<sensor_msgs::JointState>("joint_states", 1);
74 
75  joint_state.name.resize(22);
76  joint_state.position.resize(22);
77 
78  // the names are set accordingly to the names used in the xml model
79  joint_state.name[0] ="wr_j0";
80  joint_state.name[1] ="wr_j1";
81 
82  joint_state.name[2] ="th_j0";
83  joint_state.name[3] ="th_j1";
84  joint_state.name[4] ="th_j2";
85  joint_state.name[5] ="th_j3";
86 
87  joint_state.name[6] ="in_j1";
88  joint_state.name[7] ="in_j0";
89  joint_state.name[8] ="in_j2";
90  joint_state.name[9] ="in_j3";
91 
92  joint_state.name[10] ="mi_j1";
93  joint_state.name[11] ="mi_j0";
94  joint_state.name[12] ="mi_j2";
95  joint_state.name[13] ="mi_j3";
96 
97  joint_state.name[14] ="ri_j1";
98  joint_state.name[15] ="ri_j0";
99  joint_state.name[16] ="ri_j2";
100  joint_state.name[17] ="ri_j3";
101 
102  joint_state.name[18] ="pi_j1";
103  joint_state.name[19] ="pi_j0";
104  joint_state.name[20] ="pi_j2";
105  joint_state.name[21] ="pi_j3";
106 
107  // 0-pose for hand model, since only the asr_flock_of_birds tracker is tested
108  joint_state.position[0] = 0;
109  joint_state.position[1] = 0;
110  joint_state.position[2] = 0;
111  joint_state.position[3] = 0;
112  joint_state.position[4] = 0;
113  joint_state.position[5] = 0;
114  joint_state.position[6] = 0;
115  joint_state.position[7] = 0;
116  joint_state.position[8] = 0;
117  joint_state.position[9] = 0;
118  joint_state.position[10] = 0;
119  joint_state.position[11] = 0;
120  joint_state.position[12] = 0;
121  joint_state.position[13] = 0;
122  joint_state.position[14] = 0;
123  joint_state.position[15] = 0;
124  joint_state.position[16] = 0;
125  joint_state.position[17] = 0;
126  joint_state.position[18] = 0;
127  joint_state.position[19] = 0;
128  joint_state.position[20] = 0;
129  joint_state.position[21] = 0;
130 
131  ros::spin();
132 
133  return 0;
134 }
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char **argv)
Definition: test_fob.cpp:62
tf::TransformBroadcaster * pub_tf
Definition: test_fob.cpp:27
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)
void sendTransform(const StampedTransform &transform)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
sensor_msgs::JointState joint_state
Definition: test_fob.cpp:24
void callback_tf(const asr_msgs::AsrObjectConstPtr &msg)
Definition: test_fob.cpp:34
static Time now()
ros::Subscriber sub_tf
Definition: test_fob.cpp:26
geometry_msgs::TransformStamped odom_trans
Definition: test_fob.cpp:28
ros::Publisher pub_states
Definition: test_fob.cpp:23


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