a
Dependents: 3servotest 1stcomp 3rdcompfixstart 2ndcomp ... more
Fork of Servo by
servo.cpp@1:c8ecfd809e22, 2016-09-07 (annotated)
- Committer:
- choutin
- Date:
- Wed Sep 07 09:40:58 2016 +0000
- Revision:
- 1:c8ecfd809e22
- Parent:
- 0:655e1fcb96be
- Child:
- 2:442fae3b1c0e
- Child:
- 3:c112df463a8d
a
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 | 1:c8ecfd809e22 | 31 | void beltdegree(int degree) { |
choutin | 1:c8ecfd809e22 | 32 | int i; |
choutin | 1:c8ecfd809e22 | 33 | |
choutin | 1:c8ecfd809e22 | 34 | pwmarm.period_ms(20); //20ms |
choutin | 1:c8ecfd809e22 | 35 | |
choutin | 1:c8ecfd809e22 | 36 | degree=10; |
choutin | 1:c8ecfd809e22 | 37 | |
choutin | 1:c8ecfd809e22 | 38 | i=500+degree*1900/180; |
choutin | 1:c8ecfd809e22 | 39 | pwmbelt.write(i/PERIOD); |
choutin | 1:c8ecfd809e22 | 40 | |
choutin | 1:c8ecfd809e22 | 41 | } |
sakanakuuun | 0:655e1fcb96be | 42 | void close_hand(void) { |
sakanakuuun | 0:655e1fcb96be | 43 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 44 | |
sakanakuuun | 0:655e1fcb96be | 45 | pwmhand.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 46 | |
sakanakuuun | 0:655e1fcb96be | 47 | degree=175; |
sakanakuuun | 0:655e1fcb96be | 48 | |
sakanakuuun | 0:655e1fcb96be | 49 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 50 | pwmhand.pulsewidth_us(i); |
sakanakuuun | 0:655e1fcb96be | 51 | |
sakanakuuun | 0:655e1fcb96be | 52 | |
sakanakuuun | 0:655e1fcb96be | 53 | } |
sakanakuuun | 0:655e1fcb96be | 54 | |
sakanakuuun | 0:655e1fcb96be | 55 | void close_arm(void) { |
sakanakuuun | 0:655e1fcb96be | 56 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 57 | |
sakanakuuun | 0:655e1fcb96be | 58 | pwmarm.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 59 | |
sakanakuuun | 0:655e1fcb96be | 60 | degree=160; |
sakanakuuun | 0:655e1fcb96be | 61 | |
sakanakuuun | 0:655e1fcb96be | 62 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 63 | pwmarm.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 64 | |
sakanakuuun | 0:655e1fcb96be | 65 | |
sakanakuuun | 0:655e1fcb96be | 66 | } |
sakanakuuun | 0:655e1fcb96be | 67 | |
sakanakuuun | 0:655e1fcb96be | 68 | |
sakanakuuun | 0:655e1fcb96be | 69 | void open_hand(void) { |
sakanakuuun | 0:655e1fcb96be | 70 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 71 | |
sakanakuuun | 0:655e1fcb96be | 72 | pwmhand.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 73 | |
sakanakuuun | 0:655e1fcb96be | 74 | degree=90; |
sakanakuuun | 0:655e1fcb96be | 75 | |
sakanakuuun | 0:655e1fcb96be | 76 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 77 | pwmhand.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 78 | |
sakanakuuun | 0:655e1fcb96be | 79 | |
sakanakuuun | 0:655e1fcb96be | 80 | } |
sakanakuuun | 0:655e1fcb96be | 81 | |
sakanakuuun | 0:655e1fcb96be | 82 | |
sakanakuuun | 0:655e1fcb96be | 83 | |
sakanakuuun | 0:655e1fcb96be | 84 | void open_arm(void) { |
sakanakuuun | 0:655e1fcb96be | 85 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 86 | |
sakanakuuun | 0:655e1fcb96be | 87 | pwmarm.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 88 | |
sakanakuuun | 0:655e1fcb96be | 89 | degree=10; |
sakanakuuun | 0:655e1fcb96be | 90 | |
sakanakuuun | 0:655e1fcb96be | 91 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 92 | pwmarm.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 93 | |
sakanakuuun | 0:655e1fcb96be | 94 | |
sakanakuuun | 0:655e1fcb96be | 95 | } |