Library for the CustomExplorerRobot.

Dependents:   CustomExplorerRobot_test

Committer:
Usuke
Date:
Sat Feb 27 09:20:21 2016 +0000
Revision:
0:ad4667fc5a76
??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Usuke 0:ad4667fc5a76 1 /* mbed CustomExplorerRobot Library
Usuke 0:ad4667fc5a76 2 *
Usuke 0:ad4667fc5a76 3 * CustomExplorerRobot.h
Usuke 0:ad4667fc5a76 4 *
Usuke 0:ad4667fc5a76 5 * Copyright (c) 2016 ??????
Usuke 0:ad4667fc5a76 6 *
Usuke 0:ad4667fc5a76 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
Usuke 0:ad4667fc5a76 8 * of this software and associated documentation files (the "Software"), to deal
Usuke 0:ad4667fc5a76 9 * in the Software without restriction, including without limitation the rights
Usuke 0:ad4667fc5a76 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Usuke 0:ad4667fc5a76 11 * copies of the Software, and to permit persons to whom the Software is
Usuke 0:ad4667fc5a76 12 * furnished to do so, subject to the following conditions:
Usuke 0:ad4667fc5a76 13 *
Usuke 0:ad4667fc5a76 14 * The above copyright notice and this permission notice shall be included in
Usuke 0:ad4667fc5a76 15 * all copies or substantial portions of the Software.
Usuke 0:ad4667fc5a76 16 *
Usuke 0:ad4667fc5a76 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Usuke 0:ad4667fc5a76 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Usuke 0:ad4667fc5a76 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Usuke 0:ad4667fc5a76 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Usuke 0:ad4667fc5a76 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Usuke 0:ad4667fc5a76 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Usuke 0:ad4667fc5a76 23 * THE SOFTWARE.
Usuke 0:ad4667fc5a76 24 */
Usuke 0:ad4667fc5a76 25
Usuke 0:ad4667fc5a76 26 #ifndef CUSTOMEXPLORERROBOT_H
Usuke 0:ad4667fc5a76 27 #define CUSTOMEXPLORERROBOT_H
Usuke 0:ad4667fc5a76 28
Usuke 0:ad4667fc5a76 29 #include "mbed.h"
Usuke 0:ad4667fc5a76 30 #include "BD6212.h"
Usuke 0:ad4667fc5a76 31
Usuke 0:ad4667fc5a76 32 /** CustomExplorerRobot control class
Usuke 0:ad4667fc5a76 33 *
Usuke 0:ad4667fc5a76 34 * Example:
Usuke 0:ad4667fc5a76 35 * @code
Usuke 0:ad4667fc5a76 36 * // Drive the CustomExplorerRobot forward, turn left, back, turn right, at half speed for half a second
Usuke 0:ad4667fc5a76 37
Usuke 0:ad4667fc5a76 38 #include "mbed.h"
Usuke 0:ad4667fc5a76 39 #include "CustomExplorerRobot.h"
Usuke 0:ad4667fc5a76 40
Usuke 0:ad4667fc5a76 41 CustomExplorerRobot cer;
Usuke 0:ad4667fc5a76 42
Usuke 0:ad4667fc5a76 43 int main() {
Usuke 0:ad4667fc5a76 44
Usuke 0:ad4667fc5a76 45 wait(0.5f);
Usuke 0:ad4667fc5a76 46 cer.forward(0.5f);
Usuke 0:ad4667fc5a76 47 wait(0.5f);
Usuke 0:ad4667fc5a76 48 cer.left(0.5f);
Usuke 0:ad4667fc5a76 49 wait(0.5f);
Usuke 0:ad4667fc5a76 50 cer.backward(0.5f);
Usuke 0:ad4667fc5a76 51 wait(0.5f);
Usuke 0:ad4667fc5a76 52 cer.right(0.5f);
Usuke 0:ad4667fc5a76 53 wait(0.5f);
Usuke 0:ad4667fc5a76 54 cer.stop();
Usuke 0:ad4667fc5a76 55
Usuke 0:ad4667fc5a76 56 return 0;
Usuke 0:ad4667fc5a76 57 }
Usuke 0:ad4667fc5a76 58 * @endcode
Usuke 0:ad4667fc5a76 59 */
Usuke 0:ad4667fc5a76 60 class CustomExplorerRobot{
Usuke 0:ad4667fc5a76 61 public:
Usuke 0:ad4667fc5a76 62 /** Create the CustomExplorerRobot object connected to the default pins
Usuke 0:ad4667fc5a76 63 */
Usuke 0:ad4667fc5a76 64 CustomExplorerRobot();
Usuke 0:ad4667fc5a76 65
Usuke 0:ad4667fc5a76 66 /** Directly control the speed and direction of the left motor
Usuke 0:ad4667fc5a76 67 *
Usuke 0:ad4667fc5a76 68 * @param speed A normalised number -1.0 - 1.0 represents the full range.
Usuke 0:ad4667fc5a76 69 */
Usuke 0:ad4667fc5a76 70 void left_motor(float speed);
Usuke 0:ad4667fc5a76 71
Usuke 0:ad4667fc5a76 72 /** Directly control the speed and direction of the right motor
Usuke 0:ad4667fc5a76 73 *
Usuke 0:ad4667fc5a76 74 * @param speed A normalised number -1.0 - 1.0 represents the full range.
Usuke 0:ad4667fc5a76 75 */
Usuke 0:ad4667fc5a76 76 void right_motor(float speed);
Usuke 0:ad4667fc5a76 77
Usuke 0:ad4667fc5a76 78 /** Drive both motors forward as the same speed
Usuke 0:ad4667fc5a76 79 *
Usuke 0:ad4667fc5a76 80 * @param speed A normalised number 0 - 1.0 represents the full range.
Usuke 0:ad4667fc5a76 81 */
Usuke 0:ad4667fc5a76 82 void forward(float speed);
Usuke 0:ad4667fc5a76 83
Usuke 0:ad4667fc5a76 84 /** Drive both motors backward as the same speed
Usuke 0:ad4667fc5a76 85 *
Usuke 0:ad4667fc5a76 86 * @param speed A normalised number 0 - 1.0 represents the full range.
Usuke 0:ad4667fc5a76 87 */
Usuke 0:ad4667fc5a76 88 void backward(float speed);
Usuke 0:ad4667fc5a76 89
Usuke 0:ad4667fc5a76 90 /** Drive left motor backwards and right motor forwards at the same speed to turn on the spot
Usuke 0:ad4667fc5a76 91 *
Usuke 0:ad4667fc5a76 92 * @param speed A normalised number 0 - 1.0 represents the full range.
Usuke 0:ad4667fc5a76 93 */
Usuke 0:ad4667fc5a76 94 void left(float speed);
Usuke 0:ad4667fc5a76 95
Usuke 0:ad4667fc5a76 96 /** Drive left motor forward and right motor backwards at the same speed to turn on the spot
Usuke 0:ad4667fc5a76 97 * @param speed A normalised number 0 - 1.0 represents the full range.
Usuke 0:ad4667fc5a76 98 */
Usuke 0:ad4667fc5a76 99 void right(float speed);
Usuke 0:ad4667fc5a76 100
Usuke 0:ad4667fc5a76 101 /** Stop both motors
Usuke 0:ad4667fc5a76 102 *
Usuke 0:ad4667fc5a76 103 */
Usuke 0:ad4667fc5a76 104 void stop(void);
Usuke 0:ad4667fc5a76 105
Usuke 0:ad4667fc5a76 106 protected:
Usuke 0:ad4667fc5a76 107 BD6212 _right;
Usuke 0:ad4667fc5a76 108 BD6212 _left;
Usuke 0:ad4667fc5a76 109
Usuke 0:ad4667fc5a76 110 DigitalOut _redled;
Usuke 0:ad4667fc5a76 111 DigitalOut _blueled;
Usuke 0:ad4667fc5a76 112
Usuke 0:ad4667fc5a76 113 PwmOut _buzzer;
Usuke 0:ad4667fc5a76 114
Usuke 0:ad4667fc5a76 115 };
Usuke 0:ad4667fc5a76 116
Usuke 0:ad4667fc5a76 117 #endif