Skip to content

Bonus Task

Time to Shine Brighter

The battlefield needs a steady patrol route — and you are in charge of programming it. Your mission is to make the Turtlesim turtle navigate in a perfect square, using a ROS 2 subscriber node to follow goal points published by our command node.

You will:

  • Create your own ROS 2 workspace
  • Build a package containing both a goal publisher (given) and your goal follower (to be implemented)
  • Command the turtle to move from point to point using proportional control
  • Executable Provided:
    goal_publisher.py — Publishes four goal points (square vertices) on the /goal topic. The next goal is published only after the turtle reaches the current one.

  • Your Task: Implement go_to_goal.py that:

    • Subscribes to /goal to receive the next goal position (geometry_msgs/msg/Point)
    • Moves the turtle toward the goal using proportional control (linear & angular velocities)
    • Publishes the turtle’s current pose to /turtle1/goal_status when the goal is reached
  • Node Functionality:

    • Continuously receive and move to each goal until the square path is complete
    • Use /turtle1/cmd_vel to send velocity commands
    • Use /turtle1/pose to read the turtle’s current position
  • Create Workspace Open a terminal and create a new ROS 2 workspace named hb_ws:

    Terminal window
    mkdir -p ~/hb_ws/src
    cd ~/hb_ws/src
  • Create Python Package Inside hb_ws/src, create a new package named bonus_task:

    Terminal window
    ros2 pkg create --build-type ament_python bonus_task

    This will generate the basic package structure.

  • Add Python Files Inside the bonus_task/bonus_task/ directory:

    • Download the files from here.
    • Extract the downloaded file and place it inside the bonus_task folder. Kindly check the package structure mentioned below to avoid any confusion
    • Ensure there’s an init.py file (can be empty)
    • Add:
      • goal_publisher.py (provided by us)
      • go_to_goal.py- Complete your script go_to_goal.py and then run it to draw the square as given in the picture below.

    Your package structure should look like this:

    Terminal window
    hb_ws/
    └── src/
    └── bonus_task/
    ├── bonus_task/
    ├── __init__.py
    ├── goal_publisher.py
    └── go_to_goal.py
    ├── package.xml
    ├── setup.cfg
    └── setup.py
  • Edit setup.py To run both files with ros2 run, edit the setup.py so it contains:

    Terminal window
    entry_points={
    'console_scripts': [
    'goal_publisher = bonus_task.goal_publisher:main',
    'go_to_goal = bonus_task.go_to_goal:main',
    ],
    },

    Replace main with the actual function name that starts your node in each file.

  • Build the Workspace From the root of your workspace:

    Terminal window
    cd ~/hb_ws
    colcon build

    Source the workspace:

    Terminal window
    source install/setup.bash
  • Run the Simulation
    • Start Turtlesim

      Terminal window
      ros2 run turtlesim turtlesim_node
    • Run Goal Publisher in a new terminal:

      Terminal window
      cd ~/hb_ws
      source install/setup.bash
      ros2 run bonus_task goal_publisher
    • Run Your Subscriber in another terminal:

      Terminal window
      cd ~/hb_ws
      source install/setup.bash
      ros2 run bonus_task go_to_goal
The expected square patrol path traced by the turtle.