Giter VIP home page Giter VIP logo

uav_simulator's Introduction

TravisCI Docker
Build Status tag:ros-noetic

Python - Gazebo Simulation Environment for a UAV with Geometric Control

This repository includes Python codes for the position control a UAV in a Gazebo simulation environment, using geometric controllers.

Features

  • Developed using Python
  • Uses a geometric controller that works great with aggressive maneuvers
  • Uses Gazebo as the physics engine
  • Uses only minimal Gazebo/ROS codes so that if something breaks on ROS end in the future, it is easier to fix
  • Has a nice GUI for controlling the UAV
  • Can run your experiments, log data, and plot at the end of the trajectory at a click of a button
  • Estimator, controller, and trajectory generators are in their own Python classes, if you need to test your own estimator, controller, or a trajectory, you only need to modify the respective class

Landing

Why Python?

  • Python makes developing/debugging easier and shorter (no compiling)
  • Can easily find modules or libraries for different tasks

Which controller is used for the UAV control?

  • A geometric controller with decoupled-yaw attitude control is used
  • The controller is published in:
    @InProceedings{Gamagedara2019b,
        title={Geometric controls of a quadrotor uav with decoupled yaw control},
        author={Gamagedara, Kanishke and Bisheban, Mahdis and Kaufman, Evan and Lee, Taeyoung},
        booktitle={2019 American Control Conference (ACC)},
        pages={3285--3290},
        year={2019},
        organization={IEEE}
    }
  • Implementation of the same controller in C++ and Matlab can be found at https://github.com/fdcl-gwu/uav_geometric_control

How to test my own controller?

  • Make sure the desired trajectory generates the desired states required by your controller.
  • Simply update the Controller class with your controller.
  • Make sure your modified controller class outputs the variable force-moment vector (fM).

Which estimator is used for the state estimation?

  • The estimator defined in the following paper is implemented here (except the sensor bias estimation terms):
    @InProceedings{Gamagedara2019a,
        author    = {Kanishke Gamagedara and Taeyoung Lee and Murray R. Snyder},
        title     = {Real-time Kinematics {GPS} Based Telemetry System for Airborne Measurements of Ship Air Wake},
        booktitle = {{AIAA} Scitech 2019 Forum},
        year      = {2019},
        month     = {jan},
        publisher = {American Institute of Aeronautics and Astronautics},
        doi       = {10.2514/6.2019-2377}
    }
  • Matlab implementation of the above controller can be found at https://github.com/fdcl-gwu/dkf-comparison.
  • Note that the Matlab implementation has a delayed Kalman filter that has not been implemented here. Only the non-delayed parts inside DelayedKalmanFilter.m is utilized here.

How to test my own estimator?

  • Make sure your estimator provides the states for the UAV control, or if not create a separate estimator using the current estimator as the base class.
  • Update the Estimator class with your estimator.

How to test my own trajectory?

  • Add your trajectory generation function in Trajectory class.
  • Replace that with an unused mode in the calculate_desired function inside the Trajectory class.

Setting-up

