ServoRobotArm

Dependencies:   mbed BufferedSerial LSCServo DC_Stepper_Controller_Lib

Committer:
stivending
Date:
Thu Jun 03 04:56:59 2021 +0000
Revision:
0:901a3ec83ba4
Child:
1:1eb3a5a00fbb
robot arm & servo union-test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stivending 0:901a3ec83ba4 1 /*******************************************************
stivending 0:901a3ec83ba4 2 DC MODOR CONTROLLER LIBRARY
stivending 0:901a3ec83ba4 3 *******************************************************
stivending 0:901a3ec83ba4 4 IMPORTANT: GO TO README FOR DOCUMENT!
stivending 0:901a3ec83ba4 5 ********************************************************/
stivending 0:901a3ec83ba4 6
stivending 0:901a3ec83ba4 7 #include "mbed.h"
stivending 0:901a3ec83ba4 8 #include "LSCServo.h"
stivending 0:901a3ec83ba4 9 #include "DC_Motor_Controller.h"
stivending 0:901a3ec83ba4 10
stivending 0:901a3ec83ba4 11
stivending 0:901a3ec83ba4 12 DC_Motor_PID motor(D6,D3,D4,D5,792); //M1, M2, INA, INB, PPR
stivending 0:901a3ec83ba4 13 DigitalIn but(D7);
stivending 0:901a3ec83ba4 14 LSCServo robot_arm(D1, D0); //D1 = Tx, D0 = Rx
stivending 0:901a3ec83ba4 15
stivending 0:901a3ec83ba4 16 int main() {
stivending 0:901a3ec83ba4 17
stivending 0:901a3ec83ba4 18 motor.set_pid(0.008, 0, 0, 0.10);
stivending 0:901a3ec83ba4 19
stivending 0:901a3ec83ba4 20 but.mode(PullUp);
stivending 0:901a3ec83ba4 21
stivending 0:901a3ec83ba4 22
stivending 0:901a3ec83ba4 23 wait(0.5);motor.set_out(0.4,0);
stivending 0:901a3ec83ba4 24 while(1)
stivending 0:901a3ec83ba4 25 {
stivending 0:901a3ec83ba4 26 if(but) { motor.set_out(0,0); break;}
stivending 0:901a3ec83ba4 27 }
stivending 0:901a3ec83ba4 28
stivending 0:901a3ec83ba4 29 wait(0.5);
stivending 0:901a3ec83ba4 30 motor.reset();
stivending 0:901a3ec83ba4 31 wait(0.5);
stivending 0:901a3ec83ba4 32 motor.move_angle(615);
stivending 0:901a3ec83ba4 33 wait(2);
stivending 0:901a3ec83ba4 34
stivending 0:901a3ec83ba4 35 robot_arm.moveServos(3,1000,2,185,3,560,4,0); // initial pos to put an arrow
stivending 0:901a3ec83ba4 36 wait(2);
stivending 0:901a3ec83ba4 37
stivending 0:901a3ec83ba4 38 robot_arm.moveServos(3,1000,2,185,3,560,4,800); // catch/crawl the arror
stivending 0:901a3ec83ba4 39 robot_arm.moveServos(3,1000,2,185,3,190,4,800); // rotate down
stivending 0:901a3ec83ba4 40 wait(2);
stivending 0:901a3ec83ba4 41 robot_arm.moveServos(3,1500,2,760,3,190,4,800); // rotate left
stivending 0:901a3ec83ba4 42 wait(2);
stivending 0:901a3ec83ba4 43
stivending 0:901a3ec83ba4 44 robot_arm.moveServos(3,1000,2,580,3,190,4,0); // open the crawler
stivending 0:901a3ec83ba4 45 //robot_arm.moveServos(3,1000,2,600,3,190,4,0); // rotate a little back
stivending 0:901a3ec83ba4 46 motor.move_angle(420);
stivending 0:901a3ec83ba4 47
stivending 0:901a3ec83ba4 48 robot_arm.moveServos(3,1000,2,185,3,560,4,0); // reset to init
stivending 0:901a3ec83ba4 49
stivending 0:901a3ec83ba4 50 }