Objectives

This lab will put together everything you have learned so far into one assignment to be completed on a robot. In summary, you will:

  1. Create a GitHub repo for your lab group
  2. Modify the FSM code from your Lab 2.3 submission to work on the robot. You can start fresh or from one of your submissions.
    1. You do NOT need to latch the ESTOP
    2. You need a FAST way to change between modes. Consider a single keypress rather than full words.
    3. You can choose to use the Turtlesim Teleop node we used before or another of the many, many ROS2 teleoperation nodes available. Some allow the use of game controllers (we do not provide these) and other input devices. Consider using this instead: https://index.ros.org/r/teleop_twist_keyboard/
  3. Similar to Objective 2, modify your Lab 3.1 and 3.2 code to work on the robot. The output from 3.2 will be the input to a controller node in Objective 4. Make sure to output the filtered image for debugging purposes.
  4. Use what you learned in Lab 2.2 to implement TWO PID controllers, preferably in the same ROS2 node. One will control the direction and the other the forward speed of the robot. Consider how this appears in a Twist message. You can go back to Lab 1 to experiment. This will output to your FSM code in Objective 2, which will then output to the robot’s hardware interface node (when in Autonomous mode) to move the actual wheels. Your two PID controllers should be used to generate ONE message per image update.

Before Using the Robots

We have limited time this semester to work on the robots, so it is important to get started as soon as possible. Before showing up to class to use the robot, please complete the following:

  1. Understand how the Twist message used on a cmd_vel topic moves a ground robot. Again, use Lab 1 and Turtlesim to get a feel for which number causes which output.
  2. Write code that can nominally complete the above Objectives, once it is tuned and properly connected. You have the individual components, put them together and test them with the provided pingpong ball images BEFORE class. You should see a command telling the robot to go left when the object is on the left side of the screen, forward when the object is small, etc.
  3. Use ROS2 params to make tuning easier. For example, use a param to adjust the high and low end of color thresholding and the k values for your PID controllers. You only need to use one color object. It is your choice what to use.
  4. MAKE SURE YOUR CODE RESPECTS NAMESPACES! Do NOT use absolute topics (starting with a “/”) in your code.

Once you set up your robot (instructions below), you can then focus on the following steps to complete this assignment IN CLASS:

  1. Determine which topic you should subscribe to in order to get an image from the camera and which topic your code should publish to in order to drive the motors.
  2. Verify that your code receives images, that you can control the robot with teleop, and that your FSM can stop the robot quickly if something goes wrong.
  3. Tune the image processing component until it finds the object and not the background.
  4. Tune your turning control such that your robot always points at the object.
  5. Finally, tune your velocity controller such that the robot stays about 10cm away from the object. The exact distance is not important as long as it is consistent and reacts to changes.

When you arrive in class

We have limited time for this modified lab, so please do these steps, in this order, as quickly as possible:

  1. Finish any assembly on your robot
  2. Bring your robot and all group members to the instructor or one of the TAs
    1. Make sure we have your Blackboard group setup properly
    2. Verify your robot boots and is on the network
    3. Register any laptop(s) you wish to use with the robot on the network
  3. Proceed with the robot steps below.

