You are on page 1of 21

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/328131120

Real Time Operating Systems(RTOS) For Drones | Asad Abbas

Research · October 2018


DOI: 10.13140/RG.2.2.10243.35369

CITATIONS READS
0 1,036

1 author:

Asad Abbas
Technische Universität Clausthal
3 PUBLICATIONS   0 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Risk analysis of Car ICT Systems View project

All content following this page was uploaded by Asad Abbas on 07 October 2018.

The user has requested enhancement of the downloaded file.


Real Time Operating Systems(RTOS)
For Drones - ArduPilot with NuttX

Presenter: Asad Abbas


Email: asad.abbas@tu-clausthal.de
Supervisor: Priv.-Doz. Dr. Umut Durak
Subject: Graph Models and Simulation
Group: Theoretical Foundation
University: TU Clausthal, Germany

1 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


Abstract

Now a day's drones are getting way further from being treated as a
hobby for the general public use. They are getting more advanced,
reliable and equipped with advance cameras, sensors which give them
stability, well guided by remote and satellites, unmanned self control
operations, autopilot for the flights, sensing for weather conditions,
speed monitoring and control, distance travel, height and positions,
gesture control operations and many others. These features are leading
the drone technology to the autonomous capabilities and for
commercial use for various purposes. Drones are being used or planed
to used for the delivery, first aid's, firefighters, professional
photography, surveillance and others. The influence of drones to the
human life is growing and increasing the system complexity. Where
drones are need to make the decisions and process it fast at the real-
time for the precision and increasing their capabilities. In this report we
will discuss the drones and the Real Time Operating System (RTOS).
What is RTOS? Type of Drones, Do we really need RTOS in the drones?
what kind of RTOS used in drones? Types of RTOS and how does the
RTOS work with drone?

2 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


1. Introduction

Drone control and operations are managed by the firmware or


Operating system itself. Drones can have any number of propellers or
even be a fixed wing plane, with different sizes and shapes made for
different purposes or needs. Some people call them drones or some call
them Unmanned Aerial Vehicles (UAV). Drones are controlled with
computerized flight-control systems and multi-rotor technology.
Drones physically divided in to remote control, transmitter, receiver,
flight controller and body.

2. Types Of Drones

Drones are made with different types, depends upon the need and the
demand. In the most popular drones category multi rotor drones are
more in use by general public and perform well in the term of stability,
control and the reliability, but beside it also has the issue of short
flights, speed, maintenance and short battery life. Every other type of
drones need different software to control and having different
hardware. In the following table you will find the pros and cons of
drones and their preferred usage [7].

3 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


Type Pros Cons Usage
Multi-Rotor > Accessibility > Short flight times Aerial Photography and Video
> Ease of use > Small payload Aerial Inspection.
> VTOL and hover flight capacity
> Good camera control
> Can operate in a confined
area
> Long endurance > Launch and recovery Aerial Mapping, Pipeline and
Fixed-Wing > Large area coverage needs a lot of space Power line inspection
> Fast flight speed no VTOL/hover
> Harder to fly, more
training needed
> Expensive

Single-Rotor > VTOL and hover flight > More dangerous Aerial LIDAR laser scanning
> Long endurance (with gas > Harder to fly, more
power) training needed
> Heavier payload > Expensive
capability

3. RTOS

Real time operating system (RTOS) are usually used for embedded
machines, industrial robots, scientific research equipments and others.
RTOS uses real time applications because it is used for a particular
purpose in a limited time span. It is fast and able to manage task in the
particular time limit. RTOS are used for multi tasking / multi threading.
RTOS kernel is accountable for memory management, message
interpreter, device or input output management, storage management.
RTOS interfaces with the firmware or application to receive input and
send output from the hardware. RTOS task scheduling is a priority

4 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


unlike general purpose operating system (GPOS). RTOS is bounded
dispatch latency unlike GPOS. RTOS kernel is pre-emptible which is not
possible in GPOS kernel [2].

Fig 1: RTOS Architecture

3.1 Types Of RTOS

There are two types of real time operating systems, Soft RTOS and Hard
RTOS.

3.1.1 Soft RTOS

When a RTOS is usually or generally meet the deadlines is called the


soft ROTS. Example. If the task has a deadline of 10 milliseconds (ms) it
can be finished at 9 ms or 10 ms.

3.1.2 Hard RTOS

5 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


When a RTOS is deterministically manage to meet the deadlines is
called hard RTOS. Example, if the task has the deadline of 10ms it has to
be finished in 10 ms.

