Sungwoo Kim
/
HydraulicControlBoard_PostLIGHT_210420
LIGHT2
CAN/function_CAN.h@11:82d8768d7351, 2019-08-23 (annotated)
- Committer:
- Lightvalve
- Date:
- Fri Aug 23 12:28:08 2019 +0000
- Revision:
- 11:82d8768d7351
- Parent:
- 7:e9086c72bb22
- Child:
- 12:6f2531038ea4
190823
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jobuuu | 2:a1c0a37df760 | 1 | #ifndef _FUNCTION_CAN_H_ |
jobuuu | 2:a1c0a37df760 | 2 | #define _FUNCTION_CAN_H_ |
jobuuu | 2:a1c0a37df760 | 3 | |
jobuuu | 2:a1c0a37df760 | 4 | #include "mbed.h" |
jobuuu | 2:a1c0a37df760 | 5 | |
jobuuu | 7:e9086c72bb22 | 6 | extern CAN can; |
jobuuu | 7:e9086c72bb22 | 7 | extern CANMessage msg; |
jobuuu | 7:e9086c72bb22 | 8 | |
Lightvalve | 11:82d8768d7351 | 9 | // INIT_CID |
Lightvalve | 11:82d8768d7351 | 10 | #define INIT_CID_RX_CMD 100 |
Lightvalve | 11:82d8768d7351 | 11 | #define INIT_CID_RX_REF_POSITION 200 |
Lightvalve | 11:82d8768d7351 | 12 | #define INIT_CID_RX_REF_TORQUE 300 |
Lightvalve | 11:82d8768d7351 | 13 | #define INIT_CID_RX_REF_PRES_DIFF 400 |
Lightvalve | 11:82d8768d7351 | 14 | #define INIT_CID_RX_REF_VOUT 500 |
Lightvalve | 11:82d8768d7351 | 15 | #define INIT_CID_RX_REF_VALVE_POSITION 600 |
Lightvalve | 11:82d8768d7351 | 16 | |
Lightvalve | 11:82d8768d7351 | 17 | #define INIT_CID_TX_INFO 1100 |
Lightvalve | 11:82d8768d7351 | 18 | #define INIT_CID_TX_POSITION 1200 |
Lightvalve | 11:82d8768d7351 | 19 | #define INIT_CID_TX_TORQUE 1300 |
Lightvalve | 11:82d8768d7351 | 20 | #define INIT_CID_TX_PRES 1400 |
Lightvalve | 11:82d8768d7351 | 21 | #define INIT_CID_TX_VOUT 1500 |
Lightvalve | 11:82d8768d7351 | 22 | #define INIT_CID_TX_VALVE_POSITION 1600 |
Lightvalve | 11:82d8768d7351 | 23 | |
Lightvalve | 11:82d8768d7351 | 24 | |
jobuuu | 2:a1c0a37df760 | 25 | // CID_RX_CMD - RX CMD type |
jobuuu | 2:a1c0a37df760 | 26 | #define CRX_ASK_INFO 0 |
jobuuu | 2:a1c0a37df760 | 27 | #define CRX_ASK_BNO 1 |
jobuuu | 2:a1c0a37df760 | 28 | #define CRX_SET_BNO 101 |
jobuuu | 2:a1c0a37df760 | 29 | #define CRX_ASK_OPERATING_MODE 2 |
jobuuu | 2:a1c0a37df760 | 30 | #define CRX_SET_OPERATING_MODE 102 |
jobuuu | 2:a1c0a37df760 | 31 | #define CRX_SET_ENC_ZERO 103 |
jobuuu | 2:a1c0a37df760 | 32 | #define CRX_SET_FET_ON 104 |
jobuuu | 2:a1c0a37df760 | 33 | #define CRX_SET_REF_UPDATE_ENABLE 105 |
jobuuu | 2:a1c0a37df760 | 34 | #define CRX_ASK_CAN_FREQ 6 |
jobuuu | 2:a1c0a37df760 | 35 | #define CRX_SET_CAN_FREQ 106 |
jobuuu | 2:a1c0a37df760 | 36 | #define CRX_ASK_CONTROL_MODE 7 |
jobuuu | 2:a1c0a37df760 | 37 | #define CRX_SET_CONTROL_MODE 107 |
jobuuu | 2:a1c0a37df760 | 38 | #define CRX_SET_DATA_REQUEST 108 |
jobuuu | 2:a1c0a37df760 | 39 | #define CRX_ASK_JOINT_ENC_DIR 9 |
jobuuu | 2:a1c0a37df760 | 40 | #define CRX_SET_JOINT_ENC_DIR 109 |
jobuuu | 2:a1c0a37df760 | 41 | #define CRX_ASK_VALVE_DIR 10 |
jobuuu | 2:a1c0a37df760 | 42 | #define CRX_SET_VALVE_DIR 110 |
jobuuu | 2:a1c0a37df760 | 43 | #define CRX_ASK_VALVE_ENC_DIR 11 |
jobuuu | 2:a1c0a37df760 | 44 | #define CRX_SET_VALVE_ENC_DIR 111 |
jobuuu | 2:a1c0a37df760 | 45 | #define CRX_ASK_VOLTAGE_SUPPLY 12 |
jobuuu | 2:a1c0a37df760 | 46 | #define CRX_SET_VOLTAGE_SUPPLY 112 |
jobuuu | 2:a1c0a37df760 | 47 | #define CRX_ASK_VOLTAGE_VALVE 13 |
jobuuu | 2:a1c0a37df760 | 48 | #define CRX_SET_VOLTAGE_VALVE 113 |
jobuuu | 2:a1c0a37df760 | 49 | #define CRX_SET_HOMEPOS 114 |
jobuuu | 2:a1c0a37df760 | 50 | #define CRX_ASK_PID_GAIN 20 |
jobuuu | 2:a1c0a37df760 | 51 | #define CRX_SET_PID_GAIN 120 |
jobuuu | 2:a1c0a37df760 | 52 | #define CRX_ASK_VALVE_DEADZONE 21 |
jobuuu | 2:a1c0a37df760 | 53 | #define CRX_SET_VALVE_DEADZONE 121 |
jobuuu | 2:a1c0a37df760 | 54 | #define CRX_ASK_VELOCITY_COMP_GAIN 22 |
jobuuu | 2:a1c0a37df760 | 55 | #define CRX_SET_VELOCITY_COMP_GAIN 122 |
jobuuu | 2:a1c0a37df760 | 56 | #define CRX_ASK_COMPLIANCE_GAIN 23 |
jobuuu | 2:a1c0a37df760 | 57 | #define CRX_SET_COMPLIANCE_GAIN 123 |
jobuuu | 2:a1c0a37df760 | 58 | #define CRX_ASK_VALVE_FF 25 |
jobuuu | 2:a1c0a37df760 | 59 | #define CRX_SET_VALVE_FF 125 |
jobuuu | 2:a1c0a37df760 | 60 | #define CRX_ASK_BULK_MODULUS 26 |
jobuuu | 2:a1c0a37df760 | 61 | #define CRX_SET_BULK_MODULUS 126 |
jobuuu | 2:a1c0a37df760 | 62 | #define CRX_ASK_CHAMBER_VOLUME 27 |
jobuuu | 2:a1c0a37df760 | 63 | #define CRX_SET_CHAMBER_VOLUME 127 |
jobuuu | 2:a1c0a37df760 | 64 | #define CRX_ASK_PISTON_AREA 28 |
jobuuu | 2:a1c0a37df760 | 65 | #define CRX_SET_PISTON_AREA 128 |
jobuuu | 2:a1c0a37df760 | 66 | #define CRX_ASK_PRES 29 |
jobuuu | 2:a1c0a37df760 | 67 | #define CRX_SET_PRES 129 |
jobuuu | 2:a1c0a37df760 | 68 | #define CRX_ASK_ENC_LIMIT 30 |
jobuuu | 2:a1c0a37df760 | 69 | #define CRX_SET_ENC_LIMIT 130 |
jobuuu | 2:a1c0a37df760 | 70 | #define CRX_ASK_STROKE 31 |
jobuuu | 2:a1c0a37df760 | 71 | #define CRX_SET_STROKE 131 |
jobuuu | 2:a1c0a37df760 | 72 | #define CRX_ASK_VALVE_LIMIT 32 |
jobuuu | 2:a1c0a37df760 | 73 | #define CRX_SET_VALVE_LIMIT 132 |
jobuuu | 2:a1c0a37df760 | 74 | #define CRX_ASK_ENC_PULSE_PER_POSITION 33 |
jobuuu | 2:a1c0a37df760 | 75 | #define CRX_SET_ENC_PULSE_PER_POSITION 133 |
jobuuu | 2:a1c0a37df760 | 76 | #define CRX_ASK_TORQUE_SENSOR_PULSE_PER_TORQUE 34 |
jobuuu | 2:a1c0a37df760 | 77 | #define CRX_SET_TORQUE_SENSOR_PULSE_PER_TORQUE 134 |
jobuuu | 2:a1c0a37df760 | 78 | #define CRX_ASK_PRES_SENSOR_PULSE_PER_PRES 35 |
jobuuu | 2:a1c0a37df760 | 79 | #define CRX_SET_PRES_SENSOR_PULSE_PER_PRES 135 |
jobuuu | 2:a1c0a37df760 | 80 | #define CRX_ASK_FRICTION 36 |
jobuuu | 2:a1c0a37df760 | 81 | #define CRX_SET_FRICTION 136 |
jobuuu | 2:a1c0a37df760 | 82 | #define CRX_ASK_VALVE_GAIN_PLUS 37 |
jobuuu | 2:a1c0a37df760 | 83 | #define CRX_SET_VALVE_GAIN_PLUS 137 |
jobuuu | 2:a1c0a37df760 | 84 | #define CRX_ASK_VALVE_GAIN_MINUS 38 |
jobuuu | 2:a1c0a37df760 | 85 | #define CRX_SET_VALVE_GAIN_MINUS 138 |
jobuuu | 2:a1c0a37df760 | 86 | #define CRX_LOW_REF 139 |
jobuuu | 2:a1c0a37df760 | 87 | #define CRX_ASK_HOMEPOS_OFFSET 40 |
jobuuu | 2:a1c0a37df760 | 88 | #define CRX_SET_HOMEPOS_OFFSET 140 |
jobuuu | 2:a1c0a37df760 | 89 | #define CRX_ASK_HOMEPOS_VALVE_OPENING 41 |
jobuuu | 2:a1c0a37df760 | 90 | #define CRX_SET_HOMEPOS_VALVE_OPENING 141 |
Lightvalve | 11:82d8768d7351 | 91 | #define CRX_ASK_DDV_VALVE_DEADZONE 42 |
Lightvalve | 11:82d8768d7351 | 92 | #define CRX_SET_DDV_VALVE_DEADZONE 142 |
Lightvalve | 11:82d8768d7351 | 93 | #define CRX_ASK_VALVE_PWM_VS_VALVE_POS 43 |
Lightvalve | 11:82d8768d7351 | 94 | #define CRX_ASK_VALVE_POS_VS_FLOWRATE 44 |
Lightvalve | 11:82d8768d7351 | 95 | #define CRX_ASK_VALVE_POS_NUM 45 |
jobuuu | 2:a1c0a37df760 | 96 | #define CRX_SET_ERR_CLEAR 150 |
jobuuu | 2:a1c0a37df760 | 97 | #define CRX_JUMP_STATUS 255 |
jobuuu | 2:a1c0a37df760 | 98 | |
jobuuu | 7:e9086c72bb22 | 99 | // CID_TX_INFO - TX INFO type |
jobuuu | 7:e9086c72bb22 | 100 | |
jobuuu | 7:e9086c72bb22 | 101 | #define CTX_SEND_INFO 0 |
jobuuu | 7:e9086c72bb22 | 102 | #define CTX_SEND_BNO 1 |
jobuuu | 7:e9086c72bb22 | 103 | #define CTX_SEND_OPERATING_MODE 2 |
jobuuu | 7:e9086c72bb22 | 104 | #define CTX_SEND_CAN_FREQ 6 |
jobuuu | 7:e9086c72bb22 | 105 | #define CTX_SEND_CONTROL_MODE 7 |
jobuuu | 7:e9086c72bb22 | 106 | #define CTX_SEND_JOINT_ENC_DIR 9 |
jobuuu | 7:e9086c72bb22 | 107 | #define CTX_SEND_VALVE_DIR 10 |
jobuuu | 7:e9086c72bb22 | 108 | #define CTX_SEND_VALVE_ENC_DIR 11 |
jobuuu | 7:e9086c72bb22 | 109 | #define CTX_SEND_VOLTAGE_SUPPLY 12 |
jobuuu | 7:e9086c72bb22 | 110 | #define CTX_SEND_VOLTAGE_VALVE 13 |
jobuuu | 7:e9086c72bb22 | 111 | #define CTX_SEND_PID_GAIN 20 |
jobuuu | 7:e9086c72bb22 | 112 | #define CTX_SEND_VALVE_DEADZONE 21 |
jobuuu | 7:e9086c72bb22 | 113 | #define CTX_SEND_VELOCITY_COMP_GAIN 22 |
jobuuu | 7:e9086c72bb22 | 114 | #define CTX_SEND_COMPLIANCE_GAIN 23 |
jobuuu | 7:e9086c72bb22 | 115 | #define CTX_SEND_VALVE_CNETER 24 |
jobuuu | 7:e9086c72bb22 | 116 | #define CTX_SEND_VALVE_FF 25 |
jobuuu | 7:e9086c72bb22 | 117 | #define CTX_SEND_BULK_MODULUS 26 |
jobuuu | 7:e9086c72bb22 | 118 | #define CTX_SEND_CHAMBER_VOLUME 27 |
jobuuu | 7:e9086c72bb22 | 119 | #define CTX_SEND_PISTON_AREA 28 |
jobuuu | 7:e9086c72bb22 | 120 | #define CTX_SEND_PRES 29 |
jobuuu | 7:e9086c72bb22 | 121 | #define CTX_SEND_ENC_LIMIT 30 |
jobuuu | 7:e9086c72bb22 | 122 | #define CTX_SEND_STROKE 31 |
jobuuu | 7:e9086c72bb22 | 123 | #define CTX_SEND_VALVE_LIMIT 32 |
jobuuu | 7:e9086c72bb22 | 124 | #define CTX_SEND_ENC_PULSE_PER_POSITION 33 |
jobuuu | 7:e9086c72bb22 | 125 | #define CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE 34 |
jobuuu | 7:e9086c72bb22 | 126 | #define CTX_SEND_PRES_SENSOR_PULSE_PER_BAR 35 |
jobuuu | 7:e9086c72bb22 | 127 | #define CTX_SEND_FRICTION 36 |
jobuuu | 7:e9086c72bb22 | 128 | #define CTX_SEND_VALVE_GAIN_PLUS 37 |
jobuuu | 7:e9086c72bb22 | 129 | #define CTX_SEND_VALVE_GAIN_MINUS 38 |
jobuuu | 7:e9086c72bb22 | 130 | #define CTX_SEND_REFENCE_MODE 39 |
jobuuu | 7:e9086c72bb22 | 131 | #define CTX_SEND_HOMEPOS_OFFSET 40 |
jobuuu | 7:e9086c72bb22 | 132 | #define CTX_SEND_HOMEPOS_VALVE_OPENING 41 |
Lightvalve | 11:82d8768d7351 | 133 | #define CTX_SEND_DDV_VALVE_DEADZONE 42 |
Lightvalve | 11:82d8768d7351 | 134 | #define CTX_VALVE_PWM_VS_VALVE_POS 43 |
Lightvalve | 11:82d8768d7351 | 135 | #define CTX_VALVE_POS_VS_FLOWRATE 44 |
Lightvalve | 11:82d8768d7351 | 136 | #define CTX_VALVE_POS_NUM 45 |
Lightvalve | 11:82d8768d7351 | 137 | |
Lightvalve | 11:82d8768d7351 | 138 | // Sensor & State Transmission |
Lightvalve | 11:82d8768d7351 | 139 | void CAN_TX_POSITION(long t_pos, long t_vel); |
Lightvalve | 11:82d8768d7351 | 140 | void CAN_TX_TORQUE(int16_t t_torque); |
Lightvalve | 11:82d8768d7351 | 141 | void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b); |
Lightvalve | 11:82d8768d7351 | 142 | void CAN_TX_PWM(int16_t t_pwm); |
Lightvalve | 11:82d8768d7351 | 143 | void CAN_TX_VALVE_POSITION(int16_t t_valve_pos); |
jobuuu | 7:e9086c72bb22 | 144 | |
jobuuu | 2:a1c0a37df760 | 145 | // Information Transmission |
Lightvalve | 11:82d8768d7351 | 146 | void CAN_TX_INFO(void); |
Lightvalve | 11:82d8768d7351 | 147 | void CAN_TX_BNO(void); |
Lightvalve | 11:82d8768d7351 | 148 | void CAN_TX_OPERATING_MODE(void); |
Lightvalve | 11:82d8768d7351 | 149 | void CAN_TX_CAN_FREQ(void); |
Lightvalve | 11:82d8768d7351 | 150 | void CAN_TX_CONTROL_MODE(void); |
Lightvalve | 11:82d8768d7351 | 151 | void CAN_TX_JOINT_ENC_DIR(void); |
Lightvalve | 11:82d8768d7351 | 152 | void CAN_TX_VALVE_DIR(void); |
Lightvalve | 11:82d8768d7351 | 153 | void CAN_TX_VALVE_ENC_DIR(void); |
Lightvalve | 11:82d8768d7351 | 154 | void CAN_TX_VOLTAGE_SUPPLY(void); |
Lightvalve | 11:82d8768d7351 | 155 | void CAN_TX_VOLTAGE_VALVE(void); |
Lightvalve | 11:82d8768d7351 | 156 | void CAN_TX_PID_GAIN(int t_type); |
Lightvalve | 11:82d8768d7351 | 157 | void CAN_TX_VALVE_DEADZONE(void); |
Lightvalve | 11:82d8768d7351 | 158 | void CAN_TX_VELOCITY_COMP_GAIN(void); |
Lightvalve | 11:82d8768d7351 | 159 | void CAN_TX_COMPLIANCE_GAIN(void); |
Lightvalve | 11:82d8768d7351 | 160 | void CAN_TX_VALVE_FF(void); |
Lightvalve | 11:82d8768d7351 | 161 | void CAN_TX_BULK_MODULUS(void); |
Lightvalve | 11:82d8768d7351 | 162 | void CAN_TX_CHAMBER_VOLUME(void); |
Lightvalve | 11:82d8768d7351 | 163 | void CAN_TX_PISTON_AREA(void); |
Lightvalve | 11:82d8768d7351 | 164 | void CAN_TX_PRES_A_AND_B(void); |
Lightvalve | 11:82d8768d7351 | 165 | void CAN_TX_ENC_LIMIT(void); |
Lightvalve | 11:82d8768d7351 | 166 | void CAN_TX_STROKE(void); |
Lightvalve | 11:82d8768d7351 | 167 | void CAN_TX_VALVE_LIMIT(void); |
Lightvalve | 11:82d8768d7351 | 168 | void CAN_TX_ENC_PULSE_PER_POSITION(void); |
Lightvalve | 11:82d8768d7351 | 169 | void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void); |
Lightvalve | 11:82d8768d7351 | 170 | void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void); |
Lightvalve | 11:82d8768d7351 | 171 | void CAN_TX_FRICTION(void); |
Lightvalve | 11:82d8768d7351 | 172 | void CAN_TX_VALVE_GAIN_PLUS(void); |
Lightvalve | 11:82d8768d7351 | 173 | void CAN_TX_VALVE_GAIN_MINUS(void); |
Lightvalve | 11:82d8768d7351 | 174 | void CAN_TX_REFENCE_MODE(void); |
Lightvalve | 11:82d8768d7351 | 175 | void CAN_TX_HOMEPOS_OFFSET(void); |
Lightvalve | 11:82d8768d7351 | 176 | void CAN_TX_HOMPOS_VALVE_OPENING(void); |
Lightvalve | 11:82d8768d7351 | 177 | void CAN_TX_VALVE_PWM_VS_VALVE_POS(char canindex); |
Lightvalve | 11:82d8768d7351 | 178 | void CAN_TX_DDV_VALVE_DEADZONE(void); |
Lightvalve | 11:82d8768d7351 | 179 | void CAN_TX_VALVE_POS_VS_FLOWRATE(char canindex); |
Lightvalve | 11:82d8768d7351 | 180 | void CAN_TX_VALVE_POS_NUM(void); |
jobuuu | 7:e9086c72bb22 | 181 | |
jobuuu | 7:e9086c72bb22 | 182 | class State |
jobuuu | 7:e9086c72bb22 | 183 | { |
jobuuu | 7:e9086c72bb22 | 184 | public: |
jobuuu | 7:e9086c72bb22 | 185 | double sen; |
jobuuu | 7:e9086c72bb22 | 186 | double ref; |
jobuuu | 7:e9086c72bb22 | 187 | double ref_old; |
jobuuu | 7:e9086c72bb22 | 188 | double ref_diff; |
jobuuu | 7:e9086c72bb22 | 189 | double err; |
jobuuu | 7:e9086c72bb22 | 190 | double err_int; |
jobuuu | 7:e9086c72bb22 | 191 | double err_old; |
jobuuu | 7:e9086c72bb22 | 192 | double err_diff; |
jobuuu | 7:e9086c72bb22 | 193 | public: |
jobuuu | 7:e9086c72bb22 | 194 | State(){ |
jobuuu | 7:e9086c72bb22 | 195 | sen = 0.0; |
jobuuu | 7:e9086c72bb22 | 196 | ref = 0.0; |
jobuuu | 7:e9086c72bb22 | 197 | ref_old = 0.0; |
jobuuu | 7:e9086c72bb22 | 198 | ref_diff = 0.0; |
jobuuu | 7:e9086c72bb22 | 199 | err = 0.0; |
jobuuu | 7:e9086c72bb22 | 200 | err_int = 0.0; |
jobuuu | 7:e9086c72bb22 | 201 | err_old = 0.0; |
jobuuu | 7:e9086c72bb22 | 202 | err_diff = 0.0; |
jobuuu | 7:e9086c72bb22 | 203 | } |
jobuuu | 7:e9086c72bb22 | 204 | }; |
jobuuu | 7:e9086c72bb22 | 205 | |
jobuuu | 7:e9086c72bb22 | 206 | extern State pos; |
jobuuu | 7:e9086c72bb22 | 207 | extern State vel; |
jobuuu | 7:e9086c72bb22 | 208 | extern State Vout; |
jobuuu | 7:e9086c72bb22 | 209 | extern State torq; |
jobuuu | 7:e9086c72bb22 | 210 | extern State pres_A; |
jobuuu | 7:e9086c72bb22 | 211 | extern State pres_B; |
jobuuu | 7:e9086c72bb22 | 212 | extern State cur; |
jobuuu | 7:e9086c72bb22 | 213 | |
jobuuu | 2:a1c0a37df760 | 214 | // CAN Receive Functions |
jobuuu | 2:a1c0a37df760 | 215 | void ReadCMD(); |
jobuuu | 2:a1c0a37df760 | 216 | void CAN_RX_HANDLER(); |
Lightvalve | 11:82d8768d7351 | 217 | void CAN_ID_INIT(void); |
Lightvalve | 11:82d8768d7351 | 218 | |
Lightvalve | 11:82d8768d7351 | 219 | extern int ID_index_array[100]; |
jobuuu | 2:a1c0a37df760 | 220 | |
jobuuu | 2:a1c0a37df760 | 221 | #endif |