
first commit
steering_header.h@2:c857935f928e, 2021-10-25 (annotated)
- Committer:
- aalawfi
- Date:
- Mon Oct 25 01:28:53 2021 +0000
- Revision:
- 2:c857935f928e
- Child:
- 4:8b1d52dab862
- Added steering files ; - We must re-assign IO pins
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 | 2:c857935f928e | 11 | #define REF 0.0f //in meters |
aalawfi | 2:c857935f928e | 12 | #define KP 16.45 // 16.65 optimal |
aalawfi | 2:c857935f928e | 13 | #define KD 0.98 // 0.88 optimal |
aalawfi | 2:c857935f928e | 14 | #define TIME_DERIVATIVE 0.9 // good 0.8 |
aalawfi | 2:c857935f928e | 15 | //#define TI 0.02 // in seconds |
aalawfi | 2:c857935f928e | 16 | #define SEN_DIFF_TO_DIST 0.97 //in [V/m] |
aalawfi | 2:c857935f928e | 17 | #define BITS 4 |
aalawfi | 2:c857935f928e | 18 | //Construct the Ticker to call the steering control system at a set rate |
aalawfi | 2:c857935f928e | 19 | // INPUT PINS |
aalawfi | 2:c857935f928e | 20 | AnalogIn left_distance_sensor(PTB1); |
aalawfi | 2:c857935f928e | 21 | AnalogIn right_distance_sensor(PTB0); |
aalawfi | 2:c857935f928e | 22 | |
aalawfi | 2:c857935f928e | 23 | // PWM out |
aalawfi | 2:c857935f928e | 24 | PwmOut servo_motor_pwm(PTD4); |
aalawfi | 2:c857935f928e | 25 | |
aalawfi | 2:c857935f928e | 26 | // Digital outs |
aalawfi | 2:c857935f928e | 27 | DigitalOut seg1[BITS]={PTC12, PTC13, PTC16, PTC17}; // insert pin numbers |
aalawfi | 2:c857935f928e | 28 | |
aalawfi | 2:c857935f928e | 29 | |
aalawfi | 2:c857935f928e | 30 | //Interrupt In |
aalawfi | 2:c857935f928e | 31 | InterruptIn left_landmark_sensor(PTA1); |
aalawfi | 2:c857935f928e | 32 | InterruptIn right_landmark_sensor(PTA2); |
aalawfi | 2:c857935f928e | 33 | |
aalawfi | 2:c857935f928e | 34 | // Tickers |
aalawfi | 2:c857935f928e | 35 | bool steering_enabled = true; |
aalawfi | 2:c857935f928e | 36 | Ticker steering_control_ticker; |
aalawfi | 2:c857935f928e | 37 | |
aalawfi | 2:c857935f928e | 38 |