CS 354 Autonomous Robotics

Fall 2020

Introduction

The goals of this lab are to gain experience working with PID controllers, launch files, and ROS2 parameters.

Resources

Relevant Tutorials:

Source Dependencies

Deliverables

  • Modified version of a rocket-control package that uses PID control to smoothly fly a rocket to a target location. PID gain values will be adjustable through ROS2 parameter settings.
  • Commits by at least two group members.

RocketBot PID Coding

Downloading and Installing Dependencies

  • Pip install the pygame library:

    pip3 install --user pygame
  • Clone the two repositories listed in the Source Dependencies section above into your ~/dev_ws/src folder. Build and source the packages and confirm that rocketbot is running correctly:

    ros2 run rocketbot rocketbot_node 
  • Accept the PID lab assignment invitation posted to Piazza. The repository page for this lab already contains the starter code that you will be using. Clone the repository into your workspace folder:

    cd ~/dev_ws/src
    git clone GIT_URL pid_practice
  • Take a minute to read over the file guidance.py, and the file rocket.launch.py in the launch directory. Make sure you understand the contents of those files. Build and source your workspace.

  • Launch rocket.launch.py in a separate terminal:

    ros2 launch pid_practice rocket.launch.py

    You can change the target altitude by clicking in the RocketBot simulator window. Use the rqt Plot plugin to visualize /target/y and /location/y.

Using a PID Controller and Tuning Parameters

  • Modify guidance.py so that it uses the pid module (provided by the jmu_ros2_util package) to control the y-component of the thrust. You'll need to look over the documentation in pid.py for the details of the API. Here is an example if instantiating a PID object:

    from jmu_ros2_util import pid
    
    # (set up gain values)
    
    pid = pid.PID(p_gain, i_gain, d_gain, i_min, i_max)

    The i_min and i_max arguments place lower and upper bounds on the magnitude of the \(I\) term in the controller. If these aren't set the controller can potentially accumulate a large amount of integral error when it starts a long way from the target value.

  • Experiment with different values for your gain parameters until you find settings that work well. The rocket should rise smoothly to the target altitude with minimal overshoot and oscillations. (I suggest resetting the PID controller when the target location changes. Otherwise the \(D\) term will experience a large transient value that could cause significant overshoot.)

  • Once you are satisfied with your gain values, modify guidance.py so that it reads the PID gain values as parameters, then modify rocket.launch.py to set the parameters appropriately. Test the new launch file. Once everything is working, commit and push your changes. Make sure all members have joined the GitHub group.

PID for Horizontal Control

  • Have SOMEONE ELSE in your group clone your updated repository.

  • Update guidance.py to handle horizontal as well as vertical control. Your finished control node should reliably move the rocket to whatever point the user clicks in the simulator window. Note that you will need to re-factor your solution (both guidance.py and rocket.launch.py) to specify separate gain values for horizontal and vertical control.

  • Commit and push the completed version of your package.