Real Robot TurtleBot has some issues with Python and ROS2

Hi The Construct team,

I am working on the course project for ROS2 Basics in 5 Days [both Python and C++].
I have completed my code for both Py and C++ and works well in Simulation.

My C++ code works well in Real Robot - tested 3 times [1 time in consecutive 3 session booking].

My Python program fails terribly (although it does not fail in the simulation).
The problem is specifically in the “FindWall” section of the program.
Here are my steps:

  1. Find the direction of the wall and position facing the wall in the front of the robot and stop - WORKS !
  2. Move close to wall until distance in front is less than 0.3 meters and stop - FAILS !
  3. Align the front-right range facing the wall and stop - FAILS ! [since step 2 failed]

The problem is, in step two, the robot should proceed moving front until distance is less than 0.3 meters and then it should immediately stop when distance < 0.3m.
But the robot keeps continuously moving and does not stop. But somehow, my program succeeds with step two and and three, but the robot has never stopped moving front.
I have checked if the laser scanner is working or not - and it is working fine [the laser scan callback works fine].

For the stop function, initially I published zeros to /cmd_vel just once, but now I am using a for loop for 100 times. Still robot does not stop.

My queue size for publisher and subscriber (qos_profile message depth) is 10 for both.

The python program logic is exactly same as my C++ version and my C++ works successfully.

Could someone look into this issue please?

Thanks in advance.
Girish

PS: If you need my code I can provide it here.

Hi The Construct team,

After testing out my robot with two live sessions, I finally found the solution to this problem.

To be clear, this problem does not happen in the simulation. Happens only on the Real Robot.

So here are some solutions to people who have the same issue:

There are two approaches to fix this: [Either of them can be used, or even combined]

  1. Perform “move to distance” - use the laser scan to get the distance in front of the robot and move to the desired distance using a fixed speed for a fixed time.
  2. Iteratively “move, sleep and stop” - use the laser scanner to get distance in the front and keep moving forwards with the behavior “move, sleep (few millisonds) and stop”. Something like below:
    while (front_distance > 0.3):
      move_front(speed=0.025)   # meters/sec
      sleep(1.0)   # seconds
      stop_robot()
      # read_front_laser_range
    

So, apparently, moving continuously while measuring the front distance simultaneously, does not make the robot stop where it needs to stop.

– Girish

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.