Sophia, an autonomous robot based on Tamiya kits
Sophia.cpp@0:db79273ace80, 2013-05-09 (annotated)
- Committer:
- cylax
- Date:
- Thu May 09 02:45:44 2013 +0000
- Revision:
- 0:db79273ace80
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cylax | 0:db79273ace80 | 1 | #include "mbed.h" |
cylax | 0:db79273ace80 | 2 | #include "Motor.h" |
cylax | 0:db79273ace80 | 3 | #include "Sophia.h" |
cylax | 0:db79273ace80 | 4 | |
cylax | 0:db79273ace80 | 5 | Motor motor_right(PTD4, PTC13, PTC12); // pwm, fwd, rev |
cylax | 0:db79273ace80 | 6 | Motor motor_left(PTD4, PTA13, PTD5); |
cylax | 0:db79273ace80 | 7 | |
cylax | 0:db79273ace80 | 8 | void Sophia::move(float speed, int direction) { |
cylax | 0:db79273ace80 | 9 | if(direction) { |
cylax | 0:db79273ace80 | 10 | motor_right.speed(speed); |
cylax | 0:db79273ace80 | 11 | motor_left.speed(speed); |
cylax | 0:db79273ace80 | 12 | } |
cylax | 0:db79273ace80 | 13 | else { |
cylax | 0:db79273ace80 | 14 | motor_right.speed(-speed); |
cylax | 0:db79273ace80 | 15 | motor_left.speed(-speed); |
cylax | 0:db79273ace80 | 16 | } |
cylax | 0:db79273ace80 | 17 | } |
cylax | 0:db79273ace80 | 18 | |
cylax | 0:db79273ace80 | 19 | void Sophia::turn(float speed, int direction) { |
cylax | 0:db79273ace80 | 20 | if(direction) { |
cylax | 0:db79273ace80 | 21 | motor_right.speed(0.0); |
cylax | 0:db79273ace80 | 22 | motor_left.speed(speed); |
cylax | 0:db79273ace80 | 23 | } |
cylax | 0:db79273ace80 | 24 | else { |
cylax | 0:db79273ace80 | 25 | motor_right.speed(speed); |
cylax | 0:db79273ace80 | 26 | motor_left.speed(0.0); |
cylax | 0:db79273ace80 | 27 | } |
cylax | 0:db79273ace80 | 28 | } |
cylax | 0:db79273ace80 | 29 | void Sophia::spin(float speed, int direction) { |
cylax | 0:db79273ace80 | 30 | if(direction) { |
cylax | 0:db79273ace80 | 31 | motor_right.speed(-speed); |
cylax | 0:db79273ace80 | 32 | motor_left.speed(speed); |
cylax | 0:db79273ace80 | 33 | } |
cylax | 0:db79273ace80 | 34 | else { |
cylax | 0:db79273ace80 | 35 | motor_right.speed(speed); |
cylax | 0:db79273ace80 | 36 | motor_left.speed(-speed); |
cylax | 0:db79273ace80 | 37 | } |
cylax | 0:db79273ace80 | 38 | } |