first commit

Dependencies:   mbed MMA8451Q

Committer:
aalawfi
Date:
Mon Nov 22 22:27:14 2021 +0000
Revision:
34:cb9a0cec2feb
Parent:
31:d570f957e083
- 3 Laps, fastest is ~~12.3s

Who changed what in which revision?

UserRevisionLine numberNew 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 31:d570f957e083 11 float REF = 0.00f; //in meters
aalawfi 23:4c743746533c 12
aalawfi 27:0fa9d61c5fc6 13 /* most recent PID values
aalawfi 26:54ce9f642477 14 float KP = 5.3;//1.2 // 1.5
aalawfi 26:54ce9f642477 15 #define KI_STEERING 10.2//4.1985
aalawfi 26:54ce9f642477 16 float KD = 0.1;//0.05003
aalawfi 27:0fa9d61c5fc6 17 */
aalawfi 27:0fa9d61c5fc6 18
aalawfi 29:17bec543a437 19 float KP = 6.6f; //at 0.17 best is 6.0f
aalawfi 31:d570f957e083 20 float KI_STEERING = 0.3f; // at 0.17 best is 0.25f;
aalawfi 28:1c2eb25d624e 21 float KD = 0.4f; //at 0.17 best is 0.3f;
aalawfi 26:54ce9f642477 22
aalawfi 23:4c743746533c 23
aalawfi 25:8bd029d58251 24 #define TIME_DERIVATIVE 1 //0.1 // was 0.08
aalawfi 25:8bd029d58251 25 #define TIME_INTEGRAL 1 //0.5 // 0.4
aalawfi 23:4c743746533c 26
aalawfi 26:54ce9f642477 27 #define TI_STEERING 0.01f // in seconds
aalawfi 25:8bd029d58251 28 #define SEN_DIFF_TO_DIST 3.5216
aalawfi 2:c857935f928e 29 #define BITS 4
aalawfi 2:c857935f928e 30 //Construct the Ticker to call the steering control system at a set rate
aalawfi 2:c857935f928e 31 // INPUT PINS
aalawfi 2:c857935f928e 32 AnalogIn left_distance_sensor(PTB1);
aalawfi 2:c857935f928e 33 AnalogIn right_distance_sensor(PTB0);
aalawfi 2:c857935f928e 34
aalawfi 2:c857935f928e 35 // PWM out
aalawfi 2:c857935f928e 36 PwmOut servo_motor_pwm(PTD4);
aalawfi 2:c857935f928e 37
aalawfi 2:c857935f928e 38 // Digital outs
aalawfi 4:8b1d52dab862 39 DigitalOut seg1[BITS]={PTC17, PTA16,PTA17,PTE31}; // insert pin numbers
aalawfi 2:c857935f928e 40
aalawfi 2:c857935f928e 41
aalawfi 2:c857935f928e 42 //Interrupt In
aalawfi 4:8b1d52dab862 43 InterruptIn left_landmark_sensor(PTD6);
aalawfi 4:8b1d52dab862 44 InterruptIn right_landmark_sensor(PTD7);
aalawfi 2:c857935f928e 45
aalawfi 2:c857935f928e 46 // Tickers
aalawfi 5:636c3fe18aa8 47 volatile bool steering_enabled = true;
aalawfi 2:c857935f928e 48 Ticker steering_control_ticker;
aalawfi 25:8bd029d58251 49 int counter=0;
aalawfi 34:cb9a0cec2feb 50 int lap=-1;