sábado, 22 de agosto de 2015

PyQuadSim: An open-source Python Quadcopter Simulator for Linux, Windows, and Mac OS X


[1] PyQuadSim is a Python program that allows you to fly a simulated quadcopter miniature aerial vehicle (MAV) from a variety of controllers (joystick, R/C transmitter, PS3 controller). You can modify the source code to add new sensors and other features, as well as configuring the simulated environment for different kinds of missions. PyQuadSim uses the powerful Virtual Robot Experimentation Platform (V-REP), but does not require programming in Lua or writing a plugin in C++.

Instructions

You will need:
  1. The V-REP simulator
  2. The PyGame package
  3. The PyQuadStick package
  4. The PyQuadSim package
  5. Administrator (root) privileges on your computer
  6. Ability to program in Python, if you want to do more than fly with the defaults
Once you've installed V-REP and PyQuad Stick and downloaded PyQuadSim, move the PyQuadSim folder into the folder where you installed V-REP.[1] Next, edit the “Import your controller here” section of the pyquadsim_server.py script to select the controller that you are using. Clicking on the start button (or selecting Simulation / Start simulation) should start the simulation. You may experience a few seconds of delay while the simulator accesses your approximate GPS coordinates from the internet. If the simulation doesn't run, looking at the console outut at the bottom of the V-REP window will often tell you what's wrong.

Modifying the simulator

To modify the simulator, you should understand how it works. As this diagram shows, the simulator uses a client/server mechanism, in which the V-REP Lua script is the client, sending the current simulation values (location and orientation of the MAV) to a server written in Python. The Python script converts the simluation values to pseudo-sensor readings (GPS, IMU) and passes the readings, along with the current demands from the controller, to a Quadcopter object. The Quadcopter object passes the controller demands and sensor readings through a set of PID controllers to stabilize the MAV and hold its position, computing appropriate thrust values for each motor (propeller). The Quadcopter object returns these four thrust values to the server script, which converts them into three-dimensional force and torque values for each propeller, and returns the forces and torques to the Lua client script.
Three simple ways to experiment with the simualtor would be:
  1. Use the V-REP model browser (Tools / Model browser) to add obstacles like walls to the environment.
  2. In fmu.py, modify the PID parameters (K_p, K_d) based on a tutorial like this this one
  3. In pyquadsim_server.py, change GPS_NOISE_METERS to a very small nonzero value (say, .01) to see the effects of an imperfect GPS signal.
To help you debug your Python code, a runtime error in the Python code will cause the PyQuadStick window to report an exception. To detect syntax errors, we recommend using PyFlakes or another Python-checker before trying out any modifications. Syntax errors and other major failures will usually cause the simulation to abort with an error. For each simulation run, a log file is automatically created, containing whatever data you choose to write to it.

Known issues

  • This package will not work with previous (pre 3.1.3) releases of V-REP. I don't have time to support backward-compatibility.

  • When you modify the code and run the simulator, the Quadstick window may report an error indicating a problem in unpacking some of the data (typically, image data). Hitting ESC and re-running the simulator usually makes this problem go away.

Personnel

Bipeen Acharya, Fred Gisa, and Simon D. Levy. Please contact Simon with any questions or suggestions.

Copyright and licensing

Copyright and licensing information (Gnu LGPL) can be found in the header of each source file. V-REP licensing information can be found here.

Acknowledgments

This work was supported in part by a Commonwealth Research Commercialization Fund grant from the Center for Innovative Technology (CRCF #MF14F-011-MS) and a Lenfest summer research grant from Washington and Lee University.
[1] If you put the PyQuadSim folder elsewhere (not recommended), you'll need to edit the V-REP script to reflect this: launch V-REP and open the pyquadsim.ttt script from the pyquadsim folder. Go to the Tools menu, select Scripts, and double-click on Child script (associated with Quadricopter). Edit the value of the PYQUADSIM_HOME variable to reflect where you put the folder (remember to use double-backslashes on Windows!) and save the scene (File / Save scene).

0 comentarios: