Carlo Collodi / kangaroo

Dependencies:   QEI mbed

Committer:
calamaridudeman
Date:
Wed Dec 04 02:58:18 2013 +0000
Revision:
58:c0b09adb2997
Parent:
57:dfea5d24d650
KANKAN CAN DO STUFF!!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
calamaridudeman 23:112c0be5a7f3 1 #include "mbed.h"
calamaridudeman 37:bf257a0154db 2 #include "Master.hpp"
calamaridudeman 22:4d85d989af08 3
sherryxy 48:8f0e007bd305 4 DigitalOut led1(LED1);
sherryxy 48:8f0e007bd305 5
calamaridudeman 23:112c0be5a7f3 6 Serial pc(USBTX, USBRX);
calamaridudeman 37:bf257a0154db 7 QEI mEnc1(p25, p26, NC, 1200, QEI::X4_ENCODING); //hip
calamaridudeman 37:bf257a0154db 8 QEI mEnc2(p23, p24, NC, 1200, QEI::X4_ENCODING);//knee
calamaridudeman 37:bf257a0154db 9
calamaridudeman 43:68faf056ed5c 10 Motor m1(p15,p17,p18,p21,mEnc2);//hip p17 high is CCW
calamaridudeman 43:68faf056ed5c 11 Motor m2(p16,p19,p20,p22,mEnc1);//knee p19 high is CCW
calamaridudeman 25:8a34b8d6cc6e 12
alexc89 45:0db0fc9f77b1 13
calamaridudeman 54:17ea4b3c80de 14 QEI bEnc1(p27, p28, p29, 2000, QEI::X4_ENCODING); //track offset:-2.236814
calamaridudeman 54:17ea4b3c80de 15 QEI bEnc2(p5, p6, p7, 2000, QEI::X4_ENCODING); //body offset:1.770973
calamaridudeman 37:bf257a0154db 16
calamaridudeman 37:bf257a0154db 17 Kangaroo kankan(m1,m2,bEnc1,bEnc2);
calamaridudeman 37:bf257a0154db 18
calamaridudeman 43:68faf056ed5c 19 Ticker t;
calamaridudeman 43:68faf056ed5c 20
calamaridudeman 43:68faf056ed5c 21 AnalogIn aIn(p15);
alexc89 45:0db0fc9f77b1 22 DigitalOut Forward(p17);
alexc89 45:0db0fc9f77b1 23 DigitalOut Backward(p18);
alexc89 45:0db0fc9f77b1 24 PwmOut pwmOut(p21);
alexc89 45:0db0fc9f77b1 25
alexc89 46:4497e945de6b 26 int SLIP(float initLen){//SlIP Model
alexc89 46:4497e945de6b 27 //Get Length
calamaridudeman 55:ff84fbdfd1d1 28 double y = kankan.getPoint().y;
calamaridudeman 55:ff84fbdfd1d1 29 double x = kankan.getPoint().x;
sherryxy 48:8f0e007bd305 30 //float length = pow(pow(x,2.0)+pow(y,2.0),0.5);
sherryxy 48:8f0e007bd305 31 int ks = 0.5;
sherryxy 48:8f0e007bd305 32 //float mag = (initLen-length)*ks;
alexc89 46:4497e945de6b 33 //Apply Forward Kinematics
calamaridudeman 56:7015e2e79ea7 34 Point slip_p = Point((1+ks)*x,(1+ks)*y,0);
calamaridudeman 56:7015e2e79ea7 35 kankan.setPoint(slip_p);
calamaridudeman 56:7015e2e79ea7 36
alexc89 46:4497e945de6b 37 return 1;
alexc89 46:4497e945de6b 38 }
alexc89 46:4497e945de6b 39 int FLIGHT(float initM1, float initM2){
alexc89 46:4497e945de6b 40 //Pos Control
alexc89 46:4497e945de6b 41 m1.setPos(initM1);
alexc89 46:4497e945de6b 42 m2.setPos(initM2);
alexc89 46:4497e945de6b 43 //Awesome.
alexc89 46:4497e945de6b 44 return 1;
alexc89 46:4497e945de6b 45 }
calamaridudeman 37:bf257a0154db 46 int main() {
calamaridudeman 55:ff84fbdfd1d1 47 kankan.start();
calamaridudeman 55:ff84fbdfd1d1 48 kankan.zero();
calamaridudeman 58:c0b09adb2997 49 /*
calamaridudeman 58:c0b09adb2997 50 m1.stop();
calamaridudeman 57:dfea5d24d650 51 m2.stop();
calamaridudeman 57:dfea5d24d650 52 while(1){
calamaridudeman 57:dfea5d24d650 53 kankan.testEncoders(pc);
calamaridudeman 57:dfea5d24d650 54 wait(.1);
calamaridudeman 58:c0b09adb2997 55 }
calamaridudeman 58:c0b09adb2997 56 */
alexc89 46:4497e945de6b 57 //Initalize Control Varialbes
alexc89 45:0db0fc9f77b1 58 int Phase = 0;//Flight Phase
alexc89 46:4497e945de6b 59
alexc89 45:0db0fc9f77b1 60 while(true){
alexc89 45:0db0fc9f77b1 61 if (Phase == 0){//Flight Phase
alexc89 46:4497e945de6b 62 //Uses PD to Control
alexc89 46:4497e945de6b 63 //FLIGHT(initM1, initM2);
sherryxy 48:8f0e007bd305 64 //m1.setPos(-0.5);
sherryxy 48:8f0e007bd305 65 led1=0;
calamaridudeman 58:c0b09adb2997 66 kankan.setPoint(Point(0.12,-.12,0));
calamaridudeman 55:ff84fbdfd1d1 67 if(kankan.landDetection()){
alexc89 45:0db0fc9f77b1 68 //Landed going to Phase 1
sherryxy 48:8f0e007bd305 69 //Record initial Length.
alexc89 45:0db0fc9f77b1 70 Phase =1;
alexc89 45:0db0fc9f77b1 71 }
alexc89 45:0db0fc9f77b1 72 }else{ //Land Phase
sherryxy 48:8f0e007bd305 73 led1=1; //landing detected
alexc89 46:4497e945de6b 74 //Uses SLIP Model to Control
sherryxy 48:8f0e007bd305 75
calamaridudeman 58:c0b09adb2997 76 kankan.slip(750,Point(-.08,-1.5,0), pc);
calamaridudeman 56:7015e2e79ea7 77 //kankan.testEncoders(pc);
sherryxy 48:8f0e007bd305 78 //m1.setPos(-1);
calamaridudeman 55:ff84fbdfd1d1 79 if(!kankan.landDetection()){
alexc89 45:0db0fc9f77b1 80 //Lift Up going to Phase 0
alexc89 45:0db0fc9f77b1 81 Phase =0;
alexc89 45:0db0fc9f77b1 82 }
alexc89 45:0db0fc9f77b1 83
alexc89 45:0db0fc9f77b1 84 }
alexc89 45:0db0fc9f77b1 85 }
calamaridudeman 23:112c0be5a7f3 86
calamaridudeman 55:ff84fbdfd1d1 87
calamaridudeman 43:68faf056ed5c 88 m1.stop();
calamaridudeman 43:68faf056ed5c 89 m2.stop();
calamaridudeman 55:ff84fbdfd1d1 90
calamaridudeman 22:4d85d989af08 91 }