first commit

Dependencies:   mbed MMA8451Q

steering_header.h

Committer:
aalawfi
Date:
2021-10-25
Revision:
2:c857935f928e
Child:
4:8b1d52dab862

File content as of revision 2:c857935f928e:

/*
    Include libraries, IO pins 
*/
#include "cmath"
#include <algorithm>    // std::min, std::max
#define M_PI 3.14159265359f
#define MAX_TURN_ANGLE M_PI/4
#define MIN_TURN_ANGLE -M_PI/4
#define SERVO_MOTOR_FREQ 50.0f
#define CENTER_DUTY_CYCLE 0.075f
#define REF 0.0f //in meters
#define KP 16.45 //  16.65 optimal 
#define KD 0.98 // 0.88 optimal
#define TIME_DERIVATIVE 0.9 // good 0.8
//#define TI 0.02 // in seconds
#define SEN_DIFF_TO_DIST 0.97 //in [V/m]
#define BITS 4
//Construct the Ticker to call the steering control system at a set rate
// INPUT PINS 
AnalogIn left_distance_sensor(PTB1); 
AnalogIn right_distance_sensor(PTB0); 

// PWM out 
PwmOut servo_motor_pwm(PTD4);

// Digital outs 
DigitalOut seg1[BITS]={PTC12, PTC13, PTC16, PTC17}; // insert pin numbers


//Interrupt In
InterruptIn left_landmark_sensor(PTA1);
InterruptIn right_landmark_sensor(PTA2);

// Tickers
bool steering_enabled = true;
Ticker steering_control_ticker;