On the robot

  1. If you haven’t already, create a lab repo and add all group members as collaborators
  2. SSH into the robot. Your hostname is on your robot and followed by “.local”. Note that it is ALL LOWEL CASE. So, if your robot says “ABOT-04” then your hostname will be “abot-04.local”
    1. The default username and password for abots is “student” and “student”
    2. The default username for mbots is “mbot” and the password is “i<3robots!”
    3. You probably want to use X-forwarding (-X) so that you can see graphical debugging windows.
    4. For example, on ABOT-4, you would run:
      $ ssh -X student@abot-04.local
  3. Setup SSH keys on the robot as you did on your laptop for Lab 1
  4. Add the SSH keys to one of your GitHub account
  5. There is some errata to complete for each robot.
    1. On the abot: Run the following command on the robot so that your username has the ability to use the serial port. Run this command AS IS, do not change any part!
      $ sudo usermod -a -G dialout $USER

      Now, make sure you have the most recent class code:

      $ cd ~/class_ws/src/alexbot-code
      $ git pull
      $ cd ~/class_ws
      $ source install/setup.bash
      $ colcon build --symlink-install
    2. On the mbot:
      Before we flash the robot, we must put it in flashing mode. To do this, follow these steps:First, ensure that the white/green jumper wires are disconnected from your Pico.
      1. Locate the “BOOTSEL” and “RST” buttons on the board (short for “Boot Select” and “Reset”).
      2. Hold down both “RST” and “BOOTSEL”
      3. Release “RST” then “BOOTSEL” to put the board into flashing mode.Put the robot on the ground with several feet of room in every direction, then run these commands:
      cd ~/mbot_firmware_ros/build
      
      sudo mbot-upload-firmware flash mbot_calibrate_classic.uf2

      Now wait for the robot to stop moving! Then run:

      sudo mbot-upload-firmware flash mbot_classic_ros.uf2
  6. Clone your repo onto the robot in the ros_ws area:
    cd ~/ros_ws/src

    Clone your repo here.

  7. – Build your repo. First, source the class repo (on abot) or mbot repo, then run colcon build in your ros_ws repo.
    1. On abots:
      $ cd ~/ros_ws
      
      $ source ~/class_ws/install/setup.bash
      
      $ colcon build --symlink-install
      
      $ source ~/ros_ws/install/setup.bash
    2. On mbots:
      $ cd ~/ros_ws
      
      $ source ~/mbot_ws/install/setup.bash
      
      $ colcon build --symlink-install
      
      $ source ~/ros_ws/install/setup.bash
  8. FOR ABOTS:
    IMPORTANT NOTE BEFORE RUNNING CODE:
    All robots are on the same network. ROS2 is designed to allow multiple computers/robots to work together. This means ANY command can be sent from ANY computer to ANY robot and vice versa. So, if you publish something to “/cmd_vel” and all robots are listening to “/cmd_vel”, you will move ALL robots! THIS IS WHY WE NEED TO USE NAMESPACES! Any launch file you create should use a namespace with the name of your robot (or something else unique). Any ros2 run command should include a namespace. For example:

    $ ros2 run <package_name> <node_name> --ros-args -r __ns:=/<robot_name>

    FOR MBOTS:
    MBOTs run in a special environment that prevents this problem, but, as a consequence, limits the ability to run on multiple systems. In more complex settings, you will want to use namespaces. For this lab, run using the topics you can see.

  9. Your robot comes with the camera_ros package to publish camera images as ROS2 messages. Start your camera and check out the results using RQT.
    $ ros2 run camera_ros camera_node --ros-args -r __ns:=/<robot_name>
  10. Now you can make the robot move. Start the interface node.
    1. On abot:
      $ ros2 run simple_abot_interface simple_abot_interface -r __ns:=/<robot_name>
    2. On mbot: This SHOULD be running at boot. If not, see the instructor/TAs.
  11. Use ros2 topic list to see what topics are available. Put your robot up on a box so that its wheels are not touching the ground. Send some messages to YOUR ROBOT’S cmd_vel topic and see how the wheels move.
  12. Now you know how to make the robot see and move. Connect it to the code you wrote before class and start tuning!
    Tip: VSCode can connect directly to the robot to edit code onboard. Or you can edit on your computer, push to github, and pull on the robot. Either way, make sure you commit and push all code at the end of class!

Deliverables

  • Demo: By 9:00PM, find the instructor or TA and demonstrate how far you have progressed
  • Submit one PDF as a group to Blackboard:
    • Your group members names
    • Your code repo (MAKE SURE TO PUSH AFTER CLASS)
    • Describe the software you wrote before class:
      • What packages and nodes did you create?
      • How did you intend for them to work?
      • Were you able to do any testing beforehand?
    • Describe your progress in class:
      • How well did your pre-class code work?
      • What did you need to change?
      • How well did you complete the objectives?
    • What would you do differently now that you have been through this process?

Rubric

  • Code written before class: 20 points
  • Effort in class: 40 points
  • Description in PDF: 60 points