na
Fork of SeeedShieldBot by
SeeedStudioShieldBot.h@6:9479362be27f, 2013-07-15 (annotated)
- Committer:
- melse
- Date:
- Mon Jul 15 14:03:41 2013 +0000
- Revision:
- 6:9479362be27f
- Parent:
- 5:179e85a68446
- Child:
- 7:887c729fd7c1
added notes about 5v vin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
melse | 0:227158f56a11 | 1 | #include "mbed.h" |
melse | 0:227158f56a11 | 2 | |
melse | 3:ccd47cdacb7b | 3 | /** Seeed Studio Shield Bot Control Class |
melse | 5:179e85a68446 | 4 | * In order to use this properly, you need to connect a jumper between pins eight and three on the shield bot, and you can't use either pins 8 or 3, which correspond to PTA13 and PTA12, respectively. |
melse | 6:9479362be27f | 5 | * Also, in order to provide power to the freedom board, when running just of a lipo battery, you need to connect between 5V and VIN on the shield bot. |
melse | 6:9479362be27f | 6 | * Code/notes above only tested with version 0.9b, may not be needed/may not work in other cases... |
melse | 3:ccd47cdacb7b | 7 | */ |
melse | 0:227158f56a11 | 8 | class SeeedStudioShieldBot { |
melse | 0:227158f56a11 | 9 | public: |
melse | 0:227158f56a11 | 10 | |
melse | 0:227158f56a11 | 11 | // Create a shield bot object, using default settings for now... |
melse | 0:227158f56a11 | 12 | SeeedStudioShieldBot(); |
melse | 0:227158f56a11 | 13 | |
melse | 2:118efce95f3c | 14 | /** Switch on the left motor at the given speed. |
melse | 4:e2d5ac8459a4 | 15 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
melse | 2:118efce95f3c | 16 | */ |
melse | 0:227158f56a11 | 17 | void left_motor(float speed); |
melse | 4:e2d5ac8459a4 | 18 | |
melse | 4:e2d5ac8459a4 | 19 | /** Switch on the right motor at the given speed. |
melse | 4:e2d5ac8459a4 | 20 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
melse | 4:e2d5ac8459a4 | 21 | */ |
melse | 0:227158f56a11 | 22 | void right_motor(float speed); |
melse | 0:227158f56a11 | 23 | |
melse | 4:e2d5ac8459a4 | 24 | /** Switch on both motors, forwards at the given speed. |
melse | 4:e2d5ac8459a4 | 25 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
melse | 4:e2d5ac8459a4 | 26 | */ |
melse | 0:227158f56a11 | 27 | void forward(float speed); |
melse | 4:e2d5ac8459a4 | 28 | |
melse | 4:e2d5ac8459a4 | 29 | /** Switch on both motors, backwards at the given speed. |
melse | 4:e2d5ac8459a4 | 30 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
melse | 4:e2d5ac8459a4 | 31 | */ |
melse | 0:227158f56a11 | 32 | void backward(float speed); |
melse | 0:227158f56a11 | 33 | |
melse | 4:e2d5ac8459a4 | 34 | /** Switch on both motors at the given speed, in opposite directions so as to turn left. |
melse | 4:e2d5ac8459a4 | 35 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motors. |
melse | 4:e2d5ac8459a4 | 36 | */ |
melse | 0:227158f56a11 | 37 | void left(float speed); |
melse | 4:e2d5ac8459a4 | 38 | |
melse | 4:e2d5ac8459a4 | 39 | /** Switch on both motors at the given speed, in opposite directions so as to turn right. |
melse | 4:e2d5ac8459a4 | 40 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motors. |
melse | 4:e2d5ac8459a4 | 41 | */ |
melse | 0:227158f56a11 | 42 | void right(float speed); |
melse | 0:227158f56a11 | 43 | |
melse | 4:e2d5ac8459a4 | 44 | /** Disable the left motor, by driving enable pin for the second motor low... |
melse | 4:e2d5ac8459a4 | 45 | */ |
melse | 2:118efce95f3c | 46 | void disable_left_motor(); |
melse | 4:e2d5ac8459a4 | 47 | |
melse | 4:e2d5ac8459a4 | 48 | /** Disable the left motor, by driving enable pin for the first motor low... |
melse | 4:e2d5ac8459a4 | 49 | */ |
melse | 2:118efce95f3c | 50 | void disable_right_motor(); |
melse | 0:227158f56a11 | 51 | |
melse | 4:e2d5ac8459a4 | 52 | /** Enable the left motor, by driving enable pin for the second motor high... |
melse | 4:e2d5ac8459a4 | 53 | */ |
melse | 2:118efce95f3c | 54 | void enable_left_motor(); |
melse | 4:e2d5ac8459a4 | 55 | |
melse | 4:e2d5ac8459a4 | 56 | /** Enable the left motor, by driving enable pin for the first motor high... |
melse | 4:e2d5ac8459a4 | 57 | */ |
melse | 2:118efce95f3c | 58 | void enable_right_motor(); |
melse | 0:227158f56a11 | 59 | |
melse | 4:e2d5ac8459a4 | 60 | /** Stop both motors at the same time. Different to disable. |
melse | 4:e2d5ac8459a4 | 61 | */ |
melse | 0:227158f56a11 | 62 | void stopAll(); |
melse | 4:e2d5ac8459a4 | 63 | |
melse | 4:e2d5ac8459a4 | 64 | /** Stop a chosen motor. |
melse | 4:e2d5ac8459a4 | 65 | * @param motor Number, either 1 or 2 choosing the motor. |
melse | 4:e2d5ac8459a4 | 66 | */ |
melse | 2:118efce95f3c | 67 | void stop(int motor); |
melse | 0:227158f56a11 | 68 | |
melse | 0:227158f56a11 | 69 | // Need to do something to do with detected line... |
melse | 0:227158f56a11 | 70 | |
melse | 4:e2d5ac8459a4 | 71 | /** Gives an indication of the data given by the reflectivity sensors. |
melse | 4:e2d5ac8459a4 | 72 | */ |
melse | 1:5c40f2a5e1ac | 73 | float line_position(); |
melse | 0:227158f56a11 | 74 | |
melse | 0:227158f56a11 | 75 | DigitalIn rightSensor; |
melse | 0:227158f56a11 | 76 | DigitalIn inRightSensor; |
melse | 0:227158f56a11 | 77 | DigitalIn centreSensor; |
melse | 0:227158f56a11 | 78 | DigitalIn inLeftSensor; |
melse | 0:227158f56a11 | 79 | DigitalIn leftSensor; |
melse | 0:227158f56a11 | 80 | |
melse | 0:227158f56a11 | 81 | private: |
melse | 0:227158f56a11 | 82 | PwmOut motor1A; |
melse | 0:227158f56a11 | 83 | DigitalOut motor1B; |
melse | 0:227158f56a11 | 84 | DigitalOut motor1En; |
melse | 0:227158f56a11 | 85 | |
melse | 0:227158f56a11 | 86 | // motor2A or motor2B need to be PWM, but the freedom board doesn't support it at the moment... |
melse | 0:227158f56a11 | 87 | PwmOut motor2A; |
melse | 0:227158f56a11 | 88 | DigitalOut motor2B; |
melse | 0:227158f56a11 | 89 | DigitalOut motor2En; |
melse | 0:227158f56a11 | 90 | }; |