You are here:-, PX4-PX4 Research Log [5] – Multicopter software in the loop simulation on Ubuntu

PX4 Research Log [5] – Multicopter software in the loop simulation on Ubuntu

Testing development code on a flying platform is always risky, one small bug in the code could cause your beloved airframe go straight into the bin. To avoid that, always check your code stability in simulation. And the PX4 Software In the Loop (SIL) simulation is the perfect solution.

SIL uses your computer hardware to run PX4 firmware, therefore it will not behave exactly the same as your flight controller board in some cases. However it is similar enough for testing code stability. The recommended simulation software for multicopter is jMAVsim.


A quick summary:

  1. Preparation, equipment
  2. Download QGroundControl daily build (optional)
  3. Make SIL firmware
  4. Connect to QGroundControl and run an example mission
  5. Connect joystick and calibrate (optional)
  6. Disarm and fly

1. Preparation, equipment

To start SIL on Ubuntu, you need to set up the PX4 development environment correctly. Follow the steps in this link if you have not done so: PX4 development environment

You should also acquire a joystick. This is due to the fact that I haven’t found if there exists a command to control PWM values for each channel in SIL. Maybe there is, but anyway, a joystick simulates manual flight much better. Preferably a RC simulator transmitter, like the ESKY Simulator FMS:

ESKY hobby simulator FMS

ESKY hobby simulator FMS

Alternatively, a gamed pad with two analog sticks also works well, but your throttle will be trimmed at the center position.


2. Download QGroundControl daily build (optional)

For now (4/8/2016), only the daily build release of QGroundControl supports joystick integration. Skip this step if you are only testing autonomous codes. Go to the bottom of this link and download daily build for Linux: QGroundControl Download


3. Make SIL firmware

Thanks to the PX4 development team, the SIL is bundled with the source code you cloned/forked from Github. All you need to do is go to the root directory of the project and type in terminal “make posix_sitl_default jmavsim”. The command will build the code for SIL as well as launching jMAVsim, a visualization interface for your simulated multidcopter (there is only visual for quadcopter now).

If everything went smoothly, you should see a screen like this:

You should see a screen like this after you build SIL firmware and launch jMAVsim

You should see a screen like this after you build SIL firmware and launch jMAVsim

Now, if you type “commander takeoff” in the terminal, you should see the simulated quadcopter takeoff slowly in jMAVsim. Type in “commander land”, and the quadcopter should gradually descend to land.



4. Connect to QGroundControl and run an example mission

Just like real PX4 vehicle, QGroundControl can also connect to a simulated PX4 vehicle through UDP. QGroundControl is smart enough to connect to your simulation automatically. The interface is exactly the same as if you were connecting to a real vehicle, except for all sensor data is simulated. The default simulated GPS coordinates is in Seattle, you can change that easily if you need to . This is perfect for testing GPS based missions. Let us try one right now.

In the QGroundControl window, click the “A to B route” icon on the top menu bar to enter mission planning view, and then click the double gray circle with “+” to add mission way points:

Click "A to B route" icon on the top menu bar first, then click on the double gray circle with "+"

Click “A to B route” icon on the top menu bar first, then click on the double gray circle with “+”

Click anywhere on the map to create your first way point, a configuration panel will appear near the top right of the window. The first way point has to be “Takeoff” if you want to make the mission completely automatic. If the first way point is “Takeoff”, as soon as you arm the vehicle, it will climb to the altitude specified and then turn it self towards the way point, and continues to move towards the way point with pitch angle specified:

sil_takeoff

With the “+” circle highlighted, click anywhere on the map to create the first way point, the yellow configuration panel will appear near the top right corner

Now add click anywhere on the map again to add a second way point, let us make it a “Waypoint”, you can specify how long you want the vehicle to stay above this point by setting the “Hold” time, you can also change how high you want to be when you reach this point in “Altitude”. Let’s complete the mission by adding a third way point and make it “Land”. Now send the mission to vehicle by clicking the circle with a cycle icon:

sil_missionsend

When you finish planning mission, click the circle with the cycle icon and click send to vehicle

Now go back to the mission summary view by clicking the paper airplane icon, change your flight mode to Mission first (you can do that by clicking the text to the right of the battery indicator in QGroundControl). and go to the bottom of the screen, you will find the Arm button. Click it and slide to the right to arm, and the mission will be started.


5. Connect joystick and calibrate (optional)

The “commander” command in SIL can only execute some basic tasks, such as arm, disarm, takeoff and land. To have manual control in SIL you must need a joystick (at least this is the only way I know). Plug your joystick to the computer and go to QGroundControl daily build (must be daily build), click the cog wheels and go to Joystick. You should see a screen like this:

Joystick options in QGroundControl.

Joystick options in QGroundControl.

Click “enable joystick input”, you should see the little white circles move as you move your joysticks. Calibrate your joystick just like how you would calibrate your transmitter.

By |2017-05-22T05:52:57+00:00August 4th, 2016|Categories: Flight Control, PX4|4 Comments

About the Author:

4 Comments

  1. Ayesha December 19, 2016 at 4:16 pm - Reply

    Hi!

    First of all I would like to thank you for providing such detailed info.

    I am working on my master thesis project which requires me to develop a follow algorithm for Pixhawk to follow a car.
    I am a beginner and would really appreciate if you could help me. I could provide more details via email if you are interested.

    I am currently trying to display two drones in jmavsim simulator so as to emulate the car. Any pointers?

  2. salim March 10, 2017 at 1:21 pm - Reply

    Hi Guys ,

    How good JmavSim to simulation and tuning to real flight ?

    • zihao March 15, 2017 at 9:48 am - Reply

      jMAVsim uses 3DR IRIS as default vehicle, and being a simulated environment everything is perfect, so I don’t think there is much point to tune a vehicle in simulation.

Leave A Comment