3.2 Basic Functionalities of RTOS


3.2.1 Tasking
Every task has its state which is ready to run: in which the task has the
amount of recourse to run. Running: in which the task is running in the
CPU [8]. and finished: in which the task has finished it functionality or
terminated rather by itself or by force. RTOS is responsible for
managing Next task, coordination messages between the tasks and
handling them [3].

3.2.2 Messaging

RTOS manages Semaphores, event flags, mail boxes, message queues


which is necessary for multi tasking operating system to deliver the
information around multiple operations.

3.2.3 RTOS Kernel

RTOS real time Kernel is responsible managing task related operations


which includes creating the tasks, deleting eh task, holding the take
prioritizing the task and changing the state of the tasks.

3.2.4 Scheduling

Task scheduler is a main component of RTOS, that gives the ability to


schedule the launch of the tasks at pre-define time span or after the
specified time intervals.

6 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


3.2.4.1 Round Robin Scheduling

Round robin scheduling handles the task by separating the time


quanta equally between all the task in the cycle and executing
without the prioritization. If the task is not able to complete in the
particular time quanta given it is terminated and has to wait for
the next turn.

3.2.4.2 Preemptive Scheduling

RTOS kernel is responsible to hold the current running task by


force and execute the more prioritized task.

3.2.5 RTOS Services


RTOS services is responsible for handling the interrupt services, time
services, device management services, memory management services
and input output services [3].

4. Ardupilot
Ardupilot is famous in drone autopilot software and uses open source
GPL license. It supports any type of drone including fixed-wing,
helicopters and multi-rotors. It uses same telemetry protocol
(MAVLink). Ardupilot used control loop, which gets data from the
sensors and help it to run talks periodically in the cycle and send the
data to the drive rotors after processing. Ardupilot support different
hardware and operating systems for enhancing their capabilities and
improvements. It support OS NuttX for PX4Hawk flight controller and

7 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


other RTOS depending on the board, but in this report we will talk
about the NuttX RTOS [1].

4.1 MAVLink

Micro Air Vehicle Link (MAVLink) is a protocol which is used for ground
to vehicle communication with the small unmanned vehicles. It is used
for transmitting the speed orientation of the drone, and the GPS
Location.

Fig 2: ArduPilot Structural Diagram

8 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


The basic structure of ArduPilot is divided in 5 main parts. Directories,
which define the firmware for each vehicle types example: rover, plane,
copter. Hardware Abstraction Layer AP_HAL is the abstraction layer
which interacts with the OS and hardware. Libraries, all type of vehicles
shared libraries including the control code. Tools directories are the
script files which help to set the parameters or starting the simulator in
the computer. External support code is used to provide board support
or the external features. Some of the external code is for the PX4Hawk
boards which uses the core NuttX [5].

5. NuttX

NuttX is the primary external support code used in ArduPilot for


PX4Hawk. NuttX is the real time operating system (RTOS). Primarily it
supports POSIX and ANSI governing standards. It give significance small
footprint and standard compliance. In the information technology small
footprint means it occupies the less amount of space in the hardware
or software process, which makes it light and fast for the small vehicle
types and embedded systems. It support the 8bit and 32bit
microcontroller [4].

5.1 NuttX Specific Information

Every module run as a task with the list of their own file descriptor and
every task can start the number of threads for that list, and share the
same address space. Every thread/task represented by the data
structure called the task control block (TCB) and has a fixed-size stack
and all the stacks have been checked for enough free space depending
9 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.
on stack colors by a single periodic task. Nonetheless, tasks and
pthreads are distinct by the programming models [6].

 Tasks are threads which have a degree of independence.


 pThreads share some resources.

5.2 Features

Some of the main features of RTOS are given below.

 Fully Preemptible
 Highly configurable
 FIFO and round-robin scheduling
 Real-time, deterministic, with support for priority inheritance
 Task management and watchdog timers
 POSIX/ANSI-like task controls, named message queues, counting
semaphores, clocks/timers, signals, pthreads, environment
variables, file system.
 Built-in, per-thread CPU load measurements
 Custom NuttX C library
 Symmetric Multi-Processing (SMP) and more.

10 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


Fig 3: NuttX RTOS Architecture

NuttX RTOS has 3 layers working architecture as shown in fig 3. On the


