This project simulates a robot moving in a 2D space using ROS 2. It consists of two main nodes:
- Robot Node: Handles the robot's movement, position, and kinematics in the simulated environment.
- Battery Node: Simulates the robot's battery, including energy consumption, charging, and status reporting.
- ROS 2 Components: Both nodes are implemented as composable components for modularity.
- Action Servers/Clients: Used for long-running tasks such as moving to a target position and charging the battery. For the battery while chargin the server check constantly the position of the robot if it is in the charging base
- Service Servers/Clients: For checking and requesting energy from the battery node.
- Parameter Event Handlers: Dynamic parameter updates (e.g., robot base position, physical parameters) at runtime.
- TF2: For managing and broadcasting coordinate transforms between the robot and world frames.
- Timers: Periodic publishing of robot and battery status.
This project uses ROS 2 Jazzy and can be run in a Docker container for easy setup.
docker build -t robot_simple:v01 .Open two terminals and run the following:
docker run --rm -it --tag robot_simple robot_simple:v01In a second terminal, attach to the running container and use send ROS2 CLI commands.
First attach to the container a new terminal:
docker exec -it robot_simple bashOnce inside the container, initalize the bash:
source ./install/setup.bashyou can move the robot using:
ros2 action send_goal /move_to_target robot_interfaces/action/MoveToTarget "{target_position_x: 20.0, target_position_y: 0.0}"- Terminal 1 is for monitoring the ROS 2 logger output in real time (using ros2 log echo).
- Terminal 2 is for sending actions to move the robot.
You can open more terminals with docker exec -it robot_simple bash to interact with the running container.
- Make sure your host user has permission to access Docker.
- The
--network hostoption is used for ROS 2 discovery. If you are on Mac/Windows, you may need to adjust networking. - The workspace is mounted with
-v $(pwd)/src:/workspace/srcfor live code editing.
MIT License
Michele Di Lecce
michele.dilecce@hotmail.com