
- This code combines steering and driving in one ticker - Fault check is in a ticker instead of while loop
steering_header.h
- Committer:
- aalawfi
- Date:
- 2021-10-25
- Revision:
- 9:5f032ca6c9b5
- Parent:
- 5:636c3fe18aa8
File content as of revision 9:5f032ca6c9b5:
/* 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]={PTC17, PTA16,PTA17,PTE31}; // insert pin numbers //Interrupt In InterruptIn left_landmark_sensor(PTD6); InterruptIn right_landmark_sensor(PTD7); // Tickers volatile bool steering_enabled = true; Ticker steering_control_ticker;