It is a library for controlling Wallbot mini

Dependents:   wallbotmini_test

Committer:
jksoft
Date:
Sat Nov 02 01:04:00 2013 +0000
Revision:
0:a11da93ea3f6
Rev1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:a11da93ea3f6 1 /* mbed wallbot mini Library
jksoft 0:a11da93ea3f6 2 *
jksoft 0:a11da93ea3f6 3 * wallbotmini.h
jksoft 0:a11da93ea3f6 4 *
jksoft 0:a11da93ea3f6 5 * Copyright (c) 2010-2013 jksoft
jksoft 0:a11da93ea3f6 6 *
jksoft 0:a11da93ea3f6 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
jksoft 0:a11da93ea3f6 8 * of this software and associated documentation files (the "Software"), to deal
jksoft 0:a11da93ea3f6 9 * in the Software without restriction, including without limitation the rights
jksoft 0:a11da93ea3f6 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jksoft 0:a11da93ea3f6 11 * copies of the Software, and to permit persons to whom the Software is
jksoft 0:a11da93ea3f6 12 * furnished to do so, subject to the following conditions:
jksoft 0:a11da93ea3f6 13 *
jksoft 0:a11da93ea3f6 14 * The above copyright notice and this permission notice shall be included in
jksoft 0:a11da93ea3f6 15 * all copies or substantial portions of the Software.
jksoft 0:a11da93ea3f6 16 *
jksoft 0:a11da93ea3f6 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jksoft 0:a11da93ea3f6 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jksoft 0:a11da93ea3f6 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jksoft 0:a11da93ea3f6 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jksoft 0:a11da93ea3f6 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jksoft 0:a11da93ea3f6 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jksoft 0:a11da93ea3f6 23 * THE SOFTWARE.
jksoft 0:a11da93ea3f6 24 */
jksoft 0:a11da93ea3f6 25
jksoft 0:a11da93ea3f6 26 #ifndef WALLBOT_H
jksoft 0:a11da93ea3f6 27 #define WALLBOT_H
jksoft 0:a11da93ea3f6 28
jksoft 0:a11da93ea3f6 29 #include "mbed.h"
jksoft 0:a11da93ea3f6 30 #include "TB6612.h"
jksoft 0:a11da93ea3f6 31
jksoft 0:a11da93ea3f6 32 #define SENSOR_VAL_WIDTH 2000
jksoft 0:a11da93ea3f6 33
jksoft 0:a11da93ea3f6 34 /** wallbot mini control class
jksoft 0:a11da93ea3f6 35 *
jksoft 0:a11da93ea3f6 36 * Example:
jksoft 0:a11da93ea3f6 37 * @code
jksoft 0:a11da93ea3f6 38 * // Drive the wwallbot forward, turn left, back, turn right, at half speed for half a second
jksoft 0:a11da93ea3f6 39
jksoft 0:a11da93ea3f6 40 #include "mbed.h"
jksoft 0:a11da93ea3f6 41 #include "wallbotmini.h"
jksoft 0:a11da93ea3f6 42
jksoft 0:a11da93ea3f6 43 wallbotmini wb;
jksoft 0:a11da93ea3f6 44
jksoft 0:a11da93ea3f6 45 int main() {
jksoft 0:a11da93ea3f6 46
jksoft 0:a11da93ea3f6 47 wb.sensor_calibrate();
jksoft 0:a11da93ea3f6 48
jksoft 0:a11da93ea3f6 49 while(!wb.GetSw())
jksoft 0:a11da93ea3f6 50 {
jksoft 0:a11da93ea3f6 51 wb.set_led(wb.GetLinePosition());
jksoft 0:a11da93ea3f6 52 }
jksoft 0:a11da93ea3f6 53
jksoft 0:a11da93ea3f6 54 wb.forward(1.0);
jksoft 0:a11da93ea3f6 55 wait (1.0);
jksoft 0:a11da93ea3f6 56 wb.left(1.0);
jksoft 0:a11da93ea3f6 57 wait (1.0);
jksoft 0:a11da93ea3f6 58 wb.backward(1.0);
jksoft 0:a11da93ea3f6 59 wait (1.0);
jksoft 0:a11da93ea3f6 60 wb.right(1.0);
jksoft 0:a11da93ea3f6 61 wait (1.0);
jksoft 0:a11da93ea3f6 62
jksoft 0:a11da93ea3f6 63 wb.stop();
jksoft 0:a11da93ea3f6 64
jksoft 0:a11da93ea3f6 65 while(1);
jksoft 0:a11da93ea3f6 66
jksoft 0:a11da93ea3f6 67 }
jksoft 0:a11da93ea3f6 68
jksoft 0:a11da93ea3f6 69 * @endcode
jksoft 0:a11da93ea3f6 70 */
jksoft 0:a11da93ea3f6 71 class wallbotmini {
jksoft 0:a11da93ea3f6 72
jksoft 0:a11da93ea3f6 73 // Public functions
jksoft 0:a11da93ea3f6 74 public:
jksoft 0:a11da93ea3f6 75
jksoft 0:a11da93ea3f6 76 /** Create the wallbot object connected to the default pins
jksoft 0:a11da93ea3f6 77 */
jksoft 0:a11da93ea3f6 78 wallbotmini();
jksoft 0:a11da93ea3f6 79
jksoft 0:a11da93ea3f6 80 /** Sensor calibrate
jksoft 0:a11da93ea3f6 81 *
jksoft 0:a11da93ea3f6 82 */
jksoft 0:a11da93ea3f6 83 void sensor_calibrate (void);
jksoft 0:a11da93ea3f6 84
jksoft 0:a11da93ea3f6 85 /** Directly control the speed and direction of the left motor
jksoft 0:a11da93ea3f6 86 *
jksoft 0:a11da93ea3f6 87 * @param speed A normalised number -1.0 - 1.0 represents the full range.
jksoft 0:a11da93ea3f6 88 */
jksoft 0:a11da93ea3f6 89 void left_motor (float speed);
jksoft 0:a11da93ea3f6 90
jksoft 0:a11da93ea3f6 91 /** Directly control the speed and direction of the right motor
jksoft 0:a11da93ea3f6 92 *
jksoft 0:a11da93ea3f6 93 * @param speed A normalised number -1.0 - 1.0 represents the full range.
jksoft 0:a11da93ea3f6 94 */
jksoft 0:a11da93ea3f6 95 void right_motor (float speed);
jksoft 0:a11da93ea3f6 96
jksoft 0:a11da93ea3f6 97 /** Drive both motors forward as the same speed
jksoft 0:a11da93ea3f6 98 *
jksoft 0:a11da93ea3f6 99 * @param speed A normalised number 0 - 1.0 represents the full range.
jksoft 0:a11da93ea3f6 100 */
jksoft 0:a11da93ea3f6 101 void forward (float speed);
jksoft 0:a11da93ea3f6 102
jksoft 0:a11da93ea3f6 103 /** Drive both motors backward as the same speed
jksoft 0:a11da93ea3f6 104 *
jksoft 0:a11da93ea3f6 105 * @param speed A normalised number 0 - 1.0 represents the full range.
jksoft 0:a11da93ea3f6 106 */
jksoft 0:a11da93ea3f6 107 void backward (float speed);
jksoft 0:a11da93ea3f6 108
jksoft 0:a11da93ea3f6 109 /** Drive left motor backwards and right motor forwards at the same speed to turn on the spot
jksoft 0:a11da93ea3f6 110 *
jksoft 0:a11da93ea3f6 111 * @param speed A normalised number 0 - 1.0 represents the full range.
jksoft 0:a11da93ea3f6 112 */
jksoft 0:a11da93ea3f6 113 void left (float speed);
jksoft 0:a11da93ea3f6 114
jksoft 0:a11da93ea3f6 115 /** Drive left motor forward and right motor backwards at the same speed to turn on the spot
jksoft 0:a11da93ea3f6 116 * @param speed A normalised number 0 - 1.0 represents the full range.
jksoft 0:a11da93ea3f6 117 */
jksoft 0:a11da93ea3f6 118 void right (float speed);
jksoft 0:a11da93ea3f6 119
jksoft 0:a11da93ea3f6 120 /** Stop both motors
jksoft 0:a11da93ea3f6 121 *
jksoft 0:a11da93ea3f6 122 */
jksoft 0:a11da93ea3f6 123 void stop (void);
jksoft 0:a11da93ea3f6 124
jksoft 0:a11da93ea3f6 125 /** Get floorline position.(int value return.)
jksoft 0:a11da93ea3f6 126 *
jksoft 0:a11da93ea3f6 127 */
jksoft 0:a11da93ea3f6 128 int GetLinePosition(void);
jksoft 0:a11da93ea3f6 129
jksoft 0:a11da93ea3f6 130 /** Get switch .(switch OFF:0 or ON:1 return.)
jksoft 0:a11da93ea3f6 131 *
jksoft 0:a11da93ea3f6 132 */
jksoft 0:a11da93ea3f6 133 int GetSw(void);
jksoft 0:a11da93ea3f6 134
jksoft 0:a11da93ea3f6 135 /** Set status led .
jksoft 0:a11da93ea3f6 136 * @param led (bit0:LEFT bit1:UP bit2:RIGHT bit3 DOWN)
jksoft 0:a11da93ea3f6 137 */
jksoft 0:a11da93ea3f6 138 void set_led(int bit);
jksoft 0:a11da93ea3f6 139
jksoft 0:a11da93ea3f6 140 private :
jksoft 0:a11da93ea3f6 141
jksoft 0:a11da93ea3f6 142 TB6612 _right;
jksoft 0:a11da93ea3f6 143 TB6612 _left;
jksoft 0:a11da93ea3f6 144 DigitalIn _sw;
jksoft 0:a11da93ea3f6 145 BusOut _statusled;
jksoft 0:a11da93ea3f6 146 AnalogIn _sensor1;
jksoft 0:a11da93ea3f6 147 AnalogIn _sensor2;
jksoft 0:a11da93ea3f6 148 AnalogIn _sensor3;
jksoft 0:a11da93ea3f6 149
jksoft 0:a11da93ea3f6 150 int _sensor_def[3];
jksoft 0:a11da93ea3f6 151 };
jksoft 0:a11da93ea3f6 152
jksoft 0:a11da93ea3f6 153 #endif