Lab10 Simulator

Setup and use the simulation environment.

Simulator Features and Functionalities

Simulator and Plotter

Simulator is used to control the robot, while the Plotter shows the localization and trajectory. We can use a GUI to start and track the running status of the simulator and plotter.

Once click the "Reset" button, the robot will go back to the [0,0,0] pose and the plotter will clear the previous trajectories. We can also use following functions to do the same.

START_SIM() # Start the simulator
START_PLOTTER() # Start the plotter

STOP_SIM() # Stop the simulator
STOP_PLOTTER() # Stop the plotter

RESET_SIM() # Reset the simulator
RESET_PLOTTER() # Start the plotter

Interactions

In the simulator, we can use mouse and keyboard to send commands. Pressing the up and down arrow keys can increase and decrease the linear velocity of the virtual robot respectively, while left and right arrow keys are used for changing angular velocity. When angular velocity is positive, the virtual robot will rotate clockwise. By hitting spacebar, the robot will stop immediately. The j/j/k/l keys are used to move the simulator view. To zoom in/out, we can scroll the mouse wheel.

In the plotter, we can press the bottons to show or hide the odometry, ground truth, belief, map and distributions. Press the "A" button (bottom-left to the plotting box and above "Plotted Points"), the plot will auto-fit to window.

Commander Class

The Commander class allows to interact with the simulator and the plotter programmatically. Here are the functions.

Open Loop Control

Task: Make the robot follow a set of velocity commands to execute a “square” loop anywhere in the map.

I used cmdr.set_vel(linear_vel, angular_vel) to control the movement of the virtual robot. The robot will go forward at the speed of 0.5 m/s for one second, and then set the angular velocity to be 0.5*pi rad/s and last for anoter one second. Repeat the above movements for four times, we can get a square in theory. I also wrote a function plot_pose() to plot the odemtry and ground truth.

As shown in the figure below, the odometry is not accurate and the robot doesn't always execute the exact same shape. With the open loop control, the square is not perfect. Therefore, closed loop control is necessary.

Here is the demo.

Closed Loop Control

Task: Design a simple controller in your Jupyter notebook to perform a closed-loop obstacle avoidance.

There is a sensor in front of the virtual robot telling the distance to obstacles. As shown in the code below, in the while loop, if the distance is less than 0.5 m, the robot will turn 45 degrees, otherwise, it will go straight at a speed of 1 m/s.

Then I added the forward speed. I tried 3 m/s and 5 m/s and found the chances of hitting the wall increased. Meanwhile, although the threshold distance for turning was same, the virtual robot was likely to stop closer to the walls.

To make it go even faster, I implemented the PID control. The forward speed is (cmdr.get_sensor()-threshold)*KP), with threshold = 0.5, KP=10. The distance threshold of the two videos above were same, but we can see that with the P control, the virtual robot braked more promptly.

From the previous tests, we can tell that the threshold distance should be larger with a higher speed. For example, when the speed is five m/s, the threshold should be 0.5 m or even larger. As for one m/s, 0.25 m is already enough.

Given that the virtual robot is not a point robot and there is just one ToF sensor on the virtual robot, the obstacle avoidance code sometimes fails. There are three major situations, as shown in the figure below: (1) When the angle between the robot's forward direction and wall angle is very small, the left or right side of the robot may hit the wall. (2) When there is another obstacle in the way, but the ToF sensor doesn't detect it. (3) When rotating, the robot hits the wall. To minimize crashes, we can attach two ToF sensors on the left and right front or use a depth sensor with a large field of view.

Posted by Lanyue Fang on Apr 24, 2022