Understanding Command Flow


Hello all,

I’ve been stuck on this issue for quite some time and would greatly appreciate any input. My goal is simple: send commands to the Bebop 2 drone after x seconds have elapsed.

My prototype program to implement this is seen as follows and works without fault:

void doWait(int s)
    clock_t start, end;
    start = clock();
    double time;
    int done = 0;

        end = clock();
        time = ((double) (end - start) / CLOCKS_PER_SEC);
        if (time > s)
            done = 1;

int main()
    printf("2 seconds have elapsed.\n");
    printf("5 more seconds have elapsed.");

    return 0;

(Note that this resembles the sleep/usleep functions, however the application fails to recognize its use.)

When I try to implement this into the bebop’s piloting code, the host function stalls, apparently freezing the current thread until ALL instances of doWait have finished, before outputting the appropriate messages / executing commands.
The code can be seen here:

			IHM_PrintLog(ihm, "Simulating forward movement");
			error = deviceController->aRDrone3->setPilotingPCMD(deviceController->aRDrone3, (uint8_t)1, (int8_t)0, (int8_t)10, (int8_t)0, (int8_t)0, (uint32_t)0);
			error = deviceController->aRDrone3->setPilotingPCMD(deviceController->aRDrone3, (uint8_t)0, (int8_t)0, (int8_t)0, (int8_t)0, (int8_t)0, (uint32_t)0);
			IHM_PrintLog(ihm, "Simulating backward movment");
			error = deviceController->aRDrone3->setPilotingPCMD(deviceController->aRDrone3, (uint8_t)1, (int8_t)0, (int8_t)-10, (int8_t)0, (int8_t)0, (uint32_t)0);
			error = deviceController->aRDrone3->setPilotingPCMD(deviceController->aRDrone3, (uint8_t)0, (int8_t)0, (int8_t)0, (int8_t)0, (int8_t)0, (uint32_t)0);

In this instance the program would wait for 9 seconds before outputting “Simulating forward movment” and “Simulating backward movement” and only execute the first move forward command, ignoring the other 3.

Does anyone know what’s going wrong here?

I would greatly appreciate any insight; I’m at my wit’s end.



For this answer, I will assume that your code is based on our Unix BebopSample (i.e. uses ncurses for display). If that’s not the case, then the issue is probably somewhere else.

Your printing issue should be pretty straightforward: ncurses does not actually display printw(...) to the screen until a refresh command is issued. The refresh is triggered by many ncurses functions, but the two main ones are refresh() (and the whole refresh family), and the less obvious getch(), which we use on the sample in the IHM_InputProcessing() thread.

If you want to make sure that your IHM_PrintInfo() logs are immediately printed, you just have to add a refresh(); call at the end of the function.

The command issue is more tricky, but my guess would be that your active wait function (rather than a passive wait like sleep()/usleep() might interfere with the libARController threads scheduling. Do you have a reason to do active waiting instead of passive one ?



Hi Nicolas,

Using the refresh command worked beautifully, and my desire to use active waiting rather than passive was trivial; why reinvent the wheel? Everything is working stupendously now, thanks for your help!