Includes both the servo and Dc motor. Needs more comments on the servo side.

Dependencies:   Motor Servo mbed

Fork of lab3integrated by Actuator Control Lab

Files at this revision

API Documentation at this revision

Comitter:
corwinstites
Date:
Wed Oct 03 01:46:15 2018 +0000
Parent:
1:efdd0b0bbdbc
Commit message:
Updated

Changed in this revision

lab3integrated.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r efdd0b0bbdbc -r df17a1850217 lab3integrated.cpp
--- a/lab3integrated.cpp	Wed Oct 03 00:57:21 2018 +0000
+++ b/lab3integrated.cpp	Wed Oct 03 01:46:15 2018 +0000
@@ -4,37 +4,37 @@
 
 #include "mbed.h"
 #include "Servo.h"
-#include "Motor.h" //preprocessors to include Servo and Motor
+#include "Motor.h" //Preprocessors to include Servo and Motor
 
-Servo kenny(p21); 
+Servo kenny(p21); // Assigns pins to control two servos (kenny and barb)
 Servo barb(p22);
 Motor m(p26, p29, p30); // Assigns the PwmOut (pwm) pin, DigitalOut (fwd) pin, and Digital Out (rev) pin
 
 int main() 
 {
-    barb.calibrate(0.0009,90);
+    barb.calibrate(0.0009,90); // Calibrates the servo motors
     kenny.calibrate(0.0009,90);
-    kenny = 0;
-    barb = 1;
+    kenny = 0; // Sets servo kenny at the begining of his 180 degree rotation
+    barb = 1; // Sets servo barb at the end of her 180 degree rotation
     
     float k = 0.2; // value of initial speed & variable to define speed 
     float i, j; // used in 'for' loops
     
-    while(1)
+    while(1) // Continue to repeat
     {
         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);
+                 barb = 1 - i*0.0111; // Moves barb backwards 2 degrees
+                 kenny = i*0.0111; // Moves kenny forwards 2 degrees
+                  wait(.0555); //Wait .0555 seconds before moving the servos again (when this loop is repeated 90 times it takes 5 seconds)
                 }
             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;
+                 kenny = 1 - j*0.0111; //Now that the starting positions of kenny and barb are reversed this reverses the above process.
                  barb = j*0.0111;
                  wait(.0555);
                  }
@@ -43,14 +43,14 @@
         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;
+                 barb = 1 - i*0.0111; //Repeats above process indefinetly
                  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;
+                 kenny = 1 - j*0.0111; //Reverses above process indefinetly
                  barb = j*0.0111;
                  wait(.0555);
                  }