Skip to content

Commit

Permalink
feat: support ingenuity realistic flight simulation and control
Browse files Browse the repository at this point in the history
  • Loading branch information
BarisYazici committed Sep 4, 2024
1 parent 333a1f6 commit 6631108
Show file tree
Hide file tree
Showing 54 changed files with 6,426 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ingenuity_mars_helicopter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM openrobotics/space_robots_demo

COPY ingenuity_mars_helicopter /home/spaceros-user/demos_ws/src/ingenuity_mars_helicopter
COPY helicopter_flight_control /home/spaceros-user/demos_ws/src/helicopter_flight_control
COPY helicopter_flight_simulation /home/spaceros-user/demos_ws/src/helicopter_flight_simulation
COPY ingenuity_bringup /home/spaceros-user/demos_ws/src/ingenuity_bringup
COPY ingenuity_description /home/spaceros-user/demos_ws/src/ingenuity_description
COPY ./entrypoint.sh /home/spaceros-user/entrypoint.sh


RUN sudo chmod +x /home/spaceros-user/entrypoint.sh

ENTRYPOINT ["/home/spaceros-user/entrypoint.sh"]
139 changes: 139 additions & 0 deletions ingenuity_mars_helicopter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# NASA Space ROS Sim Summer Sprint Challenge
Team lead freelance username: Barisyaz
Submission title: Ingenuity Flight Simulator

# Ingenuity Flight Simulator

This project simulates the Ingenuity Mars Helicopter using Gazebo and ROS 2 in Space-ROS.

Aim of this project is to develop tools to mimic the Martian environment as close as possible. This enables space robots to easily iterate over the development cycles. This is important especially for the aerial vehicles. Because the air is much thinner and the nature events are different. Having this in mind, I develop the Ingenuity Flight Simulator, calculating the lift and drag forces as close to the Martian atmosphere and gravity as possible. This could enable Nasa engineers to develop controllers that can react to the nature events or test flight controllers with sensor noise such as IMU, altimeter or Camera.

## Structure

Each folder is a ROS 2 package. Each package has their own README.md file explaining the APIs and usage examples.

## Prerequisites

- Docker
- NVIDIA GPU (optional, but recommended for better performance)

## Setup

