RCBControllerでモータを制御します。うおーるぼっとも動かせました。

Dependencies:   BLE_API TB6612FNG2 mbed nRF51822

Fork of BLE_RCBController2 by Junichi Katsu

うまく接続できない時は、iPhone/iPadのBluetoothをOFF->ONしてキャッシュをクリアしてみてください。

ライブラリ類をUpdateするとコンパイル出来なくなります。インポートした物をそのまま使って下さい。

RCBControllerでうおーるぼっとを操縦する例 /media/uploads/robo8080/img_1671.jpg

Components / Wallbot
This robot has switch, line sensors and motors. It controls by mbed.

RCBControllerでの操縦は次の4種類あります。 それぞれうおーるぼっとの動きが異なりますので試してみてください。

  • 左十字ボタン
  • 左のみアナログ
  • 右のみアナログ
  • 両方アナログ

うおーるぼっと(LPC1768のソケット)とHRM1017の接続はこれです。

LPC1768 ー HRM1017

p11 ーーー P0_0

p12 ーーー P0_1

p13 ーーー P0_28

p14 ーーー P0_29

p21 ーーー P0_30

p22 ーーー P0_25

GND ーーー GND

/media/uploads/robo8080/img_1711.jpg

/media/uploads/robo8080/img_1703.jpg

HRM1017の電源はうおーるぼっとのUSBコネクタからとります。 /media/uploads/robo8080/img_1674.jpg

