RESOLVED - How to make a task schedule faster?

All is on the title.

deamon_task = px4_task_spawn_cmd(“myserial”,
(char * const *)&argv[0]);


Yeah I already try to change the priority but it doesn’t make the task schedule faster at all…

Here is my code:

myserial_thread_main(int argc, char *argv[])

    char str[1000]={0};
    char c='Q';
    //UART open
    int uart = uart_init("/dev/ttyS6");
    if(false == uart)return -1;
    if(false == set_uart_baudrate(uart,9600)){
            printf("[YCM]set_uart_baudrate is failed\n");
            return -1;
    printf("[YCM]uart init is successful\n");
     //QUEUE open -- does not work
    //mqd_t mqret = mq_open("xQueue",O_RDONLY);
    //UORB request
    /* subscribe to sensor_combined topic */
    int sensor_sub_fd = orb_subscribe(ORB_ID(sensor_combined));
    /* limit the update rate to 0.5 Hz */
    orb_set_interval(sensor_sub_fd, 20);
    px4_pollfd_struct_t fds[] = {
    { .fd = sensor_sub_fd,   .events = POLLIN },
    /* there could be more file descriptors here, in the form like:
     * { .fd = other_sub_fd,   .events = POLLIN },
    //main thread loop
    while (!thread_should_exit) {
        //Receive from message queue "xQueue"
        // mq_receive(mqret, (void *) data, sizeof(data),NULL);
        int poll_ret = px4_poll(fds, 1, 20);
        if(poll_ret > 0){
            if (fds[0].revents & POLLIN) {
                /* obtained data for the first file descriptor */
                struct sensor_combined_s raw;
                /* copy sensors raw data into local buffer */
                orb_copy(ORB_ID(sensor_combined), sensor_sub_fd, &raw);
                sprintf(str,"Ax %8.4f \n\r",(double)raw.accelerometer_m_s2[0]);
                sprintf(str + strlen(str),"Ay %8.4f \n\r",(double)raw.accelerometer_m_s2[1]);
                sprintf(str + strlen(str),"Az %8.4f \n\r",(double)raw.accelerometer_m_s2[2]);
                sprintf(str + strlen(str),"Gx %8.4f \n\r",(double)raw.gyro_rad[0]);
                sprintf(str + strlen(str),"Gy  %8.4f \n\r",(double)raw.gyro_rad[1]);
                sprintf(str + strlen(str),"Gz %8.4f \n\r",(double)raw.gyro_rad[2]);        
                for(int j=0;j<sizeof(str);j++){
                    c = str[j];
                    write(uart, &c, 1);

    thread_running = false;
    return 0;

Could you explain better what you mean by task schedule faster?

What I understand from what you said (correct me if I am wrong) is that you want your task to be scheduled more often.

Yeah thats what I meant, but despite incresing the system tick I don’t really know how to do it… Currently it’s approximativly each second… it’s really slow

It’s not the scheduling it’s the polling within the loop, it’s waiting for new data from sensor_combined, but it’s set to only update at 0.5 Hz.

    /* limit the update rate to 0.5 Hz */
    orb_set_interval(sensor_sub_fd, 20);

* Set the minimum interval between which updates are seen for a subscription.
* If this interval is set, the subscriber will not see more than one update
* within the period.
* Specifically, the first time an update is reported to the subscriber a timer
* is started. The update will continue to be reported via poll and orb_check, but
* once fetched via orb_copy another update will not be reported until the timer
* expires.
* This feature can be used to pace a subscriber that is watching a topic that
* would otherwise update too quickly.
* @param handle A handle returned from orb_subscribe.
* @param interval An interval period in milliseconds.
* @return OK on success, ERROR otherwise with ERRNO set accordingly.
int orb_set_interval(int handle, unsigned interval) ;

IN uORBManager.hpp

I beleived that to at first but here is the definition of this function and you see that the argv is definied in milisecond. So 50hz… Don’t beleive the commentary it’s a error due to past and copy


I tried with those value :
px4_poll(fds, 1, 1)
orb_set_interval(sensor_sub_fd, 1)

(or like in px4_simple_app)

px4_poll(fds, 1,1000)

and the periodicity is still around one seconde on the serial link. Is strange that it doesn’t seem to as an effect on it…
I am stuck since three days on that…

and if I put orb_set_interval(sensor_sub_fd, 100000000)

it’s really long ! So it have an influance on it but it seem that the faster it can get is 1000ms… I dont’t knoy why. Maybe my program require to much processing power ? It’s really strange… Maybe the upload rate of sensor data in the sensor_combined is 1000ms ? Where can I found that ?

Try removing the orb_set_interval so you can ideally schedule your task at the sensor_combined topic sampling rate (considering your task is running with max. priority).

  1. The task is set to max priority :

deamon_task = px4_task_spawn_cmd(“myserial”,
(char * const *)&argv[0]);

2 . I removed the orb_set_interval and I put to 1ms px4_poll(fds, 1, 1);

And it still work at 1 second periodicity … :frowning:

I am sure now that its come directly from the update rate of the sensor_combined topic. Were is set the upload rate of uORB message , via which timer ?

Here is a screen of top command on the cpu :

My app “myserial” doesnt seem to require so much cpu resource compare to other task… and it is the highest priority it could have 255 , So it doesn’t come from this.
Mybe changing the system tick ?
#define SCHEDULE_INTERVAL 2000 /**< The schedule interval in usec (500 Hz) */
(in /src/Firmware/src/drivers/px4fmu/fmu.cpp)
Its already 500Hz… it’s enough normally.

any other idea ? I am really stuck here…

Ok never mind , I started a new clean code with same principle and its work great… dont know were it was from… Danke !