- This code combines steering and driving in one ticker - Fault check is in a ticker instead of while loop

Dependencies:   mbed MMA8451Q

Revision:
2:c857935f928e
Child:
4:8b1d52dab862
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/steering_header.h	Mon Oct 25 01:28:53 2021 +0000
@@ -0,0 +1,38 @@
+/*
+    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;
+
+