Questions about SITL from a beginner

Hello guys,

I am a newbie with quadrotors and I have a big task that is implementing my own control algorithm using the PX4 Flight Stack. I have read the guide and practiced with the majority of the examples (https://dev.px4.io/). I have some questions:

Right now I am working on an algorithm that would make my quadrotor take off and fly to a certain position and run in SITL (jMAVSIM or Gazebo).

1) How do I send GPS positions to the simulator in code since I can’t use qgroundcontrol? (I don’t have a flight controller hardware).

2) How do IMU sensors work in the simulation? I realized that the px4_simple_app doesn’t work properly in the simulator (it doesn’t show the correct values).

3) I know I can use the commander to make my quadrotor fly, but how can I activate the motors in the simulation, e.g. arm the quadrotor with my own code? I know that is a generic question but I don’t know whether I should start writing a mixer or if that is something already done and I should focus in something else.

Any tip is welcome! Thank you.

1 Like

Have you considered using MAVROS? That might be interesting for you as it abstracts the communication with the vehicle (arming, sending missions etc)

  1. Do you mean send a mission (GPS waypoints)? You can use QGC with SITL. Alternatively you could send missions through MAVROS or your own C program that sends mavlink messages.

  2. The IMU data is generated by the simulator. In PX4 you should see those IMU messages in the uorb topic all the same. (Although I have never looked at the raw IMU data in SITL)

  3. To arm the vehicle programmatically, you need to send the appropriate mavlink messages. Again, this is nicely abstracted in MAVROS, so if ROS is an option for you, that would simplify things for you a bit.

Thank you for your answer Nicolas. You helped me a lot :slight_smile:

I wasn’t considering MAVROS because I am not familiar with it, but I will definitely consider after what you said. What is a better approach: start with the ROS itself or go straight to the MAVROS documentation page?

Also, when I set waypoints in the QGC for example, I see the vehicle flying. What is the control technique involved in the quadrotor motion? Is it related with the mc_att_control and mc_pos_control algorithms? If I want to use a different a different method (like MPC, PID) I would have to write those again, am I correct?

If you’re not familiar with ROS, I’d look at some ROS tutorials in order to understand how to write your own ROS node and how the publish/subscribe system works in ROS. Then getting and sending data through MAVROS should be quite straight forward.

The vehicle does indeed fly with mc_att_control and mc_pos_control. The navigator module generates position setpoints for the position controller, based on the mission you uploaded through QGC (or MAVROS).

If you want to write your own controller, have a look at which topics the module you want to replace subscribes and publishes to, then create your own module that consumes and produces the same data. Then, all you need to do is stop the existing controller from running and run your own.

2 Likes