first commit

Dependencies:   mbed MMA8451Q

Committer:
aalawfi
Date:
Mon Nov 08 21:08:41 2021 +0000
Revision:
26:54ce9f642477
Parent:
25:8bd029d58251
Child:
27:0fa9d61c5fc6
- 100Hz sample rate - not working as desired

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