2015_robocon_bteam / Mbed 2 deprecated 2015robot_main

Dependencies:   PID QEI mbed

Fork of 2015robot_main by Naoto Deguchi

Committer:
DeguNaoto
Date:
Wed Oct 21 08:15:06 2015 +0000
Revision:
112:717acc7c99f9
Parent:
101:b67d33e56b66
20151021 ????????????

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.***/
DeguNaoto 101:b67d33e56b66 5 PID contSwing(20.917 ,2.0 ,0.0 ,RATE);
unicore32 93:9cacc1763463 6 Ticker interruptSwingSpeed;
unicore32 93:9cacc1763463 7
DeguNaoto 112:717acc7c99f9 8 int resetSwingSpeed = 0;
DeguNaoto 112:717acc7c99f9 9
unicore32 93:9cacc1763463 10 inline void countSwingSpeed() {
unicore32 93:9cacc1763463 11 static int i = 0;
DeguNaoto 112:717acc7c99f9 12 if (resetSwingSpeed == 1) {
DeguNaoto 112:717acc7c99f9 13 i = 0;
DeguNaoto 112:717acc7c99f9 14 resetSwingSpeed = 0;
DeguNaoto 112:717acc7c99f9 15 }
DeguNaoto 101:b67d33e56b66 16 if (i <= swingspeed) {
unicore32 93:9cacc1763463 17 i+=swingspeed/10.0;
unicore32 93:9cacc1763463 18 targSwingRadVelocity=i;
unicore32 93:9cacc1763463 19 }
unicore32 93:9cacc1763463 20 else {
unicore32 94:086b53bd195e 21 interruptSwingSpeed.detach();
unicore32 93:9cacc1763463 22 }
unicore32 93:9cacc1763463 23 }
DeguNaoto 57:3fbd487e055e 24
DeguNaoto 112:717acc7c99f9 25
DeguNaoto 49:9276fda93084 26 inline void initializeSwing() {
DeguNaoto 49:9276fda93084 27 interrupter.rise(&countSwing);
DeguNaoto 49:9276fda93084 28 Motor_swing.period_us(SWING_PERIOD);
DeguNaoto 49:9276fda93084 29 //controller set
DeguNaoto 66:14df82661dfa 30 contSwing.setInputLimits(0.0, 100.0);
DeguNaoto 83:e1638c58e1f1 31 contSwing.setOutputLimits(0.0, 1.0);
DeguNaoto 49:9276fda93084 32 contSwing.setBias(0.0);
DeguNaoto 49:9276fda93084 33 contSwing.setMode(AUTO_MODE);
DeguNaoto 49:9276fda93084 34 }
DeguNaoto 57:3fbd487e055e 35 float waitTime = 0.0;
DeguNaoto 49:9276fda93084 36 void countSwing() {
DeguNaoto 49:9276fda93084 37 Indicator1 = !Indicator1;
DeguNaoto 49:9276fda93084 38 if(enableShoot){
DeguNaoto 49:9276fda93084 39 enableShoot=0;
DeguNaoto 99:ee7f78d64c14 40 // waitTime = (float)(((2.0 * PI) / swingRadVelocity) / 2.0);
DeguNaoto 99:ee7f78d64c14 41 // waitTime = (float)((((10.0 * PI) / 4.0) / swingRadVelocity) / 8.0);
DeguNaoto 101:b67d33e56b66 42 if(swingRadVelocity==0.0) waitTime = (float)((((2.0 * PI) / swingRadVelocity) / 4.0));//-0.0017);
DeguNaoto 100:5769dc0e7478 43 else waitTime=0.0;
DeguNaoto 99:ee7f78d64c14 44 if(waitTime<0.0) waitTime=0.0;
DeguNaoto 99:ee7f78d64c14 45 if(waitTime>10.0) waitTime=10.0;
DeguNaoto 99:ee7f78d64c14 46 wait(waitTime);
DeguNaoto 49:9276fda93084 47 sendData(1,6);
DeguNaoto 49:9276fda93084 48 }
DeguNaoto 49:9276fda93084 49 }
DeguNaoto 49:9276fda93084 50
DeguNaoto 55:db1797ac6cb1 51 double swingSita=0.0;
DeguNaoto 49:9276fda93084 52 inline void mesureSwing() {
DeguNaoto 55:db1797ac6cb1 53 PulsesSwing = ( double )SwingSens.getPulses();
DeguNaoto 98:ffe1247b9784 54 swingRadVelocity = (((PulsesSwing - PrefPulsesSwing) / 3000.0) * 2.0 * PI) / RATE;
DeguNaoto 55:db1797ac6cb1 55 PrefPulsesSwing = PulsesSwing;
DeguNaoto 49:9276fda93084 56 }
DeguNaoto 55:db1797ac6cb1 57
DeguNaoto 50:8ea4714316ce 58 double cont=0.0;
DeguNaoto 49:9276fda93084 59 inline void swingFollowing(){
DeguNaoto 49:9276fda93084 60 contSwing.setSetPoint(( float )targSwingRadVelocity);
DeguNaoto 49:9276fda93084 61 contSwing.setProcessValue(( float )swingRadVelocity);
DeguNaoto 50:8ea4714316ce 62 cont = contSwing.compute();
DeguNaoto 50:8ea4714316ce 63 Motor_swing = cont;
DeguNaoto 49:9276fda93084 64 }
DeguNaoto 49:9276fda93084 65
DeguNaoto 49:9276fda93084 66 #endif /*Swing.h*/