EM2019WSP01/Implementierungsdetails
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. Sie können nicht eins zu eins so übernommen und kompiliert werden, dazu muss noch ein normales Ada Programm mit .ads und .adb Dateien geschaffen werden. Hier sind keine genauen Ausführungen des Projekts zu finden. Dafür kann auf Anfrage auf das Gitlab Repository verwiesen werden.
!-- 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; -- create instance for the simple motor that can measure the motor movement collector : Simple_Motor := Make(Motor_B, Coast, 0); -- declare variables start_encoder_value and end_encoder_value start_encoder_value : Integer := 0; end_encoder_value : Integer := 0; -- measure encoder value at the start, this should be 0 start_encoder_value := Current_Encoder_Count(collector); -- start moving the collector about 180° (depends on the structure of the robot) Control_Motor(Motor_B, 20, Backward); loop -- measure encoder value end_encoder_value := Current_Encoder_Count(collector); exit when end_encoder_value <= -170; end loop; -- stop the collector movement Control_Motor(Motor_B, 0, Brake); -- braking works better with a little delay delay until Clock + Milliseconds (100);
Debugging
-- required libraries with NXT.Display; use NXT.Display; -- display the variable value for debugging Put_Noupdate(variable); Put_Line(" measuring unit");