ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

Why does turtlebot3_teleop behave differently on Windows and Linux?

asked 2022-01-14 17:41:39 -0500

rushik gravatar image

I have ROS Noetic installed on a Windows 10 PC and a Linux (Ubuntu 20.04) PC, both with the turtlebot3_teleop package.

On Windows 10, when I run

roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

and echo the /cmd_vel topic using rostopic echo /cmd_vel, I see no messages. When I press a key, say w, to send out a Twist command, I see a single message:

linear: x: 0.005 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0

On Linux, as soon as I run the roslaunch command, the message

linear: x: 0.005 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0

is repeatedly echoed at around 10 Hz. When I press a key, say w, to send out a Twist command, I see the message

linear: x: 0.005 y: 0.0 z: 0.0 angular: x: 0.0 y: 0.0 z: 0.0

also repeated at around 10 Hz.

Why does the node behave differently on the different operating systems?

edit retag flag offensive close merge delete

Comments

Hi @rushik, can you please explain what installation did you use for Windows 10? Also are you comparing simulations or working with the actual turtlebot3? Finally can you show the steps for launching teleop for Windows10?

osilva gravatar image osilva  ( 2022-01-14 18:28:52 -0500 )edit

Hi @osilva, I am using the ROS Noetic installation instructions from this ROS Wiki page. I am installing Turtlebot3 packages on my Windows 10 PC using the Windows section of this page on the Robotis e-Manual.

I am neither simulating the robot, nor working with the actual robot. I am simply comparing what the turtlebot3_teleop_key node publishes on the cmd_vel topic.

I start the node using roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch. I then listen to what it is publishing using rostopic echo /cmd_vel.

The only two nodes running are turtlebot3_teleop_key and the ROS master. My problem is that on Windows, the turtlebot3_teleop_key node publishes a single message per key press. On Linux, it repeats the messages at 10Hz. I need the Windows behavior to match the Linux behavior.

rushik gravatar image rushik  ( 2022-01-15 19:27:38 -0500 )edit

Thank you @rushik for all these details. I will reproduce this test and see if I can find something and report back. I have both setups as well.

osilva gravatar image osilva  ( 2022-01-15 19:41:09 -0500 )edit

I found the problem, but I am not sure how to fix it. The Windows implementation of the getKey function in the python code is this: if os.name == 'nt': if sys.version_info[0] >= 3: return msvcrt.getch().decode() else: return msvcrt.getch() The problem is that getch() is blocking. So, unless a key is pressed on the keyboard, the execution gets stuck inside getKey and the while loop on line 144 only publishes once per keypress.

The Linux implementation includes a 0.1 second timeout, the windows implementation does not. I tried

rushik gravatar image rushik  ( 2022-01-15 21:49:18 -0500 )edit

You could try to use pyautogui instead.

osilva gravatar image osilva  ( 2022-01-15 23:04:58 -0500 )edit

Thanks for your help! I got it to work by changing a few things!

rushik gravatar image rushik  ( 2022-01-16 00:32:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-01-16 00:31:44 -0500

rushik gravatar image

I got this to work. The Windows implementation of the getKey function in turtlebot3_teleop_key is this:

if os.name == 'nt':
    if sys.version_info[0] >= 3:
        return msvcrt.getch().decode()
    else:
        return msvcrt.getch()

The problem is that getch() is blocking. So, unless a key is pressed on the keyboard, the execution gets stuck inside getKey and the node only publishes one message per keypress instead of one message every 0.1 second like the Linux implementation. The Linux implementation includes a 0.1 second timeout, the windows implementation does not. I added a timeout using:

if os.name == 'nt':
    timeout = 0.1
    startTime = time.time()
    while(1):
        if msvcrt.kbhit():
            if sys.version_info[0] >= 3:
                return msvcrt.getch().decode()
            else:
                return msvcrt.getch()
        elif time.time() - startTime > timeout:
            return ''

That works for the most part, but rosnode init interfears with SIGINT so, we cannot stop the node using Ctrl + c anymore. To fix that, I had to change the while(1) on line 144 of the original file to while not rospy_is_shutdown. Now everything works as expected. See this pull request.

edit flag offensive delete link more

Comments

Great job! Thank you for documenting response

osilva gravatar image osilva  ( 2022-01-16 05:15:17 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2022-01-14 17:41:39 -0500

Seen: 99 times

Last updated: Jan 16 '22