It is a library for controlling Wallbot mini

Dependents:   wallbotmini_test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wallbotmini.h Source File

wallbotmini.h

00001 /* mbed wallbot mini Library
00002  *
00003  * wallbotmini.h
00004  *
00005  * Copyright (c) 2010-2013 jksoft
00006  *
00007  * Permission is hereby granted, free of charge, to any person obtaining a copy
00008  * of this software and associated documentation files (the "Software"), to deal
00009  * in the Software without restriction, including without limitation the rights
00010  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00011  * copies of the Software, and to permit persons to whom the Software is
00012  * furnished to do so, subject to the following conditions:
00013  *
00014  * The above copyright notice and this permission notice shall be included in
00015  * all copies or substantial portions of the Software.
00016  *
00017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00020  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00022  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00023  * THE SOFTWARE.
00024  */
00025 
00026 #ifndef WALLBOT_H
00027 #define WALLBOT_H
00028 
00029 #include "mbed.h"
00030 #include "TB6612.h"
00031 
00032 #define SENSOR_VAL_WIDTH    2000
00033 
00034 /** wallbot mini control class
00035  *
00036  * Example:
00037  * @code
00038  * // Drive the wwallbot forward, turn left, back, turn right, at half speed for half a second
00039 
00040 #include "mbed.h"
00041 #include "wallbotmini.h"
00042 
00043 wallbotmini wb;
00044  
00045 int main() {
00046 
00047     wb.sensor_calibrate();
00048 
00049     while(!wb.GetSw())
00050     {
00051         wb.set_led(wb.GetLinePosition());
00052     }
00053     
00054     wb.forward(1.0);
00055     wait (1.0);
00056     wb.left(1.0);
00057     wait (1.0);
00058     wb.backward(1.0);
00059     wait (1.0);
00060     wb.right(1.0);
00061     wait (1.0);
00062     
00063     wb.stop();
00064 
00065     while(1);
00066 
00067  }
00068 
00069  * @endcode
00070  */
00071 class wallbotmini  {
00072 
00073     // Public functions
00074 public:
00075 
00076     /** Create the wallbot object connected to the default pins
00077      */
00078     wallbotmini();
00079 
00080     /** Sensor calibrate
00081      *
00082      */
00083     void sensor_calibrate (void);
00084 
00085     /** Directly control the speed and direction of the left motor
00086      *
00087      * @param speed A normalised number -1.0 - 1.0 represents the full range.
00088      */
00089     void left_motor (float speed);
00090 
00091     /** Directly control the speed and direction of the right motor
00092      *
00093      * @param speed A normalised number -1.0 - 1.0 represents the full range.
00094      */
00095     void right_motor (float speed);
00096 
00097     /** Drive both motors forward as the same speed
00098      *
00099      * @param speed A normalised number 0 - 1.0 represents the full range.
00100      */
00101     void forward (float speed);
00102 
00103     /** Drive both motors backward as the same speed
00104      *
00105      * @param speed A normalised number 0 - 1.0 represents the full range.
00106      */
00107     void backward (float speed);
00108 
00109     /** Drive left motor backwards and right motor forwards at the same speed to turn on the spot
00110      *
00111      * @param speed A normalised number 0 - 1.0 represents the full range.
00112      */
00113     void left (float speed);
00114 
00115     /** Drive left motor forward and right motor backwards at the same speed to turn on the spot
00116      * @param speed A normalised number 0 - 1.0 represents the full range.
00117      */
00118     void right (float speed);
00119 
00120     /** Stop both motors
00121      *
00122      */
00123     void stop (void);
00124     
00125     /** Get floorline position.(int value return.)
00126      *
00127      */ 
00128     int GetLinePosition(void);
00129     
00130     /** Get switch .(switch OFF:0 or ON:1 return.)
00131      *
00132      */ 
00133     int GetSw(void);
00134     
00135     /** Set status led .
00136      * @param led (bit0:LEFT bit1:UP bit2:RIGHT bit3 DOWN)
00137      */ 
00138     void set_led(int bit);
00139     
00140     private :
00141 
00142     TB6612 _right;
00143     TB6612 _left;
00144     DigitalIn _sw;
00145     BusOut _statusled;
00146     AnalogIn _sensor1;
00147     AnalogIn _sensor2;
00148     AnalogIn _sensor3;
00149     
00150     int _sensor_def[3];    
00151 };
00152 
00153 #endif