2015_robocon_bteam / Mbed 2 deprecated 2015robot_main

Dependencies:   PID QEI mbed

Fork of 2015robot_main by Naoto Deguchi

Committer:
unicore32
Date:
Fri Oct 16 10:47:50 2015 +0000
Revision:
94:086b53bd195e
Parent:
93:9cacc1763463
Child:
100:5769dc0e7478
20151016 ??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DeguNaoto 49:9276fda93084 1 #ifndef SWING_H
DeguNaoto 49:9276fda93084 2 #define SWING_H
DeguNaoto 49:9276fda93084 3
DeguNaoto 49:9276fda93084 4 /***Swing.***/
unicore32 91:83c2e0381384 5 PID contSwing(10.917 ,10.0 ,0.0 ,RATE);
unicore32 93:9cacc1763463 6 Ticker interruptSwingSpeed;
unicore32 93:9cacc1763463 7
unicore32 93:9cacc1763463 8 inline void countSwingSpeed() {
unicore32 93:9cacc1763463 9 static int i = 0;
unicore32 94:086b53bd195e 10 if (i < swingspeed) {
unicore32 93:9cacc1763463 11 i+=swingspeed/10.0;
unicore32 93:9cacc1763463 12 targSwingRadVelocity=i;
unicore32 93:9cacc1763463 13 }
unicore32 93:9cacc1763463 14 else {
unicore32 94:086b53bd195e 15 interruptSwingSpeed.detach();
unicore32 93:9cacc1763463 16 }
unicore32 93:9cacc1763463 17 }
DeguNaoto 57:3fbd487e055e 18
DeguNaoto 49:9276fda93084 19 inline void initializeSwing() {
DeguNaoto 49:9276fda93084 20 interrupter.rise(&countSwing);
DeguNaoto 49:9276fda93084 21 Motor_swing.period_us(SWING_PERIOD);
DeguNaoto 49:9276fda93084 22 //controller set
DeguNaoto 66:14df82661dfa 23 contSwing.setInputLimits(0.0, 100.0);
DeguNaoto 83:e1638c58e1f1 24 contSwing.setOutputLimits(0.0, 1.0);
DeguNaoto 49:9276fda93084 25 contSwing.setBias(0.0);
DeguNaoto 49:9276fda93084 26 contSwing.setMode(AUTO_MODE);
DeguNaoto 49:9276fda93084 27 }
DeguNaoto 57:3fbd487e055e 28 float waitTime = 0.0;
DeguNaoto 49:9276fda93084 29 void countSwing() {
DeguNaoto 49:9276fda93084 30 Indicator1 = !Indicator1;
DeguNaoto 49:9276fda93084 31 if(enableShoot){
DeguNaoto 49:9276fda93084 32 enableShoot=0;
DeguNaoto 62:02a44f5bc51e 33 if(swingRadVelocity > 1.0){
DeguNaoto 79:7f86e18f40ef 34 // waitTime = (float)(((2.0 * PI) / swingRadVelocity) / 2.0);
DeguNaoto 83:e1638c58e1f1 35 waitTime = (float)((((10.0 * PI) / 4.0) / swingRadVelocity) / 8.0);
DeguNaoto 57:3fbd487e055e 36 wait(waitTime);
DeguNaoto 57:3fbd487e055e 37 }
DeguNaoto 49:9276fda93084 38 sendData(1,6);
DeguNaoto 49:9276fda93084 39 }
DeguNaoto 49:9276fda93084 40 }
DeguNaoto 49:9276fda93084 41
DeguNaoto 55:db1797ac6cb1 42 double swingSita=0.0;
DeguNaoto 49:9276fda93084 43 inline void mesureSwing() {
DeguNaoto 55:db1797ac6cb1 44 PulsesSwing = ( double )SwingSens.getPulses();
DeguNaoto 62:02a44f5bc51e 45 swingRadVelocity = (((PulsesSwing - PrefPulsesSwing) / 3450.0) * 2 * PI) / RATE;
DeguNaoto 55:db1797ac6cb1 46 PrefPulsesSwing = PulsesSwing;
DeguNaoto 49:9276fda93084 47 }
DeguNaoto 55:db1797ac6cb1 48
DeguNaoto 50:8ea4714316ce 49 double cont=0.0;
DeguNaoto 49:9276fda93084 50 inline void swingFollowing(){
DeguNaoto 49:9276fda93084 51 contSwing.setSetPoint(( float )targSwingRadVelocity);
DeguNaoto 49:9276fda93084 52 contSwing.setProcessValue(( float )swingRadVelocity);
DeguNaoto 50:8ea4714316ce 53 cont = contSwing.compute();
DeguNaoto 50:8ea4714316ce 54 Motor_swing = cont;
DeguNaoto 49:9276fda93084 55 }
DeguNaoto 49:9276fda93084 56
DeguNaoto 49:9276fda93084 57 #endif /*Swing.h*/