Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArduPilot Backend Support #2

Merged
merged 30 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fafd24a
Added ardupilot launch tool
TomerTip Aug 8, 2024
3076355
rebuild flag
TomerTip Aug 11, 2024
05d7296
worker function
TomerTip Aug 11, 2024
28c1724
UI Ardupilot + Streaming backend UI menu refactor
TomerTip Aug 12, 2024
78f1fff
Abstract Backend and BackendConfig, rename mavlink_backend to px4_mav…
TomerTip Aug 13, 2024
0d97ffb
Change ui: backend selection before vehicle selection
TomerTip Aug 14, 2024
acf2043
PX4 subprocess in seperate terminal
TomerTip Aug 14, 2024
d539258
Teminate PX4 subproccess properly
TomerTip Aug 14, 2024
f75db4a
ui_delegate.py: Backend selection logic
TomerTip Aug 14, 2024
92812f3
Working Ardupilot integration POC with X frame
TomerTip Aug 25, 2024
222c6f6
working servos, fdm communication, 400hz - panic save :)
TomerTip Aug 28, 2024
863bcd5
ArduPilot Working git add extensions/ journal.md (But slowly)...
TomerTip Aug 29, 2024
f602af8
Fixed ardupilot subprocesses kill on stop
TomerTip Sep 4, 2024
9d4327c
Pegaus Ardupilot documentation and and umls
TomerTip Sep 9, 2024
d375b17
Demo videos
TomerTip Sep 9, 2024
722755f
Another video
TomerTip Sep 10, 2024
b00da37
remove prints
TomerTip Sep 10, 2024
b0c8a3e
vidfeo
TomerTip Sep 11, 2024
5045d71
update comm scheme
TomerTip Sep 11, 2024
87ad9b5
better framerate
TomerTip Sep 15, 2024
1999115
Add multiple world settings depending on backend
TomerTip Sep 15, 2024
98a34f8
pegasus frequency measurement
TomerTip Sep 18, 2024
a6426b5
Merge branch 'ardupilot_backend' of github.com:JerichoGroup/PegasusSi…
TomerTip Oct 22, 2024
6826ce2
updated README
TomerTip Oct 22, 2024
18f4244
Fixing commit history
TomerTip Oct 22, 2024
6673066
readme setup section
TomerTip Oct 22, 2024
b042b58
Remove journal
TomerTip Oct 22, 2024
a5ca178
Added demo gif and docs
TomerTip Oct 22, 2024
fbe3821
ArduPilot docs page
TomerTip Oct 25, 2024
fadff81
updated ardupilot badge
TomerTip Oct 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