first layer which is called the user layer has the shell which works as a
interpreter for the data, user systems library and standards which
interacts with the second layer of OS for handling the drivers for the
boards and core logic and the last layer is connected with the hardware
and microcontrollers.

5.2.1 Portable Operating System Interface (POSIX)

POSIX is the standard defined by IEEE, which defines the API with the
utility interface and command line shells for the software compatibility
for Unix and other operating systems.

5.2.2 American National Standards Institute (ANSI)

ANSI is nonprofit organization that look into the voluntary consensus


standards for system and processes and coordinates the US standards
with international standards.
11 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.
5.3 ArduPilot and NuttX RTOS

The core NuttX RTOS used on Pixhawk boards, NuttX provide the
interface between Micro Controller and the firmware. ArduPilot is the
firmware for the autonomous flight, NuttX provides the real time
operational functionalities and customized library for enhancing the
flight experience with the PX4 hardware while PX4 firmware is a base
PX4 middleware and drivers used on the Pixhawk boards.

5.4 Task Control Interfaces

Task control interfaces (TCI) are defines in the in 'task ' directory under
'sched' where all the standard and non-standard interfaces are define
[6].

5.4.1 Non-standard task control interfaces (like - VxWorks)

5.4.1.1 task_create

#include <sched.h>
int task_create(char *name, int priority, int stack_size, main_t entry,
char * const argv[]);
Input Parameters:
 priority. Priority of the task
 entry. Entry point of a task
 argv. A pointer to an array of input parameters.
 name. Name of the task
 stack_size. size of the stack needed (bytes)

The function create and activate a task with the specific priority and
return the system assigned ID. This function called once the C
environment has been setup. The "main" function of the task is

12 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


addressed with entry. argv is the number of input variables that can be
provided if not required can be passed as NULL.

5.4.1.2 task_init

#include <sched.h>
int task_init(struct tcb_s *tcb, char *name, int priority, uint32_t *stack,
uint32_t stack_size, maint_t entry, char * const argv[]);
Input Parameters:
 stack. Start of the pre-allocated stack
 tcb. Address of the new task's TCB
 stack_size. size of the pre-allocated stack (bytes)
 entry. Entry point of a new task
 argv. A pointer to an array of input parameters
 name. Name of the new task
 priority. Priority of the new task

It performs the subset functionality of the task_create() function and


initialized the TCB in preparation of starting the new thread. It does not
activate the task itself unlike task_create() which has to be done by
calling the task_activate() and returns the system authenticated ID . It is
provided to support internal OS functionality. It can be failed if it is
unable to assign a new task ID to the TCB.

5.4.1.3 task_activate

#include <sched.h>
int task_activate(struct tcb_s *tcb);
Input Parameters:
 tcb. The TCB for the task for the task (task_init() argument).

13 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


The task is not eligible for the execution until it is activated, for all the
initialized tasks task_activate() is used to activate them. It has a return ID
and throw the error if it couldn't able to activate the task.

5.4.1.4 task_delete

#include <sched.h>
int task_delete(pid_t pid);
Input Parameters:
 pid. task ID of the task to delete.

This function only deletes tasks which are not running and de-allocate
the TCB and stack of the task, if the task is in running state it urge it to
exit() from the process. It can be fail if the pid does not respond to
currently executing task.

5.4.1.5 task_restart

#include <sched.h>
int task_restart(pid_t pid);
Input Parameters:
 pid. The task ID of the task to restart.

This function restart the task and reinitialize it with the same initial
parameters given in that particular task. file descriptors are not closed,
allocated memory for the task is not set to be free. It can fail if the pid is
not valid or the task could not be restarted for some reason.

14 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


5.4.2 Standard task control interfaces.

5.4.2.1 exit

#include <sched.h>
void exit(int code); // ANSI Interface

or

#include <nuttx/unistd.h>
void _exit(int code); // UNIX Interface

Input Parameters:

 code. parameter is ignored.

This function works as same as non standard function task_delete(), it


cease to exist, de-allocate the TCB and stack of the task. But it also
closes stream and file descriptors. It can execute any functionality with
on_exit() or atexit(). It has no return value and the code parameter is
ignored in the ANSI exit() which makes it differ from NuttX exit().

5.4.2.1 getpid

#include <unistd.h>
pid_t getpid(void);
Input Parameters: None.

The function return the calling task's ID. Task ID will be invalid in the
case if called at the interrupt level. It has no input parameters and but it
contains the task ID of the calling task as a return value. It is compatible
with the same name POSIX interface.

15 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