‼️ If you are running this on a virtual machine, please make sure that Gazebo can run at real-time speed. It is known that this simulation exhibits unintended behavior if the "real-time factor" of the Gazebo simulation is not closer to 1.0 (See issue#3).

Setting-up the repository

  1. Clone the repository.
    git clone https://github.com/fdcl-gwu/uav_simulator.git
  2. Update the submodules.
    cd uav_simulator
    git submodule update --init --recursive

Dependencies

You have to options here:

  1. Installing everything locally
  2. Running a docker container

Installing everything locally is probably the fastest way, but you may have to instal dependencies manually, or may have to deal with package version changes. Docker solves this by streamlining all the dependencies, up-to the OS. For example, if you are on Ubuntu 22.04 and want to test the ROS-Melodic version, docker will be the only way.

If you want to install everything locally, follow Local Install. If you want to run a docker container instead, skip to Docker Setup.

Local Install

  1. ROS: this repository has been developed using ROS Noetic, on Ubuntu 20.04. If you are on ROS Melodic with Ubuntu 18.04, please checkout ros-melodic branch before installing dependencies.
  2. Python GTK libraries for GUI (not required if you opt to not to use the GUI)
    sudo apt-get install python3-pip python3-gi
  3. Python modules: these libraries must be installed in the system
    1. NumPy
    2. Pandas
    3. Matplotlib
    python3 -m pip install numpy pandas matplotlib

Now, skip to Setting-up the plugins and Gazebo.

Docker Setup

The instructions here assume you are on Ubuntu. This has not been tested on other OS versions.

  1. Install docker following official instructions.
  2. If you are not already there, cd uav_simulator
  3. Enable xhost (required for Gazebo and GUI): xhost +
  4. Build the docker image: docker build -t uav_simulator . (see following paragraph if you just want to pull the built image instead)
  5. Run a container: bash docker_run.sh

The last command will start a docker container, install all the dependencies, and mount the local directory there. The first time you run the build command will take a while as it installs all the libraries.

You can skip the build command altogether by pulling the built docker from the Docker Hub with the following command. This is NOT required if you are building it locally using the build command.

docker pull kanishgama/uav_simulator:ros-noetic
bash docker_run.sh

After that, you only need to run the bash docker_run.sh every time you need to run the simulation. Since this mounts the local repository inside the docker, you just need to change the code in your local repository, and it will be automatically update inside the docker.

For running the code, simply follow Setting-up the plugins and Gazebo, and onwards.

Setting-up the plugins and Gazebo

You only need to do the followings once (unless you change the Gazebo plugins)

  1. Make the plugging.
    # From uav_simulator
    catkin_make
  2. Source the relevant directories (NOTE: you need to do this on every new terminal).
    # From uav_simulator
    cd devel && source setup.bash && cd ../

Running the simulation environment

  1. In the current terminal window, launch the Gazebo environment:
    # From uav_simulator
    roslaunch uav_gazebo simple_world.launch 
  2. Once the Gazebo is launched, run the rover code from a different rover terminal (if you already don't know, you may find tmux a life-saver):
    # From uav_simulator/scripts
    python3 main.py
    If you change the Python code, simply re-run the Python code. The code has been tested with Python3.8.10, which comes default with Ubuntu 20.04.

Terminal

Tips

  1. Every time you change the simulation environment, you have to kill the program, catkin_make and re-run it.
  2. If you do not make any changes to the simulation environment, you only need to kill the Python program.
  3. The UAV will re-spawn at the position and orientation defined in reset_uav() in rover.py when you run the Python code.

Control Guide

  • Simply click on the buttons on the GUI to control the UAV.
  • You can easily switch between each trajectory mode simply clicking on the radio buttons.
  • Stay mode simply commands the UAV to stay at the current position.
  • When take-off, stay, and circle trajectories end, the UAV switched to the "manual" mode.
  • When the UAV is in manual, you can use following keys (these are not case sensitive):
    • WASD: to move in horizontal plane
    • P: increase altitude
    • L: decrease altitude
    • Q: yaw rotation in anti-clockwise direction
    • E: yaw rotation in clockwise direction
  • At any point of the flight, you can use following keys (these are not case sensitive):
    • M: kill motors
    • 0-5: set the flight mode without clicking on the GUI
  • Please not that the GUI must be in focus for any of the above keys to work.
  • If you want to change the above keyboard shortcuts, you can do so by editing on_key_press function in gui.py.

Running Unit-Tests

  • Make sure you are in the main directory.
  • Run python -m unittest.
  • Unit tests have only been tested on Python 3.9.
  • Currently, unit test only covers the matrix_utils.py module.

uav_simulator's People

Contributors

kanishkegb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

uav_simulator's Issues

Question about the self.R_fg in rover.py

Hi,

I found that the following "self.R_fg" in the "rover.py" is used to transform from ENU frame to NED frame.
self.R_fg = np.array([
[1.0, 0.0, 0.0],
[0.0, -1.0, 0.0],
[0.0, 0.0, -1.0]
])
However, from my understanding, the following should be used,
self.R_fg = np.array([
[0.0, 1.0, 0.0],
[1.0, 0.0, 0.0],
[0.0, 0.0, -1.0]
])
am I wrong? maybe I miss something.

Thanks in advance for your help!

[SyntaxError] python main.py

Traceback (most recent call last):
  File "main.py", line 3, in <module>
    from rover import rover, reset_uav
  File "/home/park/catkin_ws/src/uav_simulator/scripts/rover.py", line 1, in <module>
    from matrix_utils import hat, vee, q_to_R
  File "/home/park/catkin_ws/src/uav_simulator/scripts/matrix_utils.py", line 140
    R = np.eye(3) + y * hat_r + 0.5 * y2**2 * hat_r @ hat_r
                                                    ^
SyntaxError: invalid syntax

How can I solve this syntax error?
I found the error is about decorator in Python syntax but I'm not familiar to this environment

main.py showing error

Exception in thread Thread-5:
Traceback (most recent call last):
File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/home/ayush/uav_simulator/scripts/thread_control.py", line 33, in thread_control
fM = rover.run_controller()
File "/home/ayush/uav_simulator/scripts/rover.py", line 86, in run_controller
fM = self.control.run(states, desired)
File "/home/ayush/uav_simulator/scripts/control.py", line 227, in run
LOG: thread starting ..
self.position_control()
File "/home/ayush/uav_simulator/scripts/control.py", line 311, in position_control
b3c, b3c_dot, b3c_2dot = deriv_unit_vector(-A, -A_dot, -A_2dot)
File "/home/ayush/uav_simulator/scripts/matrix_utils.py", line 83, in deriv_unit_vector
- A.dot(A_dot.dot(A_dot) + A.dot(A_2dot)) / nA3
ValueError: shapes (3,) and (1,) not aligned: 3 (dim 0) != 1 (dim 0)

small bug

thank you for your very nice package.
I found a small bug at this line

I think the legend id should be 1, otherwise the element 0 is accessed 2 times : )

Quadrotor can't hover

Thanks a lot for your project.
I build your project. when I ran 'main.py' with python3.6, project run successfully. but quadrotor can't fly correcly.

'''
[ERROR] [1654881885.678907, 1879.197000]: bad callback: <bound method Rover.ros_imu_callback of <rover.Rover object at 0x7fb62ac620f0>>
Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/home/navid/Desktop/uav_simulator/scripts/rover.py", line 110, in ros_imu_callback
self.estimator.imu_correction(R_fi, self.V_R_imu)
File "/home/navid/Desktop/uav_simulator/scripts/estimator.py", line 156, in imu_correction
del_z = 0.5 * vee(imu_R - imu_R.T)
File "/home/navid/Desktop/uav_simulator/scripts/matrix_utils.py", line 34, in vee
ensure_skew(x, 3)
File "/home/navid/Desktop/uav_simulator/scripts/matrix_utils.py", line 223, in ensure_skew
raise ValueError('Input array must be a skew-symmetric matrix')
ValueError: Input array must be a skew-symmetric matrix

'''

problem.mp4

PX4 work ok?

This simulation platform can support the px4,I see the Wrench.msg can publish to the uav, but in the hardware experiment, the controller is PX4, the Wrench.msg can work either?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.