EM2019WSP01/Implementierungsdetails

Aus Verteilte Systeme - Wiki
Zur Navigation springen Zur Suche springen

Information

Die Codebeispiele sollen einen Einblick in die Verwendung von gnatmindstorms2011, insbesondere dem Verzeichnis gnatmindstorms2011/lib/gcc/arm-eabi/4.5.3/rts-ravenscar-sfp/drivers, geben. Hier sind keine genauen Ausführungen des Projekts zu finden. Dafür wird auf das Gitlab Repository verwiesen.

Motoren

-- required libraries
with Ada.Real_Time;       use Ada.Real_Time;
with NXT;                 use NXT;
with NXT.Motor_Controls;  use NXT.Motor_Controls;

-- declaration of the motors
LeftMotor  : constant Motor_ID := Motor_A;
RightMotor : constant Motor_ID := Motor_C;

-- procedure Forward
procedure Forward is 
begin
  Control_Motor(LeftMotor, 50, Forward);
  Control_Motor(RightMotor, 50, Forward);
end Forward;

-- procedure TurnRight
procedure TurnRight is 
begin
  Control_Motor(LeftMotor, 50, Forward);
  Control_Motor(RightMotor, 50, Backward);
end TurnRight;

-- procedure BrakeAndStop
procedure BrakeAndStop is 
begin
  Control_Motor(LeftMotor, 0, Brake);
  Control_Motor(RightMotor, 0, Brake);
end BrakeAndStop;
 

Ultraschallsensor

-- required libraries
with Ada.Real_Time;                 use Ada.Real_Time;
with NXT;                           use NXT;
with NXT.Ultrasonic_Sensors;        use NXT.Ultrasonic_Sensors;
with NXT.Ultrasonic_Sensors.Ctors;  use NXT.Ultrasonic_Sensors.Ctors;

-- create instance for the front ultrasonic sensor
FrontUltrasonicSensor : Ultrasonic_Sensor := Make (Sensor_3);

-- declare variable distance
distance : Integer := 1;

-- measure distance to obstacles in front
Get_Distance(FrontUltrasonicSensor, distance);

-- measuring requires a little delay
delay until Clock + Milliseconds (100);
 

Farbsensor

-- required libraries
with Ada.Real_Time;            use Ada.Real_Time;
with NXT;                      use NXT;
with NXT.Light_Sensors;        use NXT.Light_Sensors;
with NXT.Light_Sensors.Ctors;  use NXT.Light_Sensors.Ctors;

-- create instance for the light sensor at the front (false turns the floodlight off)
FrontLightSensor : Light_Sensor := Make (Sensor_2, False);

-- declare variable color
color : Integer := 1;

-- enable floodlight
Enable_Floodlight(FrontLightSensor, True);

-- measure color of the obstacle in front
color := Normalized_Light_Value(FrontLightSensor);

-- measuring requires a little delay
delay until Clock + Milliseconds (100);

-- disable floodlight
Enable_Floodlight(FrontLightSensor, False);
 

Schaufel

-- required libraries
with Ada.Real_Time;            use Ada.Real_Time;
with NXT;                      use NXT;
with NXT.Motors;               use NXT.Motors;
with NXT.Motor_Controls;       use NXT.Motor_Controls;
with NXT.Motors.Simple;        use NXT.Motors.Simple;
with NXT.Motors.Simple.Ctors;  use NXT.Motors.Simple.Ctors;

 

Sonstiges

-- required libraries
with NXT.Display;  use NXT.Display;  -- for debugging

-- display the value for debugging
Put_Noupdate(value);
Put_Line(" measuring unit");