
first commit
steering_header.h@24:7bf492bf50f4, 2021-11-04 (annotated)
- Committer:
- aalawfi
- Date:
- Thu Nov 04 17:21:18 2021 +0000
- Revision:
- 24:7bf492bf50f4
- Parent:
- 23:4c743746533c
- Child:
- 25:8bd029d58251
- Most recent 11/4/2021. Changed gains values for calmer steering
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aalawfi | 2:c857935f928e | 1 | /* |
aalawfi | 2:c857935f928e | 2 | Include libraries, IO pins |
aalawfi | 2:c857935f928e | 3 | */ |
aalawfi | 2:c857935f928e | 4 | #include "cmath" |
aalawfi | 2:c857935f928e | 5 | #include <algorithm> // std::min, std::max |
aalawfi | 2:c857935f928e | 6 | #define M_PI 3.14159265359f |
aalawfi | 2:c857935f928e | 7 | #define MAX_TURN_ANGLE M_PI/4 |
aalawfi | 2:c857935f928e | 8 | #define MIN_TURN_ANGLE -M_PI/4 |
aalawfi | 2:c857935f928e | 9 | #define SERVO_MOTOR_FREQ 50.0f |
aalawfi | 2:c857935f928e | 10 | #define CENTER_DUTY_CYCLE 0.075f |
aalawfi | 23:4c743746533c | 11 | #define REF 0.02 //in meters |
aalawfi | 24:7bf492bf50f4 | 12 | #define KP 1.803 // 1.803 |
aalawfi | 23:4c743746533c | 13 | |
aalawfi | 23:4c743746533c | 14 | #define KD 0.5003 |
aalawfi | 24:7bf492bf50f4 | 15 | #define TIME_DERIVATIVE 0.1 // was 0.08 |
aalawfi | 23:4c743746533c | 16 | |
aalawfi | 24:7bf492bf50f4 | 17 | #define KI_STEERING 8.397 |
aalawfi | 24:7bf492bf50f4 | 18 | #define TIME_INTEGRAL 0.5 // 0.4 |
aalawfi | 23:4c743746533c | 19 | |
aalawfi | 22:08d30ea47111 | 20 | #define TI_STEERING 0.02 // in seconds |
aalawfi | 2:c857935f928e | 21 | #define SEN_DIFF_TO_DIST 0.97 //in [V/m] |
aalawfi | 2:c857935f928e | 22 | #define BITS 4 |
aalawfi | 2:c857935f928e | 23 | //Construct the Ticker to call the steering control system at a set rate |
aalawfi | 2:c857935f928e | 24 | // INPUT PINS |
aalawfi | 2:c857935f928e | 25 | AnalogIn left_distance_sensor(PTB1); |
aalawfi | 2:c857935f928e | 26 | AnalogIn right_distance_sensor(PTB0); |
aalawfi | 2:c857935f928e | 27 | |
aalawfi | 2:c857935f928e | 28 | // PWM out |
aalawfi | 2:c857935f928e | 29 | PwmOut servo_motor_pwm(PTD4); |
aalawfi | 2:c857935f928e | 30 | |
aalawfi | 2:c857935f928e | 31 | // Digital outs |
aalawfi | 4:8b1d52dab862 | 32 | DigitalOut seg1[BITS]={PTC17, PTA16,PTA17,PTE31}; // insert pin numbers |
aalawfi | 2:c857935f928e | 33 | |
aalawfi | 2:c857935f928e | 34 | |
aalawfi | 2:c857935f928e | 35 | //Interrupt In |
aalawfi | 4:8b1d52dab862 | 36 | InterruptIn left_landmark_sensor(PTD6); |
aalawfi | 4:8b1d52dab862 | 37 | InterruptIn right_landmark_sensor(PTD7); |
aalawfi | 2:c857935f928e | 38 | |
aalawfi | 2:c857935f928e | 39 | // Tickers |
aalawfi | 5:636c3fe18aa8 | 40 | volatile bool steering_enabled = true; |
aalawfi | 2:c857935f928e | 41 | Ticker steering_control_ticker; |
aalawfi | 2:c857935f928e | 42 | |
aalawfi | 2:c857935f928e | 43 |