Error in /opt/ros/melodic/include/ros/ros.h
Hi,
I'm trying to read user input from keyboard, inspired by turtlesim. When I compile I get this error:
In file included from /opt/ros/melodic/include/ros/ros.h:40:0,
from /home/alberto/tiago_dual_public_ws/src/continuos_input/src/key_reader.cpp:1:
/home/alberto/tiago_dual_public_ws/src/continuos_input/src/key_reader.cpp: In member function ‘void key_reader::keyLoop()’:
/opt/ros/melodic/include/ros/console.h:381:3: error: expected ‘;’ before ‘do’
do \
^
/opt/ros/melodic/include/ros/console.h:572:35: note: in expansion of macro ‘ROS_LOG_COND’
#define ROS_LOG(level, name, ...) ROS_LOG_COND(true, level, name, __VA_ARGS__)
^~~~~~~~~~~~
/opt/ros/melodic/include/rosconsole/macros_generated.h:58:24: note: in expansion of macro ‘ROS_LOG’
#define ROS_DEBUG(...) ROS_LOG(::ros::console::levels::Debug, ROSCONSOLE_DEFAULT_NAME, __VA_ARGS__)
^~~~~~~
/home/alberto/tiago_dual_public_ws/src/continuos_input/src/key_reader.cpp:86:17: note: in expansion of macro ‘ROS_DEBUG’
ROS_DEBUG("value: 0x%02X\n", c);
^~~~~~~~~
make[2]: *** [CMakeFiles/key_reader.dir/src/key_reader.cpp.o] Error 1
make[1]: *** [CMakeFiles/key_reader.dir/all] Error 2
make: *** [all] Error 2
cd /home/alberto/tiago_dual_public_ws/build/continuos_input; catkin build --get-env continuos_input | catkin env -si /usr/bin/make --jobserver-fds=6,7 -j; cd -
I don't understand why. It's a read-only file so I cannot modify it. Can someone help me?
This is my complete code:
#include "ros/ros.h"
#include <signal.h>
#include <termios.h>
#include <stdio.h>
#include "continuos_input/input_command.h"
#define KEYCODE_R 0x43
#define KEYCODE_L 0x44
#define KEYCODE_U 0x41
#define KEYCODE_D 0x42
#define KEYCODE_Q 0x71
class key_reader
{
public:
key_reader();
void keyLoop();
private:
ros::NodeHandle nh_;
int direction; //1 if left, -1 if right, 0 no input
ros::Publisher key_pub;
};
int kfd = 0;
struct termios cooked, raw;
key_reader::key_reader()
{
key_pub = nh_.advertise<continuos_input::input_command>("user_input", 1000);
}
void quit(int sig)
{
tcsetattr(kfd, TCSANOW, &cooked);
ros::shutdown();
exit(0);
}
void key_reader::keyLoop()
{
char c;
bool dirty = false;
fd_set set;
struct timeval timeout;
int rv;
// get the console in raw mode
tcgetattr(kfd, &cooked);
memcpy(&raw, &cooked, sizeof(struct termios));
raw.c_lflag &= ~(ICANON | ECHO);
// Setting a new line, then end of file
raw.c_cc[VEOL] = 1;
raw.c_cc[VEOF] = 2;
tcsetattr(kfd, TCSANOW, &raw);
FD_ZERO(&set); /* clear the set */
FD_SET(kfd, &set); /* add our file descriptor to the set */
timeout.tv_sec = 0;
timeout.tv_usec = 10000;
puts("Reading from keyboard");
puts("---------------------------");
puts("Use arrow keys to move the turtle.");
ros::Rate r(10);
while (ros::ok())
{
// get the next event from the keyboard
rv = select(kfd + 1, &set, NULL, NULL, &timeout);
if (rv == -1)
{
perror("select:"); /* an error accured */
exit(-1);
}
else if (rv == 0)
{
printf("Timeout"); /* a timeout occured */
direction = 0;
}
else
{
read(kfd, &c, 1)
ROS_DEBUG("value: 0x%02X\n", c);
switch (c)
{
case KEYCODE_L:
ROS_DEBUG("LEFT");
direction = 1;
dirty = true;
break;
case KEYCODE_R:
ROS_DEBUG("RIGHT");
direction = -1;
dirty = true;
break;
}
r.sleep();
}
}
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "key_reader");
key_reader kr;
signal(SIGINT, quit);
kr.keyLoop();
return (0);
}
I'm sorry to have to do this for something so seemingly unimportant, but please don't post screenshots of terminal text in question on ROS Answers. It's all text, so there is no need. Just copy-paste the text from the terminal into your question text. Do make sure to format it properly by selecting the text and pressing
ctrl+k
(or clicking the Preformatted Text button (the one with101010
on it)).You don't need to post a new question, just edit your curent one. You can use the
edit
button/link for this.After you replace the screenshot with the error message itself, we can re-open your question.
Sorry, I thought it was more readable. Anyway I have update the question, but I can't reopen because >200 points are required. Can you reopen please? Thank you.