Lu-Hsuan Chen
/
autocar_3sensor_mbed
An auto car with 3 IR sensors.
autocar/autocar.h@21:093c8525349a, 2018-07-19 (annotated)
- Committer:
- cudaChen
- Date:
- Thu Jul 19 07:41:10 2018 +0000
- Revision:
- 21:093c8525349a
- Parent:
- 19:d06f5a3ed0bc
[change] merge "PID control" and "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 | 21:093c8525349a | 28 | void readSensorValues(int *values, bool *hasObstacle, int range); |
cudaChen | 12:e95ed962be7a | 29 | |
cudaChen | 12:e95ed962be7a | 30 | long map(long x, long in_min, long in_max, long out_min, long out_max); |
cudaChen | 12:e95ed962be7a | 31 | |
cudaChen | 12:e95ed962be7a | 32 | // used for controlling the direction of auto car |
cudaChen | 12:e95ed962be7a | 33 | void DriveSingleMotor(int m, int speed, int dir); |
cudaChen | 12:e95ed962be7a | 34 | void driveMotor(bool left, bool middle, bool right); |
cudaChen | 18:d7509436e9ef | 35 | void driveMotor(bool left, bool middle, bool right, bool hasObstacle); |
cudaChen | 19:d06f5a3ed0bc | 36 | void driveMotorPID(int values, float Kp, float Ki, float Kd); |
cudaChen | 21:093c8525349a | 37 | void run(int values, float Kp, float Ki, float Kd, bool hasObstacle); |
cudaChen | 13:87cd0ae37e06 | 38 | |
cudaChen | 12:e95ed962be7a | 39 | void init(); |
cudaChen | 18:d7509436e9ef | 40 | void stop(); |
cudaChen | 12:e95ed962be7a | 41 | void forward(); |
cudaChen | 12:e95ed962be7a | 42 | void turnLeft(); |
cudaChen | 12:e95ed962be7a | 43 | void turnRight(); |
cudaChen | 12:e95ed962be7a | 44 | |
cudaChen | 12:e95ed962be7a | 45 | #endif |