linear actuator

Dependencies:   Motor PinDetect mbed

Fork of xbee_robot by Shubhojit Chattopadhyay

main.cpp

Committer:
ldeng31
Date:
2016-02-23
Revision:
1:57f1410e9614
Parent:
0:4b7f01607612
Child:
2:9a9fbbf43957

File content as of revision 1:57f1410e9614:

//Linear Actuator to control the moving rod. 

#include "mbed.h"
#include "Motor.h"
#include "PinDetect.h"


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(p21, p27, p28);        // pwm, fwd, rev //Table Actuator
Motor m2(p22, p10, p9);          // pwm, fwd, rev //Connector Actuator
InterruptIn load_sensor(p5);

PinDetect start(p6);
PinDetect reset(p7);

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) {
      
     
    }  
  
}