Personal tools

RTOS pilot

From Gluonpilot

Jump to: navigation, search

Using a real time operating system for an autopilot is as logical as using a knife to cut your cheese. It may however scare people with no prior experience.

Contents


Using threads

The main advantage of a real time OS is that you can use threads (which we will use tasks from now on). You don't need to bother anymore about the delay your telemetry processing can cause to your Kalman filter or PID control. No more need for timed loops or Timer interrupt routines. It looks perfect!

There are some things you need to keep in mind:

  • You need to prioritize every task
  • Every task has a separate stack. This stack is used for the task itself AND every interrupt routine that may be called during this task's execution

Thats about it! Let's take a look at the different tasks in gluonpilot:

  • Telemetry: All the output needed for our groundstation
  • ConsoleInput: Processing and answering all the commands you send to the autopilot
  • Sensors: Gathers and processes (filters!) all the sensors (gyroscope, accelerometer, gps, pressure sensor) on our autopilot module
  • Control: Sends the correct position to the servos! This handles both manual, stabilized and full autopilot modes.

And the prioritization of the tasks is: File:Rtospilot cpupriority.png

Keep in mind that interrupt routines have the highest priority (and the priority of ppm_in is also higher than adc!). Some code such as the uart input uses both interrupt (put received chars in a buffer) and RTOS (schedule a task when we received a complete line) features.


Configuration

Every task or code entity may require a certain configuration (eg. baud rate of the GPS module). All this configuration is saved in 1 struct "Configuration" with one instantiation: config. On booting, this struct is loaded with the data stored in the first page of the dataflash chip. Using the configuration tool the configuration can be adapted and saved to flash.

Currently, the Configuration struct contains the following fields:

// configuration.h
struct Configuration
{
struct SensorConfig sensors;
struct TelemetryConfig telemetry;
struct GpsConfig gps;
struct ControlConfig control;
};
 
// sensors.h
struct SensorConfig
{
float acc_x_neutral;
float acc_y_neutral;
float acc_z_neutral;
};
 
// telemetry.h
struct TelemetryConfig
{
unsigned char stream_PPM;
unsigned char stream_GyroAcc;
unsigned char stream_PressureTemp;
};
 
// gps.h
struct GpsConfig
{
long initial_baudrate;
long operational_baudrate;
};
 
// control.h
// TODO

This configuration data can be changed using the Configuration tool.

Different tasks

Telemetry

The task with the lowest priority is the Telemetry task (telemetry_<protocol>.c). Under no circumstances telemetry may affect the crucial autopilot tasks.

This task runs at 30Hz. The rate at which the different telemetry lines are written to the output can be configured.

Currently the following telemetry lines are implemented:

  • Gyro & Accelerometer data: used for configuration
  • RC transmitter "PPM" input: used for configuration
  • Pressure & temperature from the SCP1000 sensor
  • TODO: Basic GPS data
  • TODO: Advanced GPS data
  • TODO: Roll, pitch and yaw angles

ConsoleInput

This task is also defined in the telemetry file. Receives instructions from the groundstation or configuration utility.

Sensors

The sensors task (defined in sensors.c) is a high speed task that reads all sensors on the board:

  • Accelerometers and Gyroscopes samples from the ADC module
  • Pressure and Temperature using SPI from the SCP1000 module
  • GPS data from the connected GPS module

This data is used by the control task.

Control

The control task is defined in control.c. Three different types of control are defined:

  • Manual control: reads in the signals from the RC transmitter, mixes them and outputs them to the servos
  • Stabilized mode: the RC transmitter input is used the define the preferred roll, pitch and yaw angle. PID loops use the error between the actual angle and preferred angle to calculate the output to the servos.
  • Autopilot mode: flies to waypoints using navigation algorithms

Gluonpilot
Automating your flight!

Contact page

Products Documentation ForumShop
Copyright (C) Gluonpilot.com