2015_robocon_bteam / Mbed 2 deprecated 2015robot_main

Dependencies:   PID QEI mbed

Fork of 2015robot_main by Naoto Deguchi

Committer:
DeguNaoto
Date:
Fri Oct 16 08:08:32 2015 +0000
Revision:
98:ffe1247b9784
Parent:
95:deb2e75c42ff
Child:
99:ee7f78d64c14
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 93:9cacc1763463 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 93:9cacc1763463 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 95:deb2e75c42ff 35 // waitTime = (float)((((10.0 * PI) / 4.0) / swingRadVelocity) / 8.0);
DeguNaoto 95:deb2e75c42ff 36 waitTime = (float)(((2.0 * PI) / swingRadVelocity) / 4.0)-0.0017;
DeguNaoto 57:3fbd487e055e 37 wait(waitTime);
DeguNaoto 57:3fbd487e055e 38 }
DeguNaoto 49:9276fda93084 39 sendData(1,6);
DeguNaoto 49:9276fda93084 40 }
DeguNaoto 49:9276fda93084 41 }
DeguNaoto 49:9276fda93084 42
DeguNaoto 55:db1797ac6cb1 43 double swingSita=0.0;
DeguNaoto 49:9276fda93084 44 inline void mesureSwing() {
DeguNaoto 55:db1797ac6cb1 45 PulsesSwing = ( double )SwingSens.getPulses();
DeguNaoto 98:ffe1247b9784 46 swingRadVelocity = (((PulsesSwing - PrefPulsesSwing) / 3000.0) * 2.0 * PI) / RATE;
DeguNaoto 55:db1797ac6cb1 47 PrefPulsesSwing = PulsesSwing;
DeguNaoto 49:9276fda93084 48 }
DeguNaoto 55:db1797ac6cb1 49
DeguNaoto 50:8ea4714316ce 50 double cont=0.0;
DeguNaoto 49:9276fda93084 51 inline void swingFollowing(){
DeguNaoto 49:9276fda93084 52 contSwing.setSetPoint(( float )targSwingRadVelocity);
DeguNaoto 49:9276fda93084 53 contSwing.setProcessValue(( float )swingRadVelocity);
DeguNaoto 50:8ea4714316ce 54 cont = contSwing.compute();
DeguNaoto 50:8ea4714316ce 55 Motor_swing = cont;
DeguNaoto 49:9276fda93084 56 }
DeguNaoto 49:9276fda93084 57
DeguNaoto 49:9276fda93084 58 #endif /*Swing.h*/