Integrated Lab

Dependencies:   Motor Servo mbed

Files at this revision

API Documentation at this revision

Comitter:
tmaly45
Date:
Wed Oct 03 00:57:21 2018 +0000
Parent:
0:f5f82650e679
Commit message:
should be updated, still need some comments about the SERVO

Changed in this revision

Motor.lib Show annotated file Show diff for this revision Revisions of this file
lab3integrated.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r f5f82650e679 -r efdd0b0bbdbc Motor.lib
--- a/Motor.lib	Thu Sep 27 19:01:43 2018 +0000
+++ b/Motor.lib	Wed Oct 03 00:57:21 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/simon/code/Motor/#f265e441bcd9
+https://os.mbed.com/teams/Actuator-Control-Lab/code/Motor/#f8f70090a6e8
diff -r f5f82650e679 -r efdd0b0bbdbc lab3integrated.cpp
--- a/lab3integrated.cpp	Thu Sep 27 19:01:43 2018 +0000
+++ b/lab3integrated.cpp	Wed Oct 03 00:57:21 2018 +0000
@@ -1,8 +1,14 @@
+//Integrated Servo and Motor
+// MIDN 3/C Stites and Maly 
+// Modified 10/2/18
+
 #include "mbed.h"
 #include "Servo.h"
+#include "Motor.h" //preprocessors to include Servo and Motor
 
-Servo kenny(p21);
+Servo kenny(p21); 
 Servo barb(p22);
+Motor m(p26, p29, p30); // Assigns the PwmOut (pwm) pin, DigitalOut (fwd) pin, and Digital Out (rev) pin
 
 int main() 
 {
@@ -10,21 +16,45 @@
     kenny.calibrate(0.0009,90);
     kenny = 0;
     barb = 1;
+    
+    float k = 0.2; // value of initial speed & variable to define speed 
+    float i, j; // used in 'for' loops
+    
     while(1)
     {
-        float i;
-        for (i=0; i<90; i++)
-        {
-            barb = 1 - i*0.0111;
-            kenny = i*0.0111;
-            wait(.0555);
-        }
-        float j;
-        for (j=0; j<90; j++)
-        {
-            kenny = 1 - j*0.0111;
-            barb = j*0.0111;
-            wait(.0555);
-        }
-    }            
+        for(k=0.2; k<1.0; k += 0.1) //Increases the value of k from 0.2 to 0.99. k is the speed of DC Motor
+            {
+            m.speed(k); // Sets the speed of the DC Motor to whatever value k is as it increases 
+            for (i=0; i<90; i++) // This 'for' loop turns the two Servos in opposite directions. 
+                { // It is set after the speed of the Motor is set so they move along with the DC Motor 
+                 barb = 1 - i*0.0111;
+                 kenny = i*0.0111;
+                  wait(.0555);
+                }
+            m.speed(-k); //Sets the speed of the DC motor in the opposite direction at k speed. 
+            for (j=0; j<90; j++)// This 'for' loop turns the two Servos in opposite directions from each other and from the step before. 
+                 {// It is set after the speed/direction change of the DC Motor so the Servos change direction the same time the DC motors do. 
+                 kenny = 1 - j*0.0111;
+                 barb = j*0.0111;
+                 wait(.0555);
+                 }
+            }
+        
+        m.speed(1); // This is for when the DC motor reaches full speed, which is 1. This will start at the end of the 'for' loop of the DC motor speed (k).  
+         for (i=0; i<90; i++)// Again, a 'for' loop to turn the two Servo motors in opposite directions while the DC motor turns. 
+                {
+                 barb = 1 - i*0.0111;
+                 kenny = i*0.0111;
+                  wait(.0555);
+                }
+        m.speed(-1); // Turns the DC motor at full speed in the opposite direction.
+        for (j=0; j<90; j++)// Again, a 'for' loop to turn the two Servo motors in opposite directions while the DC motor turns. 
+                 {
+                 kenny = 1 - j*0.0111;
+                 barb = j*0.0111;
+                 wait(.0555);
+                 }
+        
+        
+        }            
 }