linear actuator

Dependencies:   Motor PinDetect mbed

Fork of xbee_robot by Shubhojit Chattopadhyay

Revision:
1:57f1410e9614
Parent:
0:4b7f01607612
Child:
2:9a9fbbf43957
--- a/main.cpp	Sun Feb 27 06:12:22 2011 +0000
+++ b/main.cpp	Tue Feb 23 00:31:03 2016 +0000
@@ -1,52 +1,73 @@
-//Robot Unit with the Xbee module
+//Linear Actuator to control the moving rod. 
 
 #include "mbed.h"
 #include "Motor.h"
+#include "PinDetect.h"
 
-Serial xbee2(p9, p10);
-DigitalOut rst2(p8);
-
-Serial pc(USBTX, USBRX);
 
-DigitalOut myled2(LED3);
-DigitalOut myled1(LED4);
+float moving_time1 = 15.0;            //we control the Table Actuator stop position by play with the moving time1; longer rising time,higher stop position
+float moving_time2 = 20.0;            //we control the Connector Actuator stop position by play with the moving time2; longer rising time,higher stop position
+float charging_time = 20.0;           //the time needed to charge the battery, during which the Connector Actuator will stay at its highest position
+float wait_time = 3.0;               //time waiting for the drone to slide to the triangle hindge
+float hold_time = 3.0;               //the time during which the Table Actuator will stay at its highest position after disconnected the connector
+
 
-Motor m1(p23, p11, p12); // pwm, fwd, rev //lEFT MOTOR
-Motor m2(p22, p14, p15); // pwm, fwd, rev //rIGHT MOTOR
+Motor m1(p21, p27, p28);        // pwm, fwd, rev //Table Actuator
+Motor m2(p22, p10, p9);          // pwm, fwd, rev //Connector Actuator
+InterruptIn load_sensor(p5);
 
-Motor m3(p23, p12, p11); // pwm, rev, fwd 
-Motor m4(p22, p15, p14); // pwm, rev, fwd
-int main() {
-    char temp = '0';
+PinDetect start(p6);
+PinDetect reset(p7);
 
-    // reset the xbees (at least 200ns)
-   // rst1 = 0;
-    rst2 = 0;
-    wait_ms(1); 
-    //rst1 = 1;
-    rst2 = 1;
-    wait_ms(1); 
- 
-     for (float s= -1.0; s < 1.0 ; s += 0.01) {
-     while(1) {
-     temp = xbee2.getc();
-     if(temp == 'C'){  //FORWARD
-        m1.speed(s); 
-        m2.speed(s);
-        wait(0.02);
-        }
-        
-         if(temp == 'D'){ //REVERSE
-        m3.speed(s); 
-        m4.speed(s);
-        wait(0.02);
-        }
-        
-                myled1 = 1;
-                wait_ms(1);
-                myled1 = 0;
-                myled2 =1;
-    
-   } 
-  }  
+void start_the_schedual(){
+    m1.speed(1);            //Table Actuator Going Up
+    wait(moving_time1);
+    m1.speed(0);            //Table Actuator Stops at its Highest Position
+    wait(wait_time);        //Waiting for the quadcoptor to slide into the triangle hindge
+    m2.speed(1);            //Connector Actuator Going Up
+    wait(moving_time2);
+    m2.speed(0);            //Connector Actuator Stops at its Highest Position
+    wait(charging_time);    //Waiting for the battery to charging
+    m2.speed(-1);           //Connector Actuator Goging down
+    wait(moving_time2);
+    m2.speed(0);            //Connector Actuator Stops at the start position
+    wait(hold_time);        //Waiting for the quadcoptpr to take off
+    m1.speed(-1);           //Connector Actuator Goging down
+    wait(moving_time1);
+    m1.speed(0);            //Table Actuator Stops at the start position
+}
+/*
+void reset_to_zero(){
+    m2.speed(-1);           //Connector Actuator Goging down
+    wait(moving_time2);
+    m2.speed(0);            //Connector Actuator Stops at the start position
+    m1.speed(-1);           //Connector Actuator Goging down
+    wait(moving_time1);
+    m1.speed(0);            //Table Actuator Stops at the start position
 }
+*/
+
+void reset_to_zero(){
+    m2.speed(-1); 
+    m1.speed(-1);             //Connector Actuator Goging down
+    wait(moving_time2);
+    m2.speed(0);            //Connector Actuator Stops at the start position
+    m1.speed(0);            //Table Actuator Stops at the start position
+}
+
+int main() {
+    start.mode(PullUp); wait(0.01);
+    start.attach_deasserted(&start_the_schedual);
+    start.setSampleFrequency();
+    reset.mode(PullUp); wait(0.01);
+    reset.attach_deasserted(&reset_to_zero);
+    reset.setSampleFrequency();
+    //load_sensor.fall(&start_the_schedual);
+    //start.fall(&start_the_schedual);
+    //reset.fall(&reset_to_zero);
+    while(1) {
+      
+     
+    }  
+  
+}