encoder, HIDscope and movement
Dependencies: Encoder HIDScope mbed
Fork of MovementandEncoder by
main.cpp@3:ac0fe759170f, 2015-10-14 (annotated)
- Committer:
- riannebulthuis
- Date:
- Wed Oct 14 09:57:31 2015 +0000
- Revision:
- 3:ac0fe759170f
- Parent:
- 2:174885cd1665
met comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsluiter | 0:0b39982f89a9 | 1 | #include "mbed.h" |
vsluiter | 0:0b39982f89a9 | 2 | #include "HIDScope.h" |
vsluiter | 0:0b39982f89a9 | 3 | #include "encoder.h" |
vsluiter | 0:0b39982f89a9 | 4 | |
arunr | 1:bac42065f837 | 5 | |
riannebulthuis | 3:ac0fe759170f | 6 | //pinverdeling en naamgeving variabelen |
riannebulthuis | 3:ac0fe759170f | 7 | Encoder motor1(D13,D12); // telt pulsen bij verdraaiing en zet dit om in de rotatiehoek |
riannebulthuis | 3:ac0fe759170f | 8 | PwmOut led(D9); |
riannebulthuis | 3:ac0fe759170f | 9 | DigitalOut motor_direction(D4); // motor direction |
riannebulthuis | 3:ac0fe759170f | 10 | PwmOut motor_speed(D5); // motor speed |
riannebulthuis | 3:ac0fe759170f | 11 | DigitalIn button_1(PTC6); // counterclockwise |
riannebulthuis | 3:ac0fe759170f | 12 | DigitalIn button_2(PTA4); // clockwise |
riannebulthuis | 3:ac0fe759170f | 13 | HIDScope scope(1); // Hidscope op channel 1??!! |
arunr | 2:174885cd1665 | 14 | |
riannebulthuis | 3:ac0fe759170f | 15 | const int pressed = 0; //signaal(beweging) bij indrukken |
arunr | 2:174885cd1665 | 16 | |
riannebulthuis | 3:ac0fe759170f | 17 | void move_motor_ccw () //beweging ccw motor 1, signaal van linker biceps |
riannebulthuis | 3:ac0fe759170f | 18 | { |
arunr | 2:174885cd1665 | 19 | motor_direction = 0; |
arunr | 2:174885cd1665 | 20 | motor_speed = 1; |
riannebulthuis | 3:ac0fe759170f | 21 | } |
riannebulthuis | 3:ac0fe759170f | 22 | |
riannebulthuis | 3:ac0fe759170f | 23 | void move_motor_cw () // beweging cw motor 1, signaal van rechter biceps |
riannebulthuis | 3:ac0fe759170f | 24 | { |
arunr | 2:174885cd1665 | 25 | motor_direction = 1; |
arunr | 2:174885cd1665 | 26 | motor_speed = 0.1; |
riannebulthuis | 3:ac0fe759170f | 27 | } |
riannebulthuis | 3:ac0fe759170f | 28 | |
riannebulthuis | 3:ac0fe759170f | 29 | void read_encoder () // aflezen van encoder via hidscope?? |
riannebulthuis | 3:ac0fe759170f | 30 | { |
riannebulthuis | 3:ac0fe759170f | 31 | scope.set(0,motor1.getPosition()); |
riannebulthuis | 3:ac0fe759170f | 32 | led.write(motor1.getPosition()/100.0); |
riannebulthuis | 3:ac0fe759170f | 33 | scope.send(); |
riannebulthuis | 3:ac0fe759170f | 34 | wait(0.2f); |
riannebulthuis | 3:ac0fe759170f | 35 | } |
riannebulthuis | 3:ac0fe759170f | 36 | |
riannebulthuis | 3:ac0fe759170f | 37 | void move() // beweging van motor 1 cw of ccw d.m.v. button 1 of 2 |
riannebulthuis | 3:ac0fe759170f | 38 | { |
riannebulthuis | 3:ac0fe759170f | 39 | if (button_1 == pressed) { |
riannebulthuis | 3:ac0fe759170f | 40 | move_motor_cw (); |
riannebulthuis | 3:ac0fe759170f | 41 | } else if (button_2 == pressed) { |
riannebulthuis | 3:ac0fe759170f | 42 | move_motor_ccw (); |
riannebulthuis | 3:ac0fe759170f | 43 | } else { |
riannebulthuis | 3:ac0fe759170f | 44 | motor_speed = 0; |
riannebulthuis | 3:ac0fe759170f | 45 | } |
riannebulthuis | 3:ac0fe759170f | 46 | } |
riannebulthuis | 3:ac0fe759170f | 47 | |
riannebulthuis | 3:ac0fe759170f | 48 | //uitvoeren van script |
riannebulthuis | 3:ac0fe759170f | 49 | int main() |
riannebulthuis | 3:ac0fe759170f | 50 | { |
riannebulthuis | 3:ac0fe759170f | 51 | while (true) { |
riannebulthuis | 3:ac0fe759170f | 52 | |
riannebulthuis | 3:ac0fe759170f | 53 | read_encoder(); |
riannebulthuis | 3:ac0fe759170f | 54 | move(); |
arunr | 2:174885cd1665 | 55 | } |
arunr | 2:174885cd1665 | 56 | |
riannebulthuis | 3:ac0fe759170f | 57 | } |