# RESOLVED - How to make a task schedule faster?

**URL:** <https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691>\
**Category:** Uncategorized\
**Created:** [June 23, 2017, 10:18am UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691 "2017-06-23T10:18:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 23, 2017, 10:18am UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/1 "2017-06-23T10:18:52Z")

</div>

All is on the title.

> deamon\_task = px4\_task\_spawn\_cmd(“myserial”,  
> SCHED\_DEFAULT,  
> SCHED\_PRIORITY\_DEFAULT,  
> 3000,  
> myserial\_thread\_main,  
> (char \* const \*)&argv[0]);

---

<div class="post-metadata">

**Author:** ![leoavelino](https://discuss.px4.io/letter_avatar_proxy/v4/letter/l/85e7bf/32.png) [@leoavelino](https://discuss.px4.io/u/leoavelino)\
**Post date:** [June 23, 2017, 11:58am UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/2 "2017-06-23T11:58:12Z")

</div>

Try replacing _SCHED\_PRIORITY\_DEFAULT_ by _SCHED\_PRIORITY\_MAX_

---

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 23, 2017, 12:12pm UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/3 "2017-06-23T12:12:32Z")

</div>

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

Here is my code:

```
int
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;
    close(uart);
    return 0;
}
```

---

<div class="post-metadata">

**Author:** ![leoavelino](https://discuss.px4.io/letter_avatar_proxy/v4/letter/l/85e7bf/32.png) [@leoavelino](https://discuss.px4.io/u/leoavelino)\
**Post date:** [June 23, 2017, 12:37pm UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/4 "2017-06-23T12:37:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 23, 2017, 12:39pm UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/5 "2017-06-23T12:39:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dagar](https://discuss.px4.io/user_avatar/discuss.px4.io/dagar/32/22_2.png) [@dagar](https://discuss.px4.io/u/dagar)\
**Post date:** [June 23, 2017, 2:05pm UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/6 "2017-06-23T14:05:01Z")

</div>

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);
```

---

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 26, 2017, 8:50am UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/7 "2017-06-26T08:50:22Z")

</div>

> /\*\*  
> \* 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

EDIT

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)  
orb\_set\_interval(sensor\_sub\_fd,200)

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…

---

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 26, 2017, 9:29am UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/8 "2017-06-26T09:29:55Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![leoavelino](https://discuss.px4.io/letter_avatar_proxy/v4/letter/l/85e7bf/32.png) [@leoavelino](https://discuss.px4.io/u/leoavelino)\
**Post date:** [June 26, 2017, 11:55am UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/9 "2017-06-26T11:55:51Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 26, 2017, 12:48pm UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/10 "2017-06-26T12:48:34Z")

</div>

1. The task is set to max priority :

deamon\_task = px4\_task\_spawn\_cmd(“myserial”,  
SCHED\_DEFAULT,  
SCHED\_PRIORITY\_MAX,  
3000,  
myserial\_thread\_main,  
(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 … ☹

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 :

 ![](https://discuss.px4.io/uploads/default/original/2X/6/608c97aacdf0e7816f38f52168adcec6f38a6383.png)  
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.

---

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 28, 2017, 9:22am UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/11 "2017-06-28T09:22:23Z")

</div>

any other idea ? I am really stuck here…

---

<div class="post-metadata">

**Author:** ![Darkus3](https://discuss.px4.io/user_avatar/discuss.px4.io/darkus3/32/1068_2.png) [@Darkus3](https://discuss.px4.io/u/Darkus3)\
**Post date:** [June 28, 2017, 12:36pm UTC](https://discuss.px4.io/t/resolved-how-to-make-a-task-schedule-faster/3691/12 "2017-06-28T12:36:38Z")

</div>

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

CLOSED
