Servers by jDrones

Quadplane SITL with gazebo

Hi,
I’m trying to run software in the loop with gazebo for quadplane similar to ‘gazebo-iris’ for copter. How do I go about creating quadplane model and simulating with Gazebo?

Any help is appreciated, Thank you

Hi, To create your own quadplane for ardupilot - gazebo
you will need

  1. Model (SDF defintion of model base links, joints, sensors and so on.)
  2. Aerodynamics (liftdrag plugin of gazebo)
  3. ArduPilot-Gazebo Interface (ardupilot plugin for gazebo)
  4. Virtual World (also SDF definition with environment, models and actors…)

Probably it is best to start with trying to understand SDF of current models, refer and look through current models such as iris, zephyr and so on.
Models can be nested.

Once you understand such, It would be much easier converting VTOL models of PX4_sitl to ArduPilot model with your understanding of SDF of ArduPilot models

After that, you will need default param for quadplane (contents are not much important, basic definition of airframe and IMU setup is enough)
and edit sim_vehicle.py file for start simulation with default params(which is SITL launch file of ArduPilot)

1 Like

Thank you for your reply. I will go through and try creating a model (SDF file). I added the quadplane information in Tools/autotest/pysim/vehicleinfo.py. Is there a need to change sim_vehicle.py? I was under the impression that no change to sim_vehicle.py is required.

Thank you.

I don’t know how it is actually working under the ArduPilot SITL
but I got the impression that ArduPilot SITL automatically parsing prefix gazebo
to connect to gazebo interface
same param file without gazebo prefix does not connect to gazebo-SITL
such as
sim_vehicle.py -v ArduCopter -f gazebo-iris
sim_vehicle.py -v ArduPlane -f gazebo-zephyr
these are valid to launch gazebo SITL

you may not need another param file but will need a launch argument
such as gazebo-quadplane
there are bunch of code to add launch arguments in the middle of sim_vehicle.py script.
Add one if you need

So what I did was add this following line in Tools/autotest/pysim/vehicleinfo.py

“gazebo-quadplane”: {
“waf_target”: “bin/arduplane”,
“default_params_filename”: “default_params/quadplane.parm”,
},

And in the terminal when I do “sim_vehicle.py -h” gazebo-quadplane does show up under frames for Arduplane

I am trying the same. I have ArduPlane talking to Gazebo, but now I am stuck without a quadplane model.

@arjun7965, would you mind sharing the model file? Also, which Gazebo Version are you using?
I am currently using Gazebo9 and the SwiftGust plugin with the gazebo9 branch.

@snuffytruffle its still a WIP and I haven’t worked on it for a while. I used the quadplane model made by px4 : https://github.com/PX4/sitl_gazebo/tree/master/models/standard_vtol
You need to make some changes to the model file for it to work with arducopter, for example you need to replace the “mavlink_interface” plugin with the “arducopter_plugin” etc. You can go through iris_with_standoffs_demo to get an idea on how/what to modify.

I made it work.
Its not super stable yet, but it flies both in VTOL and cruise and transitions.
I don’t think you can upload files here so PN me if you want it.

2 Likes

Can you share the files maybe on github

Hi, We’re trying to setup a simulation of a quadplane in Gazebo. I’ve added an entry in vehicleInfo.py, I’ve created a .parm file with INS calibration and I have a quadplane model with the ArduPilotPlugin which connects to the ArduPlane SITL.

The problem I’m facing now, is that the moment ArduPlane connects to Gazebo, it starts sending motor commands to the rotors, even though the UAV is disarmed, so the rotors are spinning (albeit slowly). When trying to fly a mission the UAV arms but the rotors do not increase in speed. I am thinking I might have to map the servos correctly, but is there an overview of which output channels are default for a quadplane setup in SITL?

Did you manage to simulate a VTOL with SITL and Gazebo?

Hi,

I’m also interested in this topic.
I’ve made a custom sdf model, edited the default params value in sim_vehicle.py.
How are the motors mapped with the channel number from the sdf model?

Thank you

Hi @PotatoesLegend,
I’m working on the same than this topic. You can set the map of motors with the .param file you are loading to SITL. If you are using a default .param file, try to connect a GCS to the SITL and look the parameters refering the motors. You will need this parameters list to understand the model configuration. You must look SERVOX_FUNCTION.

Hope I help you!

