This repository contains a Simscape/Simulink model and a ROS2 Gazebo simulation setup for a Variable Tilt Hexacopter, designed to simulate and analyze the dynamics and control of a hexacopter with adjustable propeller tilting angles. The project supports both offline modeling and real-time robotic simulation to facilitate research in geometric control, flight dynamics, and ROS-based deployment.
π VariableTiltHexacopter
βββ π matlab
βββ π modelling_scripts/ # MATLAB scripts for modeling and analysis
β β βββ π compute_params.slx # Simulink for evaluating inertia tensors
β β βββ π fixed_wrench_analysis.mlx # Livescript for wrench evaluation
β βββ π param.m # MATLAB script for hexacopter parameters
β βββ π simulation.slx # Simulink model
βββ π ros_ws/ # ROS2 workspace
β βββ π src/
β βββ π hexacopter_description/
β βββ π launch/ # ROS2 launch files
β βββ π resource/ # Package resources
β βββ π scripts/ # (Planned) ROS2 nodes for control, etc.
β βββ π urdf/ # Xacro/URDF description of the hexacopter
β βββ π worlds/ # Gazebo SDF environments
β βββ π package.xml
β βββ π setup.py
βββ .gitignore
βββ README.md
- MATLAB & Simulink (R2021b or later recommended)
- Simscape Multibody
- ROS2 (e.g., Foxy, Galactic, or Humble)
- Gazebo Fortress/Ignition
- colcon (ROS2 build tool)
- xacro,
ros_ign_gazeboplugins, and other common ROS2 packages
Start with running: sudo apt-get update
- ROS Gazebo: needed to run gazebo from ROS
sudo apt-get install ros-humble-ros-gz - ROS Gazebo Bridge: Needed to use Gazebo from ROS.
sudo apt-get install ros-humble-ros-ign-bridge - Xacro:
sudo apt install ros-humble-xacro
-
Clone the repository:
git clone https://github.com/olanrewajufarooq/VariableTiltHexacopter.git cd VariableTiltHexacopter -
Open MATLAB and navigate to the repo folder.
-
Run the parameter setup:
run('modelling_scripts/param.m') -
Open and simulate the model:
open('modelling_scripts/simulation.slx')View the physical model in Mechanics Explorer.
-
Open Bashrc
gedit ~/.bashrc
-
Add these command to automatically implement all commands for building
build-hexacopter() { cd ~/VariableTiltHexacopter/ros_ws rosdep install -i --from-path src --rosdistro humble -y rm -rf build install log source /opt/ros/humble/setup.bash colcon build source install/local_setup.bash } -
Add these command to automatically implement all commands for sourcing
src-hexacopter() { cd ~/VariableTiltHexacopter/ros_ws source /opt/ros/humble/setup.bash source install/local_setup.bash } -
Save and close the bashrc. Then, source the bashrc:
source ~/.bashrc
With these, you will not need to repeatedly type these boring commands for building or sourcing your ros workspace. However, be careful that the
cd ~/VariableTiltHexacopter/ros_wsis opening the right directory, otherwise, use the correct directory path.
build-hexacoptersrc-hexacopter-
Just Launch the Robot in an Empty world:
ros2 launch hexacopter_description spawn_robot.launch.py
You can specify the start position of the robot:
ros2 launch hexacopter_description spawn_robot.launch.py start_pos:='5.0 0.5 2.0' -
Launch the robot with simple fixed open-loop control. angles - tilt angles in rad. motor_speeds - propeller motor speeds in rad/s.
ros2 launch hexacopter_description simple_control.launch.py angles:="[0.0, 0.0, 0.0, 0.0, 0.0, 0.0]" motor_speeds:="[800.0, 800.0, 800.0, 800.0, 800.0, 800.0]"
-
Launch the robot with simple hover control.
- allocation_method - control allocation method (fixed_tilt or variable_tilt).
- tilt_angle - tilt angle of the rotors for fixed tilt in radians (one value for all).
- hover_altitude -
- hover_gain -
Use any of the following commands: depending on the default values you may want to override.
ros2 launch hexacopter_description hover_control.launch.py hover_altitude:=5.0 hover_gain:=12.0
ros2 launch hexacopter_description hover_control.launch.py allocation_method:="fixed_tilt" tilt_angle:="0.52"
ros2 launch hexacopter_description hover_control.launch.py hover_altitude:=5.0 hover_gain:=12.0 allocation_method:="fixed_tilt" tilt_angle:="0.52"
In developing the robots, we start by defining the variable_tilt_hexacopter.urdf.xacro file. This file is converted to URDF using:
ros2 run xacro xacro -o ../path/variable_tilt_hexacopter.urdf ../path/variable_tilt_hexacopter.urdf.xacro
Then, this URDF file is converted to SDF file using:
gz sdf -p ../path/variable_tilt_hexacopter.urdf > ../path/variable_tilt_hexacopter.sdf
Note: You need to replace
../path/with the actual path. However, if you are in the URDF folder, you can simply omit it.
You need to manually copy the plugins to the SDF file from the URDF file. It is not created automatically.
β
URDF/Xacro model of the hexacopter
β
ROS2 integration with Gazebo Harmonic
β
Simple world environment: empty.sdf
β
ROS2 nodes for tilt control and motor commands
β¬ GUI for Control
β
Control Allocation (Fixed Tilt)
β¬ Control Allocation (Variable Tilt)
β
Open Loop: Hover Control
β¬ Geometric-based Control
β¬ Complex world environments
β¬ Trajectory Planning
β¬ Integrate sensor plugins (IMU, camera)
β¬ State Estimation and Mapping
β¬ Extend to Floating-Base Manipulators
β¬ ... New Improvements
Feel free to fork this repo and contribute via pull requests. Open issues for bugs, feature suggestions, or integration help.
MIT License β Free to use, modify, and distribute.