Library for the Shield Bot by SeeedStudio

Dependents:   Seeed_Bot_Shield Seeed_BlueBot_demo Seeed_BlueBot_demo_test1 LAB03_Oppgav1 ... more

Fork of SeeedShieldBot by Components

Committer:
screamer
Date:
Thu Jul 31 14:42:21 2014 +0000
Revision:
8:9fd1722259a1
Parent:
7:887c729fd7c1
Change default pin for right motor

Who changed what in which revision?

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