A ROS 2 node that controls robot movement through WebSocket commands, designed to work with micro-ROS enabled robots.
This system consists of three main components:
- A ROS 2 movement controller node that accepts WebSocket commands
- A micro-ROS agent that bridges communication with the robot
- A Docker setup for easy deployment
The movement controller accepts distance and angle commands via WebSocket, converts them into appropriate velocity commands, and publishes them to the robot through ROS 2 topics.
- Docker Desktop for Mac
- Git
- Terminal access
- Clone this repository:
git clone <repository-url>
cd movement-node- Run the setup script:
./setup.shThis will:
- Set up the necessary ROS 2 workspace
- Start the movement controller container
- Start the micro-ROS agent container
-
Movement Controller Node
- Listens for WebSocket commands on port 9090
- Publishes to ROS 2 topics:
rcm/cmd_vel(geometry_msgs/Twist): Robot velocity commandsrcm/enabled(std_msgs/Bool): Robot enable status
-
micro-ROS Agent
- Runs on UDP port 8888
- Bridges communication between ROS 2 and the micro-ROS enabled robot
The WebSocket server accepts JSON messages in the following format:
{
"distance": float, // Distance to move in meters
"angle": float // Angle to turn in degrees
}Response format:
{
"status": string, // "ok", "busy", or "error"
"message": string // Status description
}- Run the setup script:
./setup.sh- Attach to the movement controller container:
docker attach ros2_movement- Inside the container, build and run the node:
source /opt/ros/iron/setup.bash
cd /ros2_ws && colcon build
source /ros2_ws/install/setup.bash
ros2 run movement_controller movement_controllerYou can send movement commands using any WebSocket client. Example using Python:
import websockets
import asyncio
import json
async def send_movement():
uri = "ws://localhost:9090"
async with websockets.connect(uri) as websocket:
# Move forward 1 meter and turn 90 degrees
command = {
"distance": 1.0,
"angle": 90.0
}
await websocket.send(json.dumps(command))
response = await websocket.recv()
print(response)
asyncio.run(send_movement())- Linear velocity: 0.3 m/s
- Angular velocity: 0.5 rad/s
- Movement sequence:
- Wait period (2 seconds)
- Rotation to target angle
- Buffer period (1 second)
- Forward movement to target distance
- Stop
For micro-ROS agent logs:
docker logs micro-ros-agentFor movement controller logs:
docker logs ros2_movementTo stop all containers:
docker compose down && docker stop micro-ros-agentTo detach from the container without stopping it:
- Press: Ctrl+P, Ctrl+Q
To reattach to the container:
docker attach ros2_movement-
WebSocket Connection Issues
- Ensure port 9090 is not in use by another application
- Check the movement controller logs for connection errors
-
Robot Communication Issues
- Verify the micro-ROS agent is running (
docker logs micro-ros-agent) - Ensure the robot is properly configured for micro-ROS
- Check UDP port 8888 is accessible
- Verify the micro-ROS agent is running (
-
Build Issues
- Try rebuilding the container:
docker compose build --no-cache - Verify all ROS 2 dependencies are installed
- Try rebuilding the container:
[Your License Here]
[Your Contributing Guidelines Here]