5.5 NuttX task scheduling interfaces.

Scheduling with strict priority is maintain in NuttX. The tasks have the
CPU ingress if they contains maximum priority until they blocked. The
processor is available to the task of lower priority at that time. If the
tasks have the equal priority first in, first out (FIFO) method is used. In
NuttX sporadic scheduling or round-robin scheduling is possible with
threads or task, on choice. Unlike priority scheduling round-robin is
similar except the tasks share the CPU time via the time-slicing
technique, time-slice is constant and set positive numeric value in the
CONFIG_RR_INTERVAL.

The NuttX scheduler provide the POSIX compliant interface in the given
functions:

 sched_setparam
 sched_getparam
 sched_setscheduler
 sched_getscheduler
 sched_yield
 sched_get_priority_max
 sched_get_priority_min
 sched_get_rr_interval

5.5 NuttX task scheduling interfaces.

Scheduling with strict priority is maintain in NuttX. The tasks have the
CPU ingress if they contains maximum priority until they blocked. The
processor is available to the task of lower priority at that time. If the
tasks have the equal priority first in, first out (FIFO) method is used. In
16 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.
NuttX sporadic scheduling or round-robin scheduling is possible with
threads or task, on choice [6]. Unlike priority scheduling round-robin is
similar except the tasks share the CPU time via the time-slicing
technique, time-slice is constant and set positive numeric value in the
CONFIG_RR_INTERVAL.

The NuttX scheduler provide the POSIX compliant interface in the given
functions:

 sched_setparam
 sched_getparam
 sched_setscheduler
 sched_getscheduler
 sched_yield
 sched_get_priority_max
 sched_get_priority_min
 sched_get_rr_interval

5.6 NuttX named message queues interfaces

Communication with the task are made by POSIX named message


queues in NuttX. All task can send or receive messages on named
message queues. Messages may also be send via named message
queues by interrupt handlers [6]. The following are the POSIX named
message queues interfaces:

 mq_open
 mq_close
 mq_unlink

17 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


 mq_send
 mq_timedsend
 mq_receive
 mq_timedreceive
 mq_notify
 mq_setattr
 mq_getattr

5.7 Semaphore Interfaces

NuttX also supports the POSIX semaphores. In NuttX mutual exclusion


and synchronization process are accomplished through semaphores.
Semaphores are the mechanism for gaining the absolute access to the
resource by multiple process [6]. The following are the POSIX
semaphore interfaces:

 sem_init
 sem_destroy
 sem_open
 sem_close
 sem_unlink
 sem_wait
 sem_timedwait
 sem_trywait
 sem_post
 sem_getvalue
 sem_getprotocol
 sem_setprotocol

18 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


6. Conclusion

ArduPilot is designed for the auto pilot capabilities while it requires the
OS to communicate and perform the real time tasks, NuttX is one of the
operating system which provide the real-time operations to the
ArduPilot and linking the hardware. It supports multiple threads
processing and perform the scheduling and interrupts for the firmware.

Drones can fly with the firmware itself because of the simultaneous
continuous improvements, hardware supports, and a firmware can
have a RTOS functionalities. On other hand, to enhance the firmware /
drone capabilities and external hardware support RTOS is useful to give
the performance.

19 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.


References

[1] Learning ArduPilot — Introduction, Copyright 2016, ArduPilot Dev


Team.

[2] Jojo, General Purpose Operating System versus Real Time Operating
System for an Embedded System. June 12, 2012

[3] Mathew Kevin, What is Real Time Operating System (RTOS) - How it
works? July 10, 2017

[4] Gregory Nutt, NuttX Wiki, Release 7.24 / Mar 2, 2018. website:
www.nuttx.org

[5] PX4 Developer Guide - PX4 Architectural Overview - OS Specific


Information, GitHub Website:
github.com/PX4/Devguide/blob/master/en/concept/architecture.md

[6] NuttX Operating System User's Manual, Chapter 2: Task Control


Interfaces - Gregory Nutt Last Updated: October 20, 2017

[7] Andrew Chapman, Types of Drones: Multi-Rotor vs Fixed-Wing vs


Single Rotor vs Hybrid VTOL, 3rd June 2016. Website:
auav.com.au/articles/drone-types/

[8] Sagar, Embedded Operating Systems for Real-Time Applications,


Electronic Systems Group, Nov 2002.

20 Real Time Operating Systems(RTOS) For Drones | Asad Abbas , TU Clausthal.

View publication stats

You might also like