changed pins for e_button and added code for turning off PCB

Dependencies:   wheelchairControlSummer2019 Watchdog ros_lib_kinetic

Revision:
11:c9afd96fa08b
Parent:
10:b4d68db3ddbd
Child:
13:1d0ed92043af
--- a/main.cpp	Thu Jun 27 16:32:18 2019 +0000
+++ b/main.cpp	Thu Jun 27 18:09:10 2019 +0000
@@ -1,9 +1,17 @@
+#include "mbed.h"
+#include <ros.h>
+#include <nav_msgs/Odometry.h>      // Contains both the twist and pose
+#include "Watchdog.h"
 #include "wheelchair.h"
+#include "rtos.h"
 
 QEI wheel (D10, D9, NC, 1200);        //Initializes right encoder
 DigitalIn pt3(D10, PullUp);          //Pull up resistors to read analog signals into digital signals
 DigitalIn pt4(D9, PullUp);
 
+double watchdogLimit = 1.00;        // Set timeout limit for watchdog timer in milliseconds
+int buttonCheck = 0;
+
 /*added*/
 //DigitalIn e_button(D4);     //emergency button will start at HIGH
 
@@ -48,7 +56,7 @@
 Thread compass;                      //Thread for compass
 Thread velocity;                      //Thread for velosity
 Thread assistSafe;                  //thread for safety stuff
-
+Thread emergencyButton;             // Thread to check button state and reset device
 
 int main(void)
 {   
@@ -66,11 +74,17 @@
     compass.start(callback(&queue, &EventQueue::dispatch_forever));      //Starts running the compass thread
     velocity.start(callback(&queue, &EventQueue::dispatch_forever));     //Starts running the velosity thread
     assistSafe.start(callback(&queue, &EventQueue::dispatch_forever));     //Starts running the velosity thread
+    queue.call_every(SAMPLEFREQ, &smart, &Wheelchair::emergencyButton_thread);      // Sets up sampling frequency of the emergencyButton_thread
     //ros_com.start(callback(&queue, &EventQueue::dispatch_forever));     //Starts running the velosity thread
         pc.printf("After starting\r\n");
 
     //added
  //   int emerg_button = e_button;
+  
+ Watchdog dog;                                                          // Creates Watchdog object
+ dog.Configure(watchdogLimit);                                          // Configures timeout for Watchdog
+ pc.printf("Code initiated/reset");
+ 
  
     int set = 0;
     while(1) {
@@ -134,6 +148,7 @@
         }
 
         wait(process);
+        dog.Service();                                                  // Service the Watchdog so it does not cause a system reset - "Kicking"/"Feeding" the dog
     }
 }