Cannot control quad in JMAVSim using actuator_controls. Reference - Writing your first application, PX4 User Guide


In the example here(First Application Tutorial (Hello Sky) | PX4 User Guide), they’ve written a code in C that reads data from a topic and prints it. I want to write a similar C program that will instruct the drone in JMAVSim to fly a certain way(give pitch, yaw, roll, throttle commands).

How did I get to this point?

I followed the Writing your first application tutorial from here(Writing your First Application · PX4 Developer Guide)
I found an example here(PX4-Autopilot/hwtest.c at main · PX4/PX4-Autopilot · GitHub) and modified it.

I have done the following before uploading code

I’ve disabled lockstep in sitl.cmake in boards/px4/sit
I’ve commented the line mc_rate_control start in PX4-Autopilot/ROMFS/px4fmu_common/init.d to disable the default application that controls the quad.

Moreover, this is the code that I’m running in px4_simple_app to control the quad:

struct actuator_controls_s actuators;
memset(&actuators, 0, sizeof(actuators));
orb_advert_t actuator_pub_ptr = orb_advertise(ORB_ID(actuator_controls_0), &actuators);

struct actuator_armed_s arm;
memset(&arm, 0, sizeof(arm));

arm.timestamp = hrt_absolute_time();
arm.ready_to_arm = true;
arm.armed = true;
orb_advert_t arm_pub_ptr = orb_advertise(ORB_ID(actuator_armed), &arm);
orb_publish(ORB_ID(actuator_armed), arm_pub_ptr, &arm);

hrt_abstime stime;

int count = 0;

while (count != 36) {
    stime = hrt_absolute_time();

    while (hrt_absolute_time() - stime < 1000000) {

        actuators.timestamp = hrt_absolute_time();
        orb_publish(ORB_ID(actuator_controls_0), actuator_pub_ptr, &actuators);

    warnx("count %i", count);


There are no errors, but I don’t see the quad flying or change yaw/pitch angles. What should I do? Am i missing something basic?

@A7sus4 Did you try arming the vehicle?

I am not sure what the expectation of sending arming commands as you are doing in your application.

There are a lot of things missing from your implementation that ensures safely operating the vehicle. If you want to have a reference, you can look at what the mc_rate_control, which you have commented out to check what your application is missing.

Hey Jaeyoung-Lim. Thank you for your reply.

Yes I did. In a modified application, I armed my vehicle by publishing to vehicle_control_mode and then publishing to vehicle_attitude_setpoint. However, I still did not get any results.I did commander stop and ran my code. The Attitude_setpoints revert back to some default value after every second iteration. I wasn’t really concerned with the safe operating of the vehicle as I just wanted to get some actuator output and see it move around.
Moreover, here’s a link to my modified code- px4_simple_app/px4_simple_app.c at fbfbe794c865811cdd8571702d2cffe15cbf2490 · wickedticket/px4_simple_app · GitHub
I’ll check out mc_rate_control.

@A7sus4 Why would you stop commander to run your code? Then this means that you need to handle what commander was doing in your code, which I believe the code is not doing and therefore not working

I tried running the code with commander start too.
here’s the output with commander stop

here’s the output with commander start

Commander start is updating the vehicle_control_status values after every iteration.

@A7sus4 I was not implying that you should run your code together with commander.

What I meant is that there are a lot of states that are being set for safety in commander, and that you need to handle these if you want to replace commander.

If you are just interested in implementing a controller, you can look at what information the mc_rate_controller is using, and just replace the mc_rate_controller with your implementation

hey @Jaeyoung-Lim . I followed your advice and went through MulticopterRateControl.cpp in src/modules/mc_rate_control thoroughly . I also decided to make some changes in it. Changes in yaw, pitch or roll are getting reflected in jmavsim only when I do commander takeoff.
For example, when I run make px4_sitl_default jmavsim, nothing happens. When i do commander takeoff, the quad takes off, but doesn’t really fly away as I’d expect it to. Commands that come under commander takeoff are probably interfering with my commands.
How do I make sure that the quad runs MulticopterRateControl.cpp with only the upthrust and yaw pitch roll values set by me?