first commit

Dependencies:   mbed MMA8451Q

Committer:
aalawfi
Date:
Sat Nov 06 16:31:02 2021 +0000
Revision:
25:8bd029d58251
Parent:
24:7bf492bf50f4
Child:
26:54ce9f642477
-

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 25:8bd029d58251 11 #define REF 0.000 //in meters
aalawfi 23:4c743746533c 12
aalawfi 25:8bd029d58251 13 float KP = 5.5;//1.2 // 1.5
aalawfi 25:8bd029d58251 14 #define KI_STEERING 1.2//4.1985
aalawfi 25:8bd029d58251 15 float KD= 0.2;//0.05003
aalawfi 23:4c743746533c 16
aalawfi 25:8bd029d58251 17 #define TIME_DERIVATIVE 1 //0.1 // was 0.08
aalawfi 25:8bd029d58251 18 #define TIME_INTEGRAL 1 //0.5 // 0.4
aalawfi 23:4c743746533c 19
aalawfi 25:8bd029d58251 20 #define TI_STEERING 0.01 // in seconds
aalawfi 25:8bd029d58251 21 #define SEN_DIFF_TO_DIST 3.5216
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 25:8bd029d58251 42 int counter=0;
aalawfi 25:8bd029d58251 43 int lap=0;