This project builds on `openrobotics/space_robots_demo` docker image. To build that docker image follow the instructions at this [README](https://github.com/space-ros/docker/blob/main/moveit2/README.md). To build that image, you also need to build the spaceros base image. You can access that [here](https://github.com/space-ros/space-ros).

After ensuring you have the `openrobotics/space_robots_demo` docker image. Go ahead and clone this repo.

1. Clone this repository:
```bash
git clone [email protected]:BarisYazici/demos.git
git checkout feat/ingenuity-helicopter-simulation

```

2. Build the Ingenuity Flight Simulator image:
```bash
cd ingenuity_flight_simulator
./build.sh
```

## Running the Simulation

First run the following to allow GUI passthrough:
```bash
xhost +local:docker
```

To start the simulation, run:
```bash
./run.sh
```

while the simulation is running in another terminal:

```bash
docker exec -it ingenuity_flight_simulator bash
```

to view all the topics coming from the simulator do:

```bash
ign topic -l
```

As an example you can subscribe to the /imu topic published from the ingenuity's body.
```bash
ign topic -et /imu
```
This will launch the Gazebo simulation with the Ingenuity model. Gazebo simulation GUI and RViz will pop up in new windows. By default, the Ingenuity's flight controller is activated and hovers the Martian helicopter to 10 meters of altitude.


## Contribution to Simulation and Control of Ingenuity

To control the ingenuity helicopter we need to change the angle of attack of the blade. There are two ways to change the angle of attack of the blades. First one is collective, this changes the angle of attack of the blades uniformly over the rotation of the blade. Collective control changes the altitude of the helicopter. Second way of control is cyclic control. This way we change the angle of attack interchangeably such that it creates different lift in different parts of the rotation. Cyclic control allows us to translate in x and y directions.

Ingenuity flight controller plugin implements a PID controller to change the collective to reach the desired altitude published as a gazebo ignition topic. This controller doesn't yet control the attitude of the helicopter.
## Demonstration
Here are some GIFs demonstrating the Ingenuity in action:
![Mars dust storm](assets/mars_dust_storm.gif)
*Demonstrate mars dust storm*
![Take-off](assets/altitude_control.gif)
*Take-off *
![Landing](assets/landing.gif)
*Landing*
![martian helicopter](assets/martian_helicopter.png)
*Close up view of Ingenuity*
![rviz visualization](assets/rviz.png)
*RViz visualization integration*
## Architecture
Here's a diagram illustrating the architecture:

```mermaid
graph TD
A[User Input] -->|/alpha_c, /alpha_s| D[Flight Simulation Plugin]
A -->|/desired_altitude| C[Flight Control Plugin]
C -->|/angle_of_attack| D
D -->|Forces & Torques| E[Gazebo Physics Engine]
E -->|Physics Update| F[Ingenuity Model]
F -->|State Feedback| E
E -->|Model State| D
D -->|Telemetry| G[Visualization]
subgraph Gazebo Simulation
E
F
end
subgraph Space ROS Environment
C
D
end
classDef userInput fill:#f9f,stroke:#333,stroke-width:2px;
classDef gazebo fill:#cfc,stroke:#333,stroke-width:2px;
classDef spaceROS fill:#fcf,stroke:#333,stroke-width:2px;
classDef visualization fill:#ccf,stroke:#333,stroke-width:2px;
class A userInput;
class E,F gazebo;
class C,D spaceROS;
class G visualization;
```


## License

Apache License 2.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ingenuity_mars_helicopter/assets/landing.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ingenuity_mars_helicopter/assets/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ingenuity_mars_helicopter/assets/rocks_mars.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ingenuity_mars_helicopter/assets/rviz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ingenuity_mars_helicopter/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t ingenuity_flight_simulator .
6 changes: 6 additions & 0 deletions ingenuity_mars_helicopter/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
source /opt/ros/humble/setup.sh
cd /home/spaceros-user/demos_ws
colcon build --packages-select helicopter_flight_control helicopter_flight_simulation ingenuity_description ingenuity_bringup
source /home/spaceros-user/demos_ws/install/setup.sh
ros2 launch ingenuity_bringup ingenuity_demo.launch.py
85 changes: 85 additions & 0 deletions ingenuity_mars_helicopter/helicopter_flight_control/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
cmake_minimum_required(VERSION 3.5)
project(helicopter_flight_control)

# Default to C11 for C and C++17 for C++
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 11)
endif()
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()

# Compiler options
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find packages
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(ignition-gazebo6 REQUIRED) # Assuming using Ignition Fortress
find_package(pluginlib REQUIRED)

if("$ENV{IGNITION_VERSION}" STREQUAL "citadel")
find_package(ignition-gazebo3 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo3_VERSION_MAJOR})
message(STATUS "Compiling against Ignition Citadel")

elseif("$ENV{IGNITION_VERSION}" STREQUAL "edifice")
find_package(ignition-gazebo5 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo5_VERSION_MAJOR})
message(STATUS "Compiling against Ignition Edifice")

elseif("$ENV{IGNITION_VERSION}" STREQUAL "fortress")
find_package(ignition-gazebo6 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo6_VERSION_MAJOR})
message(STATUS "Compiling against Ignition Fortress")

else()
find_package(ignition-gazebo6 REQUIRED)
set(IGN_GAZEBO_VER ${ignition-gazebo6_VERSION_MAJOR})
message(STATUS "Compiling against Ignition Fortress")
endif()

find_package(ignition-plugin1 REQUIRED)
set(IGN_PLUGIN_VER ${ignition-plugin1_VERSION_MAJOR})

# Include directories
include_directories(include)

# Declare a C++ library
add_library(${PROJECT_NAME} SHARED
src/helicopter_flight_control.cc
)


target_link_libraries(${PROJECT_NAME}
ignition-gazebo${IGN_GAZEBO_VER}::core
ignition-plugin${IGN_PLUGIN_VER}::register
)

# Ament target dependencies
ament_target_dependencies(${PROJECT_NAME}
rclcpp
geometry_msgs
)

# Install the library
install(TARGETS ${PROJECT_NAME}
DESTINATION lib
)

# Install header files
install(DIRECTORY include/
DESTINATION include
)

pluginlib_export_plugin_description_file(helicopter_flight_control ign_hardware_plugins.xml)


# Install launch files and other directories if necessary
# e.g., install(DIRECTORY launch DESTINATION share/${PROJECT_NAME}/)

# Setup the project
ament_package()
Loading

0 comments on commit 6631108

Please sign in to comment.