![IsaacSim 4.1.0](https://img.shields.io/badge/IsaacSim-4.1.0-brightgreen.svg)
![PX4-Autopilot 1.14.3](https://img.shields.io/badge/PX4--Autopilot-1.14.3-brightgreen.svg)
![ArduPilot-Copter 4.4](https://img.shields.io/badge/ArduPilot--Copter-4.4.0-brightgreen.svg)
![Ubuntu 22.04](https://img.shields.io/badge/Ubuntu-22.04LTS-brightgreen.svg)
[![](https://dcbadge.limes.pink/api/server/[INVITE](https://discord.gg/AjCxw2QUmt?style=flat))](https://discord.gg/AjCxw2QUmt)

**Pegasus Simulator** is a framework built on top of [NVIDIA
Omniverse](https://docs.omniverse.nvidia.com/) and [Isaac
Sim](https://docs.omniverse.nvidia.com/app_isaacsim/app_isaacsim/overview.html). It is designed to provide an easy yet powerful way of simulating the dynamics of vehicles. It provides a simulation interface for [PX4](https://px4.io/) integration as well as a custom python control interface. At the moment, only multirotor vehicles are supported, with support for other vehicle topologies planned for future versions.
Sim](https://docs.omniverse.nvidia.com/app_isaacsim/app_isaacsim/overview.html). It is designed to provide an easy yet powerful way of simulating the dynamics of vehicles. It provides a simulation interface for [PX4](https://px4.io/) and [ArduPilot](https://ardupilot.org/) integration, as well as a custom python control interface. At the moment, only multirotor vehicles are supported, with support for other vehicle topologies planned for future versions.

<p align = "center">
<a href="https://youtu.be/_11OCFwf_GE" target="_blank"><img src="docs/_static/pegasus_cover.png" alt="Pegasus Simulator image" height="300"/></a>
Expand Down
Binary file added docs/_static/ardupilot/ardupilot_camera.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 docs/_static/ardupilot/ardupilot_spawn.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 docs/_static/ardupilot/drone_takeoff.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 docs/_static/ardupilot/pegasus_backend_ui.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 docs/_static/ardupilot/pegasus_backends.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 docs/_static/ardupilot/pegasus_comm.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 docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ This simulation framework is an open-source effort, started by me, Marcelo Jacin
source/features/environments
source/features/vehicles
source/features/px4_integration
source/features/ardupilot

.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ sphinx-rtd-theme==1.2.0
sphinx_mdinclude==0.5.3
myst-parser==0.18.1
sphinxcontrib-bibtex==2.5.0
sphinxcontrib-youtube==1.2.0
sphinxcontrib-youtube==1.2.0
2 changes: 1 addition & 1 deletion docs/source/api/backends.mavlink_backend.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Mavlink Backend
===============

.. automodule:: pegasus.simulator.logic.backends.mavlink_backend
.. automodule:: pegasus.simulator.logic.backends.px4_mavlink_backend
:members:
:undoc-members:
:show-inheritance:
2 changes: 1 addition & 1 deletion docs/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Control Backends
:maxdepth: 2

backends.backend
backends.mavlink_backend
backends.px4_mavlink_backend
backends.ros2_backend

Vehicle
Expand Down
66 changes: 66 additions & 0 deletions docs/source/features/ardupilot.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.. _ardupilot:

ArduPilot
=====================

.. image:: https://img.shields.io/badge/IsaacSim-4.1.0-brightgreen.svg
:alt: IsaacSim 4.1.0

.. image:: https://img.shields.io/badge/ArduPilot--Copter-4.4.0-brightgreen.svg
:alt: ArduPilot-Copter 4.4

.. image:: https://img.shields.io/badge/Ubuntu-22.04LTS-brightgreen.svg
:alt: Ubuntu 22.04

This project bridges between the ArduPilot project and IsaacSim, allowing the ArduPilot community to leverage IsaacSim's physics simulation and photorealistic rendering capabilities!

**Notice** `PegasusArduPilot <https://github.com/TomerTip/PegasusArduPilot>`_ by `TomerTip <https://github.com/TomerTip>`_ is a fork of PegasusSimulator, containing the ArduPilot integration feature, before merging into the main project.

Backend selection:

.. figure:: /_static/ardupilot/pegasus_backend_ui.gif
:alt: Backend Selection
:align: center

Drone spawn:

.. figure:: /_static/ardupilot/ardupilot_spawn.gif
:alt: ArduPilot drone spawn
:align: center

Drone takeoff:

.. figure:: /_static/ardupilot/drone_takeoff.gif
:alt: ArduPilot drone takeoff
:align: center

Camera demo:

.. figure:: /_static/ardupilot/ardupilot_camera.gif
:alt: ArduPilot Camera Demo
:align: center

Setup
-----

1. Follow PegasusSimulator installation steps: `PegasusSimulator Installation <https://pegasussimulator.github.io/PegasusSimulator/source/setup/installation.html>`_
2. Follow ArduPilot SITL installation steps:
- `ArduPilot SITL Installation <https://ardupilot.org/dev/docs/building-setup-linux.html#building-setup-linux>`_
- `Setting up SITL on Linux <https://ardupilot.org/dev/docs/setting-up-sitl-on-linux.html#setting-up-sitl-on-linux>`_

You may install ArduPilot at ``~/ardupilot``, or change the path in the UI inside Pegasus backend selection menu.

`PyArduPilotPlugin <https://github.com/TomerTip/PyArduPilotPlugin>`_
-------------------------

To get PegasusSimulator and ArduPilot SITL talking, I created a Python implementation of the custom protocol used between ArduPilot SITL and the simulator - called `PyArduPilotPlugin <https://github.com/TomerTip/PyArduPilotPlugin>`_.
This project allows developers to create a custom simulator and integrate it with ArduPilot SITL control using Python!

Changes to main Project
-----------------------

Since the code of PegasusSimulator is currently tightly coupled with `PX4`, I had to change the backend class hierarchy to become more generic and extendable.

.. image:: /_static/ardupilot/pegasus_backends.png
:alt: Pegasus Backends
:align: center
10 changes: 5 additions & 5 deletions docs/source/features/px4_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ PX4 Integration
===============

The ``PX4-Autopilot`` support is provided by making use of the ``Control Backends API`` , and implementing a custom
``MavlinkBackend`` which contains a built-in tool to launch and kill PX4 in SITL mode automatically.
``PX4MavlinkBackend`` which contains a built-in tool to launch and kill PX4 in SITL mode automatically.

To instantiate a ``MavlinkBackend`` via Python scripting, consider the following example:
To instantiate a ``PX4MavlinkBackend`` via Python scripting, consider the following example:

.. code:: Python

# Import the Mavlink backend module
from pegasus.simulator.logic.backends.mavlink_backend import MavlinkBackend, MavlinkBackendConfig
from pegasus.simulator.logic.backends.px4_mavlink_backend import PX4MavlinkBackend, PX4MavlinkBackendConfig

# Create the multirotor configuration
# In this example we are showing the default parameters that are used if you do not specify them
mavlink_config = MavlinkBackendConfig({"vehicle_id": 0,
mavlink_config = PX4MavlinkBackendConfig({"vehicle_id": 0,
"connection_type": "tcpin",
"connection_ip": "localhost",
# The actual port that gets used = "connection_baseport" + "vehicle_id"
Expand All @@ -31,7 +31,7 @@ To instantiate a ``MavlinkBackend`` via Python scripting, consider the following
"px4_dir": "PegasusInterface().px4_path",
"px4_vehicle_model": "iris",
})
config_multirotor.backends = [MavlinkBackend(mavlink_config)]
config_multirotor.backends = [PX4MavlinkBackend(mavlink_config)]

.. note::

Expand Down
2 changes: 1 addition & 1 deletion docs/source/features/vehicles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ To create a Multirotor object from scratch, consider the following example code:
# for logging purposes) but only the first backend in the list will be used
# to send commands to the vehicles. The others will just be used to receive the
# current state of the vehicle and the data produced by the sensors
multirotor_config.backends = [MavlinkBackend()]
multirotor_config.backends = [PX4MavlinkBackend()]

# Create and spawn the multirotor object in the scene
Multirotor(
Expand Down
2 changes: 1 addition & 1 deletion docs/source/tutorials/create_custom_backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ use that to feedback into our control law.

.. note::

You can take a look on how the ``MavlinkBackend`` is implemented to check on how to parse sensor data produced by IMU, GPS, etc.
You can take a look on how the ``PX4MavlinkBackend`` is implemented to check on how to parse sensor data produced by IMU, GPS, etc.
A simple strategy is to use an if-statement to check for which sensor we are receive the data from and parse it accordingly, for example:

.. code:: Python
Expand Down
6 changes: 3 additions & 3 deletions examples/10_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# Import the Pegasus API for simulating drones
from pegasus.simulator.params import ROBOTS, SIMULATION_ENVIRONMENTS
from pegasus.simulator.logic.backends.mavlink_backend import MavlinkBackend, MavlinkBackendConfig
from pegasus.simulator.logic.backends.px4_mavlink_backend import PX4MavlinkBackend, PX4MavlinkBackendConfig
from pegasus.simulator.logic.vehicles.multirotor import Multirotor, MultirotorConfig
from pegasus.simulator.logic.interface.pegasus_interface import PegasusInterface
from pegasus.simulator.logic.graphs import ROS2CameraGraph
Expand Down Expand Up @@ -73,12 +73,12 @@ def __init__(self):
# Try to spawn the selected robot in the world to the specified namespace
config_multirotor = MultirotorConfig()
# Create the multirotor configuration
mavlink_config = MavlinkBackendConfig({
mavlink_config = PX4MavlinkBackendConfig({
"vehicle_id": 0,
"px4_autolaunch": True,
"px4_dir": "/home/marcelo/PX4-Autopilot"
})
config_multirotor.backends = [MavlinkBackend(mavlink_config)]
config_multirotor.backends = [PX4MavlinkBackend(mavlink_config)]

# Create camera graph for the existing Camera prim on the Iris model, which can be found
# at the prim path `/World/quadrotor/body/Camera`. The camera prim path is the local path from the vehicle's prim path
Expand Down
6 changes: 3 additions & 3 deletions examples/1_px4_single_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Import the Pegasus API for simulating drones
from pegasus.simulator.params import ROBOTS, SIMULATION_ENVIRONMENTS
from pegasus.simulator.logic.state import State
from pegasus.simulator.logic.backends.mavlink_backend import MavlinkBackend, MavlinkBackendConfig
from pegasus.simulator.logic.backends.px4_mavlink_backend import PX4MavlinkBackend, PX4MavlinkBackendConfig
from pegasus.simulator.logic.vehicles.multirotor import Multirotor, MultirotorConfig
from pegasus.simulator.logic.interface.pegasus_interface import PegasusInterface
# Auxiliary scipy and numpy modules
Expand Down Expand Up @@ -59,13 +59,13 @@ def __init__(self):
# Try to spawn the selected robot in the world to the specified namespace
config_multirotor = MultirotorConfig()
# Create the multirotor configuration
mavlink_config = MavlinkBackendConfig({
mavlink_config = PX4MavlinkBackendConfig({
"vehicle_id": 0,
"px4_autolaunch": True,
"px4_dir": self.pg.px4_path,
"px4_vehicle_model": self.pg.px4_default_airframe # CHANGE this line to 'iris' if using PX4 version bellow v1.14
})
config_multirotor.backends = [MavlinkBackend(mavlink_config)]
config_multirotor.backends = [PX4MavlinkBackend(mavlink_config)]

Multirotor(
"/World/quadrotor",
Expand Down
6 changes: 3 additions & 3 deletions examples/2_px4_multi_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Import the Pegasus API for simulating drones
from pegasus.simulator.params import ROBOTS, SIMULATION_ENVIRONMENTS
from pegasus.simulator.logic.state import State
from pegasus.simulator.logic.backends.mavlink_backend import MavlinkBackend, MavlinkBackendConfig
from pegasus.simulator.logic.backends.px4_mavlink_backend import PX4MavlinkBackend, PX4MavlinkBackendConfig
from pegasus.simulator.logic.vehicles.multirotor import Multirotor, MultirotorConfig
from pegasus.simulator.logic.interface.pegasus_interface import PegasusInterface
# Auxiliary scipy and numpy modules
Expand Down Expand Up @@ -78,13 +78,13 @@ def vehicle_factory(self, vehicle_id: int, gap_x_axis: float):
config_multirotor = MultirotorConfig()

# Create the multirotor configuration
mavlink_config = MavlinkBackendConfig({
mavlink_config = PX4MavlinkBackendConfig({
"vehicle_id": vehicle_id,
"px4_autolaunch": True,
"px4_dir": self.pg.px4_path,
"px4_vehicle_model": self.pg.px4_default_airframe # CHANGE this line to 'iris' if using PX4 version bellow v1.14
})
config_multirotor.backends = [MavlinkBackend(mavlink_config)]
config_multirotor.backends = [PX4MavlinkBackend(mavlink_config)]

Multirotor(
"/World/quadrotor",
Expand Down
6 changes: 3 additions & 3 deletions examples/8_camera_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pegasus.simulator.params import ROBOTS, SIMULATION_ENVIRONMENTS
from pegasus.simulator.logic.graphical_sensors.monocular_camera import MonocularCamera
from pegasus.simulator.logic.graphical_sensors.lidar import Lidar
from pegasus.simulator.logic.backends.mavlink_backend import MavlinkBackend, MavlinkBackendConfig
from pegasus.simulator.logic.backends.px4_mavlink_backend import PX4MavlinkBackend, PX4MavlinkBackendConfig
from pegasus.simulator.logic.backends.ros2_backend import ROS2Backend
from pegasus.simulator.logic.vehicles.multirotor import Multirotor, MultirotorConfig
from pegasus.simulator.logic.interface.pegasus_interface import PegasusInterface
Expand Down Expand Up @@ -75,13 +75,13 @@ def __init__(self):
# Try to spawn the selected robot in the world to the specified namespace
config_multirotor = MultirotorConfig()
# Create the multirotor configuration
mavlink_config = MavlinkBackendConfig({
mavlink_config = PX4MavlinkBackendConfig({
"vehicle_id": 0,
"px4_autolaunch": True,
"px4_dir": "/home/marcelo/PX4-Autopilot"
})
config_multirotor.backends = [
MavlinkBackend(mavlink_config),
PX4MavlinkBackend(mavlink_config),
ROS2Backend(vehicle_id=1,
config={
"namespace": 'drone',
Expand Down
6 changes: 3 additions & 3 deletions examples/9_people.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from pegasus.simulator.logic.people.person import Person
from pegasus.simulator.logic.people.person_controller import PersonController
from pegasus.simulator.logic.graphical_sensors.monocular_camera import MonocularCamera
from pegasus.simulator.logic.backends.mavlink_backend import MavlinkBackend, MavlinkBackendConfig
from pegasus.simulator.logic.backends.px4_mavlink_backend import PX4MavlinkBackend, PX4MavlinkBackendConfig
from pegasus.simulator.logic.backends.ros2_backend import ROS2Backend
from pegasus.simulator.logic.vehicles.multirotor import Multirotor, MultirotorConfig
from pegasus.simulator.logic.interface.pegasus_interface import PegasusInterface
Expand Down Expand Up @@ -138,13 +138,13 @@ def __init__(self):
# Try to spawn the selected robot in the world to the specified namespace
config_multirotor = MultirotorConfig()
# # Create the multirotor configuration
mavlink_config = MavlinkBackendConfig({
mavlink_config = PX4MavlinkBackendConfig({
"vehicle_id": 0,
"px4_autolaunch": True,
"px4_dir": "/home/marcelo/PX4-Autopilot"
})
config_multirotor.backends = [
MavlinkBackend(mavlink_config),
PX4MavlinkBackend(mavlink_config),
ROS2Backend(vehicle_id=1,
config={
"namespace": 'drone',
Expand Down
6 changes: 4 additions & 2 deletions extensions/pegasus.simulator/config/configs.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
ardupilot_default_airframe: gazebo-iris
ardupilot_dir: /home/sim/ardupilot
global_coordinates:
altitude: 90.0
latitude: 38.736832
longitude: -9.137977
px4_dir: ~/PX4-Autopilot
px4_default_airframe: gazebo-classic_iris # Change to 'iris' if using PX4 version lower than v1.14
px4_default_airframe: gazebo-classic_iris
px4_dir: /home/sim/PX4-Autopilot
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.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
| License: BSD-3-Clause. Copyright (c) 2023, Marcelo Jacinto. All rights reserved.
"""

from .backend import Backend
from .mavlink_backend import MavlinkBackend, MavlinkBackendConfig
from .backend import Backend, BackendConfig
from .px4_mavlink_backend import PX4MavlinkBackend, PX4MavlinkBackendConfig
from .ardupilot_mavlink_backend import ArduPilotMavlinkBackend, ArduPilotMavlinkBackendConfig

# Check if the ROS2 package is installed
try:
Expand Down
Loading
Loading