Application for flight simulation


I am trying to write an application base on the px4_simple_app with which I can give thrust on the quadrocopter in the gazebo simulation started with

make posix_sitl_default gazebo

My simple app publishes to the actuator_control topic to the control[3] channel. Here is the code

/* subscribe to actuator_controls topic */
int act_sub_fd = orb_subscribe(ORB_ID(actuator_controls));
/* limit the update rate to 5 Hz */
orb_set_interval(act_sub_fd, 200);

/* advertise actuator topic to give thrust */
struct actuator_controls_s act;
memset(&act, 0, sizeof(act));
orb_advert_t act_pub = orb_advertise(ORB_ID(actuator_controls), &act);

/* one could wait for multiple topics with this technique, just using one here */
px4_pollfd_struct_t fds[] = {
    { .fd = act_sub_fd,    .events = POLLIN },

int error_counter = 0;

for (int i = 0; i < 5; i++) {
    /* wait for sensor update of 1 file descriptor for 1000 ms (1 second) */
    int poll_ret = px4_poll(fds, 1, 1000);

    /* handle the poll result */
    if (poll_ret == 0) {
        /* this means none of our providers is giving us data */
        PX4_ERR("Got no data within a second");

    } else if (poll_ret < 0) {
        /* this is seriously bad - should be an emergency */
        if (error_counter < 10 || error_counter % 50 == 0) {
            /* use a counter to prevent flooding (and slowing us down) */
            PX4_ERR("ERROR return value from poll(): %d", poll_ret);


    } else {

        if (fds[0].revents & POLLIN) {

            /* obtained data for the second file descriptor */
            struct actuator_controls_s raw3;
            /* copy sensors raw data into local buffer */
            orb_copy(ORB_ID(actuator_controls), act_sub_fd, &raw3);
            PX4_INFO("Thrust Actuator:\t%8.4f",

            // Try to give the HippoC a thrust
            act.control[3] = 0.5f;
            orb_publish(ORB_ID(actuator_controls), act_pub, &act);

        /* there could be more file descriptors here, in the form like:
         * if (fds[1..n].revents & POLLIN) {}


return 0;

If I run this app in the terminal using

psh>  px4_simple_app

the publisher publishs to the actuator_controls topic as I can see from the output of the subscriber. The problem is that in the simualtion nothing happens with the quadrocopter. Does anyone has an idea what I do wrong?

Best regards
Nils Rottmann

I don’t quite get what you are trying to do but you could try to kill the mc_att_control app and then run yours.


first thanks for your answer. I tried your advice but the mc_att_control app is not running.

Here is what I try to do:
I want to just make a takeoff with the simulated quadrocopter in gazebo. Therefore I try to programm a simple app which gives to the topic actuators_control a signal that the quadrocopter should get thrust. I already checked the topic and it gets the value I published. The problem is that nothing happens in the simulation.

Best regards

I see. Why are you polling the actuator_control data though?

Did you try to arm the vehicle before running your app?


I am polling the actuator_control data just to see if my publishing on the topic works.

No I did not ry to arm the vehicle after launching

make posix_sitl_default gazebo

How do I arm the vehicle in the simulation?

Best regards


How do I arm the vehicle in the simulation?

You can use the commander commands in the terminal:

commander arm
commander disarm
commander takeoff
commander land


First for all thanks for your answers. I tried to use the

commander arm

command in the simulation. It gives me back the following:

pxh> commander arm
pxh> INFO  [commander] home: 47.3977418, 8.5455939, 488.08
INFO  [tone_alarm] arming
INFO  [sdlog2] [blackbox] rootfs/fs/microsd/log/sess001
WARN  [sdlog2] sdlog2: failed setting sched params
INFO  [sdlog2] [blackbox] recording: log004.px4log
INFO  [tone_alarm] neutral
INFO  [sdlog2] [blackbox] stopped (3227 drops)
WARN  [sdlog2] extended logging: OFF
WARN  [sdlog2] time: gps: 0 seconds
WARN  [sdlog2] not logging

For a first try I ignored the warning and run the above presented px4_simple_app to give a thrust using the actuators_control topic. But again nothing happens in the simulation. Do you know why?

Best regards

Did the simulator work before you did the modification? (arming/takeoff/land/disarming)