na
Fork of SeeedShieldBot by
SeeedStudioShieldBot.h@9:7041241217c4, 2015-08-13 (annotated)
- Committer:
- 0scar0o0o0
- Date:
- Thu Aug 13 02:13:25 2015 +0000
- Revision:
- 9:7041241217c4
- Parent:
- 8:9fd1722259a1
Robot
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 | |
screamer | 7:887c729fd7c1 | 11 | /** Create a shield bot object |
screamer | 7:887c729fd7c1 | 12 | * |
screamer | 7:887c729fd7c1 | 13 | * @param mot1A Left Motor A pin, default D5 |
screamer | 7:887c729fd7c1 | 14 | * @param mot1B Left Motor B pin, default D6 |
screamer | 7:887c729fd7c1 | 15 | * @param mot1En Left Motor enable pin, default D7 |
0scar0o0o0 | 9:7041241217c4 | 16 | |
0scar0o0o0 | 9:7041241217c4 | 17 | * @param mot2A Right Motor A pin, default D8 |
screamer | 7:887c729fd7c1 | 18 | * @param mot2B Right Motor B pin, default D9 |
screamer | 7:887c729fd7c1 | 19 | * @param mot2En Right Motor enable pin, default D10 |
0scar0o0o0 | 9:7041241217c4 | 20 | |
screamer | 7:887c729fd7c1 | 21 | * @param sensor_right Sensor right pin, default A0 |
screamer | 7:887c729fd7c1 | 22 | * @param sensor_inright Sensor in-right pin, default A1 |
screamer | 7:887c729fd7c1 | 23 | * @param sensor_center Sensor right pin, default A2 |
screamer | 7:887c729fd7c1 | 24 | * @param sensor_inleft Sensor in-left pin, default A3 |
screamer | 7:887c729fd7c1 | 25 | * @param sensor_left Sensor left pin, default D4 |
screamer | 7:887c729fd7c1 | 26 | */ |
screamer | 7:887c729fd7c1 | 27 | SeeedStudioShieldBot(PinName mot1A, PinName mot1En, PinName mot1B, PinName mot2A, PinName mot2En, PinName mot2B, PinName sensor_right, PinName sensor_inright, PinName sensor_center, PinName sensor_inleft, PinName sensor_left); |
screamer | 7:887c729fd7c1 | 28 | |
melse | 2:118efce95f3c | 29 | /** Switch on the left motor at the given speed. |
melse | 4:e2d5ac8459a4 | 30 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
screamer | 7:887c729fd7c1 | 31 | */ |
melse | 0:227158f56a11 | 32 | void left_motor(float speed); |
melse | 4:e2d5ac8459a4 | 33 | |
melse | 4:e2d5ac8459a4 | 34 | /** Switch on the right motor at the given speed. |
melse | 4:e2d5ac8459a4 | 35 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
screamer | 7:887c729fd7c1 | 36 | */ |
melse | 0:227158f56a11 | 37 | void right_motor(float speed); |
melse | 0:227158f56a11 | 38 | |
melse | 4:e2d5ac8459a4 | 39 | /** Switch on both motors, forwards at the given speed. |
melse | 4:e2d5ac8459a4 | 40 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
screamer | 7:887c729fd7c1 | 41 | */ |
melse | 0:227158f56a11 | 42 | void forward(float speed); |
melse | 4:e2d5ac8459a4 | 43 | |
melse | 4:e2d5ac8459a4 | 44 | /** Switch on both motors, backwards at the given speed. |
melse | 4:e2d5ac8459a4 | 45 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
screamer | 7:887c729fd7c1 | 46 | */ |
melse | 0:227158f56a11 | 47 | void backward(float speed); |
melse | 0:227158f56a11 | 48 | |
melse | 4:e2d5ac8459a4 | 49 | /** Switch on both motors at the given speed, in opposite directions so as to turn left. |
melse | 4:e2d5ac8459a4 | 50 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motors. |
melse | 4:e2d5ac8459a4 | 51 | */ |
melse | 0:227158f56a11 | 52 | void left(float speed); |
melse | 4:e2d5ac8459a4 | 53 | |
melse | 4:e2d5ac8459a4 | 54 | /** Switch on both motors at the given speed, in opposite directions so as to turn right. |
melse | 4:e2d5ac8459a4 | 55 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motors. |
screamer | 7:887c729fd7c1 | 56 | */ |
melse | 0:227158f56a11 | 57 | void right(float speed); |
screamer | 7:887c729fd7c1 | 58 | |
screamer | 7:887c729fd7c1 | 59 | /** Turns left. |
screamer | 7:887c729fd7c1 | 60 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
screamer | 7:887c729fd7c1 | 61 | */ |
screamer | 7:887c729fd7c1 | 62 | void turn_left(float speed); |
screamer | 7:887c729fd7c1 | 63 | |
screamer | 7:887c729fd7c1 | 64 | /** Turns right. |
screamer | 7:887c729fd7c1 | 65 | * @param speed The speed, from 0.0 to 1.0 at which to spin the motor. |
screamer | 7:887c729fd7c1 | 66 | */ |
screamer | 7:887c729fd7c1 | 67 | void turn_right(float speed); |
screamer | 7:887c729fd7c1 | 68 | |
melse | 4:e2d5ac8459a4 | 69 | /** Disable the left motor, by driving enable pin for the second motor low... |
screamer | 7:887c729fd7c1 | 70 | */ |
melse | 2:118efce95f3c | 71 | void disable_left_motor(); |
melse | 4:e2d5ac8459a4 | 72 | |
melse | 4:e2d5ac8459a4 | 73 | /** Disable the left motor, by driving enable pin for the first motor low... |
screamer | 7:887c729fd7c1 | 74 | */ |
melse | 2:118efce95f3c | 75 | void disable_right_motor(); |
melse | 0:227158f56a11 | 76 | |
melse | 4:e2d5ac8459a4 | 77 | /** Enable the left motor, by driving enable pin for the second motor high... |
screamer | 7:887c729fd7c1 | 78 | */ |
melse | 2:118efce95f3c | 79 | void enable_left_motor(); |
melse | 4:e2d5ac8459a4 | 80 | |
melse | 4:e2d5ac8459a4 | 81 | /** Enable the left motor, by driving enable pin for the first motor high... |
screamer | 7:887c729fd7c1 | 82 | */ |
melse | 2:118efce95f3c | 83 | void enable_right_motor(); |
melse | 0:227158f56a11 | 84 | |
melse | 4:e2d5ac8459a4 | 85 | /** Stop a chosen motor. |
melse | 4:e2d5ac8459a4 | 86 | * @param motor Number, either 1 or 2 choosing the motor. |
screamer | 7:887c729fd7c1 | 87 | */ |
melse | 2:118efce95f3c | 88 | void stop(int motor); |
melse | 0:227158f56a11 | 89 | |
screamer | 7:887c729fd7c1 | 90 | /** Stop left motor. |
screamer | 7:887c729fd7c1 | 91 | */ |
screamer | 7:887c729fd7c1 | 92 | void stopLeft(); |
screamer | 7:887c729fd7c1 | 93 | |
screamer | 7:887c729fd7c1 | 94 | /** Stop right motor. |
screamer | 7:887c729fd7c1 | 95 | */ |
screamer | 7:887c729fd7c1 | 96 | void stopRight(); |
screamer | 7:887c729fd7c1 | 97 | |
screamer | 7:887c729fd7c1 | 98 | /** Stop both motors at the same time. Different to disable. |
screamer | 7:887c729fd7c1 | 99 | */ |
screamer | 7:887c729fd7c1 | 100 | void stopAll(); |
screamer | 7:887c729fd7c1 | 101 | |
melse | 0:227158f56a11 | 102 | // Need to do something to do with detected line... |
melse | 0:227158f56a11 | 103 | |
melse | 4:e2d5ac8459a4 | 104 | /** Gives an indication of the data given by the reflectivity sensors. |
screamer | 7:887c729fd7c1 | 105 | */ |
melse | 1:5c40f2a5e1ac | 106 | float line_position(); |
melse | 0:227158f56a11 | 107 | |
melse | 0:227158f56a11 | 108 | DigitalIn rightSensor; |
melse | 0:227158f56a11 | 109 | DigitalIn inRightSensor; |
melse | 0:227158f56a11 | 110 | DigitalIn centreSensor; |
melse | 0:227158f56a11 | 111 | DigitalIn inLeftSensor; |
melse | 0:227158f56a11 | 112 | DigitalIn leftSensor; |
melse | 0:227158f56a11 | 113 | |
melse | 0:227158f56a11 | 114 | private: |
melse | 0:227158f56a11 | 115 | PwmOut motor1A; |
melse | 0:227158f56a11 | 116 | DigitalOut motor1B; |
melse | 0:227158f56a11 | 117 | DigitalOut motor1En; |
melse | 0:227158f56a11 | 118 | |
melse | 0:227158f56a11 | 119 | PwmOut motor2A; |
melse | 0:227158f56a11 | 120 | DigitalOut motor2B; |
melse | 0:227158f56a11 | 121 | DigitalOut motor2En; |
melse | 0:227158f56a11 | 122 | }; |