bag_tagger.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
39 #include <ros/ros.h>
40 #include <std_msgs/Header.h>
41 #include <tf/transform_listener.h>
42 
43 #include <signal.h>
44 #include <termios.h>
45 #include <stdio.h>
46 #include <cstdlib>
47 
48 #define KEYCODE_R 0x43
49 #define KEYCODE_L 0x44
50 #define KEYCODE_U 0x41
51 #define KEYCODE_D 0x42
52 #define KEYCODE_Q 0x71
53 #define KEYCODE_E 0x65
54 
55 
56 class Teleop
57 {
58 public:
59  Teleop();
60  void keyLoop();
61 
62 private:
63 
64  ros::NodeHandle nodehandle;
65  ros::Publisher tag_pub_;
66  ros::Subscriber bag_sub_;
67  std_msgs::Header header;
68  void bagCallback(const tf::tfMessage& msg);
69 };
70 
71 
73 {
74  tag_pub_ = nodehandle.advertise<std_msgs::Header>("/timetag", 1);
75  bag_sub_ = nodehandle.subscribe("/tf", 1000, &Teleop::bagCallback, this);
76 }
77 
78 int kfd = 0;
79 struct termios cooked, raw;
80 
81 void quit(int sig)
82 {
83  tcsetattr(kfd, TCSANOW, &cooked);
84  ros::shutdown();
85  exit(0);
86 }
87 
88 
89 int main(int argc, char** argv)
90 {
91  ros::init(argc, argv, "keycapture");
92  Teleop teleop_turtle;
93 
94  signal(SIGINT,quit);
95 
96  ros::Rate loop_rate(10);
97 
98  while (ros::ok())
99  {
100  teleop_turtle.keyLoop();
101  ros::spinOnce();
102  loop_rate.sleep();
103  }
104 
105  return(0);
106 }
107 
108 
110 {
111  char c;
112  bool dirty=false;
113 
114  // get the console in raw mode
115  tcgetattr(kfd, &cooked);
116  memcpy(&raw, &cooked, sizeof(struct termios));
117  raw.c_lflag &=~ (ICANON | ECHO);
118 
119  // Setting a new line, then end of file
120  raw.c_cc[VEOL] = 1;
121  raw.c_cc[VEOF] = 2;
122  tcsetattr(kfd, TCSANOW, &raw);
123 
124  puts("---------------------------");
125  puts("Use arrow keys to generate tag!");
126 
127  // get the next event from the keyboard
128  if(read(kfd, &c, 1) < 0)
129  {
130  perror("read():");
131  exit(-1);
132  }
133 
134  ROS_DEBUG("value: 0x%02X\n", c);
135 
136  switch(c)
137  {
138  case KEYCODE_L:
139  ROS_DEBUG("LEFT");
140  ROS_INFO("left");
141  dirty = true;
142  break;
143  case KEYCODE_R:
144  ROS_DEBUG("RIGHT");
145  ROS_INFO("right");
146  dirty = true;
147  break;
148  case KEYCODE_U:
149  ROS_DEBUG("UP");
150  ROS_INFO("up");
151  dirty = true;
152  break;
153  case KEYCODE_D:
154  ROS_DEBUG("DOWN");
155  ROS_INFO("down");
156  dirty = true;
157  break;
158  case KEYCODE_Q:
159  ROS_DEBUG("NEG PHI");
160  ROS_INFO("neg phi");
161  dirty = true;
162  break;
163  case KEYCODE_E:
164  ROS_DEBUG("POS PHI");
165  ROS_INFO("pos phi");
166  dirty = true;
167  break;
168  }
169 
170  if(dirty ==true)
171  {
172  ROS_INFO("time:%f",header.stamp.toSec());
173  tag_pub_.publish(header);
174  dirty=false;
175  }
176 
177  return;
178 }
179 
180 void Teleop::bagCallback(const tf::tfMessage& msg)
181 {
182  header.stamp = msg.transforms[0].header.stamp;
183  return;
184 }
185 
#define KEYCODE_E
Definition: bag_tagger.cpp:53
int main(int argc, char **argv)
Definition: bag_tagger.cpp:89
void quit(int sig)
Definition: bag_tagger.cpp:81
struct termios cooked raw
Definition: bag_tagger.cpp:79
void keyLoop()
Definition: bag_tagger.cpp:109
ros::NodeHandle nodehandle
Definition: bag_tagger.cpp:64
#define KEYCODE_U
Definition: bag_tagger.cpp:50
#define KEYCODE_R
Tag good/bad leader in bag files.
Definition: bag_tagger.cpp:48
ros::Subscriber bag_sub_
Definition: bag_tagger.cpp:66
#define KEYCODE_Q
Definition: bag_tagger.cpp:52
int kfd
Definition: bag_tagger.cpp:78
#define KEYCODE_D
Definition: bag_tagger.cpp:51
ros::Publisher tag_pub_
Definition: bag_tagger.cpp:65
void bagCallback(const tf::tfMessage &msg)
Definition: bag_tagger.cpp:180
#define KEYCODE_L
Definition: bag_tagger.cpp:49
std_msgs::Header header
Definition: bag_tagger.cpp:67


human_leader
Author(s): Procopio Stein
autogenerated on Mon Mar 2 2015 01:31:41