car using PID from centre line

Dependencies:   FRDM-TFC mbed CBuffer XBEE mbed_angular_speed motor2 MMA8451Q

Fork of KL25Z_Camera_Test by GDP 4

Revision:
17:6ae90788cc2b
Parent:
13:4e77264f254a
Child:
18:0095a3a8f8e4
diff -r 81cdffd8c5d5 -r 6ae90788cc2b main.h
--- a/main.h	Fri Dec 02 11:06:17 2016 +0000
+++ b/main.h	Fri Dec 02 14:36:37 2016 +0000
@@ -1,3 +1,15 @@
+#define BAUD_RATE 57600
+#define CAM_THRESHOLD 100
+#define CAM_DIFF 10
+#define WHEEL_RADIUS 0.025f
+#define RIGHT_MOTOR_COMPENSATION_RATIO 1.1586276
+#define USE_COMMS 1
+
+#define CLOSE_CAMERA TFC_LineScanImage0
+#define LOOKAHEAD_CAMERA TFC_LineScanImage1
+
+
+#define ALIGN_SERVO TFC_InitServos(0.00052,0.00122,0.02)
 
 typedef struct {
     float Kp;
@@ -17,3 +29,66 @@
     float output;
 } pid_instance;
 
+extern inline void handleComms();
+extern void sendString(const char *format, ...);
+extern inline void sendImage();
+extern inline void sendSpeeds();
+extern void sendBattery();
+
+extern void initVariables();
+extern void initPID(pid_instance* pid, float Kp, float Ki, float Kd);
+extern inline float findCentreValue(volatile uint16_t * cam_data, uint8_t &left, uint8_t &right);
+extern inline void PIDController();
+extern void handlePID(pid_instance *pid);
+extern inline void handleStartStop();
+extern inline void handleCornering();
+extern inline float getLineEntropy();
+extern inline void initSpeedSensors();
+
+
+//Woo global variables!
+bool onTrack;
+char curr_line[128];
+uint8_t curr_left;
+uint8_t curr_right;
+uint8_t right;
+uint8_t left;
+uint8_t farRight;
+uint8_t farLeft;
+int diff;
+int prev;
+int i = 0;
+float measuredValBuffer[64];
+uint8_t valBufferIndex;
+
+//Communication Variables
+uint8_t sendCam = 0;
+int frame_counter = 0;
+char curr_cmd = 0; // Current comms command
+union {
+    float a;
+    unsigned char bytes[4];
+} thing;
+
+//Some PID variables
+pid_instance servo_pid;
+pid_instance right_motor_pid;
+pid_instance left_motor_pid;
+
+// Maximum car speed (PWM)
+float speed;
+
+//Hacky start/stop signal detection
+int startstop;
+bool seen;
+
+// Speed sensors
+volatile float Time_L,Time_R;
+float wL, wR;
+void GetTime_L();
+void GetTime_R();
+
+// Turning detection
+int turning;
+int keepTurning;
+bool slow;