Junichi Katsu / Mbed 2 deprecated BLE_MPU6050_test6_challenge_sb

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wallbotble.h Source File

wallbotble.h

00001 /* JKsoft Wallbot BLE Library
00002  *
00003  * wallbotble.h
00004  *
00005  * Copyright (c) 2010-2014 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_BLE_H
00027 #define WALLBOT_BLE_H
00028 
00029 #include "mbed.h"
00030 #include "TB6612.h"
00031 
00032 #define SENSOR_VAL_GAIN_DEFAULT 300
00033 
00034 /** wallbot ble 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 "wallbotble.h"
00042 
00043 wallbotble 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 wallbotble  {
00072 
00073     // Public functions
00074 public:
00075 
00076     /** Create the wallbot object connected to the default pins
00077      */
00078     wallbotble();
00079     
00080     /** Set Sensor gain.
00081      *
00082      * @param Sensor gain.
00083      */
00084     void set_f_sensor_gain(int gain);
00085     /** Sensor calibrate
00086      *
00087      */
00088     void f_sensor_calibrate (void);
00089 
00090     /** Directly control the speed and direction of the left motor
00091      *
00092      * @param speed A normalised number -1.0 - 1.0 represents the full range.
00093      */
00094     void left_motor (float speed);
00095 
00096     /** Directly control the speed and direction of the right motor
00097      *
00098      * @param speed A normalised number -1.0 - 1.0 represents the full range.
00099      */
00100     void right_motor (float speed);
00101 
00102     /** Drive both motors forward as the same speed
00103      *
00104      * @param speed A normalised number 0 - 1.0 represents the full range.
00105      */
00106     void forward (float speed);
00107 
00108     /** Drive both motors backward as the same speed
00109      *
00110      * @param speed A normalised number 0 - 1.0 represents the full range.
00111      */
00112     void backward (float speed);
00113 
00114     /** Drive left motor backwards and right motor forwards at the same speed to turn on the spot
00115      *
00116      * @param speed A normalised number 0 - 1.0 represents the full range.
00117      */
00118     void left_turn (float speed);
00119 
00120     /** Drive left motor forward and right motor backwards at the same speed to turn on the spot
00121      * @param speed A normalised number 0 - 1.0 represents the full range.
00122      */
00123     void right_turn (float speed);
00124 
00125     /** Stop both motors
00126      *
00127      */
00128     void stop (void);
00129     
00130     /** Get floorline position.(int value return.)
00131      *
00132      */ 
00133     int GetLinePosition(void);
00134     
00135     /** Get switch .(switch OFF:0 or ON:1 return.)
00136      *
00137      */ 
00138     int GetSw(void);
00139     
00140     /** Set status led .
00141      * @param led (bit0:LEFT bit2:RIGHT)
00142      */ 
00143     void set_led(int bit);
00144 
00145     /** Set led1 .
00146      * @param led (0:off,1:on)
00147      */ 
00148     void set_led1(int bit);
00149 
00150     /** Set led2 .
00151      * @param led (0:off,1:on)
00152      */ 
00153     void set_led2(int bit);
00154     
00155     private :
00156 
00157     TB6612 _right;
00158     TB6612 _left;
00159     BusIn _sw;
00160     DigitalOut _outlow;
00161     BusOut _statusled;
00162     AnalogIn _f_sensor1;
00163     AnalogIn _f_sensor2;
00164     AnalogIn _f_sensor3;
00165     AnalogIn _f_sensor4;
00166     int _sensor_gain;
00167     int _sensor_def[4];  
00168 };
00169 
00170 #endif