Committer:
jksoft
Date:
Wed Aug 20 13:41:01 2014 +0000
Revision:
4:ebda47d22091
Parent:
nRF51822/nordic/nrf-sdk/app_common/app_util.h@1:48f6e08a3ac2
?????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 1:48f6e08a3ac2 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
jksoft 1:48f6e08a3ac2 2 *
jksoft 1:48f6e08a3ac2 3 * The information contained herein is property of Nordic Semiconductor ASA.
jksoft 1:48f6e08a3ac2 4 * Terms and conditions of usage are described in detail in NORDIC
jksoft 1:48f6e08a3ac2 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
jksoft 1:48f6e08a3ac2 6 *
jksoft 1:48f6e08a3ac2 7 * Licensees are granted free, non-transferable use of the information. NO
jksoft 1:48f6e08a3ac2 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
jksoft 1:48f6e08a3ac2 9 * the file.
jksoft 1:48f6e08a3ac2 10 *
jksoft 1:48f6e08a3ac2 11 */
jksoft 1:48f6e08a3ac2 12
jksoft 1:48f6e08a3ac2 13 /** @file
jksoft 1:48f6e08a3ac2 14 *
jksoft 1:48f6e08a3ac2 15 * @defgroup app_util Utility Functions and Definitions
jksoft 1:48f6e08a3ac2 16 * @{
jksoft 1:48f6e08a3ac2 17 * @ingroup app_common
jksoft 1:48f6e08a3ac2 18 *
jksoft 1:48f6e08a3ac2 19 * @brief Various types and definitions available to all applications.
jksoft 1:48f6e08a3ac2 20 */
jksoft 1:48f6e08a3ac2 21
jksoft 1:48f6e08a3ac2 22 #ifndef APP_UTIL_H__
jksoft 1:48f6e08a3ac2 23 #define APP_UTIL_H__
jksoft 1:48f6e08a3ac2 24
jksoft 1:48f6e08a3ac2 25 #include <stdint.h>
jksoft 1:48f6e08a3ac2 26 #include <stdbool.h>
jksoft 1:48f6e08a3ac2 27 #include "compiler_abstraction.h"
jksoft 1:48f6e08a3ac2 28
jksoft 1:48f6e08a3ac2 29 enum
jksoft 1:48f6e08a3ac2 30 {
jksoft 1:48f6e08a3ac2 31 UNIT_0_625_MS = 625, /**< Number of microseconds in 0.625 milliseconds. */
jksoft 1:48f6e08a3ac2 32 UNIT_1_25_MS = 1250, /**< Number of microseconds in 1.25 milliseconds. */
jksoft 1:48f6e08a3ac2 33 UNIT_10_MS = 10000 /**< Number of microseconds in 10 milliseconds. */
jksoft 1:48f6e08a3ac2 34 };
jksoft 1:48f6e08a3ac2 35
jksoft 1:48f6e08a3ac2 36 /**@brief Macro for doing static (i.e. compile time) assertion.
jksoft 1:48f6e08a3ac2 37 *
jksoft 1:48f6e08a3ac2 38 * @note If the assertion fails when compiling using Keil, the compiler will report error message
jksoft 1:48f6e08a3ac2 39 * "error: #94: the size of an array must be greater than zero" (while gcc will list the
jksoft 1:48f6e08a3ac2 40 * symbol static_assert_failed, making the error message more readable).
jksoft 1:48f6e08a3ac2 41 * If the supplied expression can not be evaluated at compile time, Keil will report
jksoft 1:48f6e08a3ac2 42 * "error: #28: expression must have a constant value".
jksoft 1:48f6e08a3ac2 43 *
jksoft 1:48f6e08a3ac2 44 * @note The macro is intentionally implemented not using do while(0), allowing it to be used
jksoft 1:48f6e08a3ac2 45 * outside function blocks (e.g. close to global type- and variable declarations).
jksoft 1:48f6e08a3ac2 46 * If used in a code block, it must be used before any executable code in this block.
jksoft 1:48f6e08a3ac2 47 *
jksoft 1:48f6e08a3ac2 48 * @param[in] EXPR Constant expression to be verified.
jksoft 1:48f6e08a3ac2 49 */
jksoft 1:48f6e08a3ac2 50
jksoft 1:48f6e08a3ac2 51 #if defined(__GNUC__)
jksoft 1:48f6e08a3ac2 52 #define STATIC_ASSERT(EXPR) typedef char __attribute__((unused)) static_assert_failed[(EXPR) ? 1 : -1]
jksoft 1:48f6e08a3ac2 53 #else
jksoft 1:48f6e08a3ac2 54 #define STATIC_ASSERT(EXPR) typedef char static_assert_failed[(EXPR) ? 1 : -1]
jksoft 1:48f6e08a3ac2 55 #endif
jksoft 1:48f6e08a3ac2 56
jksoft 1:48f6e08a3ac2 57
jksoft 1:48f6e08a3ac2 58 /**@brief type for holding an encoded (i.e. little endian) 16 bit unsigned integer. */
jksoft 1:48f6e08a3ac2 59 typedef uint8_t uint16_le_t[2];
jksoft 1:48f6e08a3ac2 60
jksoft 1:48f6e08a3ac2 61 /**@brief type for holding an encoded (i.e. little endian) 32 bit unsigned integer. */
jksoft 1:48f6e08a3ac2 62 typedef uint8_t uint32_le_t[4];
jksoft 1:48f6e08a3ac2 63
jksoft 1:48f6e08a3ac2 64 /**@brief Byte array type. */
jksoft 1:48f6e08a3ac2 65 typedef struct
jksoft 1:48f6e08a3ac2 66 {
jksoft 1:48f6e08a3ac2 67 uint16_t size; /**< Number of array entries. */
jksoft 1:48f6e08a3ac2 68 uint8_t * p_data; /**< Pointer to array entries. */
jksoft 1:48f6e08a3ac2 69 } uint8_array_t;
jksoft 1:48f6e08a3ac2 70
jksoft 1:48f6e08a3ac2 71 /**@brief Perform rounded integer division (as opposed to truncating the result).
jksoft 1:48f6e08a3ac2 72 *
jksoft 1:48f6e08a3ac2 73 * @param[in] A Numerator.
jksoft 1:48f6e08a3ac2 74 * @param[in] B Denominator.
jksoft 1:48f6e08a3ac2 75 *
jksoft 1:48f6e08a3ac2 76 * @return Rounded (integer) result of dividing A by B.
jksoft 1:48f6e08a3ac2 77 */
jksoft 1:48f6e08a3ac2 78 #define ROUNDED_DIV(A, B) (((A) + ((B) / 2)) / (B))
jksoft 1:48f6e08a3ac2 79
jksoft 1:48f6e08a3ac2 80 /**@brief Check if the integer provided is a power of two.
jksoft 1:48f6e08a3ac2 81 *
jksoft 1:48f6e08a3ac2 82 * @param[in] A Number to be tested.
jksoft 1:48f6e08a3ac2 83 *
jksoft 1:48f6e08a3ac2 84 * @return true if value is power of two.
jksoft 1:48f6e08a3ac2 85 * @return false if value not power of two.
jksoft 1:48f6e08a3ac2 86 */
jksoft 1:48f6e08a3ac2 87 #define IS_POWER_OF_TWO(A) ( ((A) != 0) && ((((A) - 1) & (A)) == 0) )
jksoft 1:48f6e08a3ac2 88
jksoft 1:48f6e08a3ac2 89 /**@brief To convert ticks to millisecond
jksoft 1:48f6e08a3ac2 90 * @param[in] time Number of millseconds that needs to be converted.
jksoft 1:48f6e08a3ac2 91 * @param[in] resolution Units to be converted.
jksoft 1:48f6e08a3ac2 92 */
jksoft 1:48f6e08a3ac2 93 #define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
jksoft 1:48f6e08a3ac2 94
jksoft 1:48f6e08a3ac2 95
jksoft 1:48f6e08a3ac2 96 /**@brief Perform integer division, making sure the result is rounded up.
jksoft 1:48f6e08a3ac2 97 *
jksoft 1:48f6e08a3ac2 98 * @details One typical use for this is to compute the number of objects with size B is needed to
jksoft 1:48f6e08a3ac2 99 * hold A number of bytes.
jksoft 1:48f6e08a3ac2 100 *
jksoft 1:48f6e08a3ac2 101 * @param[in] A Numerator.
jksoft 1:48f6e08a3ac2 102 * @param[in] B Denominator.
jksoft 1:48f6e08a3ac2 103 *
jksoft 1:48f6e08a3ac2 104 * @return Integer result of dividing A by B, rounded up.
jksoft 1:48f6e08a3ac2 105 */
jksoft 1:48f6e08a3ac2 106 #define CEIL_DIV(A, B) \
jksoft 1:48f6e08a3ac2 107 /*lint -save -e573 */ \
jksoft 1:48f6e08a3ac2 108 ((((A) - 1) / (B)) + 1) \
jksoft 1:48f6e08a3ac2 109 /*lint -restore */
jksoft 1:48f6e08a3ac2 110
jksoft 1:48f6e08a3ac2 111 /**@brief Function for encoding a uint16 value.
jksoft 1:48f6e08a3ac2 112 *
jksoft 1:48f6e08a3ac2 113 * @param[in] value Value to be encoded.
jksoft 1:48f6e08a3ac2 114 * @param[out] p_encoded_data Buffer where the encoded data is to be written.
jksoft 1:48f6e08a3ac2 115 *
jksoft 1:48f6e08a3ac2 116 * @return Number of bytes written.
jksoft 1:48f6e08a3ac2 117 */
jksoft 1:48f6e08a3ac2 118 static __INLINE uint8_t uint16_encode(uint16_t value, uint8_t * p_encoded_data)
jksoft 1:48f6e08a3ac2 119 {
jksoft 1:48f6e08a3ac2 120 p_encoded_data[0] = (uint8_t) ((value & 0x00FF) >> 0);
jksoft 1:48f6e08a3ac2 121 p_encoded_data[1] = (uint8_t) ((value & 0xFF00) >> 8);
jksoft 1:48f6e08a3ac2 122 return sizeof(uint16_t);
jksoft 1:48f6e08a3ac2 123 }
jksoft 1:48f6e08a3ac2 124
jksoft 1:48f6e08a3ac2 125 /**@brief Function for encoding a uint32 value.
jksoft 1:48f6e08a3ac2 126 *
jksoft 1:48f6e08a3ac2 127 * @param[in] value Value to be encoded.
jksoft 1:48f6e08a3ac2 128 * @param[out] p_encoded_data Buffer where the encoded data is to be written.
jksoft 1:48f6e08a3ac2 129 *
jksoft 1:48f6e08a3ac2 130 * @return Number of bytes written.
jksoft 1:48f6e08a3ac2 131 */
jksoft 1:48f6e08a3ac2 132 static __INLINE uint8_t uint32_encode(uint32_t value, uint8_t * p_encoded_data)
jksoft 1:48f6e08a3ac2 133 {
jksoft 1:48f6e08a3ac2 134 p_encoded_data[0] = (uint8_t) ((value & 0x000000FF) >> 0);
jksoft 1:48f6e08a3ac2 135 p_encoded_data[1] = (uint8_t) ((value & 0x0000FF00) >> 8);
jksoft 1:48f6e08a3ac2 136 p_encoded_data[2] = (uint8_t) ((value & 0x00FF0000) >> 16);
jksoft 1:48f6e08a3ac2 137 p_encoded_data[3] = (uint8_t) ((value & 0xFF000000) >> 24);
jksoft 1:48f6e08a3ac2 138 return sizeof(uint32_t);
jksoft 1:48f6e08a3ac2 139 }
jksoft 1:48f6e08a3ac2 140
jksoft 1:48f6e08a3ac2 141 /**@brief Function for decoding a uint16 value.
jksoft 1:48f6e08a3ac2 142 *
jksoft 1:48f6e08a3ac2 143 * @param[in] p_encoded_data Buffer where the encoded data is stored.
jksoft 1:48f6e08a3ac2 144 *
jksoft 1:48f6e08a3ac2 145 * @return Decoded value.
jksoft 1:48f6e08a3ac2 146 */
jksoft 1:48f6e08a3ac2 147 static __INLINE uint16_t uint16_decode(const uint8_t * p_encoded_data)
jksoft 1:48f6e08a3ac2 148 {
jksoft 1:48f6e08a3ac2 149 return ( (((uint16_t)((uint8_t *)p_encoded_data)[0])) |
jksoft 1:48f6e08a3ac2 150 (((uint16_t)((uint8_t *)p_encoded_data)[1]) << 8 ));
jksoft 1:48f6e08a3ac2 151 }
jksoft 1:48f6e08a3ac2 152
jksoft 1:48f6e08a3ac2 153 /**@brief Function for decoding a uint32 value.
jksoft 1:48f6e08a3ac2 154 *
jksoft 1:48f6e08a3ac2 155 * @param[in] p_encoded_data Buffer where the encoded data is stored.
jksoft 1:48f6e08a3ac2 156 *
jksoft 1:48f6e08a3ac2 157 * @return Decoded value.
jksoft 1:48f6e08a3ac2 158 */
jksoft 1:48f6e08a3ac2 159 static __INLINE uint32_t uint32_decode(const uint8_t * p_encoded_data)
jksoft 1:48f6e08a3ac2 160 {
jksoft 1:48f6e08a3ac2 161 return ( (((uint32_t)((uint8_t *)p_encoded_data)[0]) << 0) |
jksoft 1:48f6e08a3ac2 162 (((uint32_t)((uint8_t *)p_encoded_data)[1]) << 8) |
jksoft 1:48f6e08a3ac2 163 (((uint32_t)((uint8_t *)p_encoded_data)[2]) << 16) |
jksoft 1:48f6e08a3ac2 164 (((uint32_t)((uint8_t *)p_encoded_data)[3]) << 24 ));
jksoft 1:48f6e08a3ac2 165 }
jksoft 1:48f6e08a3ac2 166
jksoft 1:48f6e08a3ac2 167 /** @brief Function for converting the input voltage (in milli volts) into percentage of 3.0 Volts.
jksoft 1:48f6e08a3ac2 168 *
jksoft 1:48f6e08a3ac2 169 * @details The calculation is based on a linearized version of the battery's discharge
jksoft 1:48f6e08a3ac2 170 * curve. 3.0V returns 100% battery level. The limit for power failure is 2.1V and
jksoft 1:48f6e08a3ac2 171 * is considered to be the lower boundary.
jksoft 1:48f6e08a3ac2 172 *
jksoft 1:48f6e08a3ac2 173 * The discharge curve for CR2032 is non-linear. In this model it is split into
jksoft 1:48f6e08a3ac2 174 * 4 linear sections:
jksoft 1:48f6e08a3ac2 175 * - Section 1: 3.0V - 2.9V = 100% - 42% (58% drop on 100 mV)
jksoft 1:48f6e08a3ac2 176 * - Section 2: 2.9V - 2.74V = 42% - 18% (24% drop on 160 mV)
jksoft 1:48f6e08a3ac2 177 * - Section 3: 2.74V - 2.44V = 18% - 6% (12% drop on 300 mV)
jksoft 1:48f6e08a3ac2 178 * - Section 4: 2.44V - 2.1V = 6% - 0% (6% drop on 340 mV)
jksoft 1:48f6e08a3ac2 179 *
jksoft 1:48f6e08a3ac2 180 * These numbers are by no means accurate. Temperature and
jksoft 1:48f6e08a3ac2 181 * load in the actual application is not accounted for!
jksoft 1:48f6e08a3ac2 182 *
jksoft 1:48f6e08a3ac2 183 * @param[in] mvolts The voltage in mV
jksoft 1:48f6e08a3ac2 184 *
jksoft 1:48f6e08a3ac2 185 * @return Battery level in percent.
jksoft 1:48f6e08a3ac2 186 */
jksoft 1:48f6e08a3ac2 187 static __INLINE uint8_t battery_level_in_percent(const uint16_t mvolts)
jksoft 1:48f6e08a3ac2 188 {
jksoft 1:48f6e08a3ac2 189 uint8_t battery_level;
jksoft 1:48f6e08a3ac2 190
jksoft 1:48f6e08a3ac2 191 if (mvolts >= 3000)
jksoft 1:48f6e08a3ac2 192 {
jksoft 1:48f6e08a3ac2 193 battery_level = 100;
jksoft 1:48f6e08a3ac2 194 }
jksoft 1:48f6e08a3ac2 195 else if (mvolts > 2900)
jksoft 1:48f6e08a3ac2 196 {
jksoft 1:48f6e08a3ac2 197 battery_level = 100 - ((3000 - mvolts) * 58) / 100;
jksoft 1:48f6e08a3ac2 198 }
jksoft 1:48f6e08a3ac2 199 else if (mvolts > 2740)
jksoft 1:48f6e08a3ac2 200 {
jksoft 1:48f6e08a3ac2 201 battery_level = 42 - ((2900 - mvolts) * 24) / 160;
jksoft 1:48f6e08a3ac2 202 }
jksoft 1:48f6e08a3ac2 203 else if (mvolts > 2440)
jksoft 1:48f6e08a3ac2 204 {
jksoft 1:48f6e08a3ac2 205 battery_level = 18 - ((2740 - mvolts) * 12) / 300;
jksoft 1:48f6e08a3ac2 206 }
jksoft 1:48f6e08a3ac2 207 else if (mvolts > 2100)
jksoft 1:48f6e08a3ac2 208 {
jksoft 1:48f6e08a3ac2 209 battery_level = 6 - ((2440 - mvolts) * 6) / 340;
jksoft 1:48f6e08a3ac2 210 }
jksoft 1:48f6e08a3ac2 211 else
jksoft 1:48f6e08a3ac2 212 {
jksoft 1:48f6e08a3ac2 213 battery_level = 0;
jksoft 1:48f6e08a3ac2 214 }
jksoft 1:48f6e08a3ac2 215
jksoft 1:48f6e08a3ac2 216 return battery_level;
jksoft 1:48f6e08a3ac2 217 }
jksoft 1:48f6e08a3ac2 218
jksoft 1:48f6e08a3ac2 219 /**@brief Function for checking if a pointer value is aligned to a 4 byte boundary.
jksoft 1:48f6e08a3ac2 220 *
jksoft 1:48f6e08a3ac2 221 * @param[in] p Pointer value to be checked.
jksoft 1:48f6e08a3ac2 222 *
jksoft 1:48f6e08a3ac2 223 * @return TRUE if pointer is aligned to a 4 byte boundary, FALSE otherwise.
jksoft 1:48f6e08a3ac2 224 */
jksoft 1:48f6e08a3ac2 225 static __INLINE bool is_word_aligned(void * p)
jksoft 1:48f6e08a3ac2 226 {
jksoft 1:48f6e08a3ac2 227 return (((uintptr_t)p & 0x03) == 0);
jksoft 1:48f6e08a3ac2 228 }
jksoft 1:48f6e08a3ac2 229
jksoft 1:48f6e08a3ac2 230 #endif // APP_UTIL_H__
jksoft 1:48f6e08a3ac2 231
jksoft 1:48f6e08a3ac2 232 /** @} */