33

Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

  • Upload
    adacore

  • View
    371

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo
Page 2: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Ada 2012 and SPARK Crazyflie and Railway demos

Eric Perlade2015/10/01

Page 3: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

CrazyFlie 2.0• 27g ready to fly drone • Ideal for indoor use • Android and iOS app (Bluetooth LE)• Python client using a radio dongle• Based on STM32F4 (ARM Cortex M4) and NRF5181 (radio chip)• Firmware entirely written in C• 5900 lines of code (without including drivers, HAL and external

libs)• Based on FreeRTOS (tasking)

Page 4: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Why ? • Drones security and safety becoming an important issue• Stricter certification regime for drones coming in Europe• AdaCore is partnering with Squadrone Systems to build open-

source certifiable drone in Ada/SPARK • Will show the feasibility of this project

Page 5: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

First Steps … towards safetyQ1 ) What code parts are the most critical in a drone firmware?Answer: the parts related to the stabilization system

Action Items: – Re-implementing stabilization system in SPARK 2014 – Proving absence of runtime errors

Page 6: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Stabilization systemStabilization system

Page 7: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Issues with original source code• The C code was not designed to be formally proved• Stabilization system in C uses C predefined types (float, int etc.)• Absence of runtime errors can’t be proved on calculations with general types• Example:

float calculateError(float measured, float desired) {

return desired – measured; } // Will cause an obvious overflow if called with // FLT_MIN and FLT_MAX…

Page 8: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Solution with SPARK 2014• Each module of the stabilization system transformed into a SPARK

package• Use of constrained types and subtypes (ex: defining a type T_Angle

instead of using the general Ada type Float)• Genericity for sharing code• Insert saturation when needed

Result• Proof of absence of runtime errors on every package• Discovery of one bug related to overflows, corrected by the Bitcraze

team later

Page 9: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Next Steps … towards more safetyQ2) What code parts are critical in a drone firmware?Answer: whole!

Action Items: Re-implementing the whole firmware in Ada 2012 and SPARK

• Replacing the OS by Ravenscar runtime• Rewriting other modules and drivers

Page 10: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

SPARK 2014 and CSPARK 2014

Stabilization System

High-Level C codeCommunication System

Low-Level C code

Free RTOS ST peripheral Drivers Crazyflie Drivers (sensors, actuators)

Page 11: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Runtime and Drivers• Replace FreeRTOS by a Ravenscar based runtime targeting the

STM32F4• Replace all the FreeRTOS tasks using the Ravenscar tasking

model (tasks, protected objects)• Rewrite the Crazyflie drivers using ST Peripheral Drivers in Ada

Page 12: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

SPARK 2014, Ada 2012 and no CSPARK 2014

Stabilization System

High-Level Ada 2012 codeCommunication System

Low-Level Ada 2012 code

Ravenscar RT ST peripheral Drivers Crazyflie Drivers (sensors, actuators)

Page 13: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Goal achieved ?• Crazyflie with a 100% Ada and SPARK firmware in 5 months

without any previous Ada nor fomal methods experience• But still not easy to pilot

One last question, what code part would be critical in a drone firmware?Answer: A secret recovery featureAction Item:

Implementing free fall recovery mode

Page 14: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Free Fall detection

When placed on a flat surface Free-fall detected

Page 15: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Recovery and Landing• Set desired angles to 0.0 for roll and pitch• High thrust applied after a free-fall• Thrust slowly decreased until a minimum that permits the drone to

land properly

• Calculate the acceleration variance when the drone is in the descending phase

• If variance is high, the drone has landed, recovery is over !

Page 16: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Real life validationAction Item:

Dropping the flie

Page 17: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Railway safe signaling Demo

Page 18: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Why ?• To prove the absence of collision using SPARK 2014• To get closer to customer experience• And mainly to play with our new Raspberry Pi 2 port !

Page 19: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Hardware• Electrical railway modelling kit• On-off power relay to control trains • Hall effect sensors to detect trains• Turnout motors to control switches • Raspberry Pi 2

Page 20: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

One way track model

Controlled sectionOn/Off

Uncontrolled sectionalways on

Sensor

Page 21: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Slow train coming

Page 22: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Slow train going on

Page 23: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Slow train detected

Page 24: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Slow train still going

Page 25: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Slow train detected again

Page 26: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Slow train going away

Page 27: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Turnout the tricky part

Page 28: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Turnout the tricky part

Page 29: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Railway layout

Page 30: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Software designwith SPARK_Mode

Signaling Manager(protected object)Sensor monitoring

(Task)

SDL Graphical Interface (task)

Train Simulator(Task)

HW interfaceRaspberry Pi 2 GPIO

Page 31: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

SPARK proof

Page 32: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Real life validationAction Item:

Dropping the train

Page 33: Tech Days 2015: Ada 2012 and Spark Crazyflie and Railway Demo

Conclusion• It works!

• Ada 2012 mixed with SPARK 2014 are ready for the industry

• Easy to access and learn technology

• Demo sources will be available on GitHub

• Have a look at AdaCore University • http://university.adacore.com/