Hi i use docker container to develop in ros2 humble environment While I was converting the open manipulator pick and place to ros2 humble in the container, I wrote the same code from the existing ros1 kinetic.
It's this part.
bool OMExample::kbhit()
{
termios term;
tcgetattr(0, &term);
termios term2 = term;
term2.c_lflag &= ~ICANON;
tcsetattr(0, TCSANOW, &term2);
int byteswaiting;
ioctl(0, FIONREAD, &byteswaiting);
tcsetattr(0, TCSANOW, &term);
printf("byteswaiting: %d\n", byteswaiting);
return byteswaiting > 0;
}
This function returns Boolean value by checking whether a key has been pressed on the original keyboard, but it doesn't respond even if I keep pressing the key. Also, the value of 'byteswaiting' in the middle of printf also appears as 0.
Just in case, I'll leave a command when I run a docker container
sudo docker run --privileged -v /home/irasc-eunsung/humble_openmanipulator_4dof:/root/home -v /dev:/dev -it --network host --ipc host --pid host --volume /tmp/.X11-unix:/tmp/.X11-unix:ro -e DISPLAY=unix$DISPLAY --name humble_openmanipulator_4dof --gpus all irasc/ros:humble-turtlebot3-desktop
bool OMExample::kbhit()
{
pollfd fds;
fds.fd = STDIN_FILENO; // Standard input
fds.events = POLLIN; // There is data to read
// Check if input is available without waiting
bool key_was_pressed = poll(&fds, 1, 0) > 0;
// Print out the bool value
std::cout << std::boolalpha << key_was_pressed << std::endl;
return key_was_pressed;
}
i tried in this way,too. but nothing change.