The old ParallaxRobotShield library

Dependencies:   mbed

Committer:
omarrasheedk
Date:
Thu Aug 20 21:50:32 2015 +0000
Revision:
0:0fd8d387c5a0
The old ParallaxRobotShield library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
omarrasheedk 0:0fd8d387c5a0 1 #include "mbed.h"
omarrasheedk 0:0fd8d387c5a0 2
omarrasheedk 0:0fd8d387c5a0 3 /** Parallax Robot Shield Control Class
omarrasheedk 0:0fd8d387c5a0 4 */
omarrasheedk 0:0fd8d387c5a0 5 class ParallaxRobotShield
omarrasheedk 0:0fd8d387c5a0 6 {
omarrasheedk 0:0fd8d387c5a0 7 public:
omarrasheedk 0:0fd8d387c5a0 8
omarrasheedk 0:0fd8d387c5a0 9 /** Create a new ParallaxRobotShield object on any mbed pin
omarrasheedk 0:0fd8d387c5a0 10 *
omarrasheedk 0:0fd8d387c5a0 11 * @param leftServoPin Left Servomotor Signal pin - default D10
omarrasheedk 0:0fd8d387c5a0 12 * @param rightServoPin Right Servomotor Signal pin - default D11
omarrasheedk 0:0fd8d387c5a0 13 * @param leftWhiskerPin Left Whisker digital pin connection
omarrasheedk 0:0fd8d387c5a0 14 * @param rightWhiskerPin Right Whisker digital pin connection
omarrasheedk 0:0fd8d387c5a0 15 */
omarrasheedk 0:0fd8d387c5a0 16 ParallaxRobotShield(PinName leftServoPin = D10, PinName rightServoPin = D11, PinName leftWhiskerPin = NC, PinName rightWhiskerPin = NC);
omarrasheedk 0:0fd8d387c5a0 17
omarrasheedk 0:0fd8d387c5a0 18
omarrasheedk 0:0fd8d387c5a0 19 /** Switch on the left servo at the given speed. Can be used with loops to run the left servomotor.
omarrasheedk 0:0fd8d387c5a0 20 * @param speed The speed, from 0 to 100 at which to spin the servomotor. - 100 by default
omarrasheedk 0:0fd8d387c5a0 21 */
omarrasheedk 0:0fd8d387c5a0 22 void left_servo(int speed = 100); // Just for internal functions
omarrasheedk 0:0fd8d387c5a0 23
omarrasheedk 0:0fd8d387c5a0 24
omarrasheedk 0:0fd8d387c5a0 25 /** Switch on the right servo at the given speed. Can be used with loops to run the right servomotor.
omarrasheedk 0:0fd8d387c5a0 26 * @param speed The speed, from 0 to 100 at which to spin the servomotor. - 100 by default
omarrasheedk 0:0fd8d387c5a0 27 */
omarrasheedk 0:0fd8d387c5a0 28 void right_servo(int speed = 100); // Just for internal functions
omarrasheedk 0:0fd8d387c5a0 29
omarrasheedk 0:0fd8d387c5a0 30
omarrasheedk 0:0fd8d387c5a0 31 /** Switch on both servomotors, forwards at the given speed.
omarrasheedk 0:0fd8d387c5a0 32 * @param speed The speed, from 0 to 100 at which to spin the servomotors. - 100 by default
omarrasheedk 0:0fd8d387c5a0 33 * @param time The time period to go forward (in seconds) - 1s by default
omarrasheedk 0:0fd8d387c5a0 34 */
omarrasheedk 0:0fd8d387c5a0 35 void forward(int speed = 100, float time = 1);
omarrasheedk 0:0fd8d387c5a0 36
omarrasheedk 0:0fd8d387c5a0 37
omarrasheedk 0:0fd8d387c5a0 38 /** Switch on both servomotors, backwards at the given speed.
omarrasheedk 0:0fd8d387c5a0 39 * @param speed The speed, from 0 to 100 at which to spin the servomotors. - 100 by default
omarrasheedk 0:0fd8d387c5a0 40 * @param time The time period to go backward (in seconds) - 1s by default
omarrasheedk 0:0fd8d387c5a0 41 */
omarrasheedk 0:0fd8d387c5a0 42 void backward(int speed = 100, float time = 1);
omarrasheedk 0:0fd8d387c5a0 43
omarrasheedk 0:0fd8d387c5a0 44
omarrasheedk 0:0fd8d387c5a0 45 /** Switch on both servomotors at the given speed, in opposite directions so as to turn left.
omarrasheedk 0:0fd8d387c5a0 46 * @param speed The speed, from 0 to 100 at which to spin the servomotors. - 100 by default
omarrasheedk 0:0fd8d387c5a0 47 * @param time The time period to take a left (in seconds) - 1s by default
omarrasheedk 0:0fd8d387c5a0 48 */
omarrasheedk 0:0fd8d387c5a0 49 void left(int speed = 100, float time = 1);
omarrasheedk 0:0fd8d387c5a0 50
omarrasheedk 0:0fd8d387c5a0 51
omarrasheedk 0:0fd8d387c5a0 52 /** Switch on both servomotors at the given speed, in opposite directions so as to turn right.
omarrasheedk 0:0fd8d387c5a0 53 * @param speed The speed, from 0 to 100 at which to spin the servomotors. - 100 by default
omarrasheedk 0:0fd8d387c5a0 54 * @param time The time period to take a right (in seconds) - 1s by default
omarrasheedk 0:0fd8d387c5a0 55 */
omarrasheedk 0:0fd8d387c5a0 56 void right(int speed = 100, float time = 1);
omarrasheedk 0:0fd8d387c5a0 57
omarrasheedk 0:0fd8d387c5a0 58
omarrasheedk 0:0fd8d387c5a0 59 /** Turns left by switching the right servo off and running the left servo.
omarrasheedk 0:0fd8d387c5a0 60 * @param speed The speed, from 0 to 100 at which to spin the left servomotor. - 100 by default
omarrasheedk 0:0fd8d387c5a0 61 * @param time The time period for the left servo to run (in seconds) - 1s by default
omarrasheedk 0:0fd8d387c5a0 62 */
omarrasheedk 0:0fd8d387c5a0 63 void turn_left(int speed = 100, float time = 1);
omarrasheedk 0:0fd8d387c5a0 64
omarrasheedk 0:0fd8d387c5a0 65
omarrasheedk 0:0fd8d387c5a0 66 /** Turns right by switching the left servo off and running the right servo.
omarrasheedk 0:0fd8d387c5a0 67 * @param speed The speed, from 0 to 100 at which to spin the right servomotor. - 100 by default
omarrasheedk 0:0fd8d387c5a0 68 * @param time The time period for the right servo to run (in seconds) - 1s by default
omarrasheedk 0:0fd8d387c5a0 69 */
omarrasheedk 0:0fd8d387c5a0 70 void turn_right(int speed = 100, float time = 1);
omarrasheedk 0:0fd8d387c5a0 71
omarrasheedk 0:0fd8d387c5a0 72
omarrasheedk 0:0fd8d387c5a0 73 /** Disable the left motor
omarrasheedk 0:0fd8d387c5a0 74 */
omarrasheedk 0:0fd8d387c5a0 75 void disable_left_motor(); // Just for internal functions
omarrasheedk 0:0fd8d387c5a0 76
omarrasheedk 0:0fd8d387c5a0 77
omarrasheedk 0:0fd8d387c5a0 78 /** Disable the right servomotor
omarrasheedk 0:0fd8d387c5a0 79 */
omarrasheedk 0:0fd8d387c5a0 80 void disable_right_motor(); // Just for internal functions
omarrasheedk 0:0fd8d387c5a0 81
omarrasheedk 0:0fd8d387c5a0 82
omarrasheedk 0:0fd8d387c5a0 83 /** Enable the left servomotor
omarrasheedk 0:0fd8d387c5a0 84 */
omarrasheedk 0:0fd8d387c5a0 85 void enable_left_motor();
omarrasheedk 0:0fd8d387c5a0 86
omarrasheedk 0:0fd8d387c5a0 87
omarrasheedk 0:0fd8d387c5a0 88 /** Enable the right servomotor
omarrasheedk 0:0fd8d387c5a0 89 */
omarrasheedk 0:0fd8d387c5a0 90 void enable_right_motor();
omarrasheedk 0:0fd8d387c5a0 91
omarrasheedk 0:0fd8d387c5a0 92
omarrasheedk 0:0fd8d387c5a0 93 /** Stop a chosen motor.
omarrasheedk 0:0fd8d387c5a0 94 * @param motor Number, either, 1 = Right or 2 = Left, choosing the motor.
omarrasheedk 0:0fd8d387c5a0 95 */
omarrasheedk 0:0fd8d387c5a0 96 void stop(int motor);
omarrasheedk 0:0fd8d387c5a0 97
omarrasheedk 0:0fd8d387c5a0 98
omarrasheedk 0:0fd8d387c5a0 99 /** Stop left servomotor.
omarrasheedk 0:0fd8d387c5a0 100 */
omarrasheedk 0:0fd8d387c5a0 101 void stopLeft();
omarrasheedk 0:0fd8d387c5a0 102
omarrasheedk 0:0fd8d387c5a0 103
omarrasheedk 0:0fd8d387c5a0 104 /** Stop right servomotor.
omarrasheedk 0:0fd8d387c5a0 105 */
omarrasheedk 0:0fd8d387c5a0 106 void stopRight();
omarrasheedk 0:0fd8d387c5a0 107
omarrasheedk 0:0fd8d387c5a0 108
omarrasheedk 0:0fd8d387c5a0 109 /** Stop both servomotors at the same time.
omarrasheedk 0:0fd8d387c5a0 110 */
omarrasheedk 0:0fd8d387c5a0 111 void stopAll(); // Different from disable.
omarrasheedk 0:0fd8d387c5a0 112
omarrasheedk 0:0fd8d387c5a0 113
omarrasheedk 0:0fd8d387c5a0 114 /** Returns an integer corresponding to the state of the left whisker.
omarrasheedk 0:0fd8d387c5a0 115 * @return 1 if the Left whisker is in contact, 0 otherwise.
omarrasheedk 0:0fd8d387c5a0 116 */
omarrasheedk 0:0fd8d387c5a0 117 int leftWhiskerContact();
omarrasheedk 0:0fd8d387c5a0 118
omarrasheedk 0:0fd8d387c5a0 119
omarrasheedk 0:0fd8d387c5a0 120 /** Returns an integer corresponding to the state of the right whisker.
omarrasheedk 0:0fd8d387c5a0 121 * @return 1 if the Right whisker is in contact, 0 otherwise.
omarrasheedk 0:0fd8d387c5a0 122 */
omarrasheedk 0:0fd8d387c5a0 123 int rightWhiskerContact();
omarrasheedk 0:0fd8d387c5a0 124
omarrasheedk 0:0fd8d387c5a0 125
omarrasheedk 0:0fd8d387c5a0 126 /** Returns an integer correspondingly if there is a black color is detected.
omarrasheedk 0:0fd8d387c5a0 127 * Uses the QTR-1RC Light sensor
omarrasheedk 0:0fd8d387c5a0 128 * @param lightSensor the QTR-1RC signal pin
omarrasheedk 0:0fd8d387c5a0 129 * @return 1 if Black color is detected, 0 otherwise.
omarrasheedk 0:0fd8d387c5a0 130 */
omarrasheedk 0:0fd8d387c5a0 131 int lightSensor(PinName lightSensor);
omarrasheedk 0:0fd8d387c5a0 132
omarrasheedk 0:0fd8d387c5a0 133
omarrasheedk 0:0fd8d387c5a0 134 /** Returns an integer correspondingly if an object is detected within 10cm.
omarrasheedk 0:0fd8d387c5a0 135 * Uses the Sharp GP2Y0D810Z0F Digital Distance Sensor - 10cm
omarrasheedk 0:0fd8d387c5a0 136 * @param bumpSensor the pin the bump sensor is connected to.
omarrasheedk 0:0fd8d387c5a0 137 * @return 1 if something is detected, 0 otherwise.
omarrasheedk 0:0fd8d387c5a0 138 */
omarrasheedk 0:0fd8d387c5a0 139 int bumpSensor(PinName bumpSensor);
omarrasheedk 0:0fd8d387c5a0 140
omarrasheedk 0:0fd8d387c5a0 141
omarrasheedk 0:0fd8d387c5a0 142 /** Returns the distance of the nearest object.
omarrasheedk 0:0fd8d387c5a0 143 * Uses the HC-SR04 Distance Sensor.
omarrasheedk 0:0fd8d387c5a0 144 * @param trigPin the pin to which the trig pin is connected
omarrasheedk 0:0fd8d387c5a0 145 * @param echoPin the pin to which the echo pin is connected
omarrasheedk 0:0fd8d387c5a0 146 * @return the distance in cm.
omarrasheedk 0:0fd8d387c5a0 147 */
omarrasheedk 0:0fd8d387c5a0 148 double distanceSensor(PinName trigPin, PinName echoPin);
omarrasheedk 0:0fd8d387c5a0 149
omarrasheedk 0:0fd8d387c5a0 150
omarrasheedk 0:0fd8d387c5a0 151 /** Optional implementation for future use
omarrasheedk 0:0fd8d387c5a0 152 * Turns on the corresponding LED to indicate if the whisker came into contact.
omarrasheedk 0:0fd8d387c5a0 153 * @param left_LED the pin to which the left LED is connected to
omarrasheedk 0:0fd8d387c5a0 154 * @param right_LED the pin to which the right LED is connected to
omarrasheedk 0:0fd8d387c5a0 155 *
omarrasheedk 0:0fd8d387c5a0 156 * void whiskersLED(PinName left_LED, PinName right_LED);
omarrasheedk 0:0fd8d387c5a0 157 */
omarrasheedk 0:0fd8d387c5a0 158
omarrasheedk 0:0fd8d387c5a0 159
omarrasheedk 0:0fd8d387c5a0 160 private:
omarrasheedk 0:0fd8d387c5a0 161
omarrasheedk 0:0fd8d387c5a0 162 PwmOut leftServo1;
omarrasheedk 0:0fd8d387c5a0 163 PwmOut rightServo1;
omarrasheedk 0:0fd8d387c5a0 164
omarrasheedk 0:0fd8d387c5a0 165 int leftPosition; // used for the left servo motor
omarrasheedk 0:0fd8d387c5a0 166 int rightPosition; // used for the right servo motor
omarrasheedk 0:0fd8d387c5a0 167
omarrasheedk 0:0fd8d387c5a0 168 DigitalOut leftServo; // the left servo motor
omarrasheedk 0:0fd8d387c5a0 169 DigitalOut rightServo; // the right servo motor
omarrasheedk 0:0fd8d387c5a0 170
omarrasheedk 0:0fd8d387c5a0 171 DigitalIn leftWhisker; // for the left Whisker
omarrasheedk 0:0fd8d387c5a0 172 DigitalIn rightWhisker; // for the right Whisker
omarrasheedk 0:0fd8d387c5a0 173
omarrasheedk 0:0fd8d387c5a0 174 Ticker leftPulse; // for the left servo motor
omarrasheedk 0:0fd8d387c5a0 175 Ticker rightPulse; // for the right servo motor
omarrasheedk 0:0fd8d387c5a0 176
omarrasheedk 0:0fd8d387c5a0 177 Timeout leftPulseStop; // for the left servo motor (Kill switch)
omarrasheedk 0:0fd8d387c5a0 178 Timeout rightPulseStop; // for the right servo motor (Kill switch)
omarrasheedk 0:0fd8d387c5a0 179
omarrasheedk 0:0fd8d387c5a0 180 };