2018.07.26

Dependencies:   EthernetInterface TextLCD USBDevice USBHost2 mbed

Committer:
sayzyas
Date:
Thu Jul 26 00:29:55 2018 +0000
Revision:
1:392f3708c3e2
Parent:
0:2cb1be240f50
2018.07.26

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sayzyas 0:2cb1be240f50 1 /*
sayzyas 0:2cb1be240f50 2 DEBUG PRINT MACRO
sayzyas 0:2cb1be240f50 3 http://qiita.com/saltheads/items/e1b0ab54d3d6029c9593
sayzyas 0:2cb1be240f50 4 http://tricky-code.net/nicecode/code10.php
sayzyas 0:2cb1be240f50 5 */
sayzyas 0:2cb1be240f50 6 /* Information */
sayzyas 0:2cb1be240f50 7 #define LatestUpDate "2016.11.04"
sayzyas 0:2cb1be240f50 8 #define ProgramRevision "Rev 2.40"
sayzyas 0:2cb1be240f50 9 #define Author "ZisNotRevast"
sayzyas 0:2cb1be240f50 10 #define Company "Revast Co.,Ltd."
sayzyas 0:2cb1be240f50 11
sayzyas 0:2cb1be240f50 12 //#define __CREATE_SETTING_FILE__
sayzyas 0:2cb1be240f50 13 //#define __TARGET_BOARD_CHECK__
sayzyas 0:2cb1be240f50 14
sayzyas 0:2cb1be240f50 15
sayzyas 0:2cb1be240f50 16 //#define __WInchDebug__ // For debugging
sayzyas 0:2cb1be240f50 17
sayzyas 0:2cb1be240f50 18
sayzyas 0:2cb1be240f50 19 // Comment out if net setting is FIX.
sayzyas 0:2cb1be240f50 20 // #define __NET_SETTING_FROM_LFS__
sayzyas 0:2cb1be240f50 21
sayzyas 0:2cb1be240f50 22
sayzyas 0:2cb1be240f50 23 // Read motor current
sayzyas 0:2cb1be240f50 24 #define __READ_TFM_MOTOR_CURRENT__
sayzyas 0:2cb1be240f50 25
sayzyas 0:2cb1be240f50 26 #define __IIC_COMAMND_SEND__
sayzyas 0:2cb1be240f50 27
sayzyas 0:2cb1be240f50 28 #define __SET_WINCH_MOTOR_SPEED_BY_VOLUME__
sayzyas 0:2cb1be240f50 29
sayzyas 0:2cb1be240f50 30 // ======================================================================
sayzyas 0:2cb1be240f50 31 // For Debugging
sayzyas 0:2cb1be240f50 32 // ======================================================================
sayzyas 0:2cb1be240f50 33 #define __DEBUG_PRINT_SW__ // Display SW Status to console
sayzyas 0:2cb1be240f50 34 //#define __DEBUG_L0__
sayzyas 0:2cb1be240f50 35 //#define __DEBUG_L1__
sayzyas 0:2cb1be240f50 36 //#define __DEBUG_L2__
sayzyas 0:2cb1be240f50 37 //#define __DEBUG_L3__
sayzyas 0:2cb1be240f50 38 //#define __DEBUG_L4__
sayzyas 0:2cb1be240f50 39 #define __DEBUG_L5__
sayzyas 0:2cb1be240f50 40
sayzyas 0:2cb1be240f50 41 #define __DEBUG_WINCH_DATA__
sayzyas 0:2cb1be240f50 42
sayzyas 0:2cb1be240f50 43
sayzyas 0:2cb1be240f50 44 #ifdef __DEBUG_WINCH_DATA__
sayzyas 0:2cb1be240f50 45 #define DEBUG_PRINT_WINCH_DATA(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 46 #else
sayzyas 0:2cb1be240f50 47 #define DEBUG_PRINT_WINCH_DATA(...)
sayzyas 0:2cb1be240f50 48 #endif
sayzyas 0:2cb1be240f50 49
sayzyas 0:2cb1be240f50 50 #ifdef __DEBUG_PRINT_SW__
sayzyas 0:2cb1be240f50 51 #define DEBUG_PRINT_SW(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 52 #else
sayzyas 0:2cb1be240f50 53 #define DEBUG_PRINT_SW(...)
sayzyas 0:2cb1be240f50 54 #endif
sayzyas 0:2cb1be240f50 55
sayzyas 0:2cb1be240f50 56 #ifdef __DEBUG_L0__
sayzyas 0:2cb1be240f50 57 #define DEBUG_PRINT_L0(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 58 #else
sayzyas 0:2cb1be240f50 59 #define DEBUG_PRINT_L0(...)
sayzyas 0:2cb1be240f50 60 #endif
sayzyas 0:2cb1be240f50 61 #ifdef __DEBUG_L1__
sayzyas 0:2cb1be240f50 62 #define DEBUG_PRINT_L1(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 63 #else
sayzyas 0:2cb1be240f50 64 #define DEBUG_PRINT_L1(...)
sayzyas 0:2cb1be240f50 65 #endif
sayzyas 0:2cb1be240f50 66 #ifdef __DEBUG_L2__
sayzyas 0:2cb1be240f50 67 #define DEBUG_PRINT_L2(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 68 #else
sayzyas 0:2cb1be240f50 69 #define DEBUG_PRINT_L2(...)
sayzyas 0:2cb1be240f50 70 #endif
sayzyas 0:2cb1be240f50 71 #ifdef __DEBUG_L3__
sayzyas 0:2cb1be240f50 72 #define DEBUG_PRINT_L3(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 73 #else
sayzyas 0:2cb1be240f50 74 #define DEBUG_PRINT_L3(...)
sayzyas 0:2cb1be240f50 75 #endif
sayzyas 0:2cb1be240f50 76 #ifdef __DEBUG_L4__
sayzyas 0:2cb1be240f50 77 #define DEBUG_PRINT_L4(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 78 #else
sayzyas 0:2cb1be240f50 79 #define DEBUG_PRINT_L4(...)
sayzyas 0:2cb1be240f50 80 #endif
sayzyas 0:2cb1be240f50 81 #ifdef __DEBUG_L5__
sayzyas 0:2cb1be240f50 82 #define DEBUG_PRINT_L5(...) pc.printf(__VA_ARGS__)
sayzyas 0:2cb1be240f50 83 #else
sayzyas 0:2cb1be240f50 84 #define DEBUG_PRINT_L5(...)
sayzyas 0:2cb1be240f50 85 #endif
sayzyas 0:2cb1be240f50 86
sayzyas 0:2cb1be240f50 87 // Motor Controller RoboCAN ID definition
sayzyas 0:2cb1be240f50 88 #define MCTR_CANID_PANTILTWCH 2 // Pan/Tilt or Winch motor's ID
sayzyas 0:2cb1be240f50 89 #define MCTR_CANID_TFM 3 // Trabsform motor's ID
sayzyas 0:2cb1be240f50 90 #define MCTR_CANID_CRW 1 // Crawler motor's ID
sayzyas 0:2cb1be240f50 91
sayzyas 0:2cb1be240f50 92 #define NUMBER_OF_MCCMD 7
sayzyas 0:2cb1be240f50 93 #define WINCH_OFFSET_VALUE 20
sayzyas 0:2cb1be240f50 94
sayzyas 0:2cb1be240f50 95 #define LED_IND_BLINK_PERIOD 15
sayzyas 0:2cb1be240f50 96 #define LED_IND_BLINK_PERIOD2 2
sayzyas 0:2cb1be240f50 97 #define LED_IND_BLINK_PERIOD8 18
sayzyas 0:2cb1be240f50 98
sayzyas 0:2cb1be240f50 99 /*
sayzyas 0:2cb1be240f50 100 B1/B2 demo machine controller control command list
sayzyas 0:2cb1be240f50 101 */
sayzyas 0:2cb1be240f50 102 enum{
sayzyas 0:2cb1be240f50 103 XX_WICH, // Winch
sayzyas 0:2cb1be240f50 104 XX_CLRF, // R Crawler
sayzyas 0:2cb1be240f50 105 XX_CLLB, // L Crawler
sayzyas 0:2cb1be240f50 106 XX_TFRF, // R Transform
sayzyas 0:2cb1be240f50 107 XX_TFLB, // R Transform
sayzyas 0:2cb1be240f50 108 ZTRF_I_1, // RF-I Transform ON
sayzyas 0:2cb1be240f50 109 ZTRF_I_0, // RF-I Transform OFF
sayzyas 0:2cb1be240f50 110 ZTRF_K_1, // RF-K Transform ON
sayzyas 0:2cb1be240f50 111 ZTRF_K_0, // RF-K Transform OFF
sayzyas 0:2cb1be240f50 112 ZTLB_I_1, // LB-I Transform ON
sayzyas 0:2cb1be240f50 113 ZTLB_I_0, // LB-I Transform OFF
sayzyas 0:2cb1be240f50 114 ZTLB_K_1, // LB-K Transform ON
sayzyas 0:2cb1be240f50 115 ZTLB_K_0, // LB-K Transform OFF
sayzyas 0:2cb1be240f50 116 ZCP_FW_1, // Camera PAN Forward ON
sayzyas 0:2cb1be240f50 117 ZCP_FW_0, // Camera PAN Forward OFF
sayzyas 0:2cb1be240f50 118 ZCP_RS_1, // Camera PAN Reverse ON
sayzyas 0:2cb1be240f50 119 ZCP_RS_0, // Camera PAN Reverse OFF
sayzyas 0:2cb1be240f50 120 ZCT_FW_1, // Camera TILT Forward ON
sayzyas 0:2cb1be240f50 121 ZCT_FW_0, // Camera TILT Forward OFF
sayzyas 0:2cb1be240f50 122 ZCT_RS_1, // Camera TILT Reverse ON
sayzyas 0:2cb1be240f50 123 ZCT_RS_0, // Camera TILT Reverse OFF
sayzyas 0:2cb1be240f50 124 ZESHAPE_I, // Shape I : Switch ON
sayzyas 0:2cb1be240f50 125 ZESHAPE_K, // Shape K : Switch OFF
sayzyas 0:2cb1be240f50 126 ZTFCWP_VD, // TFM,CRW Part valid : Switch ON
sayzyas 0:2cb1be240f50 127 ZWICHP_VD // Winch Part valid : Switch OFF
sayzyas 0:2cb1be240f50 128 };
sayzyas 0:2cb1be240f50 129
sayzyas 0:2cb1be240f50 130
sayzyas 0:2cb1be240f50 131 enum{
sayzyas 0:2cb1be240f50 132 MOTOR_NO0,
sayzyas 0:2cb1be240f50 133 MOTOR_NO1,
sayzyas 0:2cb1be240f50 134 MOTOR_NO2,
sayzyas 0:2cb1be240f50 135 MOTOR_NO3
sayzyas 0:2cb1be240f50 136 };
sayzyas 0:2cb1be240f50 137
sayzyas 0:2cb1be240f50 138 enum{
sayzyas 0:2cb1be240f50 139 MOTOR_FORWARD,
sayzyas 0:2cb1be240f50 140 MOTOR_REVERSE,
sayzyas 0:2cb1be240f50 141 MOTOR_STOP
sayzyas 0:2cb1be240f50 142 };
sayzyas 0:2cb1be240f50 143
sayzyas 0:2cb1be240f50 144 #define MC_LOCK_COUNT 5
sayzyas 0:2cb1be240f50 145
sayzyas 0:2cb1be240f50 146 #define DEAD_ZONE_BAND_WIDTH 10
sayzyas 0:2cb1be240f50 147 #define CALIBRATION_COUNT 300
sayzyas 0:2cb1be240f50 148
sayzyas 0:2cb1be240f50 149 /* ********************************************* */
sayzyas 0:2cb1be240f50 150
sayzyas 0:2cb1be240f50 151 #define MOTOR_1 '1'
sayzyas 0:2cb1be240f50 152 #define MOTOR_2 '2'
sayzyas 0:2cb1be240f50 153
sayzyas 0:2cb1be240f50 154 #define MOTOR_
sayzyas 0:2cb1be240f50 155
sayzyas 0:2cb1be240f50 156 /* Above is still under construction ..... */
sayzyas 0:2cb1be240f50 157
sayzyas 0:2cb1be240f50 158 #define __DISP_GAMAPAD_STATUS_ALL__
sayzyas 0:2cb1be240f50 159 #define __DISP_WRITE_VALUE__
sayzyas 0:2cb1be240f50 160
sayzyas 0:2cb1be240f50 161 #define I2C_ADDRESS_HANDY 0x20
sayzyas 0:2cb1be240f50 162 #define I2C_ADDRESS_WINCH 0x10
sayzyas 0:2cb1be240f50 163 #define I2C_ADDRESS_TRANSFORM 0x08
sayzyas 0:2cb1be240f50 164 #define I2C_ADDRESS_CRAWLER 0x04
sayzyas 0:2cb1be240f50 165 #define I2C_ADDRESS_RESOLVER 0x02
sayzyas 0:2cb1be240f50 166
sayzyas 0:2cb1be240f50 167
sayzyas 0:2cb1be240f50 168 #define _OK_ 1
sayzyas 0:2cb1be240f50 169 #define _NG_ 0
sayzyas 0:2cb1be240f50 170 #define _FAIL_ 0
sayzyas 0:2cb1be240f50 171
sayzyas 0:2cb1be240f50 172 #define ON 1
sayzyas 0:2cb1be240f50 173 #define OFF 0
sayzyas 0:2cb1be240f50 174
sayzyas 0:2cb1be240f50 175 #define LFS_READ_COUNT 3
sayzyas 0:2cb1be240f50 176 #define TARGET_CHECK_COUNT 10
sayzyas 0:2cb1be240f50 177
sayzyas 0:2cb1be240f50 178 //#define __DSP_MOTOR_CURRENT_
sayzyas 0:2cb1be240f50 179
sayzyas 0:2cb1be240f50 180 /* Usually this should be comment out */
sayzyas 0:2cb1be240f50 181 //#define _COMMUNCATE_PC_BY_SERIAL_
sayzyas 0:2cb1be240f50 182
sayzyas 0:2cb1be240f50 183 // Should validate this definition when you use DHCP.
sayzyas 0:2cb1be240f50 184 //#define __ETERNET_DHCP__
sayzyas 0:2cb1be240f50 185
sayzyas 0:2cb1be240f50 186 #define NumberOfPcCommand 11
sayzyas 0:2cb1be240f50 187 #define NumberOfI2CCommand 14
sayzyas 0:2cb1be240f50 188
sayzyas 0:2cb1be240f50 189 /* Winch Operating mode */
sayzyas 0:2cb1be240f50 190 enum{
sayzyas 0:2cb1be240f50 191 WINCH_POSITION_CLEAR,
sayzyas 0:2cb1be240f50 192 WINCH_PRESET_BASEDATA,
sayzyas 0:2cb1be240f50 193 WINCH_MMODE_RELATIVE,
sayzyas 0:2cb1be240f50 194 WINCH_MMODE_ABSOLUTE,
sayzyas 0:2cb1be240f50 195 WINCH_STEPDOWN_BTN_ON,
sayzyas 0:2cb1be240f50 196 WINCH_STEPDOWN_BTN_OFF,
sayzyas 0:2cb1be240f50 197 WINCH_STEPUP_BTN_ON,
sayzyas 0:2cb1be240f50 198 WINCH_STEPUP_BTN_OFF,
sayzyas 0:2cb1be240f50 199 WINCH_U_STEPDOWN_BTN_ON,
sayzyas 0:2cb1be240f50 200 WINCH_U_STEPDOWN_BTN_OFF,
sayzyas 0:2cb1be240f50 201 WINCH_U_STEPUP_BTN_ON,
sayzyas 0:2cb1be240f50 202 WINCH_U_STEPUP_BTN_OFF,
sayzyas 0:2cb1be240f50 203 WINCH_PRESET_POSITION,
sayzyas 0:2cb1be240f50 204 };
sayzyas 0:2cb1be240f50 205
sayzyas 0:2cb1be240f50 206 /* Game Pad defnition */
sayzyas 0:2cb1be240f50 207 #define GAMEPAD_VID_LOGICOOL 0x046d
sayzyas 0:2cb1be240f50 208 #define GAMEPAD_PID_LOGICOOL_F710 0xc219
sayzyas 0:2cb1be240f50 209 #define GAMEPAD_PID_LOGICOOL_F310 0xc216
sayzyas 0:2cb1be240f50 210
sayzyas 0:2cb1be240f50 211 #define GAMEPAD_VID_SANWA 0x12bd
sayzyas 0:2cb1be240f50 212 #define GAMEPAD_PID_SANWA_JYP70US 0xc003
sayzyas 0:2cb1be240f50 213
sayzyas 0:2cb1be240f50 214 #define GAMEPAD_VID_ELECOM 0x056e
sayzyas 0:2cb1be240f50 215 #define GAMEPAD_PID_ELECOM_JCU3613M 0x2003
sayzyas 0:2cb1be240f50 216
sayzyas 0:2cb1be240f50 217 #define GAMEPAD_VID_RSTHANDY 0x1234
sayzyas 0:2cb1be240f50 218 #define GAMEPAD_PID_RSTHANDY 0x0006
sayzyas 0:2cb1be240f50 219
sayzyas 0:2cb1be240f50 220
sayzyas 0:2cb1be240f50 221 /* Ether net */
sayzyas 0:2cb1be240f50 222 #define TCP_SERVER_PORT 10002
sayzyas 0:2cb1be240f50 223 #define UDP_SERVER_PORT 10000
sayzyas 0:2cb1be240f50 224 //#define ECHO_SERVER_PORT 7
sayzyas 0:2cb1be240f50 225
sayzyas 0:2cb1be240f50 226 #define MOTOR_FWD 'F' /* Forward Rotation */
sayzyas 0:2cb1be240f50 227 #define MOTOR_RVS 'R' /* Reverse Rotation */
sayzyas 0:2cb1be240f50 228 #define MOTOR_STP 'S' /* Stop */
sayzyas 0:2cb1be240f50 229
sayzyas 0:2cb1be240f50 230 // =========================================================
sayzyas 0:2cb1be240f50 231 // Setting Values
sayzyas 0:2cb1be240f50 232 // =========================================================
sayzyas 0:2cb1be240f50 233 typedef struct {
sayzyas 0:2cb1be240f50 234 int8_t sv_JS_ShapeMode; // JS Shape: 0=I, 1=KO
sayzyas 0:2cb1be240f50 235 int8_t sv_JS_OpeMode; // JS Operation: 0=single, 1=dual
sayzyas 0:2cb1be240f50 236 int8_t sv_WinchValid; // Winch function valid or not: 0=Tfm, Crawler valid, 1=Winch valid
sayzyas 0:2cb1be240f50 237 int8_t res;
sayzyas 0:2cb1be240f50 238 } basic_operation_t;
sayzyas 0:2cb1be240f50 239
sayzyas 0:2cb1be240f50 240 typedef struct {
sayzyas 0:2cb1be240f50 241 uint8_t rjs_upper_dzone; // 1 R Joystick upper dead zone width
sayzyas 0:2cb1be240f50 242 uint8_t rjs_lower_dzone; // 1 R Joystick lower dead zone width
sayzyas 0:2cb1be240f50 243 uint8_t rjs_right_dzone; // 1 R Joystick lower dead zone width
sayzyas 0:2cb1be240f50 244 uint8_t rjs_left_dzone; // 1 R Joystick lower dead zone width
sayzyas 0:2cb1be240f50 245 uint8_t reserved_1; // 1 reserved for future use
sayzyas 0:2cb1be240f50 246 uint8_t reserved_2; // 1 reserved for future use
sayzyas 0:2cb1be240f50 247 uint8_t reserved_3; // 1 reserved for future use
sayzyas 0:2cb1be240f50 248 uint8_t reserved_4; // 1 reserved for future use
sayzyas 0:2cb1be240f50 249 } js_SetValue_t;
sayzyas 0:2cb1be240f50 250
sayzyas 0:2cb1be240f50 251 typedef struct SetValue {
sayzyas 0:2cb1be240f50 252 js_SetValue_t jsCtrl;
sayzyas 0:2cb1be240f50 253 } setValue_t;
sayzyas 0:2cb1be240f50 254
sayzyas 0:2cb1be240f50 255
sayzyas 0:2cb1be240f50 256
sayzyas 0:2cb1be240f50 257
sayzyas 0:2cb1be240f50 258 #define SLOWDOWN_DISTANCE 23 // <--10 2016.06.01
sayzyas 0:2cb1be240f50 259 #define SLOWDOWN_NEAR_DISTANCE 3
sayzyas 0:2cb1be240f50 260 /*
sayzyas 0:2cb1be240f50 261 typedef struct {
sayzyas 0:2cb1be240f50 262 int16_t dt_WinchCntPosition; // Current winch posittion
sayzyas 0:2cb1be240f50 263 int16_t dt_WinchRtvValue; // Winch Moving distance
sayzyas 0:2cb1be240f50 264 int16_t dt_WinchDstPosition; // Destination Position
sayzyas 0:2cb1be240f50 265 char operation;
sayzyas 0:2cb1be240f50 266 int8_t dt_WinchMotorCurrent; // Winch motor current
sayzyas 0:2cb1be240f50 267 } winchData_t;
sayzyas 0:2cb1be240f50 268 */
sayzyas 0:2cb1be240f50 269
sayzyas 0:2cb1be240f50 270 typedef struct {
sayzyas 0:2cb1be240f50 271 int16_t dt_WinchCntPosition; // Current winch posittion
sayzyas 0:2cb1be240f50 272 int16_t dt_WinchRtvValue; // Winch Moving distance
sayzyas 0:2cb1be240f50 273 int16_t dt_WinchDstPosition; // Destination Position
sayzyas 0:2cb1be240f50 274 uint8_t operation;
sayzyas 0:2cb1be240f50 275 uint8_t dt_WinchMotor1Current; // Winch motor 1 current
sayzyas 0:2cb1be240f50 276 uint8_t dt_WinchMotor2Current; // Winch motor 2 current
sayzyas 0:2cb1be240f50 277 uint8_t res;
sayzyas 0:2cb1be240f50 278 } winchData_t;
sayzyas 0:2cb1be240f50 279
sayzyas 0:2cb1be240f50 280
sayzyas 0:2cb1be240f50 281 #define ROTATE_PER_RESOLUTION 24
sayzyas 0:2cb1be240f50 282
sayzyas 0:2cb1be240f50 283 #define __READ_CURRENT_AT_CIF_TASK__
sayzyas 0:2cb1be240f50 284
sayzyas 0:2cb1be240f50 285 //mv_WinchMvData