Skip to content

A comprehensive ROS2 control package for STM32 micro-ROS robots with dual-mode support for both hardware control and Gazebo simulation. Features a unified launcher interface, intelligent GUI controller, and seamless mode switching between physical hardware and physics simulation.

Notifications You must be signed in to change notification settings

luiscoelho23/stm32_ros2_main_controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

STM32 ROS2 Main Controller

A comprehensive ROS2 control package for STM32 micro-ROS robot with dual-mode support for both hardware control and Gazebo simulation.

๐Ÿš€ Overview

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.

Key Features

  • ๐ŸŽฎ 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

๐Ÿ“ฆ Package Structure

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

โœจ Recent Improvements

๐ŸŽฏ URDF Selection Feature

  • 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

๐Ÿ› ๏ธ Enhanced Process Management

  • 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

๐Ÿ“ Improved Package Organization

  • 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

๐Ÿ”ง Package Name Consistency

  • Unified Naming: Resolved all package name inconsistencies across files
  • Launch Scripts: Fixed launcher and GUI references
  • URDF References: Corrected plugin path configurations

๐Ÿš€ Installation

Prerequisites

# 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

Build Instructions

  1. Navigate to your workspace:

    cd ~/your_workspace
  2. Install dependencies:

    rosdep install --from-paths src --ignore-src -r -y
  3. Build the package:

    colcon build --packages-select stm32_ros2_main_controller
    source install/setup.bash

๐ŸŽฎ Usage

Quick Start - Launcher GUI

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

Individual Components

1. ๐Ÿ—๏ธ Gazebo Simulation

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

2. ๐ŸŽฏ GUI Controller - STM32 Mode

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

3. ๐Ÿค– GUI Controller - Gazebo Mode

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

โš™๏ธ Controller Configuration

Available Controllers

# 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

Launch Arguments

# 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

๐Ÿ”— Integration with Other Packages

Example: Trajectory Generation with URDF Selection

# Using with skill acquisition packages
python3 trajectory_mapping.py input.csv output.csv 3 manipulator.urdf

Example: Micro-ROS Integration

# 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

๐Ÿ“Š Monitoring and Debugging

System Health Checks

# 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

Debug Commands

# 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

๐Ÿ› ๏ธ Troubleshooting

Common Issues and Solutions

๐Ÿ”ด Launcher GUI Issues

  • 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

๐Ÿ”ด RViz Visualization Issues

  • 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

๐Ÿ”ด Controller Connection Issues

  • STM32 "Disconnected": Verify micro-ROS agent and STM32 hardware
  • Gazebo "Disconnected": Ensure Gazebo simulation is running
  • Joint states missing: Check /joint_states topic publication

๐Ÿ”ด URDF Selection Issues

  • 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

Advanced Debugging

# 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

๐Ÿงช Development and Extension

Package Dependencies

<!-- 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>

Adding New Features

  1. ๐ŸŽฎ New Control Modes: Extend gui_controller.py with additional robot interfaces
  2. โš™๏ธ Custom Controllers: Add configurations to controllers.yaml
  3. ๐ŸŽฏ Enhanced GUIs: Modify launcher or controller interfaces
  4. ๐Ÿค– Robot Models: Add new URDF files to resources/urdf/
  5. ๐ŸŒ Simulation Worlds: Create custom Gazebo environments

Contributing Guidelines

  1. Code Style: Follow ROS2 Python style guidelines
  2. Documentation: Update README.md for new features
  3. Testing: Verify compatibility with both STM32 and Gazebo modes
  4. Integration: Ensure compatibility with other packages

๐Ÿ“„ License

This project is licensed under the MIT License.

๐Ÿ†˜ Support

Getting Help

  • 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

Useful Resources


๐Ÿค– Happy Robot Controlling! ๐Ÿš€

About

A comprehensive ROS2 control package for STM32 micro-ROS robots with dual-mode support for both hardware control and Gazebo simulation. Features a unified launcher interface, intelligent GUI controller, and seamless mode switching between physical hardware and physics simulation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published