linear actuator

Dependencies:   Motor PinDetect mbed

Fork of xbee_robot by Shubhojit Chattopadhyay

Committer:
ldeng31
Date:
Tue Feb 23 00:31:03 2016 +0000
Revision:
1:57f1410e9614
Parent:
0:4b7f01607612
Child:
2:9a9fbbf43957
linear actuator schedule

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ldeng31 1:57f1410e9614 1 //Linear Actuator to control the moving rod.
buntyshubho 0:4b7f01607612 2
buntyshubho 0:4b7f01607612 3 #include "mbed.h"
buntyshubho 0:4b7f01607612 4 #include "Motor.h"
ldeng31 1:57f1410e9614 5 #include "PinDetect.h"
buntyshubho 0:4b7f01607612 6
buntyshubho 0:4b7f01607612 7
ldeng31 1:57f1410e9614 8 float moving_time1 = 15.0; //we control the Table Actuator stop position by play with the moving time1; longer rising time,higher stop position
ldeng31 1:57f1410e9614 9 float moving_time2 = 20.0; //we control the Connector Actuator stop position by play with the moving time2; longer rising time,higher stop position
ldeng31 1:57f1410e9614 10 float charging_time = 20.0; //the time needed to charge the battery, during which the Connector Actuator will stay at its highest position
ldeng31 1:57f1410e9614 11 float wait_time = 3.0; //time waiting for the drone to slide to the triangle hindge
ldeng31 1:57f1410e9614 12 float hold_time = 3.0; //the time during which the Table Actuator will stay at its highest position after disconnected the connector
ldeng31 1:57f1410e9614 13
buntyshubho 0:4b7f01607612 14
ldeng31 1:57f1410e9614 15 Motor m1(p21, p27, p28); // pwm, fwd, rev //Table Actuator
ldeng31 1:57f1410e9614 16 Motor m2(p22, p10, p9); // pwm, fwd, rev //Connector Actuator
ldeng31 1:57f1410e9614 17 InterruptIn load_sensor(p5);
buntyshubho 0:4b7f01607612 18
ldeng31 1:57f1410e9614 19 PinDetect start(p6);
ldeng31 1:57f1410e9614 20 PinDetect reset(p7);
buntyshubho 0:4b7f01607612 21
ldeng31 1:57f1410e9614 22 void start_the_schedual(){
ldeng31 1:57f1410e9614 23 m1.speed(1); //Table Actuator Going Up
ldeng31 1:57f1410e9614 24 wait(moving_time1);
ldeng31 1:57f1410e9614 25 m1.speed(0); //Table Actuator Stops at its Highest Position
ldeng31 1:57f1410e9614 26 wait(wait_time); //Waiting for the quadcoptor to slide into the triangle hindge
ldeng31 1:57f1410e9614 27 m2.speed(1); //Connector Actuator Going Up
ldeng31 1:57f1410e9614 28 wait(moving_time2);
ldeng31 1:57f1410e9614 29 m2.speed(0); //Connector Actuator Stops at its Highest Position
ldeng31 1:57f1410e9614 30 wait(charging_time); //Waiting for the battery to charging
ldeng31 1:57f1410e9614 31 m2.speed(-1); //Connector Actuator Goging down
ldeng31 1:57f1410e9614 32 wait(moving_time2);
ldeng31 1:57f1410e9614 33 m2.speed(0); //Connector Actuator Stops at the start position
ldeng31 1:57f1410e9614 34 wait(hold_time); //Waiting for the quadcoptpr to take off
ldeng31 1:57f1410e9614 35 m1.speed(-1); //Connector Actuator Goging down
ldeng31 1:57f1410e9614 36 wait(moving_time1);
ldeng31 1:57f1410e9614 37 m1.speed(0); //Table Actuator Stops at the start position
ldeng31 1:57f1410e9614 38 }
ldeng31 1:57f1410e9614 39 /*
ldeng31 1:57f1410e9614 40 void reset_to_zero(){
ldeng31 1:57f1410e9614 41 m2.speed(-1); //Connector Actuator Goging down
ldeng31 1:57f1410e9614 42 wait(moving_time2);
ldeng31 1:57f1410e9614 43 m2.speed(0); //Connector Actuator Stops at the start position
ldeng31 1:57f1410e9614 44 m1.speed(-1); //Connector Actuator Goging down
ldeng31 1:57f1410e9614 45 wait(moving_time1);
ldeng31 1:57f1410e9614 46 m1.speed(0); //Table Actuator Stops at the start position
buntyshubho 0:4b7f01607612 47 }
ldeng31 1:57f1410e9614 48 */
ldeng31 1:57f1410e9614 49
ldeng31 1:57f1410e9614 50 void reset_to_zero(){
ldeng31 1:57f1410e9614 51 m2.speed(-1);
ldeng31 1:57f1410e9614 52 m1.speed(-1); //Connector Actuator Goging down
ldeng31 1:57f1410e9614 53 wait(moving_time2);
ldeng31 1:57f1410e9614 54 m2.speed(0); //Connector Actuator Stops at the start position
ldeng31 1:57f1410e9614 55 m1.speed(0); //Table Actuator Stops at the start position
ldeng31 1:57f1410e9614 56 }
ldeng31 1:57f1410e9614 57
ldeng31 1:57f1410e9614 58 int main() {
ldeng31 1:57f1410e9614 59 start.mode(PullUp); wait(0.01);
ldeng31 1:57f1410e9614 60 start.attach_deasserted(&start_the_schedual);
ldeng31 1:57f1410e9614 61 start.setSampleFrequency();
ldeng31 1:57f1410e9614 62 reset.mode(PullUp); wait(0.01);
ldeng31 1:57f1410e9614 63 reset.attach_deasserted(&reset_to_zero);
ldeng31 1:57f1410e9614 64 reset.setSampleFrequency();
ldeng31 1:57f1410e9614 65 //load_sensor.fall(&start_the_schedual);
ldeng31 1:57f1410e9614 66 //start.fall(&start_the_schedual);
ldeng31 1:57f1410e9614 67 //reset.fall(&reset_to_zero);
ldeng31 1:57f1410e9614 68 while(1) {
ldeng31 1:57f1410e9614 69
ldeng31 1:57f1410e9614 70
ldeng31 1:57f1410e9614 71 }
ldeng31 1:57f1410e9614 72
ldeng31 1:57f1410e9614 73 }