megan gimple / Mbed 2 deprecated OCE360_Final_Project

Dependencies:   mbed MMA8452Q MS5837 SDFileSystem SCI_SENSOR

Revision:
12:54b498af39df
Parent:
11:fc58334fd36b
Parent:
10:b2fe6d1dee81
Child:
13:c886dcc0ea41
--- a/main.cpp	Thu Dec 02 14:31:52 2021 +0000
+++ b/main.cpp	Thu Dec 02 14:34:09 2021 +0000
@@ -43,10 +43,18 @@
 //functions
 void welcome();
 void log_data();
+
 //IMU related
 void accel_update(); //update accelerometer related variables. we use imu_ticker to call this function
+
+//Control Parameters
+float tim =5;           //define thruster on time
+float percent = 1.2;    //user defined percent of thrust power
+
 //Control related functions
 void thrust_on(float pw, float on_time);  //input is pulse width
+//void thrust_off(float pw, float on_time); // turn off pulse width
+
 
 //global variables
 
@@ -58,17 +66,20 @@
    //inital set the thruster esc to 1ms duty cycle
     thruster.period(0.002);      // 2 ms period
     thruster.pulsewidth(1.0/1000.000);   
+    
     //Initialize accelerometer:
     accel.init();
     led1=1;
+    
     //initialize pressure sensor
     pc.printf("setting the pressure sensor\r\n");
     p_sensor.MS5837Reset();
     p_sensor.MS5837Init();
-    pc.printf("settting the tickers\r\n");
+    pc.printf("setting the tickers\r\n");
     t.start();
     led2=1;
     welcome();
+    
     //-----setup ticker-------//
     //setup ticker to separate log and IMU data update.
     //so we could have all our control code in the while loop
@@ -76,9 +87,13 @@
     accel_ticker.attach(&accel_update,0.1);  //10Hz
     log_ticker.attach(&log_data,0.5);
     wait(1);
+    
     while(1)
     {
-      // put your main control code here
+      float pw= percent;
+      float on_time =tim;
+      thrust_on(pw, on_time); //turn thruster on for 5 seconds
+      return 0;
     }
 
 }
@@ -165,6 +180,7 @@
 ////                       on_time-> thruster on time.
 void thrust_on(float pw, float on_time)  //input is pulse width
 {
+    
     float pw_max=2.0;
     if(pw>pw_max)
     {
@@ -180,6 +196,8 @@
     //PWM will be kept until time out
     while(tt.read()<=on_time)
     {
+        
+        pc.printf("thruster on?...mack is cool\r\n"); //print check
     }
     //stop the timer
     tt.stop();
@@ -189,3 +207,5 @@
 
 }
 
+///void thrust_off(float pw, float on_time)  //input is pulse width
+//
\ No newline at end of file