key_commands.cpp
Go to the documentation of this file.
1 #include <memory.h>
2 #include <ros/ros.h>
3 #include <signal.h>
4 #include <std_msgs/Char.h>
5 #include <stdio.h>
6 #include <termios.h>
7 #include <unistd.h>
8 
10 int kfd = 0;
11 struct termios cooked, raw;
12 
13 void quit(int sig)
14 {
15  (void)sig;
16  tcsetattr(kfd, TCSANOW, &cooked);
17  ros::shutdown();
18  exit(0);
19 }
20 
21 void keyLoop()
22 {
23  char c;
24 
25  // get the console in raw mode
26  tcgetattr(kfd, &cooked);
27  memcpy(&raw, &cooked, sizeof(struct termios));
28  raw.c_lflag &= ~(ICANON | ECHO);
29  // Setting a new line, then end of file
30  raw.c_cc[VEOL] = 1;
31  raw.c_cc[VEOF] = 2;
32  tcsetattr(kfd, TCSANOW, &raw);
33 
34  puts("Reading from keyboard");
35  puts("---------------------------");
36 
37  std_msgs::Char char_msg;
38 
39  for (;;)
40  {
41  // get the next event from the keyboard
42  if (::read(kfd, &c, 1) < 0)
43  {
44  perror("read():");
45  exit(-1);
46  }
47 
48  char_msg.data = c;
49  cmd_pub.publish(char_msg);
50  }
51 
52  return;
53 }
54 
55 int main(int argc, char** argv)
56 {
57  ros::init(argc, argv, "teleop_turtle");
58 
59  ros::NodeHandle nh;
60 
61  cmd_pub = nh.advertise<std_msgs::Char>("track_cmd", 1);
62 
63  signal(SIGINT, quit);
64 
65  keyLoop();
66 
67  return (0);
68 }
void publish(const boost::shared_ptr< M > &message) const
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void quit(int sig)
struct termios cooked raw
ros::Publisher cmd_pub
Definition: key_commands.cpp:9
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void keyLoop()
ROSCPP_DECL void shutdown()
int kfd


vtec_tracker
Author(s):
autogenerated on Sat Dec 7 2019 03:17:05