Starting point for the student buggy project

Dependencies:   microbit

Fork of microbit-hello-world by micro:bit

Committer:
OyaideA
Date:
Sat Aug 12 21:46:41 2017 +0000
Revision:
6:edbaeaaf08bb
Parent:
5:a33f016d5962
Updated the comments in Buggy.h to explain what each function does

Who changed what in which revision?

UserRevisionLine numberNew contents of line
OyaideA 2:47b7a55b0805 1 /*
OyaideA 2:47b7a55b0805 2 This file contains the main function prototypes for the Buggy project
OyaideA 2:47b7a55b0805 3 */
OyaideA 2:47b7a55b0805 4 #ifndef _BUGGY_H_
OyaideA 2:47b7a55b0805 5 #define _BUGGY_H_
OyaideA 2:47b7a55b0805 6
OyaideA 2:47b7a55b0805 7 #include "MicroBit.h"
OyaideA 2:47b7a55b0805 8
OyaideA 2:47b7a55b0805 9 /*******************************************************************
OyaideA 2:47b7a55b0805 10 Definition of global constants to control how to move the buggy
OyaideA 2:47b7a55b0805 11 *******************************************************************/
OyaideA 2:47b7a55b0805 12 #define MOVE_FORWARD 0
OyaideA 2:47b7a55b0805 13 #define MOVE_BACKWARD 1
OyaideA 2:47b7a55b0805 14 #define ROTATE_CLOCKWISE 2
OyaideA 2:47b7a55b0805 15 #define ROTATE_ANTICLOCKWISE 3
OyaideA 2:47b7a55b0805 16
OyaideA 2:47b7a55b0805 17
OyaideA 6:edbaeaaf08bb 18 /*This command should be called when we want to stop the buggy because of a
OyaideA 6:edbaeaaf08bb 19 detected obstacle*/
OyaideA 2:47b7a55b0805 20 void PauseLastCommand();
OyaideA 6:edbaeaaf08bb 21 /*This command should be called once we are sure that the detected obstacle is
OyaideA 6:edbaeaaf08bb 22 no longer present and the buggy will complete the last command it was executing
OyaideA 6:edbaeaaf08bb 23 before it was paused*/
OyaideA 2:47b7a55b0805 24 void ContinueLastCommand();
OyaideA 6:edbaeaaf08bb 25 /*This command should be polled whilst the buggy is moving. It returns a true
OyaideA 6:edbaeaaf08bb 26 when the last command has been completed and is also responsible for stopping the
OyaideA 6:edbaeaaf08bb 27 buggy once the last command has been completed. Without polling this command,
OyaideA 6:edbaeaaf08bb 28 the buggy will continue to run*/
OyaideA 2:47b7a55b0805 29 bool hasLastCommandCompleted();
OyaideA 6:edbaeaaf08bb 30 /*This command initialises the microbit runtime, sets up the buttons to receive events
OyaideA 6:edbaeaaf08bb 31 and kicks off the sonar pulses.*/
OyaideA 2:47b7a55b0805 32 void InitialiseBuggy();
OyaideA 6:edbaeaaf08bb 33 /*This function returns the latest sonar timing in microseconds. The user needs
OyaideA 6:edbaeaaf08bb 34 to convert this to a distance measure at some point*/
OyaideA 2:47b7a55b0805 35 unsigned int GetSonarTime_us();
OyaideA 6:edbaeaaf08bb 36 /*Test function to test the anti-collision function. The buggy will run forward
OyaideA 6:edbaeaaf08bb 37 at the input motor Voltage for a maximum of Time_ms, but will pause when it detects
OyaideA 6:edbaeaaf08bb 38 that an obstacle is within a sonar echo of SonarTime_us microseconds. This is here
OyaideA 6:edbaeaaf08bb 39 as a tip for the user to know how to use the above functions.*/
OyaideA 3:c3a42966b47c 40 void TestAntiCollision(unsigned int Voltage, unsigned int Time_ms, unsigned int SonarTime_us);
OyaideA 6:edbaeaaf08bb 41 /*Test function to assist the user in relating a motor voltage to the speed that
OyaideA 6:edbaeaaf08bb 42 the motor travels at. Pushing button A will toggle the test to different settings
OyaideA 6:edbaeaaf08bb 43 for motor speed and direction. Pushing button B then starts the test after a
OyaideA 6:edbaeaaf08bb 44 3, 2, 1 countdown.*/
OyaideA 4:2d939ef2b09c 45 void MotorSpeedCharacterisation(void);
OyaideA 6:edbaeaaf08bb 46 /*Function to test the buggy after a build. The buggy will first use the LEDs
OyaideA 6:edbaeaaf08bb 47 to display the sonar result for 10 secs, the drive forward, backwards, rotate
OyaideA 6:edbaeaaf08bb 48 clockwise, then anti-clockwise*/
OyaideA 5:a33f016d5962 49 void SelfTest();
OyaideA 6:edbaeaaf08bb 50 /*Function to print the sonar echo in ms using the LEDs and if connected to a PC,
OyaideA 6:edbaeaaf08bb 51 also using the COMMS port (serial output). This can be used to characterise the
OyaideA 6:edbaeaaf08bb 52 ultrasonic sensor*/
OyaideA 5:a33f016d5962 53 void DisplaySonarTiming();
OyaideA 5:a33f016d5962 54
OyaideA 6:edbaeaaf08bb 55 //Export of the microbit runtime instance.
OyaideA 2:47b7a55b0805 56 extern MicroBit uBit;
OyaideA 2:47b7a55b0805 57
OyaideA 2:47b7a55b0805 58
OyaideA 2:47b7a55b0805 59
OyaideA 2:47b7a55b0805 60 #endif
OyaideA 3:c3a42966b47c 61
OyaideA 5:a33f016d5962 62