a
Dependents: 3servotest 1stcomp 3rdcompfixstart 2ndcomp ... more
Fork of Servo by
servo.cpp@4:5ae6ed80dc46, 2016-09-09 (annotated)
- Committer:
- choutin
- Date:
- Fri Sep 09 11:40:55 2016 +0000
- Revision:
- 4:5ae6ed80dc46
- Parent:
- 3:c112df463a8d
- Child:
- 5:58ef29cb8785
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 | 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 | |
choutin | 4:5ae6ed80dc46 | 46 | void beltstop(void){ |
choutin | 4:5ae6ed80dc46 | 47 | |
choutin | 4:5ae6ed80dc46 | 48 | pwmarm.period_ms(20); //20ms |
choutin | 4:5ae6ed80dc46 | 49 | pwmbelt.write(0.075); |
choutin | 4:5ae6ed80dc46 | 50 | |
choutin | 4:5ae6ed80dc46 | 51 | } |
choutin | 4:5ae6ed80dc46 | 52 | |
sakanakuuun | 0:655e1fcb96be | 53 | void close_hand(void) { |
sakanakuuun | 0:655e1fcb96be | 54 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 55 | |
sakanakuuun | 0:655e1fcb96be | 56 | pwmhand.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 57 | |
choutin | 4:5ae6ed80dc46 | 58 | degree=130; |
sakanakuuun | 0:655e1fcb96be | 59 | |
sakanakuuun | 0:655e1fcb96be | 60 | i=500+degree*1900/180; |
choutin | 3:c112df463a8d | 61 | pwmhand.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 62 | |
sakanakuuun | 0:655e1fcb96be | 63 | |
sakanakuuun | 0:655e1fcb96be | 64 | } |
sakanakuuun | 0:655e1fcb96be | 65 | |
sakanakuuun | 0:655e1fcb96be | 66 | void close_arm(void) { |
sakanakuuun | 0:655e1fcb96be | 67 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 68 | |
sakanakuuun | 0:655e1fcb96be | 69 | pwmarm.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 70 | |
choutin | 3:c112df463a8d | 71 | degree=100; |
sakanakuuun | 0:655e1fcb96be | 72 | |
sakanakuuun | 0:655e1fcb96be | 73 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 74 | pwmarm.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 75 | |
sakanakuuun | 0:655e1fcb96be | 76 | |
sakanakuuun | 0:655e1fcb96be | 77 | } |
sakanakuuun | 0:655e1fcb96be | 78 | |
sakanakuuun | 0:655e1fcb96be | 79 | |
sakanakuuun | 0:655e1fcb96be | 80 | void open_hand(void) { |
sakanakuuun | 0:655e1fcb96be | 81 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 82 | |
sakanakuuun | 0:655e1fcb96be | 83 | pwmhand.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 84 | |
sakanakuuun | 0:655e1fcb96be | 85 | degree=90; |
sakanakuuun | 0:655e1fcb96be | 86 | |
sakanakuuun | 0:655e1fcb96be | 87 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 88 | pwmhand.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 89 | |
sakanakuuun | 0:655e1fcb96be | 90 | |
sakanakuuun | 0:655e1fcb96be | 91 | } |
sakanakuuun | 0:655e1fcb96be | 92 | |
sakanakuuun | 0:655e1fcb96be | 93 | |
sakanakuuun | 0:655e1fcb96be | 94 | |
sakanakuuun | 0:655e1fcb96be | 95 | void open_arm(void) { |
sakanakuuun | 0:655e1fcb96be | 96 | int i,degree; |
sakanakuuun | 0:655e1fcb96be | 97 | |
sakanakuuun | 0:655e1fcb96be | 98 | pwmarm.period_ms(20); //20ms |
sakanakuuun | 0:655e1fcb96be | 99 | |
sakanakuuun | 0:655e1fcb96be | 100 | degree=10; |
sakanakuuun | 0:655e1fcb96be | 101 | |
sakanakuuun | 0:655e1fcb96be | 102 | i=500+degree*1900/180; |
sakanakuuun | 0:655e1fcb96be | 103 | pwmarm.write(i/PERIOD); |
sakanakuuun | 0:655e1fcb96be | 104 | |
sakanakuuun | 0:655e1fcb96be | 105 | |
sakanakuuun | 0:655e1fcb96be | 106 | } |