The goals of this lab are to gain experience working with PID controllers, launch files, and the ROS parameter server.
$ cd ~/catkin_ws/src $ git clone GIT_URL pid_chase
pid_chase.py
in the
scripts directory, and the file pid_chase.launch
in the
launch directory. Make sure you understand the contents of those
files.
source ~/catkin_ws/devel/setup.bash
.
pid_chase.launch
. Point the robot toward a wall
and run pid_chase.py
. The robot should reach the target
distance, but the process isn't very pretty.
pid_chase.py
so that it reads the PID gain
parameters from the parameter server and uses the PID controller to
set the velocity. (You'll need to modify your script to
use pid_control
instead of bang_control
.)
rosparam
command line utility to set the three
parameters expected by pid_chase.py
to some initial
values and re-execute pid_chase.py
.
Experiment with different values for your gain parameters until you
find settings that work well. You want the Turtlebot to smoothly
approach the target distance then stop at the appropriate point
without excessive oscillations. The p_error
term
should be driven to a value that is very close to 0.
The pid_chase.py
node publishes all three error terms.
You can echo them to a terminal:
rostopic echo /p_erroror you can visualize them using rqt_plot:
rosrun rqt_plot rqt_plot /p_error/data /i_error/data
pid_chase.launch
to set the parameters
appropriately. The launch file XML format is described
on this wiki
page. Test the new launch file. Once everything is working,
commit and push your changes. Make sure all members have joined
the Github group. One weakness of the current version of this code is that the robot makes fast velocity changes when the distance changes: for example, when someone steps in front of the depth sensor. This results in jerky motions that are hard on the robot's motors.
We can force the velocity to change smoothly by taking a weighted average between the previous velocity and the desired velocity:
new_velocity = α × desired_velocity + (1 - α) × previous_velocityValues of α near 1 will lead to fast velocity changes, while values of α near 0 will lead to slow changes in velocity.
pid_chase.py
to implement velocity smoothing.
(You may need to re-tune your PID gain terms. In effect, smoothing
the velocity changes the dynamics of the system that the PID
controller is trying to control.)