Maze project, robot_control_class.py shows error in get_odom

updated code for robot_control_class.py shows error in get_odom

In the course “Python 3 for Robotics” chapter 6 maze, I updated the code for the robot_control_class.py class, which contains the new rotate() method.

VSCode indicates an error in get_odom as shown in below screenshot.

minimal example failing

Running the following minimal example

  • can print output from rc.get_front_laser()
  • gets stuck at rc.rotate(10)

from robot_control_class import RobotControl
rc = RobotControl()
dist_front = rc.get_front_laser()
print(dist_front)
rc.rotate(10)
rc.stop_robot()

terminal output

After about 30s I hit Ctrl+C and get following terminal output:

Traceback (most recent call last): File “move_maze.py”, line 72, in
rc.rotate(10)
File “/home/user/catkin_ws/src/robot_control/robot_control_class.py”, line 195, in rotate
(position, rotation) = self.get_odom()
File “/home/user/catkin_ws/src/robot_control/robot_control_class.py”, line 175, in get_odom
self.tf_listener.waitForTransform(
File “/opt/ros/noetic/lib/python3/dist-packages/tf/listener.py”, line 74, in waitForTransform
can_transform, error_msg = self._buffer.can_transform(strip_leading_slash(target_frame), strip_leading_slash(source_f
rame), time, timeout, return_debug_tuple=True)
File “/opt/ros/noetic/lib/python3/dist-packages/tf2_ros/buffer.py”, line 123, in can_transform
r.sleep()
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/timer.py”, line 103, in sleep
sleep(self._remaining(curr_time))
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/timer.py”, line 165, in sleep
raise rospy.exceptions.ROSInterruptException(“ROS shutdown request”)
rospy.exceptions.ROSInterruptException: ROS shutdown request

did I miss something?

Is there a updated version of robot_control_class.py ?

cc: @albertoezquerro

Any hint how to proceed?

I would love to guide Donatello out of the maze :blush:

Hello @fadri.pestalozzi,

when you hit the keyboard interrupt key (this is, when you hit Ctrl +C ) to a running Python program it will raise a KeyboardInterrupt exception by default. The error messages that you see are not error messages of the program itself but error messages that Python produces because it does not know what to do with the KeyboardInterrupt exception it raised. You can, if you want, just ignore these error messages since they appear only after you close the program. However, if you want to be able to close the program without these error messages showing then you must handle the KeyboardInterrupt exception.

To do so you can put your code inside a try , except block like shown here:

    rc = RobotControl()
    try:
        rc = RobotControl()
        dist_front = rc.get_front_laser()
        print(dist_front)
        rc.rotate(10)
        rc.stop_robot()

    except rospy.ROSInterruptException:
        pass

Hope this helps.

Roberto

Thanks Roberto, this solved my issue :blush:

2 Likes