Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of 2015robot_main by
Swing.h@101:b67d33e56b66, 2015-10-17 (annotated)
- Committer:
- DeguNaoto
- Date:
- Sat Oct 17 06:04:49 2015 +0000
- Revision:
- 101:b67d33e56b66
- Parent:
- 100:5769dc0e7478
- Child:
- 112:717acc7c99f9
20151017 ?????????????
Who changed what in which revision?
| User | Revision | Line number | New 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 | |
| unicore32 | 93:9cacc1763463 | 8 | inline void countSwingSpeed() { | 
| unicore32 | 93:9cacc1763463 | 9 | static int i = 0; | 
| DeguNaoto | 101:b67d33e56b66 | 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 | 99:ee7f78d64c14 | 33 | // waitTime = (float)(((2.0 * PI) / swingRadVelocity) / 2.0); | 
| DeguNaoto | 99:ee7f78d64c14 | 34 | // waitTime = (float)((((10.0 * PI) / 4.0) / swingRadVelocity) / 8.0); | 
| DeguNaoto | 101:b67d33e56b66 | 35 | if(swingRadVelocity==0.0) waitTime = (float)((((2.0 * PI) / swingRadVelocity) / 4.0));//-0.0017); | 
| DeguNaoto | 100:5769dc0e7478 | 36 | else waitTime=0.0; | 
| DeguNaoto | 99:ee7f78d64c14 | 37 | if(waitTime<0.0) waitTime=0.0; | 
| DeguNaoto | 99:ee7f78d64c14 | 38 | if(waitTime>10.0) waitTime=10.0; | 
| DeguNaoto | 99:ee7f78d64c14 | 39 | wait(waitTime); | 
| DeguNaoto | 49:9276fda93084 | 40 | sendData(1,6); | 
| DeguNaoto | 49:9276fda93084 | 41 | } | 
| DeguNaoto | 49:9276fda93084 | 42 | } | 
| DeguNaoto | 49:9276fda93084 | 43 | |
| DeguNaoto | 55:db1797ac6cb1 | 44 | double swingSita=0.0; | 
| DeguNaoto | 49:9276fda93084 | 45 | inline void mesureSwing() { | 
| DeguNaoto | 55:db1797ac6cb1 | 46 | PulsesSwing = ( double )SwingSens.getPulses(); | 
| DeguNaoto | 98:ffe1247b9784 | 47 | swingRadVelocity = (((PulsesSwing - PrefPulsesSwing) / 3000.0) * 2.0 * PI) / RATE; | 
| DeguNaoto | 55:db1797ac6cb1 | 48 | PrefPulsesSwing = PulsesSwing; | 
| DeguNaoto | 49:9276fda93084 | 49 | } | 
| DeguNaoto | 55:db1797ac6cb1 | 50 | |
| DeguNaoto | 50:8ea4714316ce | 51 | double cont=0.0; | 
| DeguNaoto | 49:9276fda93084 | 52 | inline void swingFollowing(){ | 
| DeguNaoto | 49:9276fda93084 | 53 | contSwing.setSetPoint(( float )targSwingRadVelocity); | 
| DeguNaoto | 49:9276fda93084 | 54 | contSwing.setProcessValue(( float )swingRadVelocity); | 
| DeguNaoto | 50:8ea4714316ce | 55 | cont = contSwing.compute(); | 
| DeguNaoto | 50:8ea4714316ce | 56 | Motor_swing = cont; | 
| DeguNaoto | 49:9276fda93084 | 57 | } | 
| DeguNaoto | 49:9276fda93084 | 58 | |
| DeguNaoto | 49:9276fda93084 | 59 | #endif /*Swing.h*/ | 

