Skip to content

AhmedAbdelrazeq/VariableTiltHexacopter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

81 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Variable Tilt Hexacopter

Overview

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.


Repository Structure

πŸ“‚ 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

Getting Started

Prerequisites

MATLAB Simulation

  • MATLAB & Simulink (R2021b or later recommended)
  • Simscape Multibody

ROS2 Simulation

  • ROS2 (e.g., Foxy, Galactic, or Humble)
  • Gazebo Fortress/Ignition
  • colcon (ROS2 build tool)
  • xacro, ros_ign_gazebo plugins, and other common ROS2 packages

Installing Extra Dependencies for ROS2

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
    

MATLAB Usage

  1. Clone the repository:

    git clone https://github.com/olanrewajufarooq/VariableTiltHexacopter.git
    cd VariableTiltHexacopter
  2. Open MATLAB and navigate to the repo folder.

  3. Run the parameter setup:

    run('modelling_scripts/param.m')
  4. Open and simulate the model:

    open('modelling_scripts/simulation.slx')

    View the physical model in Mechanics Explorer.


ROS2 + Gazebo Usage

0. Setup the Bash for workspace building and sourcing

  • 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_ws is opening the right directory, otherwise, use the correct directory path.

1. Build the workspace

build-hexacopter

2. Source the workspace

src-hexacopter

3. Launch the hexacopter in Gazebo Fortress

  • 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"

Important Development Notes

Creating SDF file from URDF Xacro.

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.


Features & Roadmap

βœ… 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


Contributing

Feel free to fork this repo and contribute via pull requests. Open issues for bugs, feature suggestions, or integration help.


License

MIT License – Free to use, modify, and distribute.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors