z ysaito / Mbed 2 deprecated MMC_ThrmTemMea_CtrlMain

Dependencies:   F7_Ethernet mbed mbed-rtos

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers common.h Source File

common.h

00001 /* 
00002    DEBUG PRINT MACRO
00003    http://qiita.com/saltheads/items/e1b0ab54d3d6029c9593
00004    http://tricky-code.net/nicecode/code10.php
00005 */
00006 /* Information */
00007 #define LatestUpDate    "2020.07.02"
00008 #define ProgramRevision "Rev 0.01" 
00009 #define Author          "y.saito"
00010 #define Company         "Sanei Co.,Ltd."
00011 
00012 //#define __CREATE_SETTING_FILE__
00013 //#define __TARGET_BOARD_CHECK__
00014 
00015 
00016 //#define __WInchDebug__  // For debugging 
00017 
00018 
00019 // Comment out if net setting is FIX.
00020 // #define __NET_SETTING_FROM_LFS__
00021 
00022 
00023 // Read motor current 
00024 #define __READ_TFM_MOTOR_CURRENT__
00025 
00026 #define __IIC_COMAMND_SEND__
00027 
00028 #define __SET_WINCH_MOTOR_SPEED_BY_VOLUME__
00029 
00030 /********************************************** 
00031  For Debugging
00032 ***********************************************/ 
00033 #define __DEBUG_L0__
00034 #define __DEBUG_L1__
00035 #define __DEBUG_L2__
00036 #define __DEBUG_L3__
00037 #define __DEBUG_L4__
00038 #define __DEBUG_L5__
00039 
00040 #ifdef __DEBUG_L0__
00041     #define DEBUG_PRINT_L0(...)  pc.printf(__VA_ARGS__)
00042 #else
00043     #define DEBUG_PRINT_L0(...) 
00044 #endif
00045 #ifdef __DEBUG_L1__
00046     #define DEBUG_PRINT_L1(...)  pc.printf(__VA_ARGS__)
00047 #else
00048     #define DEBUG_PRINT_L1(...) 
00049 #endif
00050 #ifdef __DEBUG_L2__
00051     #define DEBUG_PRINT_L2(...)  pc.printf(__VA_ARGS__)
00052 #else
00053     #define DEBUG_PRINT_L2(...) 
00054 #endif
00055 #ifdef __DEBUG_L3__
00056     #define DEBUG_PRINT_L3(...)  pc.printf(__VA_ARGS__)
00057 #else
00058     #define DEBUG_PRINT_L3(...) 
00059 #endif
00060 #ifdef __DEBUG_L4__
00061     #define DEBUG_PRINT_L4(...)  pc.printf(__VA_ARGS__)
00062 #else
00063     #define DEBUG_PRINT_L4(...) 
00064 #endif
00065 #ifdef __DEBUG_L5__
00066     #define DEBUG_PRINT_L5(...)  pc.printf(__VA_ARGS__)
00067 #else
00068     #define DEBUG_PRINT_L5(...) 
00069 #endif
00070 
00071 
00072 
00073 /* *****
00074  Constant definition
00075 ***** */
00076 #define BLINKING_RATE_MS  100 /* Blinking rate */
00077 
00078 
00079 #define DIR_CCW 1
00080 #define DIR_CW 0
00081 #define MOTOR_ON 1
00082 #define MOTOR_OFF 0
00083 
00084 #define L_001mm 1000 * 2
00085 #define L_002mm 2000 * 2
00086 #define L_003mm 3000 * 2
00087 #define L_004mm 4000 * 2
00088 #define L_005mm 5000 * 2
00089 #define L_006mm 6000 * 2
00090 #define L_007mm 7000 * 2
00091 #define L_008mm 8000 * 2
00092 #define L_009mm 9000 * 2
00093 #define L_010mm 10000 * 2
00094 #define L_050mm 50000 * 2
00095 #define L_100mm 100000 * 2
00096 
00097 
00098 
00099 
00100 
00101 
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 
00112 
00113 
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123 /* Above is still under construction ..... */
00124 
00125 #define __DISP_GAMAPAD_STATUS_ALL__
00126 #define __DISP_WRITE_VALUE__
00127 
00128 #define I2C_ADDRESS_HANDY       0x20
00129 #define I2C_ADDRESS_WINCH       0x10
00130 #define I2C_ADDRESS_TRANSFORM   0x08
00131 #define I2C_ADDRESS_CRAWLER     0x04
00132 #define I2C_ADDRESS_RESOLVER    0x02
00133 
00134 
00135 #define _OK_ 1
00136 #define _NG_ 0
00137 #define _FAIL_ 0
00138 
00139 #define ON 1
00140 #define OFF 0
00141 
00142 #define LFS_READ_COUNT 3
00143 #define TARGET_CHECK_COUNT 10
00144 
00145 //#define __DSP_MOTOR_CURRENT_
00146 
00147 /* Usually this should be comment out */
00148 //#define _COMMUNCATE_PC_BY_SERIAL_
00149 
00150 // Should validate this definition when you use DHCP.
00151 //#define __ETERNET_DHCP__
00152 
00153 #define NumberOfPcCommand 11
00154 #define NumberOfI2CCommand 14
00155 
00156 /* I2C Command packet to motor controller */
00157 /* For motor controller */
00158 enum{
00159     I2C_CP_PREAMBLE,        // Preamble of command packet
00160     I2C_CP_COMMAND,         // instruction command
00161     I2C_CP_M1_DIR,          // motor1 rotation direction   
00162     I2C_CP_M1_SPEED,        // motor1 rotation speed    
00163     I2C_CP_M1_FWD_CNTTH_U,  // motor1 current limit detection threshold upper byte 
00164     I2C_CP_M1_FWD_CNTTH_L,  // motor1 current limit detection threshold lower byte 
00165     I2C_CP_M1_RVS_CNTTH_U,  // motor1 current limit detection threshold upper byte
00166     I2C_CP_M1_RVS_CNTTH_L,  // motor1 current limit detection threshold lower byte   
00167     I2C_CP_M2_DIR,          // motor2 rotation direction   
00168     I2C_CP_M2_SPEED,        // motor2 rotation speed   
00169     I2C_CP_M2_FWD_CNTTH_U,  // motor2 current limit detection threshold upper byte   
00170     I2C_CP_M2_FWD_CNTTH_L,  // motor2 current limit detection threshold lower byte  
00171     I2C_CP_M2_RVS_CNTTH_U,  // motor2 current limit detection threshold upper byte
00172     I2C_CP_M2_RVS_CNTTH_L,  // motor2 current limit detection threshold lower byte    
00173 };
00174 /* For resolver reader controller */
00175 enum{
00176     I2C_CP_PREAMBLE_R,        // Sub command
00177     I2C_CP_COMMAND_R,           // instruction command
00178     I2C_CP_WDRAM_DIA_UPPER,     // motor1 rotation direction   
00179     I2C_CP_WDRAM_DIA_LOWER,     // motor1 rotation speed    
00180     I2C_CP_CCABLE_DIA_UPPER,    // motor1 current limit detection threshold upper byte 
00181     I2C_CP_CCABLE_DIA_LOWER,    // motor1 current limit detection threshold lower byte 
00182     I2C_CP_RESOLVER_RESO,       // motor1 current limit detection threshold upper byte
00183     I2C_CP_PRESET_CPOS_UPPER,   // reserved   
00184     I2C_CP_PRESET_CPOS_LOWER,   // reserved    
00185     I2C_CP_RES3,                // reserved   
00186     I2C_CP_RES4,                // reserved   
00187     I2C_CP_RES5,                // reserved  
00188     I2C_CP_RES6,                // reserved
00189     I2C_CP_RES7,                // reserved    
00190 };
00191 
00192 
00193 
00194 /* Winch Operating mode */
00195 enum{
00196     WINCH_POSITION_CLEAR,
00197     WINCH_PRESET_BASEDATA,
00198     WINCH_MMODE_RELATIVE,
00199     WINCH_MMODE_ABSOLUTE,
00200     WINCH_STEPDOWN_BTN_ON,
00201     WINCH_STEPDOWN_BTN_OFF,
00202     WINCH_STEPUP_BTN_ON,
00203     WINCH_STEPUP_BTN_OFF,
00204     WINCH_U_STEPDOWN_BTN_ON,
00205     WINCH_U_STEPDOWN_BTN_OFF,
00206     WINCH_U_STEPUP_BTN_ON,
00207     WINCH_U_STEPUP_BTN_OFF,
00208     WINCH_PRESET_POSITION,
00209 };
00210 
00211 /* Game Pad defnition */
00212 #define GAMEPAD_VID_LOGICOOL        0x046d
00213 #define GAMEPAD_PID_LOGICOOL_F710   0xc219
00214 #define GAMEPAD_PID_LOGICOOL_F310   0xc216
00215 
00216 #define GAMEPAD_VID_SANWA           0x12bd
00217 #define GAMEPAD_PID_SANWA_JYP70US   0xc003
00218 
00219 #define GAMEPAD_VID_ELECOM          0x056e
00220 #define GAMEPAD_PID_ELECOM_JCU3613M 0x2003
00221 
00222 #define GAMEPAD_VID_RSTHANDY        0x1234
00223 #define GAMEPAD_PID_RSTHANDY        0x0006
00224 
00225 
00226 /* Ether net */
00227 #define TCP_SERVER_PORT   10002
00228 #define UDP_SERVER_PORT   10000
00229 //#define ECHO_SERVER_PORT   7
00230 
00231 #define MOTOR_FWD   'F'     /* Forward Rotation */
00232 #define MOTOR_RVS   'R'     /* Reverse Rotation */
00233 #define MOTOR_STP   'S'     /* Stop */
00234 
00235 // =========================================================
00236 // Setting Values
00237 // =========================================================
00238 typedef struct {
00239     int8_t  sv_JS_ShapeMode;    // JS Shape: 0=I, 1=KO
00240     int8_t  sv_JS_OpeMode;      // JS Operation: 0=single, 1=dual
00241     int8_t  sv_WinchValid;      // Winch function valid or not: 0=Tfm, Crawler valid, 1=Winch valid
00242     int8_t  res;
00243 } basic_operation_t;
00244 
00245 typedef struct {
00246     uint16_t    sv_WDM_ith_F;           // 2 Current Threshold Winch Dram Motor Fwd rotation.
00247     uint16_t    sv_WDM_ith_R;           // 2 Current Threshold Winch Dram Motor Rvs rotation.
00248     uint16_t    sv_WRM_ith_F;           // 2 Current Threshold Winch .... Motor Fwd rotation.
00249     uint16_t    sv_WRM_ith_R;           // 2 Current Threshold Winch .... Motor Rvs rotation.
00250     uint8_t     sv_WDM_hsrto_F;         // 1 Winch Dram Motor high speed ratio Fwd
00251     uint8_t     sv_WDM_hsrto_R;         // 1 Winch Dram Motor high speed ratio Rvs
00252     uint8_t     sv_WDM_lsrto_F;         // 1 Winch Dram Motor low speed ratio Fwd 
00253     uint8_t     sv_WDM_lsrto_R;         // 1 Winch Dram Motor low speed ratio Rvs 
00254     uint8_t     sv_WRM_hsrto_F;         // 1 Winch .... Motor high speed limit Fwd
00255     uint8_t     sv_WRM_hsrto_R;         // 1 Winch .... Motor high speed limit Rvs
00256     uint8_t     sv_WRM_lsrto_F;         // 1 Winch .... Motor low speed ratio Fwd 
00257     uint8_t     sv_WRM_lsrto_R;         // 1 Winch .... Motor low speed ratio Rvs   
00258     uint16_t    sv_WRS_DramDmrx100;     // 2 Winch Dram diameter x 100;
00259     uint16_t    sv_WRS_CCableDmrx100;   // 2 Winch CCable diameter x 100
00260     uint8_t     sv_WRS_RResolution;     // 1 Winch Resolver resolution (bit)
00261     uint8_t     reserved;               // 1 reserved for future use
00262 } winch_SetValue_t;                     // 22 byte
00263 
00264 typedef struct {
00265     uint16_t    sv_RFTM_ith_F;          // 2 RF transform motor Fwd roration current threshold 
00266     uint16_t    sv_RFTM_ith_R;          // 2 RF transform motor Rvs roration current threshold
00267     uint16_t    sv_LBTM_ith_F;          // 2 LB transform motor Fwd roration current threshold
00268     uint16_t    sv_LBTM_ith_R;          // 2 LB transform motor Rvs roration current threshold
00269     uint8_t     sv_RFTM_srto_F;         // 1 RF transform motor Fwd rotation speed ratio
00270     uint8_t     sv_RFTM_srto_R;         // 1 RF transform motor Rvs rotation speed ratio
00271     uint8_t     sv_LBTM_srto_F;         // 1 LB transform motor Fwd rotation speed ratio
00272     uint8_t     sv_LBTM_srto_R;         // 1 LB transform motor Rvs rotation speed ratio
00273 } tfm_SetValue_t;                       // 12 byte 
00274 
00275 typedef struct {
00276     uint16_t    sv_RFCM_ith_F;      // 2 RF Crawler motor Fwd rotation current threshold
00277     uint16_t    sv_RFCM_ith_R;      // 2 RF Crawler motor Rvs rotation current threshold
00278     uint16_t    sv_LBCM_ith_F;      // 2 LB Crawler motor Fwd rotation current threshold
00279     uint16_t    sv_LBCM_ith_R;      // 2 LB Crawler motor Rvs rotation current threshold
00280     uint8_t     sv_RFCM_srto_F;     // 1 RF Crawler motor Fwd rotation speed limnit
00281     uint8_t     sv_RFCM_srto_R;     // 1 RF Crawler motor Rvs rotation speed limnit
00282     uint8_t     sv_LBCM_srto_F;     // 1 LB Crawler motor Fwd rotation speed limnit     
00283     uint8_t     sv_LBCM_srto_R;     // 1 LB Crawler motor Rvs rotation speed limnit
00284     uint8_t     sv_RFCM_dzu;        // 1 R-Joystick upper dead zone width
00285     uint8_t     sv_RFCM_dzc;        // 1 R-Joystick center value
00286     uint8_t     sv_RFCM_dzl;        // 1 R-Joystick lower dead zone width
00287     uint8_t     sv_LBCM_dzu;        // 1 L-Joystick upper dead zone width
00288     uint8_t     sv_LBCM_dzc;        // 1 L-Joystick center value
00289     uint8_t     sv_LBCM_dzl;        // 1 L-Joystick lower dead zone width
00290     uint8_t     reserved1;          // 1
00291     uint8_t     reserved2;          // 1
00292 } crawler_SetValue_t;               // 20 byte
00293 
00294 typedef struct {
00295     uint8_t sv_centerValue;
00296     uint8_t sv_nsenseBand_s;
00297     uint8_t sv_nsenseBand_w;
00298 } js_SetValue_t;
00299 
00300 typedef struct SetValue {
00301 //    operation_t             operation;
00302     winch_SetValue_t        winchCtrl;
00303     tfm_SetValue_t          tfmCtrl;
00304     crawler_SetValue_t      crawlerCtrl;
00305 //    js_SetValue_t           jsCtrl; 
00306 } setValue_t;
00307 
00308 
00309 
00310 
00311 #define SLOWDOWN_DISTANCE 23    // <--10 2016.06.01
00312 #define SLOWDOWN_NEAR_DISTANCE 3
00313 /*
00314 typedef struct {
00315     int16_t dt_WinchCntPosition;    // Current winch posittion
00316     int16_t dt_WinchRtvValue;       // Winch Moving distance
00317     int16_t dt_WinchDstPosition;    // Destination Position
00318     char operation;
00319     int8_t  dt_WinchMotorCurrent;        // Winch motor current
00320 } winchData_t;
00321 */
00322 
00323 typedef struct {
00324     int16_t dt_WinchCntPosition;    // Current winch posittion
00325     int16_t dt_WinchRtvValue;       // Winch Moving distance
00326     int16_t dt_WinchDstPosition;    // Destination Position
00327     uint8_t operation;
00328     uint8_t dt_WinchMotor1Current;        // Winch motor 1 current
00329     uint8_t dt_WinchMotor2Current;        // Winch motor 2 current
00330     uint8_t res;
00331 } winchData_t;
00332 
00333 
00334 #define ROTATE_PER_RESOLUTION 24
00335   
00336 #define __READ_CURRENT_AT_CIF_TASK__    
00337 
00338 //mv_WinchMvData