implemented untested version of freefall detection

devel_freefall
Jonas Arnold 3 years ago
parent 06f2ea67ee
commit 467506e5ce
  1. 56
      ASYD_Safety/Ada_Microbit/examples/MicroBit/jumper/src/main.adb

@ -1,5 +1,5 @@
------------------------------------------------------------------------------
-- Template --
-- JUMPER TEAM BJS --
------------------------------------------------------------------------------
with LSM303; use LSM303;
@ -7,24 +7,31 @@ with LSM303; use LSM303;
with MicroBit.Display;
with MicroBit.Accelerometer;
with MicroBit.Console;
with MicroBit.IOs;
with MicroBit.Time;
use MicroBit;
use MicroBit.IOs;
procedure Main is
Data : LSM303.All_Axes_Data;
Value : MicroBit.IOs.Analog_Value;
FreeFallCounter : Integer;
FreeFallDetectionCycles : Integer;
FreeFallCondition : Boolean;
Threshold : Axis_Data;
begin
Console.Put_Line ("Jumper - starting up ..");
loop
-- Initialization
FreeFallCondition := False;
FreeFallCounter := 0;
FreeFallDetectionCycles := 100; -- 100 * 5ms = 500ms
Threshold := 20;
loop
-- READ DATA
-- Read the accelerometer data
Data := Accelerometer.Data;
@ -32,28 +39,37 @@ begin
Console.Put_Line ("X:" & Data.X'Img & ASCII.HT &
"Y:" & Data.Y'Img & ASCII.HT &
"Z:" & Data.Z'Img);
--------------------------------------------------------------------
-- FREEFALL DETECTION
-- check wether all axis are sub-threshold => increment counter
if abs(Data.X) < Threshold and
abs(Data.Y) < Threshold and
abs(Data.Z) < Threshold then
FreeFallCounter := FreeFallCounter + 1;
-- otherwise reset counter
else
FreeFallCounter := 0;
end if;
-- Set free fall condition when counter reaches threshold
if FreeFallCounter >= FreeFallDetectionCycles then
FreeFallCondition := True;
end if;
--------------------------------------------------------------------
-- DISPLAY
-- Clear the LED matrix
Display.Clear;
-- Check, whether we are free floating or not (to be refined ...)
if -100 < Data.X and Data.X < 100 then
Display.Display ('0');
else
-- Check, wether FreeFallCondition was triggered
if FreeFallCondition then
Display.Display ('X');
end if;
-- Read analogue pin (could be 0,1,2,3,4, or 10)
Value := MicroBit.IOs.Analog (2);
Console.Put_Line ("Value : " & Value'Image);
-- Set output
if Value > Analog_Value(200) then
MicroBit.IOs.Set (12, True);
else
MicroBit.IOs.Set (12, False);
Display.Display ('0');
end if;
Time.Sleep (50);
Time.Sleep (5); -- 200 samples / s
end loop;
end Main;

Loading…
Cancel
Save