Junichi Katsu
/
wallbotLED_base
うおーるぼっとLEDのワークショップ用
wallbotLED/wallbotLED.h@0:9fcc79b3f00e, 2017-02-03 (annotated)
- Committer:
- jksoft
- Date:
- Fri Feb 03 06:26:54 2017 +0000
- Revision:
- 0:9fcc79b3f00e
- Child:
- 3:b707c09b4433
??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:9fcc79b3f00e | 1 | /* JKsoft Wallbot LED Library |
jksoft | 0:9fcc79b3f00e | 2 | * |
jksoft | 0:9fcc79b3f00e | 3 | * wallbotLED.h |
jksoft | 0:9fcc79b3f00e | 4 | * |
jksoft | 0:9fcc79b3f00e | 5 | * Copyright (c) 2010-2016 jksoft |
jksoft | 0:9fcc79b3f00e | 6 | * |
jksoft | 0:9fcc79b3f00e | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
jksoft | 0:9fcc79b3f00e | 8 | * of this software and associated documentation files (the "Software"), to deal |
jksoft | 0:9fcc79b3f00e | 9 | * in the Software without restriction, including without limitation the rights |
jksoft | 0:9fcc79b3f00e | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
jksoft | 0:9fcc79b3f00e | 11 | * copies of the Software, and to permit persons to whom the Software is |
jksoft | 0:9fcc79b3f00e | 12 | * furnished to do so, subject to the following conditions: |
jksoft | 0:9fcc79b3f00e | 13 | * |
jksoft | 0:9fcc79b3f00e | 14 | * The above copyright notice and this permission notice shall be included in |
jksoft | 0:9fcc79b3f00e | 15 | * all copies or substantial portions of the Software. |
jksoft | 0:9fcc79b3f00e | 16 | * |
jksoft | 0:9fcc79b3f00e | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
jksoft | 0:9fcc79b3f00e | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
jksoft | 0:9fcc79b3f00e | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
jksoft | 0:9fcc79b3f00e | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIALED FOR ANY CLAIM, DAMAGES OR OTHER |
jksoft | 0:9fcc79b3f00e | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jksoft | 0:9fcc79b3f00e | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
jksoft | 0:9fcc79b3f00e | 23 | * THE SOFTWARE. |
jksoft | 0:9fcc79b3f00e | 24 | */ |
jksoft | 0:9fcc79b3f00e | 25 | |
jksoft | 0:9fcc79b3f00e | 26 | #ifndef WALLBOT_LED_H |
jksoft | 0:9fcc79b3f00e | 27 | #define WALLBOT_LED_H |
jksoft | 0:9fcc79b3f00e | 28 | |
jksoft | 0:9fcc79b3f00e | 29 | #include "mbed.h" |
jksoft | 0:9fcc79b3f00e | 30 | #include "I2Cdev.h" |
jksoft | 0:9fcc79b3f00e | 31 | #include "TB6612.h" |
jksoft | 0:9fcc79b3f00e | 32 | #include "MPU6050.h" |
jksoft | 0:9fcc79b3f00e | 33 | #include "Adafruit_LEDBackpack.h" |
jksoft | 0:9fcc79b3f00e | 34 | #include "Adafruit_GFX.h" |
jksoft | 0:9fcc79b3f00e | 35 | |
jksoft | 0:9fcc79b3f00e | 36 | #define SENSOR_VAL_GAIN_DEFAULT 100 |
jksoft | 0:9fcc79b3f00e | 37 | #define SENSOR_VAL_DEFAULT 950 |
jksoft | 0:9fcc79b3f00e | 38 | |
jksoft | 0:9fcc79b3f00e | 39 | /** wallbot LED control class |
jksoft | 0:9fcc79b3f00e | 40 | * |
jksoft | 0:9fcc79b3f00e | 41 | * Example: |
jksoft | 0:9fcc79b3f00e | 42 | * @code |
jksoft | 0:9fcc79b3f00e | 43 | * // Drive the wwallbot forward, turn left, back, turn right, at half speed for half a second |
jksoft | 0:9fcc79b3f00e | 44 | |
jksoft | 0:9fcc79b3f00e | 45 | #include "mbed.h" |
jksoft | 0:9fcc79b3f00e | 46 | #include "wallbotLED.h" |
jksoft | 0:9fcc79b3f00e | 47 | |
jksoft | 0:9fcc79b3f00e | 48 | wallbotLED wb; |
jksoft | 0:9fcc79b3f00e | 49 | |
jksoft | 0:9fcc79b3f00e | 50 | int main() { |
jksoft | 0:9fcc79b3f00e | 51 | |
jksoft | 0:9fcc79b3f00e | 52 | wb.sensor_calibrate(); |
jksoft | 0:9fcc79b3f00e | 53 | |
jksoft | 0:9fcc79b3f00e | 54 | while(!wb.GetSw()) |
jksoft | 0:9fcc79b3f00e | 55 | { |
jksoft | 0:9fcc79b3f00e | 56 | wb.set_led(wb.GetLinePosition()); |
jksoft | 0:9fcc79b3f00e | 57 | } |
jksoft | 0:9fcc79b3f00e | 58 | |
jksoft | 0:9fcc79b3f00e | 59 | wb.forward(1.0); |
jksoft | 0:9fcc79b3f00e | 60 | wait (1.0); |
jksoft | 0:9fcc79b3f00e | 61 | wb.left(1.0); |
jksoft | 0:9fcc79b3f00e | 62 | wait (1.0); |
jksoft | 0:9fcc79b3f00e | 63 | wb.backward(1.0); |
jksoft | 0:9fcc79b3f00e | 64 | wait (1.0); |
jksoft | 0:9fcc79b3f00e | 65 | wb.right(1.0); |
jksoft | 0:9fcc79b3f00e | 66 | wait (1.0); |
jksoft | 0:9fcc79b3f00e | 67 | |
jksoft | 0:9fcc79b3f00e | 68 | wb.stop(); |
jksoft | 0:9fcc79b3f00e | 69 | |
jksoft | 0:9fcc79b3f00e | 70 | while(1); |
jksoft | 0:9fcc79b3f00e | 71 | |
jksoft | 0:9fcc79b3f00e | 72 | } |
jksoft | 0:9fcc79b3f00e | 73 | |
jksoft | 0:9fcc79b3f00e | 74 | * @endcode |
jksoft | 0:9fcc79b3f00e | 75 | */ |
jksoft | 0:9fcc79b3f00e | 76 | class wallbotLED { |
jksoft | 0:9fcc79b3f00e | 77 | |
jksoft | 0:9fcc79b3f00e | 78 | // Public functions |
jksoft | 0:9fcc79b3f00e | 79 | public: |
jksoft | 0:9fcc79b3f00e | 80 | |
jksoft | 0:9fcc79b3f00e | 81 | /** Create the wallbot object connected to the default pins |
jksoft | 0:9fcc79b3f00e | 82 | */ |
jksoft | 0:9fcc79b3f00e | 83 | wallbotLED(); |
jksoft | 0:9fcc79b3f00e | 84 | |
jksoft | 0:9fcc79b3f00e | 85 | /** Set Sensor gain. |
jksoft | 0:9fcc79b3f00e | 86 | * |
jksoft | 0:9fcc79b3f00e | 87 | * @param Sensor gain. |
jksoft | 0:9fcc79b3f00e | 88 | */ |
jksoft | 0:9fcc79b3f00e | 89 | void SetFloorSensorGain(int gain); |
jksoft | 0:9fcc79b3f00e | 90 | /** Sensor calibrate |
jksoft | 0:9fcc79b3f00e | 91 | * |
jksoft | 0:9fcc79b3f00e | 92 | */ |
jksoft | 0:9fcc79b3f00e | 93 | void FloorSensorCalibrate (void); |
jksoft | 0:9fcc79b3f00e | 94 | |
jksoft | 0:9fcc79b3f00e | 95 | /** Directly control the speed and direction of the left motor |
jksoft | 0:9fcc79b3f00e | 96 | * |
jksoft | 0:9fcc79b3f00e | 97 | * @param speed A normalised number -1.0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 98 | */ |
jksoft | 0:9fcc79b3f00e | 99 | void driveLeftMotor(float speed); |
jksoft | 0:9fcc79b3f00e | 100 | |
jksoft | 0:9fcc79b3f00e | 101 | /** Directly control the speed and direction of the right motor |
jksoft | 0:9fcc79b3f00e | 102 | * |
jksoft | 0:9fcc79b3f00e | 103 | * @param speed A normalised number -1.0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 104 | * @param speed A normalised number -1.0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 105 | */ |
jksoft | 0:9fcc79b3f00e | 106 | void driveMotor(float r_speed,float l_speed); |
jksoft | 0:9fcc79b3f00e | 107 | |
jksoft | 0:9fcc79b3f00e | 108 | /** Directly control the speed and direction of the right motor |
jksoft | 0:9fcc79b3f00e | 109 | * |
jksoft | 0:9fcc79b3f00e | 110 | * @param speed A normalised number -100 - 100 represents the full range. |
jksoft | 0:9fcc79b3f00e | 111 | * @param speed A normalised number -100 - 100 represents the full range. |
jksoft | 0:9fcc79b3f00e | 112 | */ |
jksoft | 0:9fcc79b3f00e | 113 | void driveMotor(int r_speed,int l_speed); |
jksoft | 0:9fcc79b3f00e | 114 | |
jksoft | 0:9fcc79b3f00e | 115 | /** Drive both motors |
jksoft | 0:9fcc79b3f00e | 116 | * |
jksoft | 0:9fcc79b3f00e | 117 | * @param speed A normalised number -1.0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 118 | */ |
jksoft | 0:9fcc79b3f00e | 119 | void driveRightMotor(float speed); |
jksoft | 0:9fcc79b3f00e | 120 | |
jksoft | 0:9fcc79b3f00e | 121 | /** Drive both motors forward as the same speed |
jksoft | 0:9fcc79b3f00e | 122 | * |
jksoft | 0:9fcc79b3f00e | 123 | * @param speed A normalised number 0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 124 | */ |
jksoft | 0:9fcc79b3f00e | 125 | void forward(float speed); |
jksoft | 0:9fcc79b3f00e | 126 | |
jksoft | 0:9fcc79b3f00e | 127 | /** Drive both motors backward as the same speed |
jksoft | 0:9fcc79b3f00e | 128 | * |
jksoft | 0:9fcc79b3f00e | 129 | * @param speed A normalised number 0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 130 | */ |
jksoft | 0:9fcc79b3f00e | 131 | void backward(float speed); |
jksoft | 0:9fcc79b3f00e | 132 | |
jksoft | 0:9fcc79b3f00e | 133 | /** Drive left motor backwards and right motor forwards at the same speed to turn on the spot |
jksoft | 0:9fcc79b3f00e | 134 | * |
jksoft | 0:9fcc79b3f00e | 135 | * @param speed A normalised number 0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 136 | */ |
jksoft | 0:9fcc79b3f00e | 137 | void leftTurn(float speed); |
jksoft | 0:9fcc79b3f00e | 138 | |
jksoft | 0:9fcc79b3f00e | 139 | /** Drive left motor forward and right motor backwards at the same speed to turn on the spot |
jksoft | 0:9fcc79b3f00e | 140 | * @param speed A normalised number 0 - 1.0 represents the full range. |
jksoft | 0:9fcc79b3f00e | 141 | */ |
jksoft | 0:9fcc79b3f00e | 142 | void rightTurn(float speed); |
jksoft | 0:9fcc79b3f00e | 143 | |
jksoft | 0:9fcc79b3f00e | 144 | /** Stop both motors |
jksoft | 0:9fcc79b3f00e | 145 | * |
jksoft | 0:9fcc79b3f00e | 146 | */ |
jksoft | 0:9fcc79b3f00e | 147 | void stop(void); |
jksoft | 0:9fcc79b3f00e | 148 | |
jksoft | 0:9fcc79b3f00e | 149 | /** Get floorline position.(int value return.) |
jksoft | 0:9fcc79b3f00e | 150 | * |
jksoft | 0:9fcc79b3f00e | 151 | */ |
jksoft | 0:9fcc79b3f00e | 152 | int GetLinePosition(void); |
jksoft | 0:9fcc79b3f00e | 153 | |
jksoft | 0:9fcc79b3f00e | 154 | /** Get switch .(switch OFF:0 or ON:1 return.) |
jksoft | 0:9fcc79b3f00e | 155 | * |
jksoft | 0:9fcc79b3f00e | 156 | */ |
jksoft | 0:9fcc79b3f00e | 157 | int GetSw(void); |
jksoft | 0:9fcc79b3f00e | 158 | bool GetSw1(void); |
jksoft | 0:9fcc79b3f00e | 159 | bool GetSw2(void); |
jksoft | 0:9fcc79b3f00e | 160 | |
jksoft | 0:9fcc79b3f00e | 161 | /** Set status led . |
jksoft | 0:9fcc79b3f00e | 162 | * @param led (bit0:LEFT bit2:RIGHT) |
jksoft | 0:9fcc79b3f00e | 163 | */ |
jksoft | 0:9fcc79b3f00e | 164 | void SetLed(int bit); |
jksoft | 0:9fcc79b3f00e | 165 | |
jksoft | 0:9fcc79b3f00e | 166 | /** Set led1 . |
jksoft | 0:9fcc79b3f00e | 167 | * @param led (0:off,1:on) |
jksoft | 0:9fcc79b3f00e | 168 | */ |
jksoft | 0:9fcc79b3f00e | 169 | void SetLed1(int bit); |
jksoft | 0:9fcc79b3f00e | 170 | |
jksoft | 0:9fcc79b3f00e | 171 | /** Set led2 . |
jksoft | 0:9fcc79b3f00e | 172 | * @param led (0:off,1:on) |
jksoft | 0:9fcc79b3f00e | 173 | */ |
jksoft | 0:9fcc79b3f00e | 174 | void SetLed2(int bit); |
jksoft | 0:9fcc79b3f00e | 175 | |
jksoft | 0:9fcc79b3f00e | 176 | bool GetFloorSensor1(); |
jksoft | 0:9fcc79b3f00e | 177 | bool GetFloorSensor2(); |
jksoft | 0:9fcc79b3f00e | 178 | bool GetFloorSensor3(); |
jksoft | 0:9fcc79b3f00e | 179 | bool GetFloorSensor4(); |
jksoft | 0:9fcc79b3f00e | 180 | |
jksoft | 0:9fcc79b3f00e | 181 | uint16_t GetFloorSensorRaw1(); |
jksoft | 0:9fcc79b3f00e | 182 | uint16_t GetFloorSensorRaw2(); |
jksoft | 0:9fcc79b3f00e | 183 | uint16_t GetFloorSensorRaw3(); |
jksoft | 0:9fcc79b3f00e | 184 | uint16_t GetFloorSensorRaw4(); |
jksoft | 0:9fcc79b3f00e | 185 | |
jksoft | 0:9fcc79b3f00e | 186 | void GetAcceleration(float *x,float *y,float *z); |
jksoft | 0:9fcc79b3f00e | 187 | float GetAccelerationX(); |
jksoft | 0:9fcc79b3f00e | 188 | float GetAccelerationY(); |
jksoft | 0:9fcc79b3f00e | 189 | float GetAccelerationZ(); |
jksoft | 0:9fcc79b3f00e | 190 | |
jksoft | 0:9fcc79b3f00e | 191 | void GetGyro(float *x,float *y,float *z); |
jksoft | 0:9fcc79b3f00e | 192 | float GetGyroX(); |
jksoft | 0:9fcc79b3f00e | 193 | float GetGyroY(); |
jksoft | 0:9fcc79b3f00e | 194 | float GetGyroZ(); |
jksoft | 0:9fcc79b3f00e | 195 | |
jksoft | 0:9fcc79b3f00e | 196 | void SetLedPanel(char data[][16]); |
jksoft | 0:9fcc79b3f00e | 197 | void SetLedPanel(int x, int y, int flag); |
jksoft | 0:9fcc79b3f00e | 198 | |
jksoft | 0:9fcc79b3f00e | 199 | private : |
jksoft | 0:9fcc79b3f00e | 200 | |
jksoft | 0:9fcc79b3f00e | 201 | TB6612 _right; |
jksoft | 0:9fcc79b3f00e | 202 | TB6612 _left; |
jksoft | 0:9fcc79b3f00e | 203 | MPU6050 _mpu; |
jksoft | 0:9fcc79b3f00e | 204 | I2C _i2c; |
jksoft | 0:9fcc79b3f00e | 205 | Adafruit_8x8matrix _matrix1; |
jksoft | 0:9fcc79b3f00e | 206 | Adafruit_8x8matrix _matrix2; |
jksoft | 0:9fcc79b3f00e | 207 | BusIn _sw; |
jksoft | 0:9fcc79b3f00e | 208 | DigitalOut _outlow; |
jksoft | 0:9fcc79b3f00e | 209 | BusOut _statusled; |
jksoft | 0:9fcc79b3f00e | 210 | AnalogIn _f_sensor1; |
jksoft | 0:9fcc79b3f00e | 211 | AnalogIn _f_sensor2; |
jksoft | 0:9fcc79b3f00e | 212 | AnalogIn _f_sensor3; |
jksoft | 0:9fcc79b3f00e | 213 | AnalogIn _f_sensor4; |
jksoft | 0:9fcc79b3f00e | 214 | int _sensor_gain; |
jksoft | 0:9fcc79b3f00e | 215 | int _sensor_def[4]; |
jksoft | 0:9fcc79b3f00e | 216 | }; |
jksoft | 0:9fcc79b3f00e | 217 | |
jksoft | 0:9fcc79b3f00e | 218 | #endif |