Lu-Hsuan Chen
/
autocar_3sensor_mbed
An auto car with 3 IR sensors.
autocar/autocar.h@18:d7509436e9ef, 2018-07-18 (annotated)
- Committer:
- cudaChen
- Date:
- Wed Jul 18 12:38:54 2018 +0000
- Revision:
- 18:d7509436e9ef
- Parent:
- 15:1d440beb24d3
- Child:
- 19:d06f5a3ed0bc
[add] add obstacle avoidance feature
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cudaChen | 12:e95ed962be7a | 1 | #ifndef AUTOCAR_H |
cudaChen | 12:e95ed962be7a | 2 | #define AUTOCAR_H |
cudaChen | 12:e95ed962be7a | 3 | |
cudaChen | 12:e95ed962be7a | 4 | #include "mbed.h" |
cudaChen | 12:e95ed962be7a | 5 | |
cudaChen | 18:d7509436e9ef | 6 | #include "Ping.h" |
cudaChen | 18:d7509436e9ef | 7 | |
cudaChen | 15:1d440beb24d3 | 8 | // used for motors |
cudaChen | 15:1d440beb24d3 | 9 | extern DigitalOut M1_enable; |
cudaChen | 15:1d440beb24d3 | 10 | extern DigitalOut M2_enable; |
cudaChen | 15:1d440beb24d3 | 11 | extern DigitalOut M1_in1; |
cudaChen | 15:1d440beb24d3 | 12 | extern DigitalOut M1_in2; |
cudaChen | 15:1d440beb24d3 | 13 | extern DigitalOut M2_in3; |
cudaChen | 15:1d440beb24d3 | 14 | extern DigitalOut M2_in4; |
cudaChen | 12:e95ed962be7a | 15 | |
cudaChen | 12:e95ed962be7a | 16 | // used for IR sensors |
cudaChen | 15:1d440beb24d3 | 17 | extern AnalogIn leftIR; |
cudaChen | 15:1d440beb24d3 | 18 | extern AnalogIn middleIR; |
cudaChen | 15:1d440beb24d3 | 19 | extern AnalogIn rightIR; |
cudaChen | 15:1d440beb24d3 | 20 | |
cudaChen | 18:d7509436e9ef | 21 | // used for ultrasonic sensors |
cudaChen | 18:d7509436e9ef | 22 | extern Ping ultrasonic; |
cudaChen | 18:d7509436e9ef | 23 | |
cudaChen | 15:1d440beb24d3 | 24 | // read the value of IR sensors |
cudaChen | 12:e95ed962be7a | 25 | void readIR(bool* left, bool* middle, bool* right, int threshold); |
cudaChen | 13:87cd0ae37e06 | 26 | int readIRValues(); |
cudaChen | 18:d7509436e9ef | 27 | void readSensor(bool* left, bool* middle, bool* right, bool* hasObstacle, int threshold, int range); |
cudaChen | 12:e95ed962be7a | 28 | |
cudaChen | 12:e95ed962be7a | 29 | long map(long x, long in_min, long in_max, long out_min, long out_max); |
cudaChen | 12:e95ed962be7a | 30 | |
cudaChen | 12:e95ed962be7a | 31 | // used for controlling the direction of auto car |
cudaChen | 12:e95ed962be7a | 32 | void DriveSingleMotor(int m, int speed, int dir); |
cudaChen | 12:e95ed962be7a | 33 | void driveMotor(bool left, bool middle, bool right); |
cudaChen | 18:d7509436e9ef | 34 | void driveMotor(bool left, bool middle, bool right, bool hasObstacle); |
cudaChen | 18:d7509436e9ef | 35 | void driveMotorPID(float values, float Kp, float Ki, float Kd); |
cudaChen | 13:87cd0ae37e06 | 36 | |
cudaChen | 12:e95ed962be7a | 37 | void init(); |
cudaChen | 18:d7509436e9ef | 38 | void stop(); |
cudaChen | 12:e95ed962be7a | 39 | void forward(); |
cudaChen | 12:e95ed962be7a | 40 | void turnLeft(); |
cudaChen | 12:e95ed962be7a | 41 | void turnRight(); |
cudaChen | 12:e95ed962be7a | 42 | |
cudaChen | 12:e95ed962be7a | 43 | #endif |