a
Dependents: 3servotest 1stcomp 3rdcompfixstart 2ndcomp ... more
Fork of Servo by
servo.cpp@3:c112df463a8d, 2016-09-08 (annotated)
- Committer:
- choutin
- Date:
- Thu Sep 08 10:07:15 2016 +0000
- Revision:
- 3:c112df463a8d
- Parent:
- 1:c8ecfd809e22
- Child:
- 4:5ae6ed80dc46
k
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sakanakuuun | 0:655e1fcb96be | 1 | #include "mbed.h" |
sakanakuuun | 0:655e1fcb96be | 2 | |
sakanakuuun | 0:655e1fcb96be | 3 | PwmOut pwmarm(PC_6); |
sakanakuuun | 0:655e1fcb96be | 4 | PwmOut pwmhand(PC_8); |
choutin | 1:c8ecfd809e22 | 5 | PwmOut pwmbelt(PC_9); |
sakanakuuun | 0:655e1fcb96be | 6 | float PERIOD=20000; |
sakanakuuun | 0:655e1fcb96be | 7 | |
choutin | 1:c8ecfd809e22 | 8 | void armdegree(int degree) { |
choutin | 1:c8ecfd809e22 | 9 | int i; |
choutin | 1:c8ecfd809e22 | 10 | |
choutin | 1:c8ecfd809e22 | 11 | pwmarm.period_ms(20); //20ms |
choutin | 1:c8ecfd809e22 | 12 | |
choutin | 1:c8ecfd809e22 | 13 | degree=10; |
choutin | 1:c8ecfd809e22 | 14 | |
choutin | 1:c8ecfd809e22 | 15 | i=500+degree*1900/180; |
choutin | 1:c8ecfd809e22 | 16 | pwmarm.write(i/PERIOD); |
choutin | 1:c8ecfd809e22 | 17 | } |
choutin | 1:c8ecfd809e22 | 18 | |
choutin | 1:c8ecfd809e22 | 19 | void handdegree(int degree) { |
choutin | 1:c8ecfd809e22 | 20 | int i; |
choutin | 1:c8ecfd809e22 | 21 | |
choutin | 1:c8ecfd809e22 | 22 | pwmarm.period_ms(20); //20ms |
choutin | 1:c8ecfd809e22 | 23 | |
choutin | 1:c8ecfd809e22 | 24 | degree=10; |
choutin | 1:c8ecfd809e22 | 25 | |
choutin | 1:c8ecfd809e22 | 26 | i=500+degree*1900/180; |
choutin | 1:c8ecfd809e22 | 27 | pwmhand.write(i/PERIOD); |
choutin | 1:c8ecfd809e22 | 28 | |
choutin | 1:c8ecfd809e22 | 29 | } |
choutin | 1:c8ecfd809e22 | 30 | |
choutin | 3:c112df463a8d | 31 | void beltup(void){ |
choutin | 1:c8ecfd809e22 | 32 | |
choutin | 1:c8ecfd809e22 | 33 | pwmarm.period_ms(20); //20ms |
choutin | 3:c112df463a8d | 34 | pwmbelt.write(0.05); |
choutin | 1:c8ecfd809e22 | 35 | |
choutin | 1:c8ecfd809e22 | 36 | } |
choutin | 3:c112df463a8d | 37 | |
choutin | 3:c112df463a8d | 38 | void beltdown(void){ |
choutin | 3:c112df463a8d | 39 | |
choutin | 3:c112df463a8d | 40 | pwmarm.period_ms(20); //20ms |
choutin | 3:c112df463a8d | 41 | pwmbelt.write(0.1); |
choutin | 3:c112df463a8d | 42 | |
choutin | 3:c112df463a8d | 43 | } |
choutin | 3:c112df463a8d | 44 | |
choutin | 3:c112df463a8d | 45 | |
sakanakuuun | 0:655e1fcb96be | 46 | void close_hand(void) { |
sakanakuuun | 0:655e1fcb96be | 47 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 48 | |
sakanakuuun | 0:655e1fcb96be | 49 | pwmhand.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 50 | |
sakanakuuun | 0:655e1fcb96be | 51 | degree=175; |
sakanakuuun | 0:655e1fcb96be | 52 | |
sakanakuuun | 0:655e1fcb96be | 53 | i=500+degree*1900/180; |
choutin | 3:c112df463a8d | 54 | pwmhand.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 55 | |
sakanakuuun | 0:655e1fcb96be | 56 | |
sakanakuuun | 0:655e1fcb96be | 57 | } |
sakanakuuun | 0:655e1fcb96be | 58 | |
sakanakuuun | 0:655e1fcb96be | 59 | void close_arm(void) { |
sakanakuuun | 0:655e1fcb96be | 60 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 61 | |
sakanakuuun | 0:655e1fcb96be | 62 | pwmarm.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 63 | |
choutin | 3:c112df463a8d | 64 | degree=100; |
sakanakuuun | 0:655e1fcb96be | 65 | |
sakanakuuun | 0:655e1fcb96be | 66 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 67 | pwmarm.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 68 | |
sakanakuuun | 0:655e1fcb96be | 69 | |
sakanakuuun | 0:655e1fcb96be | 70 | } |
sakanakuuun | 0:655e1fcb96be | 71 | |
sakanakuuun | 0:655e1fcb96be | 72 | |
sakanakuuun | 0:655e1fcb96be | 73 | void open_hand(void) { |
sakanakuuun | 0:655e1fcb96be | 74 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 75 | |
sakanakuuun | 0:655e1fcb96be | 76 | pwmhand.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 77 | |
sakanakuuun | 0:655e1fcb96be | 78 | degree=90; |
sakanakuuun | 0:655e1fcb96be | 79 | |
sakanakuuun | 0:655e1fcb96be | 80 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 81 | pwmhand.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 82 | |
sakanakuuun | 0:655e1fcb96be | 83 | |
sakanakuuun | 0:655e1fcb96be | 84 | } |
sakanakuuun | 0:655e1fcb96be | 85 | |
sakanakuuun | 0:655e1fcb96be | 86 | |
sakanakuuun | 0:655e1fcb96be | 87 | |
sakanakuuun | 0:655e1fcb96be | 88 | void open_arm(void) { |
sakanakuuun | 0:655e1fcb96be | 89 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 90 | |
sakanakuuun | 0:655e1fcb96be | 91 | pwmarm.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 92 | |
sakanakuuun | 0:655e1fcb96be | 93 | degree=10; |
sakanakuuun | 0:655e1fcb96be | 94 | |
sakanakuuun | 0:655e1fcb96be | 95 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 96 | pwmarm.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 97 | |
sakanakuuun | 0:655e1fcb96be | 98 | |
sakanakuuun | 0:655e1fcb96be | 99 | } |