Hi @slucasm,
Thanks for your reply.
Since last post, I’ve searched and learned about ROS.
There is a plugin named mavros who help me extract all data from SITL.
Now I’m trying to understand how SITL and Gazebo work together? SITL is a simulator but Gazebo is also a simulator, that confuse me a bit. If i’d like to make a good simulation, which part of the simulation has to be done in SITL, and which one has to be done in gazebo?
Do I only have to send rotor command, and gazebo will lift the drone with the liftdrag_plugin?
Now, I’ve sent position and orientation info from SITL to gazebo and it mimic the behaviour, but I think there is more we can do here? What do you think?
Also there no mass and inertia in SITL (or I didn’t found it yet), how SITL simulate that?

Hi @PotatoesLegend,

To connect SITL with Gazebo properly the best option is develop a Gazebo Plugin, like Ardupilot_gazebo plugin (explained in the wiki).
I think what should be done is from SITL receive the commands from the motors and with the LiftDrag plugin move the drone in Gazebo. Then you have to send to SITL the values of the IMU sensor that your Gazebo model must carry.

Try to read and understand all the code of Ardupilot - Gazebo plugin and this will help you.

Also, if you want work with mavros take a look on this post from wiki. In the video another plugin is shown, try to understand the code and you will understand what you need.

Hi @slucasm,
I’ve made the connection between sitl and gazebo with mavros.
I can send motor command from sitl.
I have still 2 obstacle:

-I’m sending joint effort with a ros service using ‘gazebo/apply_joint_effort’. It works for a couple of second and then the model crash and go back at the center of the world (half below the ground)

-I’m trying to send imu data through mavros and but sitl doesn’t even take it into account.
Do you have any idea how i can override sitl imu data? I can even send position and orientation from a gazebo topic.

Thank you

Hi @PotatoesLegend,

I’m not currently using ROS, so I can’t help you with the first question. I’m sending the motor parameters with a Gazebo plugin. And for the second question I’m sending the IMU data through APM Socket, and SITL is taking it into account automatically. Are you designing a Plugin for your model?

Regards.

@slucasm,
What do you mean APM socket? like with HIL?
For the gazebo plugin, do you think I can use it direct for more propeller? I’ve read the code and I’ve tried to send command to a vtol with the same plugin but I need to find a way to read data comming from sitl.
Do you know how to read it?
For example, I make a custom copter in the sitl launcher (with gazebo) in /ardupilot/Tools/autotest/pysim/vehicleinfo.py
Like this one:
“gazebo-iris”: {
“waf_target”: “bin/arducopter”,
“default_params_filename”: [“default_params/copter.parm”,
“default_params/gazebo-iris.parm”],
},
But with another custom .parm file where I choose my own frame (maybe even one that I add to “/ardupilot/libraries/AP_Motors/AP_MotorsMatrix.cpp” or “/ardupilot/libraries/AP_Motors/AP_MotorsMatrixTS.cpp”)

And with this, I’d like to read and use the RC output from sitl and send it to gazebo.
From Gazebo, I’d send imu data back to sitl.
If I understand how to read the data, from sitl I may be able to go to the next step.

Thanks for your help again, I’ts really useful.

Kind Regard

Hi @PotatoesLegend,

To connect to SITL without using ROS, you can connect through APM Socket (you can check the file here from ArduPilot repo). With this functions you can send and receive data from SITL simulation.

Once you can receive and send data, what you cand send is the IMU data, and you are goingo to receive is an array of servo commands. What you are going to receive from SITL is described in this
file on same repo as before. So, if your model are using 4 motors, the SITL will send you the information of this 4 motors.

In respect of your own custom copter, your work is good. What I recommend you is try to connect, your simulation with Mission Planner. Once you are connected with Mission Planner, open MavLink Inspector (with Control + F and selecting the correct option of the list). With the MavLink inspection and your simulation running you will be able to understand wich outputs are generating SITL from your motors. The outputs of the motors will be a value in PWM.

If you are watching in the MavLink Inspector that SITL is printing the servo commands on the first 4 motors, you will get this commands in your code in the first 4 positions of the servo array explained before.

Hope you understand this process and it will help you.

Hi @slucasm,
I didn’t use Mission planner since i’ve seen it’s for windows at first (I’m on Ubuntu since I started this “quest”), but I’ve found that there is a way to make it work in Ubuntu. It’s a great tool and much more easy to work with than command line (even if i’m used to it now). I’ve seen the motor output and other info. It’s similar to what mavros give us.
For the socket, It’s new to me but it seems that is the key to make it work. In the ArduPilotPlugin
So i’ll try to understand these 3 file and make it works together.

Kind regards

Servers by jDrones