A comprehensive ROS2 control package for STM32 micro-ROS robot with dual-mode support for both hardware control and Gazebo simulation.
This package provides a unified control interface for STM32-based robots with seamless switching between hardware and simulation modes. It includes a comprehensive launcher GUI for service management and advanced process control capabilities.
- ๐ฎ Unified Launcher Interface: Comprehensive GUI for service management and system monitoring
- ๐ Dual Mode Controller: Native support for STM32 hardware and Gazebo simulation
- ๐ ๏ธ Advanced Process Management: Intelligent service lifecycle management with proper cleanup
- ๐ Real-time Monitoring: Live status tracking, logging, and debugging capabilities
- ๐ฏ URDF Selection: Dynamic robot model selection for trajectory generation
- ๐ง Enhanced RViz Integration: Proper visualization with custom configuration
stm32_ros2_main_controller/
โโโ scripts/
โ โโโ launcher_gui.py # ๐ฎ Main launcher interface
โ โโโ gui_controller.py # ๐ฏ Dual-mode GUI controller
โโโ launch/
โ โโโ launch.py # ๐ Comprehensive launch configuration
โโโ config/
โ โโโ controllers.yaml # โ๏ธ ROS2 controller configuration
โโโ resources/ # ๐ Organized resource directory
โ โโโ urdf/ # ๐ค Robot description files
โ โ โโโ stm32_robot.urdf.xacro
โ โ โโโ stm32_robot_gazebo.urdf.xacro
โ โโโ rviz/ # ๐๏ธ RViz visualization config
โ โโโ config.rviz
โโโ package.xml # ๐ Package dependencies
โโโ CMakeLists.txt # ๐จ Build configuration
โโโ README.md # ๐ This file
- Dynamic URDF Selection: Users can now choose different robot models when generating trajectories
- Backward Compatibility: Maintains compatibility with existing trajectory scripts
- Validation: Automatic URDF file existence validation
- Integration: Seamless integration with other packages
- Robust Termination: Multiple-layer process killing for stubborn GUI components
- Selective Targeting: Precise process identification to avoid killing the launcher itself
- Graceful Shutdown: Proper SIGTERM before SIGKILL approach
- Joint State Publisher GUI: Fixed termination issues with joint_state_publisher_gui
- Resources Directory: Centralized resource management under
resources/
- URDF Organization: Moved URDF files to
resources/urdf/
for better structure - RViz Configuration: Added proper RViz config file for visualization
- Build System: Updated CMakeLists.txt for new directory structure
- Unified Naming: Resolved all package name inconsistencies across files
- Launch Scripts: Fixed launcher and GUI references
- URDF References: Corrected plugin path configurations
# ROS2 Humble
sudo apt update
sudo apt install -y \
ros-humble-ros2-control \
ros-humble-ros2-controllers \
ros-humble-gazebo-ros2-control \
ros-humble-joint-state-publisher-gui \
python3-tkinter
-
Navigate to your workspace:
cd ~/your_workspace
-
Install dependencies:
rosdep install --from-paths src --ignore-src -r -y
-
Build the package:
colcon build --packages-select stm32_ros2_main_controller source install/setup.bash
The recommended way to use the system:
ros2 run stm32_ros2_main_controller launcher_gui.py
Launcher Capabilities:
- ๐ข Start Gazebo: Full simulation with robot model, controllers, and RViz
- ๐ฎ Start Control GUI: Launch controller in STM32 or Gazebo mode
- ๐ System Status: Real-time service monitoring and connection status
- ๐ Stop All Services: Comprehensive cleanup of all ROS processes
- ๐ Log Management: Live system logs with save/clear functionality
ros2 launch stm32_ros2_main_controller launch.py gazebo:=true rviz:=true
Features:
- Full physics simulation environment
- Robot state visualization in RViz
- Multiple controller support (position, trajectory)
- Joint state broadcasting
- Customizable world files
ros2 run stm32_ros2_main_controller gui_controller.py --ros-args -p control_mode:=stm32
STM32 Mode Features:
- Units: Degrees (0-180ยฐ)
- Communication: JointJog messages to
/joint_command
- Presets: Home (0ยฐ), Middle (90ยฐ), Full (180ยฐ), Random positions
- Real-time Feedback: Live position monitoring from hardware
ros2 run stm32_ros2_main_controller gui_controller.py --ros-args -p control_mode:=gazebo
Gazebo Mode Features:
- Units: Radians (0-ฯ)
- Communication: Float64MultiArray to
/position_controller/commands
- Trajectory Support: Smooth JointTrajectory movements
- Physics Integration: Full collision detection and dynamics
# config/controllers.yaml
controller_manager:
ros__parameters:
joint_state_broadcaster: # Joint state publishing
type: joint_state_broadcaster/JointStateBroadcaster
position_controller: # Direct position control
type: position_controllers/JointGroupPositionController
joint_trajectory_controller: # Smooth trajectory execution
type: joint_trajectory_controller/JointTrajectoryController
# Controller selection
ros2 launch stm32_ros2_main_controller launch.py controller_type:=position_controller
# Service toggling
ros2 launch stm32_ros2_main_controller launch.py rviz:=true gazebo:=true joint_state_publisher:=true
# World customization
ros2 launch stm32_ros2_main_controller launch.py world:=custom_world.xml
# Using with skill acquisition packages
python3 trajectory_mapping.py input.csv output.csv 3 manipulator.urdf
# Start micro-ROS agent for STM32 communication
ros2 run micro_ros_agent udp4 --port 8888
# Then start STM32 mode controller
ros2 run stm32_ros2_main_controller gui_controller.py --ros-args -p control_mode:=stm32
# Check running nodes
ros2 node list | grep -E "(robot|gazebo|controller)"
# Monitor topics
ros2 topic list | grep -E "(joint|position|trajectory|command)"
# Controller status
ros2 control list_controllers
# Joint states
ros2 topic echo /joint_states --once
# STM32 mode monitoring
ros2 topic echo /joint_command
# Gazebo mode monitoring
ros2 topic echo /position_controller/commands
# Service debugging
ros2 service list | grep controller_manager
- Services not starting: Check workspace sourcing and dependencies
- Process termination problems: Use enhanced "Stop All Services" with selective targeting
- Log errors: Review real-time log output for specific error messages
- Model not loading: Verify URDF files in
resources/urdf/
- Config not found: Ensure
resources/rviz/config.rviz
exists - TF errors: Check robot_state_publisher and joint_state_broadcaster
- STM32 "Disconnected": Verify micro-ROS agent and STM32 hardware
- Gazebo "Disconnected": Ensure Gazebo simulation is running
- Joint states missing: Check
/joint_states
topic publication
- File not found: Verify URDF exists in the target package
- Validation errors: Check URDF syntax and package references
- Trajectory generation fails: Ensure backward compatibility with script arguments
# Process management debugging
ps aux | grep -E "(ros2|gazebo|rviz)" | head -20
# Service dependency checking
ros2 pkg executables stm32_ros2_main_controller
# Launch file validation
ros2 launch stm32_ros2_main_controller launch.py --show-args
# Topic bandwidth monitoring
ros2 topic bw /joint_states
<!-- Core ROS2 -->
<depend>rclcpp</depend>
<depend>rclpy</depend>
<depend>std_msgs</depend>
<depend>sensor_msgs</depend>
<depend>control_msgs</depend>
<depend>trajectory_msgs</depend>
<!-- ROS2 Control -->
<depend>controller_manager</depend>
<depend>ros2_control</depend>
<depend>ros2_controllers</depend>
<!-- Simulation -->
<depend>gazebo-ros2-control</depend>
<depend>urdf</depend>
<!-- GUI -->
<depend>python3-tkinter</depend>
- ๐ฎ New Control Modes: Extend
gui_controller.py
with additional robot interfaces - โ๏ธ Custom Controllers: Add configurations to
controllers.yaml
- ๐ฏ Enhanced GUIs: Modify launcher or controller interfaces
- ๐ค Robot Models: Add new URDF files to
resources/urdf/
- ๐ Simulation Worlds: Create custom Gazebo environments
- Code Style: Follow ROS2 Python style guidelines
- Documentation: Update README.md for new features
- Testing: Verify compatibility with both STM32 and Gazebo modes
- Integration: Ensure compatibility with other packages
This project is licensed under the MIT License.
- Issues: Create GitHub issues for bugs and feature requests
- Documentation: Refer to ROS2 documentation for additional guidance
- Integration: Check package compatibility when integrating with other systems
๐ค Happy Robot Controlling! ๐