keyboard_float_generator.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
36 
37 #include <cstdio>
38 #include <ros/ros.h>
39 #include <std_msgs/Float64.h>
40 
41 #include <unistd.h>
42 #include <termios.h>
43 
44 int main(int argc, char** argv)
45 {
46  // Setup terminal settings for getchar
47  const int fd = fileno(stdin);
48  termios prev_flags ;
49  tcgetattr(fd, &prev_flags) ;
50  termios flags ;
51  tcgetattr(fd,&flags);
52  flags.c_lflag &= ~ICANON; // set raw (unset canonical modes)
53  flags.c_cc[VMIN] = 0; // i.e. min 1 char for blocking, 0 chars for non-blocking
54  flags.c_cc[VTIME] = 0; // block if waiting for char
55  tcsetattr(fd,TCSANOW,&flags);
56 
57  ros::init(argc, argv, "keyboard_float_generator");
58 
59  ros::NodeHandle nh;
60 
61  ros::Publisher pub = nh.advertise<std_msgs::Float64>("keyboard_float", 10);
62 
63  const double increment = .01;
64 
65  ROS_INFO("Press '=' to increment, and '-' to decrement");
66 
67  std_msgs::Float64 shift_val;
68  shift_val.data = 0.0;
69  while (nh.ok())
70  {
71  char c = getchar();
72 
73  bool should_publish = false;
74 
75 
76  switch (c)
77  {
78  case '=': shift_val.data += increment; should_publish = true; break;
79  case '+': shift_val.data += increment; should_publish = true; break;
80  case '-': shift_val.data -= increment; should_publish = true; break;
81  default:
82  usleep(100);
83  break;
84  }
85 
86  if (should_publish)
87  {
88  ROS_INFO("Publishing Float: % .3f", shift_val.data);
89  pub.publish(shift_val);
90  }
91  }
92 
93  tcsetattr(fd,TCSANOW, &prev_flags) ; // Undo any terminal changes that we made
94 
95  return 0;
96 }
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_INFO(...)
int main(int argc, char **argv)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
bool ok() const


laser_joint_projector
Author(s): Vijay Pradeep
autogenerated on Tue Jun 1 2021 02:50:56