Sungwoo Kim
/
HydraulicControlBoard_PostLIGHT_210420
LIGHT2
CAN/function_CAN.cpp@240:c93d3eabff75, 2022-03-31 (annotated)
- Committer:
- Lightvalve
- Date:
- Thu Mar 31 02:39:48 2022 +0000
- Revision:
- 240:c93d3eabff75
- Parent:
- 238:4e660aa77eb7
- Child:
- 243:b235d67d25ba
LVDT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jobuuu | 2:a1c0a37df760 | 1 | #include "function_CAN.h" |
Lightvalve | 11:82d8768d7351 | 2 | #include "setting.h" |
Lightvalve | 11:82d8768d7351 | 3 | #include "function_utilities.h" |
Lightvalve | 11:82d8768d7351 | 4 | #include "SPI_EEP_ENC.h" |
Lightvalve | 16:903b5a4433b4 | 5 | #include "stm32f4xx_flash.h" |
Lightvalve | 16:903b5a4433b4 | 6 | #include "FlashWriter.h" |
jobuuu | 2:a1c0a37df760 | 7 | |
jobuuu | 2:a1c0a37df760 | 8 | // CAN ID Setting Variables |
jobuuu | 2:a1c0a37df760 | 9 | int CID_RX_CMD = 100; |
jobuuu | 2:a1c0a37df760 | 10 | int CID_RX_REF_POSITION = 200; |
hyhoon | 227:699c3e572283 | 11 | int CID_RX_REF_OPENLOOP = 300; |
Lightvalve | 49:e7bcfc244d40 | 12 | int CID_RX_REF_PWM = 400; |
jobuuu | 2:a1c0a37df760 | 13 | |
jobuuu | 2:a1c0a37df760 | 14 | int CID_TX_INFO = 1100; |
hyhoon | 227:699c3e572283 | 15 | int CID_TX_POS_VEL_TORQ = 1200; |
hyhoon | 227:699c3e572283 | 16 | int CID_TX_PWM = 1300; |
jobuuu | 230:2c3e5ecbe7e1 | 17 | int CID_TX_SOMETHING = 1400; |
jobuuu | 230:2c3e5ecbe7e1 | 18 | |
hyhoon | 227:699c3e572283 | 19 | int CID_TX_CURRENT = 1400; |
jobuuu | 7:e9086c72bb22 | 20 | int CID_TX_VOUT = 1500; |
jobuuu | 2:a1c0a37df760 | 21 | int CID_TX_VALVE_POSITION = 1600; |
jobuuu | 2:a1c0a37df760 | 22 | |
Lightvalve | 12:6f2531038ea4 | 23 | // variables |
Lightvalve | 12:6f2531038ea4 | 24 | uint8_t can_index = 0; |
Lightvalve | 67:c2812cf26c38 | 25 | |
Lightvalve | 66:a8e6799dbce3 | 26 | extern DigitalOut LED; |
Lightvalve | 12:6f2531038ea4 | 27 | |
Lightvalve | 99:7bbcb3c0fb06 | 28 | extern float u_past[]; |
Lightvalve | 68:328e1be06f5d | 29 | extern float x_past[]; |
Lightvalve | 85:a3b46118b5cd | 30 | extern float x_future[]; |
Lightvalve | 68:328e1be06f5d | 31 | extern float f_past[]; |
Lightvalve | 68:328e1be06f5d | 32 | extern float f_future[]; |
Lightvalve | 73:f80dc3970c99 | 33 | extern float input_NN[]; |
Lightvalve | 68:328e1be06f5d | 34 | |
Lightvalve | 11:82d8768d7351 | 35 | /******************************************************************************* |
jobuuu | 230:2c3e5ecbe7e1 | 36 | * State Class functions |
jobuuu | 230:2c3e5ecbe7e1 | 37 | ******************************************************************************/ |
jobuuu | 230:2c3e5ecbe7e1 | 38 | void State::UpdateSen(float sen_new, float Freq_update, float f_cut) { |
jobuuu | 230:2c3e5ecbe7e1 | 39 | if(f_cut<=0.0f) f_cut=0.001f; |
jobuuu | 230:2c3e5ecbe7e1 | 40 | |
jobuuu | 230:2c3e5ecbe7e1 | 41 | this->sen_diff = (sen_new-this->sen)*Freq_update; |
jobuuu | 230:2c3e5ecbe7e1 | 42 | float alpha_update = 1.0f / (1.0f + Freq_update / (2.0f * 3.14f * f_cut)); // f_cutoff : 100Hz |
jobuuu | 230:2c3e5ecbe7e1 | 43 | this->sen = (1.0f - alpha_update) * this->sen + alpha_update * sen_new; |
jobuuu | 230:2c3e5ecbe7e1 | 44 | } |
jobuuu | 230:2c3e5ecbe7e1 | 45 | |
jobuuu | 230:2c3e5ecbe7e1 | 46 | void State::UpdateRef(float ref_new) { |
jobuuu | 230:2c3e5ecbe7e1 | 47 | this->ref = ref_new; |
jobuuu | 230:2c3e5ecbe7e1 | 48 | } |
jobuuu | 230:2c3e5ecbe7e1 | 49 | |
jobuuu | 230:2c3e5ecbe7e1 | 50 | void State::Reset() { |
jobuuu | 230:2c3e5ecbe7e1 | 51 | this->sen = 0.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 52 | this->sen_diff = 0.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 53 | this->ref = 0.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 54 | this->err = 0.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 55 | this->err_int = 0.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 56 | this->err_old = 0.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 57 | this->err_diff = 0.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 58 | } |
jobuuu | 230:2c3e5ecbe7e1 | 59 | |
jobuuu | 230:2c3e5ecbe7e1 | 60 | /******************************************************************************* |
Lightvalve | 11:82d8768d7351 | 61 | * CAN functions |
Lightvalve | 11:82d8768d7351 | 62 | ******************************************************************************/ |
Lightvalve | 170:42c938a40313 | 63 | void CAN_ID_INIT(void) |
Lightvalve | 170:42c938a40313 | 64 | { |
jobuuu | 7:e9086c72bb22 | 65 | |
Lightvalve | 11:82d8768d7351 | 66 | CID_RX_CMD = (int) (BNO + INIT_CID_RX_CMD); |
Lightvalve | 11:82d8768d7351 | 67 | CID_RX_REF_POSITION = (int) (BNO + INIT_CID_RX_REF_POSITION); |
hyhoon | 227:699c3e572283 | 68 | CID_RX_REF_OPENLOOP = (int) (BNO + INIT_CID_RX_REF_OPENLOOP); |
Lightvalve | 45:35fa6884d0c6 | 69 | CID_RX_REF_PWM = (int) (BNO + INIT_CID_RX_REF_PWM); |
Lightvalve | 11:82d8768d7351 | 70 | |
Lightvalve | 11:82d8768d7351 | 71 | CID_TX_INFO = (int) (BNO + INIT_CID_TX_INFO); |
hyhoon | 227:699c3e572283 | 72 | CID_TX_POS_VEL_TORQ = (int) (BNO + INIT_CID_TX_POS_VEL_TORQ); |
hyhoon | 227:699c3e572283 | 73 | CID_TX_PWM = (int) (BNO + INIT_CID_TX_PWM); |
hyhoon | 227:699c3e572283 | 74 | CID_TX_CURRENT = (int) (BNO + INIT_CID_TX_CURRENT); |
Lightvalve | 11:82d8768d7351 | 75 | CID_TX_VOUT = (int) (BNO + INIT_CID_TX_VOUT); |
Lightvalve | 11:82d8768d7351 | 76 | CID_TX_VALVE_POSITION = (int) (BNO + INIT_CID_TX_VALVE_POSITION); |
jeongyeseong | 225:9c0becc196ba | 77 | CID_TX_SOMETHING = (int) (BNO + INIT_CID_TX_SOMETHING); |
Lightvalve | 11:82d8768d7351 | 78 | } |
jobuuu | 2:a1c0a37df760 | 79 | |
Lightvalve | 28:2a62d73e3dd0 | 80 | void ReadCMD(int16_t CMD) |
jobuuu | 2:a1c0a37df760 | 81 | { |
Lightvalve | 170:42c938a40313 | 82 | switch(CMD) { |
Lightvalve | 11:82d8768d7351 | 83 | case CRX_ASK_INFO: { |
Lightvalve | 11:82d8768d7351 | 84 | CAN_TX_INFO(); |
Lightvalve | 11:82d8768d7351 | 85 | break; |
Lightvalve | 11:82d8768d7351 | 86 | } |
Lightvalve | 11:82d8768d7351 | 87 | case CRX_ASK_BNO: { |
Lightvalve | 11:82d8768d7351 | 88 | CAN_TX_BNO(); |
Lightvalve | 11:82d8768d7351 | 89 | break; |
Lightvalve | 11:82d8768d7351 | 90 | } |
Lightvalve | 11:82d8768d7351 | 91 | case CRX_SET_BNO: { |
Lightvalve | 11:82d8768d7351 | 92 | BNO = (int16_t) msg.data[1]; |
Lightvalve | 170:42c938a40313 | 93 | spi_eeprom_write(RID_BNO, (int16_t) BNO); |
Lightvalve | 11:82d8768d7351 | 94 | CAN_ID_INIT(); // can id init |
Lightvalve | 11:82d8768d7351 | 95 | break; |
Lightvalve | 11:82d8768d7351 | 96 | } |
Lightvalve | 11:82d8768d7351 | 97 | case CRX_ASK_OPERATING_MODE: { |
Lightvalve | 11:82d8768d7351 | 98 | CAN_TX_OPERATING_MODE(); |
Lightvalve | 11:82d8768d7351 | 99 | break; |
Lightvalve | 11:82d8768d7351 | 100 | } |
Lightvalve | 11:82d8768d7351 | 101 | case CRX_SET_OPERATING_MODE: { |
Lightvalve | 52:8ea76864368a | 102 | OPERATING_MODE = (uint8_t) msg.data[1]; |
Lightvalve | 52:8ea76864368a | 103 | SENSING_MODE = (uint8_t) msg.data[2]; |
Lightvalve | 52:8ea76864368a | 104 | CURRENT_CONTROL_MODE = (uint8_t) msg.data[3]; |
Lightvalve | 52:8ea76864368a | 105 | FLAG_VALVE_DEADZONE = (uint8_t) msg.data[4]; |
Lightvalve | 170:42c938a40313 | 106 | spi_eeprom_write(RID_OPERATING_MODE, (int16_t) OPERATING_MODE); |
Lightvalve | 170:42c938a40313 | 107 | spi_eeprom_write(RID_SENSING_MODE, (int16_t) SENSING_MODE); |
Lightvalve | 170:42c938a40313 | 108 | spi_eeprom_write(RID_CURRENT_CONTROL_MODE, (int16_t) CURRENT_CONTROL_MODE); |
Lightvalve | 170:42c938a40313 | 109 | spi_eeprom_write(RID_FLAG_VALVE_DEADZONE, (int16_t) FLAG_VALVE_DEADZONE); |
Lightvalve | 11:82d8768d7351 | 110 | break; |
Lightvalve | 11:82d8768d7351 | 111 | } |
Lightvalve | 11:82d8768d7351 | 112 | case CRX_SET_ENC_ZERO: { |
Lightvalve | 11:82d8768d7351 | 113 | ENC_SET_ZERO(); |
Lightvalve | 11:82d8768d7351 | 114 | |
Lightvalve | 11:82d8768d7351 | 115 | break; |
Lightvalve | 11:82d8768d7351 | 116 | } |
Lightvalve | 11:82d8768d7351 | 117 | case CRX_SET_FET_ON: { |
Lightvalve | 11:82d8768d7351 | 118 | |
Lightvalve | 11:82d8768d7351 | 119 | break; |
Lightvalve | 11:82d8768d7351 | 120 | } |
Lightvalve | 11:82d8768d7351 | 121 | |
Lightvalve | 45:35fa6884d0c6 | 122 | case CRX_SET_POS_TORQ_TRANS: { |
Lightvalve | 45:35fa6884d0c6 | 123 | MODE_POS_FT_TRANS = (int16_t) msg.data[1]; |
Lightvalve | 45:35fa6884d0c6 | 124 | /* |
Lightvalve | 45:35fa6884d0c6 | 125 | MODE_POS_FT_TRANS == 0 : Position Control |
Lightvalve | 45:35fa6884d0c6 | 126 | MODE_POS_FT_TRANS == 1 : Trasition(Position->Torque) |
Lightvalve | 45:35fa6884d0c6 | 127 | MODE_POS_FT_TRANS == 2 : Torque Control (Convert to 2 automatically 3sec after transition) |
Lightvalve | 45:35fa6884d0c6 | 128 | MODE_POS_FT_TRANS == 3 : Transition(Toque->Position) |
Lightvalve | 45:35fa6884d0c6 | 129 | */ |
Lightvalve | 11:82d8768d7351 | 130 | break; |
Lightvalve | 11:82d8768d7351 | 131 | } |
Lightvalve | 11:82d8768d7351 | 132 | |
Lightvalve | 11:82d8768d7351 | 133 | case CRX_ASK_CAN_FREQ: { |
Lightvalve | 11:82d8768d7351 | 134 | CAN_TX_CAN_FREQ(); |
Lightvalve | 11:82d8768d7351 | 135 | |
Lightvalve | 11:82d8768d7351 | 136 | break; |
Lightvalve | 11:82d8768d7351 | 137 | } |
Lightvalve | 11:82d8768d7351 | 138 | |
Lightvalve | 11:82d8768d7351 | 139 | case CRX_SET_CAN_FREQ: { |
Lightvalve | 11:82d8768d7351 | 140 | CAN_FREQ = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 170:42c938a40313 | 141 | spi_eeprom_write(RID_CAN_FREQ, (int16_t) CAN_FREQ); |
Lightvalve | 11:82d8768d7351 | 142 | break; |
Lightvalve | 11:82d8768d7351 | 143 | } |
Lightvalve | 11:82d8768d7351 | 144 | |
Lightvalve | 11:82d8768d7351 | 145 | case CRX_ASK_CONTROL_MODE: { |
Lightvalve | 11:82d8768d7351 | 146 | CAN_TX_CONTROL_MODE(); |
Lightvalve | 11:82d8768d7351 | 147 | |
Lightvalve | 11:82d8768d7351 | 148 | break; |
Lightvalve | 11:82d8768d7351 | 149 | } |
Lightvalve | 11:82d8768d7351 | 150 | |
Lightvalve | 11:82d8768d7351 | 151 | case CRX_SET_CONTROL_MODE: { |
Lightvalve | 57:f4819de54e7a | 152 | CONTROL_UTILITY_MODE = (int16_t) (msg.data[1]); |
Lightvalve | 12:6f2531038ea4 | 153 | if (CONTROL_MODE == 22) { //MODE_FIND_HOME |
Lightvalve | 11:82d8768d7351 | 154 | FLAG_FIND_HOME = true; |
hyhoon | 226:82a3ca333004 | 155 | FINDHOME_STAGE = FINDHOME_INIT; |
Lightvalve | 11:82d8768d7351 | 156 | } |
Lightvalve | 11:82d8768d7351 | 157 | break; |
Lightvalve | 11:82d8768d7351 | 158 | } |
Lightvalve | 11:82d8768d7351 | 159 | |
Lightvalve | 11:82d8768d7351 | 160 | case CRX_SET_DATA_REQUEST: { |
Lightvalve | 11:82d8768d7351 | 161 | int request_type = msg.data[2]; |
Lightvalve | 11:82d8768d7351 | 162 | flag_data_request[request_type] = msg.data[1]; |
Lightvalve | 11:82d8768d7351 | 163 | |
Lightvalve | 12:6f2531038ea4 | 164 | // if (flag_data_request[1] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC |
Lightvalve | 15:bd0d12728506 | 165 | //if (flag_data_request[1] == HIGH) dac_1 = PRES_A_VREF/3.3; |
Lightvalve | 12:6f2531038ea4 | 166 | // if (flag_data_request[2] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC |
Lightvalve | 15:bd0d12728506 | 167 | //if (flag_data_request[2] == HIGH) dac_2 = PRES_B_VREF/3.3; |
Lightvalve | 11:82d8768d7351 | 168 | |
hyhoon | 227:699c3e572283 | 169 | |
Lightvalve | 11:82d8768d7351 | 170 | break; |
Lightvalve | 11:82d8768d7351 | 171 | } |
Lightvalve | 11:82d8768d7351 | 172 | |
Lightvalve | 11:82d8768d7351 | 173 | case CRX_ASK_JOINT_ENC_DIR: { |
Lightvalve | 11:82d8768d7351 | 174 | CAN_TX_JOINT_ENC_DIR(); |
Lightvalve | 11:82d8768d7351 | 175 | |
Lightvalve | 11:82d8768d7351 | 176 | break; |
Lightvalve | 11:82d8768d7351 | 177 | } |
Lightvalve | 11:82d8768d7351 | 178 | |
Lightvalve | 11:82d8768d7351 | 179 | case CRX_SET_JOINT_ENC_DIR: { |
Lightvalve | 11:82d8768d7351 | 180 | DIR_JOINT_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 11:82d8768d7351 | 181 | if (DIR_JOINT_ENC >= 0) |
Lightvalve | 11:82d8768d7351 | 182 | DIR_JOINT_ENC = 1; |
Lightvalve | 11:82d8768d7351 | 183 | else |
Lightvalve | 11:82d8768d7351 | 184 | DIR_JOINT_ENC = -1; |
Lightvalve | 170:42c938a40313 | 185 | |
Lightvalve | 170:42c938a40313 | 186 | spi_eeprom_write(RID_JOINT_ENC_DIR, (int16_t) DIR_JOINT_ENC); |
Lightvalve | 11:82d8768d7351 | 187 | |
Lightvalve | 11:82d8768d7351 | 188 | break; |
Lightvalve | 11:82d8768d7351 | 189 | } |
Lightvalve | 11:82d8768d7351 | 190 | |
Lightvalve | 11:82d8768d7351 | 191 | case CRX_ASK_VALVE_DIR: { |
Lightvalve | 11:82d8768d7351 | 192 | CAN_TX_VALVE_DIR(); |
Lightvalve | 11:82d8768d7351 | 193 | |
Lightvalve | 11:82d8768d7351 | 194 | break; |
Lightvalve | 11:82d8768d7351 | 195 | } |
Lightvalve | 11:82d8768d7351 | 196 | |
Lightvalve | 11:82d8768d7351 | 197 | case CRX_SET_VALVE_DIR: { |
Lightvalve | 11:82d8768d7351 | 198 | DIR_VALVE = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 11:82d8768d7351 | 199 | if (DIR_VALVE >= 0) |
Lightvalve | 11:82d8768d7351 | 200 | DIR_VALVE = 1; |
Lightvalve | 11:82d8768d7351 | 201 | else |
Lightvalve | 11:82d8768d7351 | 202 | DIR_VALVE = -1; |
Lightvalve | 170:42c938a40313 | 203 | |
Lightvalve | 170:42c938a40313 | 204 | spi_eeprom_write(RID_VALVE_DIR, (int16_t) DIR_VALVE); |
Lightvalve | 11:82d8768d7351 | 205 | |
Lightvalve | 11:82d8768d7351 | 206 | break; |
Lightvalve | 11:82d8768d7351 | 207 | } |
Lightvalve | 11:82d8768d7351 | 208 | |
Lightvalve | 11:82d8768d7351 | 209 | case CRX_ASK_VALVE_ENC_DIR: { |
Lightvalve | 11:82d8768d7351 | 210 | CAN_TX_VALVE_ENC_DIR(); |
Lightvalve | 11:82d8768d7351 | 211 | |
Lightvalve | 11:82d8768d7351 | 212 | break; |
Lightvalve | 11:82d8768d7351 | 213 | } |
Lightvalve | 11:82d8768d7351 | 214 | |
Lightvalve | 11:82d8768d7351 | 215 | case CRX_SET_VALVE_ENC_DIR: { |
Lightvalve | 11:82d8768d7351 | 216 | DIR_VALVE_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 11:82d8768d7351 | 217 | if (DIR_VALVE_ENC >= 0) |
Lightvalve | 11:82d8768d7351 | 218 | DIR_VALVE_ENC = 1; |
Lightvalve | 11:82d8768d7351 | 219 | else |
Lightvalve | 11:82d8768d7351 | 220 | DIR_VALVE_ENC = -1; |
Lightvalve | 11:82d8768d7351 | 221 | |
Lightvalve | 170:42c938a40313 | 222 | spi_eeprom_write(RID_VALVE_ENC_DIR, (int16_t) DIR_VALVE_ENC); |
Lightvalve | 11:82d8768d7351 | 223 | |
Lightvalve | 11:82d8768d7351 | 224 | break; |
Lightvalve | 11:82d8768d7351 | 225 | } |
Lightvalve | 11:82d8768d7351 | 226 | |
Lightvalve | 11:82d8768d7351 | 227 | case CRX_ASK_VOLTAGE_SUPPLY: { |
Lightvalve | 11:82d8768d7351 | 228 | CAN_TX_VOLTAGE_SUPPLY(); |
Lightvalve | 11:82d8768d7351 | 229 | |
Lightvalve | 11:82d8768d7351 | 230 | break; |
Lightvalve | 11:82d8768d7351 | 231 | } |
Lightvalve | 11:82d8768d7351 | 232 | |
Lightvalve | 11:82d8768d7351 | 233 | case CRX_SET_VOLTAGE_SUPPLY: { |
Lightvalve | 30:8d561f16383b | 234 | SUPPLY_VOLTAGE = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.0f; |
Lightvalve | 170:42c938a40313 | 235 | |
Lightvalve | 170:42c938a40313 | 236 | |
Lightvalve | 170:42c938a40313 | 237 | spi_eeprom_write(RID_VOLATGE_SUPPLY, (int16_t) (SUPPLY_VOLTAGE * 10.0f)); |
Lightvalve | 11:82d8768d7351 | 238 | |
Lightvalve | 11:82d8768d7351 | 239 | break; |
Lightvalve | 11:82d8768d7351 | 240 | } |
Lightvalve | 11:82d8768d7351 | 241 | |
Lightvalve | 11:82d8768d7351 | 242 | case CRX_ASK_VOLTAGE_VALVE: { |
Lightvalve | 11:82d8768d7351 | 243 | CAN_TX_VOLTAGE_VALVE(); |
Lightvalve | 11:82d8768d7351 | 244 | |
Lightvalve | 11:82d8768d7351 | 245 | break; |
Lightvalve | 11:82d8768d7351 | 246 | } |
Lightvalve | 11:82d8768d7351 | 247 | |
Lightvalve | 11:82d8768d7351 | 248 | case CRX_SET_VOLTAGE_VALVE: { |
Lightvalve | 30:8d561f16383b | 249 | VALVE_VOLTAGE_LIMIT = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.0f; |
Lightvalve | 170:42c938a40313 | 250 | |
Lightvalve | 170:42c938a40313 | 251 | spi_eeprom_write(RID_VOLTAGE_VALVE, (int16_t) (VALVE_VOLTAGE_LIMIT * 10.0f)); |
Lightvalve | 11:82d8768d7351 | 252 | |
Lightvalve | 11:82d8768d7351 | 253 | |
Lightvalve | 11:82d8768d7351 | 254 | break; |
Lightvalve | 11:82d8768d7351 | 255 | } |
Lightvalve | 12:6f2531038ea4 | 256 | |
Lightvalve | 11:82d8768d7351 | 257 | case CRX_SET_HOMEPOS: { |
Lightvalve | 57:f4819de54e7a | 258 | CONTROL_UTILITY_MODE = 22; |
Lightvalve | 11:82d8768d7351 | 259 | break; |
Lightvalve | 11:82d8768d7351 | 260 | } |
jobuuu | 230:2c3e5ecbe7e1 | 261 | |
jobuuu | 230:2c3e5ecbe7e1 | 262 | case CRX_ASK_VARIABLE_SUPPLY: |
jobuuu | 230:2c3e5ecbe7e1 | 263 | { |
jobuuu | 230:2c3e5ecbe7e1 | 264 | CAN_TX_VARIABLE_SUPPLY_ONOFF(); |
jobuuu | 230:2c3e5ecbe7e1 | 265 | break; |
jobuuu | 230:2c3e5ecbe7e1 | 266 | } |
jobuuu | 230:2c3e5ecbe7e1 | 267 | |
jobuuu | 230:2c3e5ecbe7e1 | 268 | case CRX_SET_VARIABLE_SUPPLY: |
jobuuu | 230:2c3e5ecbe7e1 | 269 | { |
jobuuu | 230:2c3e5ecbe7e1 | 270 | SUPPLY_PRESSURE_UPDATE = msg.data[1]; |
jobuuu | 230:2c3e5ecbe7e1 | 271 | break; |
jobuuu | 230:2c3e5ecbe7e1 | 272 | } |
Lightvalve | 11:82d8768d7351 | 273 | |
Lightvalve | 11:82d8768d7351 | 274 | case CRX_ASK_PID_GAIN: { |
Lightvalve | 11:82d8768d7351 | 275 | CAN_TX_PID_GAIN(msg.data[1]); |
Lightvalve | 11:82d8768d7351 | 276 | |
Lightvalve | 11:82d8768d7351 | 277 | break; |
Lightvalve | 11:82d8768d7351 | 278 | } |
Lightvalve | 11:82d8768d7351 | 279 | |
Lightvalve | 11:82d8768d7351 | 280 | case CRX_SET_PID_GAIN: { |
Lightvalve | 11:82d8768d7351 | 281 | if (msg.data[1] == 0) { |
Lightvalve | 11:82d8768d7351 | 282 | P_GAIN_VALVE_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8); |
Lightvalve | 11:82d8768d7351 | 283 | I_GAIN_VALVE_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8); |
Lightvalve | 11:82d8768d7351 | 284 | D_GAIN_VALVE_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8); |
Lightvalve | 170:42c938a40313 | 285 | |
Lightvalve | 170:42c938a40313 | 286 | spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION); |
Lightvalve | 170:42c938a40313 | 287 | spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION); |
Lightvalve | 170:42c938a40313 | 288 | spi_eeprom_write(RID_D_GAIN_VALVE_POSITION, (int16_t) D_GAIN_VALVE_POSITION); |
Lightvalve | 11:82d8768d7351 | 289 | |
Lightvalve | 11:82d8768d7351 | 290 | } else if (msg.data[1] == 1) { |
Lightvalve | 11:82d8768d7351 | 291 | P_GAIN_JOINT_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8); |
Lightvalve | 11:82d8768d7351 | 292 | I_GAIN_JOINT_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8); |
Lightvalve | 11:82d8768d7351 | 293 | D_GAIN_JOINT_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8); |
Lightvalve | 170:42c938a40313 | 294 | |
Lightvalve | 170:42c938a40313 | 295 | spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION); |
Lightvalve | 170:42c938a40313 | 296 | spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION); |
Lightvalve | 170:42c938a40313 | 297 | spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION); |
Lightvalve | 170:42c938a40313 | 298 | |
Lightvalve | 11:82d8768d7351 | 299 | } else if (msg.data[1] == 2) { |
Lightvalve | 11:82d8768d7351 | 300 | P_GAIN_JOINT_TORQUE = (int16_t) (msg.data[2] | msg.data[3] << 8); |
Lightvalve | 11:82d8768d7351 | 301 | I_GAIN_JOINT_TORQUE = (int16_t) (msg.data[4] | msg.data[5] << 8); |
Lightvalve | 11:82d8768d7351 | 302 | D_GAIN_JOINT_TORQUE = (int16_t) (msg.data[6] | msg.data[7] << 8); |
Lightvalve | 170:42c938a40313 | 303 | |
Lightvalve | 170:42c938a40313 | 304 | spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE); |
Lightvalve | 170:42c938a40313 | 305 | spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE); |
Lightvalve | 170:42c938a40313 | 306 | spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE); |
Lightvalve | 170:42c938a40313 | 307 | |
Lightvalve | 46:2694daea349b | 308 | } else if (msg.data[1] == 3) { |
Lightvalve | 67:c2812cf26c38 | 309 | K_SPRING = (float) (((float) ((int16_t) (msg.data[2] | msg.data[3] << 8))) * 0.1f); |
Lightvalve | 67:c2812cf26c38 | 310 | D_DAMPER = (float) (((float) ((int16_t) (msg.data[4] | msg.data[5] << 8))) * 0.01f); |
Lightvalve | 170:42c938a40313 | 311 | |
Lightvalve | 170:42c938a40313 | 312 | // spi_eeprom_write(RID_K_SPRING, (int16_t) K_SPRING); |
Lightvalve | 170:42c938a40313 | 313 | // spi_eeprom_write(RID_D_DAMPER, (int16_t) D_DAMPER); |
Lightvalve | 170:42c938a40313 | 314 | |
Lightvalve | 72:3436ce769b1e | 315 | } else if (msg.data[1] == 4) { |
Lightvalve | 72:3436ce769b1e | 316 | P_GAIN_JOINT_TORQUE_FF = (int16_t) (msg.data[2] | msg.data[3] << 8); |
Lightvalve | 72:3436ce769b1e | 317 | I_GAIN_JOINT_TORQUE_FF = (int16_t) (msg.data[4] | msg.data[5] << 8); |
Lightvalve | 72:3436ce769b1e | 318 | D_GAIN_JOINT_TORQUE_FF = (int16_t) (msg.data[6] | msg.data[7] << 8); |
Lightvalve | 170:42c938a40313 | 319 | |
Lightvalve | 11:82d8768d7351 | 320 | } |
Lightvalve | 11:82d8768d7351 | 321 | |
Lightvalve | 11:82d8768d7351 | 322 | break; |
Lightvalve | 11:82d8768d7351 | 323 | } |
Lightvalve | 11:82d8768d7351 | 324 | |
Lightvalve | 11:82d8768d7351 | 325 | case CRX_ASK_VALVE_DEADZONE: { |
Lightvalve | 11:82d8768d7351 | 326 | CAN_TX_VALVE_DEADZONE(); |
Lightvalve | 11:82d8768d7351 | 327 | |
Lightvalve | 11:82d8768d7351 | 328 | break; |
Lightvalve | 11:82d8768d7351 | 329 | } |
Lightvalve | 11:82d8768d7351 | 330 | |
Lightvalve | 11:82d8768d7351 | 331 | case CRX_SET_VALVE_DEADZONE: { |
Lightvalve | 11:82d8768d7351 | 332 | VALVE_CENTER = (int16_t) (msg.data[1] | msg.data[2] << 8); |
hyhoon | 226:82a3ca333004 | 333 | VALVE_DEADZONE_PLUS = (int16_t)(msg.data[3] | msg.data[4] << 8); |
hyhoon | 226:82a3ca333004 | 334 | VALVE_DEADZONE_MINUS = (int16_t)(msg.data[5] | msg.data[6] << 8); |
Lightvalve | 170:42c938a40313 | 335 | |
hyhoon | 226:82a3ca333004 | 336 | spi_eeprom_write(RID_VALVE_CNETER, VALVE_CENTER); |
hyhoon | 226:82a3ca333004 | 337 | spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, VALVE_DEADZONE_PLUS); |
hyhoon | 226:82a3ca333004 | 338 | spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, VALVE_DEADZONE_MINUS); |
Lightvalve | 11:82d8768d7351 | 339 | |
Lightvalve | 11:82d8768d7351 | 340 | break; |
Lightvalve | 11:82d8768d7351 | 341 | } |
Lightvalve | 11:82d8768d7351 | 342 | |
Lightvalve | 11:82d8768d7351 | 343 | case CRX_ASK_VELOCITY_COMP_GAIN: { |
Lightvalve | 11:82d8768d7351 | 344 | CAN_TX_VELOCITY_COMP_GAIN(); |
Lightvalve | 11:82d8768d7351 | 345 | |
Lightvalve | 11:82d8768d7351 | 346 | break; |
Lightvalve | 11:82d8768d7351 | 347 | } |
Lightvalve | 11:82d8768d7351 | 348 | |
Lightvalve | 11:82d8768d7351 | 349 | case CRX_SET_VELOCITY_COMP_GAIN: { |
Lightvalve | 11:82d8768d7351 | 350 | VELOCITY_COMP_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 170:42c938a40313 | 351 | |
Lightvalve | 170:42c938a40313 | 352 | |
Lightvalve | 170:42c938a40313 | 353 | spi_eeprom_write(RID_VELOCITY_COMP_GAIN, (int16_t) VELOCITY_COMP_GAIN); |
Lightvalve | 11:82d8768d7351 | 354 | |
Lightvalve | 11:82d8768d7351 | 355 | break; |
Lightvalve | 11:82d8768d7351 | 356 | } |
Lightvalve | 11:82d8768d7351 | 357 | |
Lightvalve | 238:4e660aa77eb7 | 358 | case CRX_ASK_VALVE_ELECTRIC_CENTER: { |
Lightvalve | 238:4e660aa77eb7 | 359 | CAN_TX_VALVE_ELECTRIC_CENTER(); |
Lightvalve | 11:82d8768d7351 | 360 | |
Lightvalve | 11:82d8768d7351 | 361 | break; |
Lightvalve | 11:82d8768d7351 | 362 | } |
Lightvalve | 11:82d8768d7351 | 363 | |
Lightvalve | 238:4e660aa77eb7 | 364 | case CRX_SET_VALVE_ELECTRIC_CENTER: { |
Lightvalve | 238:4e660aa77eb7 | 365 | VALVE_ELECTRIC_CENTER = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 11:82d8768d7351 | 366 | |
Lightvalve | 170:42c938a40313 | 367 | |
Lightvalve | 238:4e660aa77eb7 | 368 | spi_eeprom_write(RID_VALVE_ELECTRIC_CENTER, (int16_t) VALVE_ELECTRIC_CENTER); |
Lightvalve | 11:82d8768d7351 | 369 | |
Lightvalve | 11:82d8768d7351 | 370 | break; |
Lightvalve | 11:82d8768d7351 | 371 | } |
Lightvalve | 11:82d8768d7351 | 372 | |
Lightvalve | 11:82d8768d7351 | 373 | case CRX_ASK_VALVE_FF: { |
Lightvalve | 11:82d8768d7351 | 374 | CAN_TX_VALVE_FF(); |
Lightvalve | 11:82d8768d7351 | 375 | |
Lightvalve | 11:82d8768d7351 | 376 | break; |
Lightvalve | 11:82d8768d7351 | 377 | } |
Lightvalve | 11:82d8768d7351 | 378 | |
Lightvalve | 11:82d8768d7351 | 379 | case CRX_SET_VALVE_FF: { |
Lightvalve | 11:82d8768d7351 | 380 | VALVE_FF = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 170:42c938a40313 | 381 | |
Lightvalve | 170:42c938a40313 | 382 | spi_eeprom_write(RID_VALVE_FF, (int16_t) VALVE_FF); |
Lightvalve | 11:82d8768d7351 | 383 | |
Lightvalve | 11:82d8768d7351 | 384 | break; |
Lightvalve | 11:82d8768d7351 | 385 | } |
Lightvalve | 11:82d8768d7351 | 386 | |
Lightvalve | 11:82d8768d7351 | 387 | case CRX_ASK_BULK_MODULUS: { |
Lightvalve | 11:82d8768d7351 | 388 | CAN_TX_BULK_MODULUS(); |
Lightvalve | 11:82d8768d7351 | 389 | |
Lightvalve | 11:82d8768d7351 | 390 | break; |
Lightvalve | 11:82d8768d7351 | 391 | } |
Lightvalve | 11:82d8768d7351 | 392 | |
Lightvalve | 11:82d8768d7351 | 393 | case CRX_SET_BULK_MODULUS: { |
Lightvalve | 11:82d8768d7351 | 394 | BULK_MODULUS = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 170:42c938a40313 | 395 | spi_eeprom_write(RID_BULK_MODULUS, (int16_t) BULK_MODULUS); |
Lightvalve | 11:82d8768d7351 | 396 | |
Lightvalve | 11:82d8768d7351 | 397 | break; |
Lightvalve | 11:82d8768d7351 | 398 | } |
Lightvalve | 11:82d8768d7351 | 399 | |
Lightvalve | 11:82d8768d7351 | 400 | case CRX_ASK_CHAMBER_VOLUME: { |
Lightvalve | 11:82d8768d7351 | 401 | CAN_TX_CHAMBER_VOLUME(); |
Lightvalve | 11:82d8768d7351 | 402 | |
Lightvalve | 11:82d8768d7351 | 403 | break; |
Lightvalve | 11:82d8768d7351 | 404 | } |
Lightvalve | 11:82d8768d7351 | 405 | |
Lightvalve | 11:82d8768d7351 | 406 | case CRX_SET_CHAMBER_VOLUME: { |
Lightvalve | 11:82d8768d7351 | 407 | CHAMBER_VOLUME_A = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 11:82d8768d7351 | 408 | CHAMBER_VOLUME_B = (int16_t) (msg.data[3] | msg.data[4] << 8); |
Lightvalve | 11:82d8768d7351 | 409 | |
Lightvalve | 170:42c938a40313 | 410 | spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A); |
Lightvalve | 170:42c938a40313 | 411 | spi_eeprom_write(RID_CHAMBER_VOLUME_B, (int16_t) CHAMBER_VOLUME_B); |
Lightvalve | 11:82d8768d7351 | 412 | |
Lightvalve | 11:82d8768d7351 | 413 | break; |
Lightvalve | 11:82d8768d7351 | 414 | } |
Lightvalve | 11:82d8768d7351 | 415 | |
Lightvalve | 11:82d8768d7351 | 416 | case CRX_ASK_PISTON_AREA: { |
Lightvalve | 11:82d8768d7351 | 417 | CAN_TX_PISTON_AREA(); |
Lightvalve | 11:82d8768d7351 | 418 | |
Lightvalve | 11:82d8768d7351 | 419 | break; |
Lightvalve | 11:82d8768d7351 | 420 | } |
Lightvalve | 11:82d8768d7351 | 421 | |
Lightvalve | 11:82d8768d7351 | 422 | case CRX_SET_PISTON_AREA: { |
Lightvalve | 11:82d8768d7351 | 423 | PISTON_AREA_A = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 11:82d8768d7351 | 424 | PISTON_AREA_B = (int16_t) (msg.data[3] | msg.data[4] << 8); |
Lightvalve | 69:3995ffeaa786 | 425 | PISTON_AREA_alpha = (double)PISTON_AREA_A/(double)PISTON_AREA_B; |
Lightvalve | 57:f4819de54e7a | 426 | alpha3 = PISTON_AREA_alpha * PISTON_AREA_alpha*PISTON_AREA_alpha; |
Lightvalve | 170:42c938a40313 | 427 | |
Lightvalve | 170:42c938a40313 | 428 | spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A); |
Lightvalve | 170:42c938a40313 | 429 | spi_eeprom_write(RID_PISTON_AREA_B, (int16_t) PISTON_AREA_B); |
Lightvalve | 11:82d8768d7351 | 430 | break; |
Lightvalve | 11:82d8768d7351 | 431 | } |
Lightvalve | 11:82d8768d7351 | 432 | |
jobuuu | 230:2c3e5ecbe7e1 | 433 | case CRX_ASK_SUP_PRES: { |
jobuuu | 230:2c3e5ecbe7e1 | 434 | CAN_TX_SUP_PRES(); |
Lightvalve | 11:82d8768d7351 | 435 | break; |
Lightvalve | 11:82d8768d7351 | 436 | } |
Lightvalve | 11:82d8768d7351 | 437 | |
jobuuu | 230:2c3e5ecbe7e1 | 438 | case CRX_SET_SUP_PRES: { |
jobuuu | 230:2c3e5ecbe7e1 | 439 | int16_t temp = (int16_t) (msg.data[1] | msg.data[2] << 8); |
jobuuu | 230:2c3e5ecbe7e1 | 440 | spi_eeprom_write(RID_PRES_SUPPLY, temp); |
jobuuu | 230:2c3e5ecbe7e1 | 441 | PRES_SUPPLY_NOM = (float)temp; |
jobuuu | 230:2c3e5ecbe7e1 | 442 | PRES_SUPPLY = PRES_SUPPLY_NOM; |
Lightvalve | 11:82d8768d7351 | 443 | break; |
Lightvalve | 11:82d8768d7351 | 444 | } |
Lightvalve | 11:82d8768d7351 | 445 | |
Lightvalve | 11:82d8768d7351 | 446 | case CRX_ASK_ENC_LIMIT: { |
Lightvalve | 11:82d8768d7351 | 447 | CAN_TX_ENC_LIMIT(); |
Lightvalve | 11:82d8768d7351 | 448 | |
Lightvalve | 11:82d8768d7351 | 449 | break; |
Lightvalve | 11:82d8768d7351 | 450 | } |
Lightvalve | 11:82d8768d7351 | 451 | |
Lightvalve | 11:82d8768d7351 | 452 | case CRX_SET_ENC_LIMIT: { |
Lightvalve | 11:82d8768d7351 | 453 | ENC_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 11:82d8768d7351 | 454 | ENC_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8); |
Lightvalve | 170:42c938a40313 | 455 | spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS); |
Lightvalve | 170:42c938a40313 | 456 | spi_eeprom_write(RID_ENC_LIMIT_PLUS, (int16_t) ENC_LIMIT_PLUS); |
Lightvalve | 11:82d8768d7351 | 457 | |
Lightvalve | 11:82d8768d7351 | 458 | break; |
Lightvalve | 11:82d8768d7351 | 459 | } |
Lightvalve | 11:82d8768d7351 | 460 | |
Lightvalve | 11:82d8768d7351 | 461 | case CRX_ASK_STROKE: { |
Lightvalve | 11:82d8768d7351 | 462 | CAN_TX_STROKE(); |
Lightvalve | 11:82d8768d7351 | 463 | break; |
Lightvalve | 11:82d8768d7351 | 464 | } |
Lightvalve | 11:82d8768d7351 | 465 | |
Lightvalve | 11:82d8768d7351 | 466 | case CRX_SET_STROKE: { |
Lightvalve | 11:82d8768d7351 | 467 | STROKE = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 170:42c938a40313 | 468 | spi_eeprom_write(RID_STROKE, (int16_t) STROKE); |
Lightvalve | 11:82d8768d7351 | 469 | |
Lightvalve | 11:82d8768d7351 | 470 | break; |
Lightvalve | 11:82d8768d7351 | 471 | } |
Lightvalve | 11:82d8768d7351 | 472 | |
Lightvalve | 11:82d8768d7351 | 473 | case CRX_ASK_VALVE_LIMIT: { |
Lightvalve | 11:82d8768d7351 | 474 | CAN_TX_VALVE_LIMIT(); |
Lightvalve | 11:82d8768d7351 | 475 | |
Lightvalve | 11:82d8768d7351 | 476 | break; |
Lightvalve | 11:82d8768d7351 | 477 | } |
Lightvalve | 11:82d8768d7351 | 478 | |
Lightvalve | 11:82d8768d7351 | 479 | case CRX_SET_VALVE_LIMIT: { |
Lightvalve | 57:f4819de54e7a | 480 | VALVE_MIN_POS = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 57:f4819de54e7a | 481 | VALVE_MAX_POS = (int16_t) (msg.data[3] | msg.data[4] << 8); |
Lightvalve | 170:42c938a40313 | 482 | |
Lightvalve | 170:42c938a40313 | 483 | spi_eeprom_write(RID_VALVE_MAX_POS, (int16_t) VALVE_MAX_POS); |
Lightvalve | 170:42c938a40313 | 484 | spi_eeprom_write(RID_VALVE_MIN_POS, (int16_t) VALVE_MIN_POS); |
Lightvalve | 11:82d8768d7351 | 485 | |
Lightvalve | 11:82d8768d7351 | 486 | break; |
Lightvalve | 11:82d8768d7351 | 487 | } |
Lightvalve | 11:82d8768d7351 | 488 | |
Lightvalve | 11:82d8768d7351 | 489 | case CRX_ASK_ENC_PULSE_PER_POSITION: { |
Lightvalve | 11:82d8768d7351 | 490 | CAN_TX_ENC_PULSE_PER_POSITION(); |
Lightvalve | 11:82d8768d7351 | 491 | |
Lightvalve | 11:82d8768d7351 | 492 | break; |
Lightvalve | 11:82d8768d7351 | 493 | } |
Lightvalve | 11:82d8768d7351 | 494 | |
Lightvalve | 11:82d8768d7351 | 495 | case CRX_SET_ENC_PULSE_PER_POSITION: { |
Lightvalve | 11:82d8768d7351 | 496 | ENC_PULSE_PER_POSITION = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 180:02be1711ee0b | 497 | spi_eeprom_write(RID_ENC_PULSE_PER_POSITION, (int16_t) (ENC_PULSE_PER_POSITION)); |
Lightvalve | 11:82d8768d7351 | 498 | |
Lightvalve | 11:82d8768d7351 | 499 | break; |
Lightvalve | 11:82d8768d7351 | 500 | } |
Lightvalve | 11:82d8768d7351 | 501 | |
Lightvalve | 11:82d8768d7351 | 502 | case CRX_ASK_TORQUE_SENSOR_PULSE_PER_TORQUE: { |
Lightvalve | 11:82d8768d7351 | 503 | CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(); |
Lightvalve | 11:82d8768d7351 | 504 | |
Lightvalve | 11:82d8768d7351 | 505 | break; |
Lightvalve | 11:82d8768d7351 | 506 | } |
Lightvalve | 11:82d8768d7351 | 507 | |
Lightvalve | 11:82d8768d7351 | 508 | case CRX_SET_TORQUE_SENSOR_PULSE_PER_TORQUE: { |
Lightvalve | 240:c93d3eabff75 | 509 | // TORQUE_SENSOR_PULSE_PER_TORQUE = (float) ((int16_t) (msg.data[1] | msg.data[2] << 8) * 0.01f); |
Lightvalve | 240:c93d3eabff75 | 510 | TORQUE_SENSOR_PULSE_PER_TORQUE = ((float) ((int16_t) (msg.data[1] | msg.data[2] << 8)))*0.001f; |
Lightvalve | 240:c93d3eabff75 | 511 | spi_eeprom_write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE, (int16_t) (TORQUE_SENSOR_PULSE_PER_TORQUE*1000.0f)); |
Lightvalve | 11:82d8768d7351 | 512 | |
Lightvalve | 11:82d8768d7351 | 513 | break; |
Lightvalve | 11:82d8768d7351 | 514 | } |
Lightvalve | 11:82d8768d7351 | 515 | |
Lightvalve | 11:82d8768d7351 | 516 | case CRX_ASK_PRES_SENSOR_PULSE_PER_PRES: { |
Lightvalve | 11:82d8768d7351 | 517 | CAN_TX_PRES_SENSOR_PULSE_PER_PRES(); |
Lightvalve | 11:82d8768d7351 | 518 | |
Lightvalve | 11:82d8768d7351 | 519 | break; |
Lightvalve | 11:82d8768d7351 | 520 | } |
Lightvalve | 11:82d8768d7351 | 521 | |
Lightvalve | 11:82d8768d7351 | 522 | case CRX_SET_PRES_SENSOR_PULSE_PER_PRES: { |
Lightvalve | 30:8d561f16383b | 523 | PRES_SENSOR_A_PULSE_PER_BAR = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) * 0.01f; |
Lightvalve | 30:8d561f16383b | 524 | PRES_SENSOR_B_PULSE_PER_BAR = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) * 0.01f; |
Lightvalve | 170:42c938a40313 | 525 | spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 170:42c938a40313 | 526 | spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f)); |
Lightvalve | 11:82d8768d7351 | 527 | |
Lightvalve | 11:82d8768d7351 | 528 | break; |
Lightvalve | 11:82d8768d7351 | 529 | } |
Lightvalve | 11:82d8768d7351 | 530 | |
Lightvalve | 11:82d8768d7351 | 531 | case CRX_ASK_FRICTION: { |
Lightvalve | 11:82d8768d7351 | 532 | CAN_TX_FRICTION(); |
Lightvalve | 11:82d8768d7351 | 533 | |
Lightvalve | 11:82d8768d7351 | 534 | break; |
Lightvalve | 11:82d8768d7351 | 535 | } |
Lightvalve | 11:82d8768d7351 | 536 | |
Lightvalve | 11:82d8768d7351 | 537 | case CRX_SET_FRICTION: { |
Lightvalve | 30:8d561f16383b | 538 | FRICTION = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.0f; |
Lightvalve | 170:42c938a40313 | 539 | spi_eeprom_write(RID_FRICTION, (int16_t) (FRICTION * 10.0f)); |
Lightvalve | 11:82d8768d7351 | 540 | |
Lightvalve | 11:82d8768d7351 | 541 | break; |
Lightvalve | 11:82d8768d7351 | 542 | } |
Lightvalve | 11:82d8768d7351 | 543 | |
Lightvalve | 11:82d8768d7351 | 544 | case CRX_ASK_VALVE_GAIN_PLUS: { |
Lightvalve | 11:82d8768d7351 | 545 | CAN_TX_VALVE_GAIN_PLUS(); |
Lightvalve | 11:82d8768d7351 | 546 | |
Lightvalve | 11:82d8768d7351 | 547 | break; |
Lightvalve | 11:82d8768d7351 | 548 | } |
Lightvalve | 11:82d8768d7351 | 549 | case CRX_SET_VALVE_GAIN_PLUS: { |
Lightvalve | 30:8d561f16383b | 550 | VALVE_GAIN_LPM_PER_V[0] = (double) msg.data[1] / 50.0f; |
Lightvalve | 30:8d561f16383b | 551 | VALVE_GAIN_LPM_PER_V[2] = (double) msg.data[2] / 50.0f; |
Lightvalve | 30:8d561f16383b | 552 | VALVE_GAIN_LPM_PER_V[4] = (double) msg.data[3] / 50.0f; |
Lightvalve | 30:8d561f16383b | 553 | VALVE_GAIN_LPM_PER_V[6] = (double) msg.data[4] / 50.0f; |
Lightvalve | 30:8d561f16383b | 554 | VALVE_GAIN_LPM_PER_V[8] = (double) msg.data[5] / 50.0f; |
Lightvalve | 170:42c938a40313 | 555 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[0] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 556 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[2] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 557 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[4] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 558 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[6] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 559 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[8] * 100.0f)); |
Lightvalve | 11:82d8768d7351 | 560 | |
Lightvalve | 11:82d8768d7351 | 561 | break; |
Lightvalve | 11:82d8768d7351 | 562 | } |
Lightvalve | 11:82d8768d7351 | 563 | |
Lightvalve | 11:82d8768d7351 | 564 | case CRX_ASK_VALVE_GAIN_MINUS: { |
Lightvalve | 11:82d8768d7351 | 565 | CAN_TX_VALVE_GAIN_MINUS(); |
Lightvalve | 11:82d8768d7351 | 566 | |
Lightvalve | 11:82d8768d7351 | 567 | break; |
Lightvalve | 11:82d8768d7351 | 568 | } |
Lightvalve | 11:82d8768d7351 | 569 | case CRX_SET_VALVE_GAIN_MINUS: { |
Lightvalve | 30:8d561f16383b | 570 | VALVE_GAIN_LPM_PER_V[1] = (double) msg.data[1] / 50.0f; |
Lightvalve | 30:8d561f16383b | 571 | VALVE_GAIN_LPM_PER_V[3] = (double) msg.data[2] / 50.0f; |
Lightvalve | 30:8d561f16383b | 572 | VALVE_GAIN_LPM_PER_V[5] = (double) msg.data[3] / 50.0f; |
Lightvalve | 30:8d561f16383b | 573 | VALVE_GAIN_LPM_PER_V[7] = (double) msg.data[4] / 50.0f; |
Lightvalve | 30:8d561f16383b | 574 | VALVE_GAIN_LPM_PER_V[9] = (double) msg.data[5] / 50.0f; |
Lightvalve | 170:42c938a40313 | 575 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[1] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 576 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[3] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 577 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[5] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 578 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[7] * 100.0f)); |
Lightvalve | 170:42c938a40313 | 579 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[9] * 100.0f)); |
Lightvalve | 11:82d8768d7351 | 580 | |
Lightvalve | 11:82d8768d7351 | 581 | break; |
Lightvalve | 11:82d8768d7351 | 582 | } |
Lightvalve | 11:82d8768d7351 | 583 | |
Lightvalve | 11:82d8768d7351 | 584 | case CRX_LOW_REF: { |
Lightvalve | 11:82d8768d7351 | 585 | REFERENCE_MODE = msg.data[1]; |
Lightvalve | 11:82d8768d7351 | 586 | |
Lightvalve | 11:82d8768d7351 | 587 | REF_NUM = msg.data[2]; |
Lightvalve | 30:8d561f16383b | 588 | REF_PERIOD = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) / 100.0f; |
Lightvalve | 30:8d561f16383b | 589 | if (REF_PERIOD <= 0.0f) REF_MOVE_TIME_5k = TMR_FREQ_5k / CAN_FREQ; |
Lightvalve | 11:82d8768d7351 | 590 | else REF_MOVE_TIME_5k = (int) (REF_PERIOD * (double) TMR_FREQ_5k); |
Lightvalve | 30:8d561f16383b | 591 | REF_MAG = (double) ((int16_t) (msg.data[5] | msg.data[6] << 8)) / 100.0f; |
Lightvalve | 11:82d8768d7351 | 592 | |
Lightvalve | 11:82d8768d7351 | 593 | break; |
Lightvalve | 11:82d8768d7351 | 594 | } |
Lightvalve | 11:82d8768d7351 | 595 | |
Lightvalve | 11:82d8768d7351 | 596 | case CRX_JUMP_STATUS: { |
Lightvalve | 11:82d8768d7351 | 597 | MODE_JUMP_STATUS = msg.data[1]; |
Lightvalve | 11:82d8768d7351 | 598 | |
Lightvalve | 11:82d8768d7351 | 599 | break; |
Lightvalve | 11:82d8768d7351 | 600 | } |
Lightvalve | 11:82d8768d7351 | 601 | |
Lightvalve | 11:82d8768d7351 | 602 | case CRX_SET_ERR_CLEAR: { |
Lightvalve | 11:82d8768d7351 | 603 | |
Lightvalve | 12:6f2531038ea4 | 604 | for (int i = 0; i < num_err; i++) { |
Lightvalve | 11:82d8768d7351 | 605 | flag_err[i] = FALSE; |
Lightvalve | 11:82d8768d7351 | 606 | flag_err_old[i] = FALSE; |
Lightvalve | 11:82d8768d7351 | 607 | } |
Lightvalve | 11:82d8768d7351 | 608 | |
Lightvalve | 11:82d8768d7351 | 609 | flag_err_rt = FALSE; |
Lightvalve | 11:82d8768d7351 | 610 | |
Lightvalve | 11:82d8768d7351 | 611 | |
Lightvalve | 11:82d8768d7351 | 612 | break; |
Lightvalve | 11:82d8768d7351 | 613 | } |
Lightvalve | 11:82d8768d7351 | 614 | |
Lightvalve | 11:82d8768d7351 | 615 | case CRX_ASK_HOMEPOS_OFFSET: { |
Lightvalve | 11:82d8768d7351 | 616 | CAN_TX_HOMEPOS_OFFSET(); |
Lightvalve | 11:82d8768d7351 | 617 | break; |
Lightvalve | 11:82d8768d7351 | 618 | } |
Lightvalve | 11:82d8768d7351 | 619 | case CRX_SET_HOMEPOS_OFFSET: { |
hyhoon | 226:82a3ca333004 | 620 | HOMEPOS_OFFSET = (int16_t)(msg.data[1] | msg.data[2] << 8); |
Lightvalve | 170:42c938a40313 | 621 | spi_eeprom_write(RID_HOMEPOS_OFFSET, (int16_t) HOMEPOS_OFFSET); |
Lightvalve | 11:82d8768d7351 | 622 | break; |
Lightvalve | 11:82d8768d7351 | 623 | } |
Lightvalve | 11:82d8768d7351 | 624 | |
Lightvalve | 11:82d8768d7351 | 625 | case CRX_ASK_HOMEPOS_VALVE_OPENING: { |
Lightvalve | 11:82d8768d7351 | 626 | CAN_TX_HOMPOS_VALVE_OPENING(); |
Lightvalve | 11:82d8768d7351 | 627 | break; |
Lightvalve | 11:82d8768d7351 | 628 | } |
Lightvalve | 11:82d8768d7351 | 629 | case CRX_SET_HOMEPOS_VALVE_OPENING: { |
Lightvalve | 11:82d8768d7351 | 630 | HOMEPOS_VALVE_OPENING = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 170:42c938a40313 | 631 | spi_eeprom_write(RID_HOMEPOS_VALVE_OPENING, (int16_t) HOMEPOS_VALVE_OPENING); |
Lightvalve | 11:82d8768d7351 | 632 | break; |
Lightvalve | 11:82d8768d7351 | 633 | } |
Lightvalve | 11:82d8768d7351 | 634 | |
Lightvalve | 11:82d8768d7351 | 635 | case CRX_ASK_VALVE_PWM_VS_VALVE_POS: { |
Lightvalve | 11:82d8768d7351 | 636 | can_index = (int16_t) msg.data[1]; |
Lightvalve | 11:82d8768d7351 | 637 | CAN_TX_VALVE_PWM_VS_VALVE_POS(can_index); |
Lightvalve | 11:82d8768d7351 | 638 | break; |
Lightvalve | 11:82d8768d7351 | 639 | } |
Lightvalve | 11:82d8768d7351 | 640 | case CRX_ASK_VALVE_POS_VS_FLOWRATE: { |
Lightvalve | 11:82d8768d7351 | 641 | can_index = (int16_t) msg.data[1]; |
Lightvalve | 11:82d8768d7351 | 642 | CAN_TX_VALVE_POS_VS_FLOWRATE(can_index); |
Lightvalve | 11:82d8768d7351 | 643 | break; |
Lightvalve | 11:82d8768d7351 | 644 | } |
Lightvalve | 11:82d8768d7351 | 645 | case CRX_ASK_VALVE_POS_NUM: { |
Lightvalve | 11:82d8768d7351 | 646 | CAN_TX_VALVE_POS_NUM(); |
Lightvalve | 11:82d8768d7351 | 647 | break; |
Lightvalve | 11:82d8768d7351 | 648 | } |
Lightvalve | 170:42c938a40313 | 649 | |
Lightvalve | 28:2a62d73e3dd0 | 650 | case CRX_SET_ROM: { |
Lightvalve | 28:2a62d73e3dd0 | 651 | break; |
Lightvalve | 28:2a62d73e3dd0 | 652 | } |
Lightvalve | 237:c2cfe349f5c1 | 653 | |
Lightvalve | 237:c2cfe349f5c1 | 654 | case CRX_ASK_BUFFER: { |
Lightvalve | 237:c2cfe349f5c1 | 655 | cnt_buffer = (int16_t) (msg.data[1] | msg.data[2] << 8); |
Lightvalve | 237:c2cfe349f5c1 | 656 | CAN_TX_BUFFER(cnt_buffer); |
Lightvalve | 237:c2cfe349f5c1 | 657 | break; |
Lightvalve | 237:c2cfe349f5c1 | 658 | } |
Lightvalve | 237:c2cfe349f5c1 | 659 | case CRX_SET_STEP_TEST: { |
Lightvalve | 237:c2cfe349f5c1 | 660 | cnt_step_test = 0; |
Lightvalve | 237:c2cfe349f5c1 | 661 | CONTROL_UTILITY_MODE = 37; |
Lightvalve | 237:c2cfe349f5c1 | 662 | break; |
Lightvalve | 237:c2cfe349f5c1 | 663 | } |
Lightvalve | 237:c2cfe349f5c1 | 664 | case CRX_SET_FREQ_TEST: { |
Lightvalve | 237:c2cfe349f5c1 | 665 | cnt_freq_test = 0; |
Lightvalve | 237:c2cfe349f5c1 | 666 | CONTROL_UTILITY_MODE = 34; |
Lightvalve | 237:c2cfe349f5c1 | 667 | break; |
Lightvalve | 237:c2cfe349f5c1 | 668 | } |
Lightvalve | 192:637092202815 | 669 | |
Lightvalve | 170:42c938a40313 | 670 | default: |
Lightvalve | 170:42c938a40313 | 671 | break; |
jobuuu | 2:a1c0a37df760 | 672 | } |
jobuuu | 2:a1c0a37df760 | 673 | } |
jobuuu | 2:a1c0a37df760 | 674 | |
jobuuu | 2:a1c0a37df760 | 675 | void CAN_RX_HANDLER() |
jobuuu | 2:a1c0a37df760 | 676 | { |
Lightvalve | 170:42c938a40313 | 677 | |
jobuuu | 2:a1c0a37df760 | 678 | can.read(msg); |
jobuuu | 2:a1c0a37df760 | 679 | unsigned int address = msg.id; |
Lightvalve | 170:42c938a40313 | 680 | if(address==CID_RX_CMD) { |
jobuuu | 2:a1c0a37df760 | 681 | unsigned int CMD = msg.data[0]; |
jobuuu | 2:a1c0a37df760 | 682 | ReadCMD(CMD); |
Lightvalve | 170:42c938a40313 | 683 | |
jobuuu | 7:e9086c72bb22 | 684 | } else if(address==CID_RX_REF_POSITION) { |
Lightvalve | 170:42c938a40313 | 685 | |
jobuuu | 230:2c3e5ecbe7e1 | 686 | int16_t temp_pos = (int16_t) (msg.data[0] | msg.data[1] << 8); |
Lightvalve | 43:b084e5f5d0d5 | 687 | int16_t temp_vel = (int16_t) (msg.data[2] | msg.data[3] << 8); |
Lightvalve | 57:f4819de54e7a | 688 | int16_t temp_torq = (int16_t) (msg.data[4] | msg.data[5] << 8); |
Lightvalve | 170:42c938a40313 | 689 | |
Lightvalve | 57:f4819de54e7a | 690 | if((OPERATING_MODE&0b001)==0) { // Rotary Actuator |
Lightvalve | 232:2976cf1b4252 | 691 | REF_POSITION = (float)temp_pos / 200.0f; |
Lightvalve | 232:2976cf1b4252 | 692 | REF_VELOCITY = (float)temp_vel / 20.0f; |
Lightvalve | 232:2976cf1b4252 | 693 | REF_TORQUE = (float)temp_torq * 0.1f / TORQUE_SENSOR_PULSE_PER_TORQUE; // pulse >> Nm |
Lightvalve | 170:42c938a40313 | 694 | } else { //Linear Actuator |
Lightvalve | 232:2976cf1b4252 | 695 | REF_POSITION = (float)temp_pos / 200.0f; |
Lightvalve | 232:2976cf1b4252 | 696 | REF_VELOCITY = (float)temp_vel / 20.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 697 | REF_FORCE = (float)temp_torq * 0.1f / TORQUE_SENSOR_PULSE_PER_TORQUE; // pulse >> N |
Lightvalve | 57:f4819de54e7a | 698 | } |
Lightvalve | 170:42c938a40313 | 699 | |
jobuuu | 230:2c3e5ecbe7e1 | 700 | if(SUPPLY_PRESSURE_UPDATE == 1) { |
jobuuu | 230:2c3e5ecbe7e1 | 701 | int16_t temp_REF_Ps = (int16_t) (msg.data[6] | msg.data[7] << 8); |
jobuuu | 230:2c3e5ecbe7e1 | 702 | PRES_SUPPLY = ((float)temp_REF_Ps) / 100.0; |
jobuuu | 230:2c3e5ecbe7e1 | 703 | if(PRES_SUPPLY<35.0f) PRES_SUPPLY = 35.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 704 | else if(PRES_SUPPLY>210.0f) PRES_SUPPLY = 210.0f; |
jobuuu | 230:2c3e5ecbe7e1 | 705 | } else { |
jobuuu | 230:2c3e5ecbe7e1 | 706 | PRES_SUPPLY = PRES_SUPPLY_NOM; |
jobuuu | 230:2c3e5ecbe7e1 | 707 | } |
hyhoon | 226:82a3ca333004 | 708 | |
hyhoon | 226:82a3ca333004 | 709 | if(CAN_FREQ == -1) { |
jobuuu | 230:2c3e5ecbe7e1 | 710 | |
hyhoon | 226:82a3ca333004 | 711 | // Position, Velocity, and Torque (ID:1200) |
hyhoon | 226:82a3ca333004 | 712 | if (flag_data_request[0] == HIGH) { |
hyhoon | 226:82a3ca333004 | 713 | if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator |
Lightvalve | 231:e00e71ca3e80 | 714 | CAN_TX_POSITION_FT((int16_t) (pos.sen*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (torq.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f)); |
hyhoon | 226:82a3ca333004 | 715 | } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator |
Lightvalve | 231:e00e71ca3e80 | 716 | CAN_TX_POSITION_FT((int16_t) (pos.sen*200.0f), (int16_t) (vel.sen*20.0f), (int16_t) (force.sen*TORQUE_SENSOR_PULSE_PER_TORQUE*10.0f)); |
jeongyeseong | 225:9c0becc196ba | 717 | } |
jeongyeseong | 225:9c0becc196ba | 718 | } |
hyhoon | 226:82a3ca333004 | 719 | |
jobuuu | 230:2c3e5ecbe7e1 | 720 | // Valve Position (ID:1300) |
hyhoon | 226:82a3ca333004 | 721 | if (flag_data_request[1] == HIGH) { |
jobuuu | 230:2c3e5ecbe7e1 | 722 | CAN_TX_PWM((int16_t)(cur.sen/mA_PER_pulse)); |
hyhoon | 226:82a3ca333004 | 723 | } |
hyhoon | 226:82a3ca333004 | 724 | |
jobuuu | 230:2c3e5ecbe7e1 | 725 | // Others : Pressure A, B, Supply Pressure, etc. (for Debugging) (ID:1400) |
hyhoon | 226:82a3ca333004 | 726 | if (flag_data_request[2] == HIGH) { |
jobuuu | 230:2c3e5ecbe7e1 | 727 | CAN_TX_SOMETHING((int16_t)(pres_A.sen*100.0f), (int16_t)(pres_B.sen*100.0f), (int16_t) (0), (int16_t) (0)); |
hyhoon | 226:82a3ca333004 | 728 | } |
jeongyeseong | 225:9c0becc196ba | 729 | } |
Lightvalve | 68:328e1be06f5d | 730 | |
hyhoon | 227:699c3e572283 | 731 | } else if(address==CID_RX_REF_OPENLOOP) { |
Lightvalve | 47:fdcb8bd86fd6 | 732 | int16_t temp_ref_valve_pos = (int16_t) (msg.data[0] | msg.data[1] << 8); |
Lightvalve | 170:42c938a40313 | 733 | |
Lightvalve | 57:f4819de54e7a | 734 | if (((OPERATING_MODE&0b110)>>1) == 0) { //Moog Valve |
jobuuu | 230:2c3e5ecbe7e1 | 735 | valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~10000) |
Lightvalve | 57:f4819de54e7a | 736 | } else if (((OPERATING_MODE&0b110)>>1) == 1) { //KNR Valve |
jobuuu | 230:2c3e5ecbe7e1 | 737 | valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~30000) |
Lightvalve | 57:f4819de54e7a | 738 | } else { //SW Valve |
Lightvalve | 57:f4819de54e7a | 739 | if(temp_ref_valve_pos >= 0) { |
Lightvalve | 238:4e660aa77eb7 | 740 | // valve_pos.ref = (double)VALVE_ELECTRIC_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_ELECTRIC_CENTER)/10000.0f; |
Lightvalve | 238:4e660aa77eb7 | 741 | valve_pos.ref = (double)temp_ref_valve_pos; // -10000~10000 |
Lightvalve | 57:f4819de54e7a | 742 | } else { |
Lightvalve | 238:4e660aa77eb7 | 743 | // valve_pos.ref = (double)VALVE_ELECTRIC_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_ELECTRIC_CENTER)/10000.0f; |
Lightvalve | 238:4e660aa77eb7 | 744 | valve_pos.ref = (double)temp_ref_valve_pos; // -10000~10000 |
Lightvalve | 57:f4819de54e7a | 745 | } |
Lightvalve | 47:fdcb8bd86fd6 | 746 | } |
Lightvalve | 170:42c938a40313 | 747 | } else if(address==CID_RX_REF_PWM) { |
Lightvalve | 49:e7bcfc244d40 | 748 | int temp_ref_pwm = (int16_t) (msg.data[0] | msg.data[1] << 8); |
Lightvalve | 49:e7bcfc244d40 | 749 | Vout.ref = (double) temp_ref_pwm; |
Lightvalve | 170:42c938a40313 | 750 | } |
jeongyeseong | 225:9c0becc196ba | 751 | |
jeongyeseong | 225:9c0becc196ba | 752 | |
jobuuu | 2:a1c0a37df760 | 753 | } |
jobuuu | 2:a1c0a37df760 | 754 | |
jobuuu | 2:a1c0a37df760 | 755 | /****************************************************************************** |
jobuuu | 2:a1c0a37df760 | 756 | Information Transmission Functions |
jobuuu | 2:a1c0a37df760 | 757 | *******************************************************************************/ |
Lightvalve | 11:82d8768d7351 | 758 | |
Lightvalve | 170:42c938a40313 | 759 | void CAN_TX_INFO(void) |
Lightvalve | 170:42c938a40313 | 760 | { |
Lightvalve | 12:6f2531038ea4 | 761 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 762 | |
jobuuu | 2:a1c0a37df760 | 763 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 764 | temp_msg.len = 7; |
Lightvalve | 12:6f2531038ea4 | 765 | temp_msg.data[0] = (uint8_t) CTX_SEND_INFO; |
Lightvalve | 12:6f2531038ea4 | 766 | temp_msg.data[1] = (uint8_t) BNO; |
Lightvalve | 12:6f2531038ea4 | 767 | temp_msg.data[2] = (uint8_t) CAN_FREQ; |
Lightvalve | 12:6f2531038ea4 | 768 | temp_msg.data[3] = (uint8_t) (CAN_FREQ >> 8); |
Lightvalve | 12:6f2531038ea4 | 769 | temp_msg.data[4] = (uint8_t) (flag_err[7] << 7 | flag_err[6] << 6 | flag_err[5] << 5 | flag_err[4] << 4 | flag_err[3] << 3 | flag_err[2] << 2 | flag_err[1] << 1 | flag_err[0]); |
Lightvalve | 57:f4819de54e7a | 770 | temp_msg.data[5] = (uint8_t) CONTROL_UTILITY_MODE; |
Lightvalve | 12:6f2531038ea4 | 771 | temp_msg.data[6] = (uint8_t) OPERATING_MODE; |
jobuuu | 2:a1c0a37df760 | 772 | |
jobuuu | 2:a1c0a37df760 | 773 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 774 | } |
jobuuu | 2:a1c0a37df760 | 775 | |
Lightvalve | 170:42c938a40313 | 776 | void CAN_TX_BNO(void) |
Lightvalve | 170:42c938a40313 | 777 | { |
Lightvalve | 12:6f2531038ea4 | 778 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 779 | |
jobuuu | 2:a1c0a37df760 | 780 | temp_msg.id = CID_TX_INFO; |
jeongyeseong | 225:9c0becc196ba | 781 | //temp_msg.len = 2; |
hyhoon | 226:82a3ca333004 | 782 | temp_msg.len = 2; |
Lightvalve | 12:6f2531038ea4 | 783 | temp_msg.data[0] = (uint8_t) CTX_SEND_BNO; |
Lightvalve | 12:6f2531038ea4 | 784 | temp_msg.data[1] = (uint8_t) BNO; |
jobuuu | 2:a1c0a37df760 | 785 | |
jobuuu | 2:a1c0a37df760 | 786 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 787 | } |
jobuuu | 2:a1c0a37df760 | 788 | |
Lightvalve | 170:42c938a40313 | 789 | void CAN_TX_OPERATING_MODE(void) |
Lightvalve | 170:42c938a40313 | 790 | { |
jobuuu | 2:a1c0a37df760 | 791 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 792 | |
jobuuu | 2:a1c0a37df760 | 793 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 794 | temp_msg.len = 5; |
Lightvalve | 12:6f2531038ea4 | 795 | temp_msg.data[0] = (uint8_t) CTX_SEND_OPERATING_MODE; |
Lightvalve | 12:6f2531038ea4 | 796 | temp_msg.data[1] = (uint8_t) OPERATING_MODE; |
Lightvalve | 52:8ea76864368a | 797 | temp_msg.data[2] = (uint8_t) SENSING_MODE; |
Lightvalve | 52:8ea76864368a | 798 | temp_msg.data[3] = (uint8_t) CURRENT_CONTROL_MODE; |
Lightvalve | 52:8ea76864368a | 799 | temp_msg.data[4] = (uint8_t) FLAG_VALVE_DEADZONE; |
jobuuu | 2:a1c0a37df760 | 800 | |
jobuuu | 2:a1c0a37df760 | 801 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 802 | } |
jobuuu | 2:a1c0a37df760 | 803 | |
Lightvalve | 170:42c938a40313 | 804 | void CAN_TX_CAN_FREQ(void) |
Lightvalve | 170:42c938a40313 | 805 | { |
jobuuu | 2:a1c0a37df760 | 806 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 807 | |
jobuuu | 2:a1c0a37df760 | 808 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 809 | temp_msg.len = 3; |
jobuuu | 2:a1c0a37df760 | 810 | temp_msg.data[0] = (uint8_t) CTX_SEND_CAN_FREQ; |
jobuuu | 2:a1c0a37df760 | 811 | temp_msg.data[1] = (uint8_t) CAN_FREQ; |
jobuuu | 2:a1c0a37df760 | 812 | temp_msg.data[2] = (uint8_t) (CAN_FREQ >> 8); |
jobuuu | 2:a1c0a37df760 | 813 | |
jobuuu | 2:a1c0a37df760 | 814 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 815 | } |
Lightvalve | 11:82d8768d7351 | 816 | |
Lightvalve | 170:42c938a40313 | 817 | void CAN_TX_CONTROL_MODE(void) |
Lightvalve | 170:42c938a40313 | 818 | { |
jobuuu | 2:a1c0a37df760 | 819 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 820 | |
jobuuu | 2:a1c0a37df760 | 821 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 822 | temp_msg.len = 2; |
Lightvalve | 12:6f2531038ea4 | 823 | temp_msg.data[0] = (uint8_t) CTX_SEND_CONTROL_MODE; |
Lightvalve | 57:f4819de54e7a | 824 | temp_msg.data[1] = (uint8_t) CONTROL_UTILITY_MODE; |
jobuuu | 2:a1c0a37df760 | 825 | |
jobuuu | 2:a1c0a37df760 | 826 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 827 | } |
Lightvalve | 11:82d8768d7351 | 828 | |
Lightvalve | 170:42c938a40313 | 829 | void CAN_TX_JOINT_ENC_DIR(void) |
Lightvalve | 170:42c938a40313 | 830 | { |
jobuuu | 2:a1c0a37df760 | 831 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 832 | |
jobuuu | 2:a1c0a37df760 | 833 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 834 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 835 | temp_msg.data[0] = (uint8_t) CTX_SEND_JOINT_ENC_DIR; |
Lightvalve | 12:6f2531038ea4 | 836 | temp_msg.data[1] = (uint8_t) DIR_JOINT_ENC; |
Lightvalve | 12:6f2531038ea4 | 837 | temp_msg.data[2] = (uint8_t) (DIR_JOINT_ENC >> 8); |
jobuuu | 2:a1c0a37df760 | 838 | |
jobuuu | 2:a1c0a37df760 | 839 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 840 | } |
jobuuu | 2:a1c0a37df760 | 841 | |
Lightvalve | 170:42c938a40313 | 842 | void CAN_TX_VALVE_DIR(void) |
Lightvalve | 170:42c938a40313 | 843 | { |
jobuuu | 2:a1c0a37df760 | 844 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 845 | |
jobuuu | 2:a1c0a37df760 | 846 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 847 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 848 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DIR; |
Lightvalve | 12:6f2531038ea4 | 849 | temp_msg.data[1] = (uint8_t) DIR_VALVE; |
Lightvalve | 12:6f2531038ea4 | 850 | temp_msg.data[2] = (uint8_t) (DIR_VALVE >> 8); |
jobuuu | 2:a1c0a37df760 | 851 | |
jobuuu | 2:a1c0a37df760 | 852 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 853 | } |
jobuuu | 2:a1c0a37df760 | 854 | |
Lightvalve | 170:42c938a40313 | 855 | void CAN_TX_VALVE_ENC_DIR(void) |
Lightvalve | 170:42c938a40313 | 856 | { |
jobuuu | 2:a1c0a37df760 | 857 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 858 | |
jobuuu | 2:a1c0a37df760 | 859 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 860 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 861 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ENC_DIR; |
Lightvalve | 12:6f2531038ea4 | 862 | temp_msg.data[1] = (uint8_t) DIR_VALVE_ENC; |
Lightvalve | 12:6f2531038ea4 | 863 | temp_msg.data[2] = (uint8_t) (DIR_VALVE_ENC >> 8); |
jobuuu | 2:a1c0a37df760 | 864 | |
jobuuu | 2:a1c0a37df760 | 865 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 866 | } |
jobuuu | 2:a1c0a37df760 | 867 | |
Lightvalve | 170:42c938a40313 | 868 | void CAN_TX_VOLTAGE_SUPPLY(void) |
Lightvalve | 170:42c938a40313 | 869 | { |
Lightvalve | 49:e7bcfc244d40 | 870 | int16_t send_voltage_supply = (int16_t) (SUPPLY_VOLTAGE * 10.0f); |
jobuuu | 2:a1c0a37df760 | 871 | |
jobuuu | 2:a1c0a37df760 | 872 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 873 | |
jobuuu | 2:a1c0a37df760 | 874 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 875 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 876 | temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_SUPPLY; |
Lightvalve | 12:6f2531038ea4 | 877 | temp_msg.data[1] = (uint8_t) (send_voltage_supply); |
Lightvalve | 12:6f2531038ea4 | 878 | temp_msg.data[2] = (uint8_t) (send_voltage_supply >> 8); |
jobuuu | 2:a1c0a37df760 | 879 | |
jobuuu | 2:a1c0a37df760 | 880 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 881 | } |
jobuuu | 2:a1c0a37df760 | 882 | |
Lightvalve | 170:42c938a40313 | 883 | void CAN_TX_VOLTAGE_VALVE(void) |
Lightvalve | 170:42c938a40313 | 884 | { |
Lightvalve | 49:e7bcfc244d40 | 885 | int16_t send_voltage_valve = (int16_t) (VALVE_VOLTAGE_LIMIT * 10.0f); |
jobuuu | 2:a1c0a37df760 | 886 | |
jobuuu | 2:a1c0a37df760 | 887 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 888 | |
jobuuu | 2:a1c0a37df760 | 889 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 890 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 891 | temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_VALVE; |
Lightvalve | 12:6f2531038ea4 | 892 | temp_msg.data[1] = (uint8_t) send_voltage_valve; |
Lightvalve | 12:6f2531038ea4 | 893 | temp_msg.data[2] = (uint8_t) (send_voltage_valve >> 8); |
jobuuu | 2:a1c0a37df760 | 894 | |
jobuuu | 2:a1c0a37df760 | 895 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 896 | } |
Lightvalve | 11:82d8768d7351 | 897 | |
jobuuu | 230:2c3e5ecbe7e1 | 898 | void CAN_TX_VARIABLE_SUPPLY_ONOFF(void) |
jobuuu | 230:2c3e5ecbe7e1 | 899 | { |
jobuuu | 230:2c3e5ecbe7e1 | 900 | CANMessage temp_msg; |
jobuuu | 230:2c3e5ecbe7e1 | 901 | temp_msg.id = CID_TX_INFO; |
jobuuu | 230:2c3e5ecbe7e1 | 902 | temp_msg.len = 2; |
jobuuu | 230:2c3e5ecbe7e1 | 903 | temp_msg.data[0] = (uint8_t) CTX_SEND_VARIABLE_SUPPLY; |
jobuuu | 230:2c3e5ecbe7e1 | 904 | temp_msg.data[1] = (uint8_t) SUPPLY_PRESSURE_UPDATE; |
jobuuu | 230:2c3e5ecbe7e1 | 905 | |
jobuuu | 230:2c3e5ecbe7e1 | 906 | can.write(temp_msg); |
jobuuu | 230:2c3e5ecbe7e1 | 907 | } |
jobuuu | 2:a1c0a37df760 | 908 | |
Lightvalve | 170:42c938a40313 | 909 | void CAN_TX_PID_GAIN(int t_type) |
Lightvalve | 170:42c938a40313 | 910 | { |
jobuuu | 2:a1c0a37df760 | 911 | // t_type = 0 : valve position control gain |
jobuuu | 2:a1c0a37df760 | 912 | // t_type = 1 : joint position control gain |
jobuuu | 2:a1c0a37df760 | 913 | // t_type = 2 : joint torque control gain |
jobuuu | 2:a1c0a37df760 | 914 | |
Lightvalve | 12:6f2531038ea4 | 915 | int16_t sendPgain=0, sendIgain=0, sendDgain=0; |
jobuuu | 2:a1c0a37df760 | 916 | if (t_type == 0) { |
Lightvalve | 30:8d561f16383b | 917 | sendPgain = (int16_t) (P_GAIN_VALVE_POSITION); |
Lightvalve | 30:8d561f16383b | 918 | sendIgain = (int16_t) (I_GAIN_VALVE_POSITION); |
Lightvalve | 30:8d561f16383b | 919 | sendDgain = (int16_t) (D_GAIN_VALVE_POSITION); |
jobuuu | 2:a1c0a37df760 | 920 | } else if (t_type == 1) { |
Lightvalve | 12:6f2531038ea4 | 921 | sendPgain = (int16_t) (P_GAIN_JOINT_POSITION); |
Lightvalve | 12:6f2531038ea4 | 922 | sendIgain = (int16_t) (I_GAIN_JOINT_POSITION); |
Lightvalve | 12:6f2531038ea4 | 923 | sendDgain = (int16_t) (D_GAIN_JOINT_POSITION); |
jobuuu | 2:a1c0a37df760 | 924 | } else if (t_type == 2) { |
Lightvalve | 12:6f2531038ea4 | 925 | sendPgain = (int16_t) (P_GAIN_JOINT_TORQUE); |
Lightvalve | 12:6f2531038ea4 | 926 | sendIgain = (int16_t) (I_GAIN_JOINT_TORQUE); |
Lightvalve | 12:6f2531038ea4 | 927 | sendDgain = (int16_t) (D_GAIN_JOINT_TORQUE); |
Lightvalve | 46:2694daea349b | 928 | } else if (t_type == 3) { |
Lightvalve | 67:c2812cf26c38 | 929 | sendPgain = (int16_t) (K_SPRING * 10.0f); |
Lightvalve | 67:c2812cf26c38 | 930 | sendIgain = (int16_t) (D_DAMPER * 100.0f); |
jobuuu | 2:a1c0a37df760 | 931 | } |
jobuuu | 2:a1c0a37df760 | 932 | |
jobuuu | 2:a1c0a37df760 | 933 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 934 | |
jobuuu | 2:a1c0a37df760 | 935 | temp_msg.id = CID_TX_INFO; |
jobuuu | 2:a1c0a37df760 | 936 | temp_msg.len = 8; |
Lightvalve | 12:6f2531038ea4 | 937 | temp_msg.data[0] = (uint8_t) CTX_SEND_PID_GAIN; |
Lightvalve | 12:6f2531038ea4 | 938 | temp_msg.data[1] = (uint8_t) t_type; |
Lightvalve | 12:6f2531038ea4 | 939 | temp_msg.data[2] = (uint8_t) sendPgain; |
Lightvalve | 12:6f2531038ea4 | 940 | temp_msg.data[3] = (uint8_t) (sendPgain >> 8); |
Lightvalve | 12:6f2531038ea4 | 941 | temp_msg.data[4] = (uint8_t) sendIgain; |
Lightvalve | 12:6f2531038ea4 | 942 | temp_msg.data[5] = (uint8_t) (sendIgain >> 8); |
Lightvalve | 12:6f2531038ea4 | 943 | temp_msg.data[6] = (uint8_t) sendDgain; |
Lightvalve | 12:6f2531038ea4 | 944 | temp_msg.data[7] = (uint8_t) (sendDgain >> 8); |
jobuuu | 2:a1c0a37df760 | 945 | |
jobuuu | 2:a1c0a37df760 | 946 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 947 | } |
jobuuu | 2:a1c0a37df760 | 948 | |
Lightvalve | 11:82d8768d7351 | 949 | |
Lightvalve | 170:42c938a40313 | 950 | void CAN_TX_VALVE_DEADZONE(void) |
Lightvalve | 170:42c938a40313 | 951 | { |
jobuuu | 2:a1c0a37df760 | 952 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 953 | |
jobuuu | 2:a1c0a37df760 | 954 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 955 | temp_msg.len = 7; |
Lightvalve | 12:6f2531038ea4 | 956 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE; |
Lightvalve | 57:f4819de54e7a | 957 | temp_msg.data[1] = (uint8_t) VALVE_CENTER; |
Lightvalve | 57:f4819de54e7a | 958 | temp_msg.data[2] = (uint8_t) (VALVE_CENTER >> 8); |
hyhoon | 226:82a3ca333004 | 959 | temp_msg.data[3] = (uint8_t) VALVE_DEADZONE_PLUS; |
hyhoon | 226:82a3ca333004 | 960 | temp_msg.data[4] = (uint8_t) (VALVE_DEADZONE_PLUS >> 8); |
hyhoon | 226:82a3ca333004 | 961 | temp_msg.data[5] = (uint8_t) VALVE_DEADZONE_MINUS; |
hyhoon | 226:82a3ca333004 | 962 | temp_msg.data[6] = (uint8_t) (VALVE_DEADZONE_MINUS >> 8); |
jobuuu | 2:a1c0a37df760 | 963 | |
jobuuu | 2:a1c0a37df760 | 964 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 965 | } |
jobuuu | 2:a1c0a37df760 | 966 | |
Lightvalve | 170:42c938a40313 | 967 | void CAN_TX_VELOCITY_COMP_GAIN(void) |
Lightvalve | 170:42c938a40313 | 968 | { |
Lightvalve | 11:82d8768d7351 | 969 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 970 | |
Lightvalve | 11:82d8768d7351 | 971 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 972 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 973 | temp_msg.data[0] = (uint8_t) CTX_SEND_VELOCITY_COMP_GAIN; |
Lightvalve | 12:6f2531038ea4 | 974 | temp_msg.data[1] = (uint8_t) VELOCITY_COMP_GAIN; |
Lightvalve | 12:6f2531038ea4 | 975 | temp_msg.data[2] = (uint8_t) (VELOCITY_COMP_GAIN >> 8); |
Lightvalve | 11:82d8768d7351 | 976 | |
Lightvalve | 11:82d8768d7351 | 977 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 978 | } |
Lightvalve | 11:82d8768d7351 | 979 | |
Lightvalve | 238:4e660aa77eb7 | 980 | void CAN_TX_VALVE_ELECTRIC_CENTER(void) |
Lightvalve | 170:42c938a40313 | 981 | { |
Lightvalve | 11:82d8768d7351 | 982 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 983 | |
Lightvalve | 11:82d8768d7351 | 984 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 985 | temp_msg.len = 3; |
Lightvalve | 238:4e660aa77eb7 | 986 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ELECTRIC_CENTER; |
Lightvalve | 238:4e660aa77eb7 | 987 | temp_msg.data[1] = (uint8_t) VALVE_ELECTRIC_CENTER; |
Lightvalve | 238:4e660aa77eb7 | 988 | temp_msg.data[2] = (uint8_t) (VALVE_ELECTRIC_CENTER >> 8); |
Lightvalve | 11:82d8768d7351 | 989 | |
Lightvalve | 11:82d8768d7351 | 990 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 991 | } |
Lightvalve | 11:82d8768d7351 | 992 | |
Lightvalve | 170:42c938a40313 | 993 | void CAN_TX_VALVE_FF(void) |
Lightvalve | 170:42c938a40313 | 994 | { |
Lightvalve | 11:82d8768d7351 | 995 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 996 | |
Lightvalve | 11:82d8768d7351 | 997 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 998 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 999 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_FF; |
Lightvalve | 12:6f2531038ea4 | 1000 | temp_msg.data[1] = (uint8_t) VALVE_FF; |
Lightvalve | 12:6f2531038ea4 | 1001 | temp_msg.data[2] = (uint8_t) (VALVE_FF >> 8); |
Lightvalve | 11:82d8768d7351 | 1002 | |
Lightvalve | 11:82d8768d7351 | 1003 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1004 | } |
Lightvalve | 11:82d8768d7351 | 1005 | |
Lightvalve | 170:42c938a40313 | 1006 | void CAN_TX_BULK_MODULUS(void) |
Lightvalve | 170:42c938a40313 | 1007 | { |
Lightvalve | 11:82d8768d7351 | 1008 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1009 | |
Lightvalve | 11:82d8768d7351 | 1010 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1011 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1012 | temp_msg.data[0] = (uint8_t) CTX_SEND_BULK_MODULUS; |
Lightvalve | 12:6f2531038ea4 | 1013 | temp_msg.data[1] = (uint8_t) BULK_MODULUS; |
Lightvalve | 12:6f2531038ea4 | 1014 | temp_msg.data[2] = (uint8_t) (BULK_MODULUS >> 8); |
Lightvalve | 11:82d8768d7351 | 1015 | |
Lightvalve | 11:82d8768d7351 | 1016 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1017 | } |
Lightvalve | 11:82d8768d7351 | 1018 | |
Lightvalve | 170:42c938a40313 | 1019 | void CAN_TX_CHAMBER_VOLUME(void) |
Lightvalve | 170:42c938a40313 | 1020 | { |
Lightvalve | 11:82d8768d7351 | 1021 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1022 | |
Lightvalve | 11:82d8768d7351 | 1023 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1024 | temp_msg.len = 5; |
Lightvalve | 12:6f2531038ea4 | 1025 | temp_msg.data[0] = (uint8_t) CTX_SEND_CHAMBER_VOLUME; |
Lightvalve | 12:6f2531038ea4 | 1026 | temp_msg.data[1] = (uint8_t) CHAMBER_VOLUME_A; |
Lightvalve | 12:6f2531038ea4 | 1027 | temp_msg.data[2] = (uint8_t) (CHAMBER_VOLUME_A >> 8); |
Lightvalve | 12:6f2531038ea4 | 1028 | temp_msg.data[3] = (uint8_t) CHAMBER_VOLUME_B; |
Lightvalve | 12:6f2531038ea4 | 1029 | temp_msg.data[4] = (uint8_t) (CHAMBER_VOLUME_B >> 8); |
Lightvalve | 11:82d8768d7351 | 1030 | |
Lightvalve | 11:82d8768d7351 | 1031 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1032 | } |
Lightvalve | 11:82d8768d7351 | 1033 | |
Lightvalve | 170:42c938a40313 | 1034 | void CAN_TX_PISTON_AREA(void) |
Lightvalve | 170:42c938a40313 | 1035 | { |
jobuuu | 2:a1c0a37df760 | 1036 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1037 | |
Lightvalve | 11:82d8768d7351 | 1038 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1039 | temp_msg.len = 5; |
Lightvalve | 12:6f2531038ea4 | 1040 | temp_msg.data[0] = (uint8_t) CTX_SEND_PISTON_AREA; |
Lightvalve | 12:6f2531038ea4 | 1041 | temp_msg.data[1] = (uint8_t) PISTON_AREA_A; |
Lightvalve | 12:6f2531038ea4 | 1042 | temp_msg.data[2] = (uint8_t) (PISTON_AREA_A >> 8); |
Lightvalve | 12:6f2531038ea4 | 1043 | temp_msg.data[3] = (uint8_t) PISTON_AREA_B; |
Lightvalve | 12:6f2531038ea4 | 1044 | temp_msg.data[4] = (uint8_t) (PISTON_AREA_B >> 8); |
jobuuu | 2:a1c0a37df760 | 1045 | |
Lightvalve | 11:82d8768d7351 | 1046 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1047 | } |
Lightvalve | 11:82d8768d7351 | 1048 | |
jobuuu | 230:2c3e5ecbe7e1 | 1049 | void CAN_TX_SUP_PRES(void) |
Lightvalve | 170:42c938a40313 | 1050 | { |
Lightvalve | 11:82d8768d7351 | 1051 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1052 | |
jobuuu | 230:2c3e5ecbe7e1 | 1053 | int16_t temp_PRES_SUPPLY = (int16_t) (PRES_SUPPLY); |
Lightvalve | 11:82d8768d7351 | 1054 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1055 | temp_msg.len = 5; |
jobuuu | 230:2c3e5ecbe7e1 | 1056 | temp_msg.data[0] = (uint8_t) CTX_SEND_SUP_PRES; |
jobuuu | 230:2c3e5ecbe7e1 | 1057 | temp_msg.data[1] = (uint8_t) temp_PRES_SUPPLY; |
jobuuu | 230:2c3e5ecbe7e1 | 1058 | temp_msg.data[2] = (uint8_t) (temp_PRES_SUPPLY >> 8); |
jobuuu | 230:2c3e5ecbe7e1 | 1059 | temp_msg.data[3] = 0; |
jobuuu | 230:2c3e5ecbe7e1 | 1060 | temp_msg.data[4] = 0; |
Lightvalve | 11:82d8768d7351 | 1061 | |
Lightvalve | 11:82d8768d7351 | 1062 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1063 | } |
Lightvalve | 11:82d8768d7351 | 1064 | |
Lightvalve | 170:42c938a40313 | 1065 | void CAN_TX_ENC_LIMIT(void) |
Lightvalve | 170:42c938a40313 | 1066 | { |
Lightvalve | 11:82d8768d7351 | 1067 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1068 | |
Lightvalve | 11:82d8768d7351 | 1069 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1070 | temp_msg.len = 5; |
Lightvalve | 12:6f2531038ea4 | 1071 | temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_LIMIT; |
Lightvalve | 12:6f2531038ea4 | 1072 | temp_msg.data[1] = (uint8_t) ENC_LIMIT_MINUS; |
Lightvalve | 12:6f2531038ea4 | 1073 | temp_msg.data[2] = (uint8_t) (ENC_LIMIT_MINUS >> 8); |
Lightvalve | 12:6f2531038ea4 | 1074 | temp_msg.data[3] = (uint8_t) ENC_LIMIT_PLUS; |
Lightvalve | 12:6f2531038ea4 | 1075 | temp_msg.data[4] = (uint8_t) (ENC_LIMIT_PLUS >> 8); |
Lightvalve | 11:82d8768d7351 | 1076 | |
Lightvalve | 11:82d8768d7351 | 1077 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1078 | } |
Lightvalve | 11:82d8768d7351 | 1079 | |
Lightvalve | 170:42c938a40313 | 1080 | void CAN_TX_STROKE(void) |
Lightvalve | 170:42c938a40313 | 1081 | { |
Lightvalve | 11:82d8768d7351 | 1082 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1083 | |
Lightvalve | 11:82d8768d7351 | 1084 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1085 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1086 | temp_msg.data[0] = (uint8_t) CTX_SEND_STROKE; |
Lightvalve | 12:6f2531038ea4 | 1087 | temp_msg.data[1] = (uint8_t) STROKE; |
Lightvalve | 12:6f2531038ea4 | 1088 | temp_msg.data[2] = (uint8_t) (STROKE >> 8); |
Lightvalve | 11:82d8768d7351 | 1089 | |
Lightvalve | 11:82d8768d7351 | 1090 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1091 | } |
Lightvalve | 11:82d8768d7351 | 1092 | |
Lightvalve | 170:42c938a40313 | 1093 | void CAN_TX_VALVE_LIMIT(void) |
Lightvalve | 170:42c938a40313 | 1094 | { |
Lightvalve | 11:82d8768d7351 | 1095 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1096 | |
Lightvalve | 11:82d8768d7351 | 1097 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1098 | temp_msg.len = 5; |
Lightvalve | 12:6f2531038ea4 | 1099 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT; |
Lightvalve | 57:f4819de54e7a | 1100 | temp_msg.data[1] = (uint8_t) VALVE_MIN_POS; |
Lightvalve | 57:f4819de54e7a | 1101 | temp_msg.data[2] = (uint8_t) (VALVE_MIN_POS >> 8); |
Lightvalve | 57:f4819de54e7a | 1102 | temp_msg.data[3] = (uint8_t) VALVE_MAX_POS; |
Lightvalve | 57:f4819de54e7a | 1103 | temp_msg.data[4] = (uint8_t) (VALVE_MAX_POS >> 8); |
Lightvalve | 11:82d8768d7351 | 1104 | |
Lightvalve | 11:82d8768d7351 | 1105 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1106 | } |
Lightvalve | 11:82d8768d7351 | 1107 | |
Lightvalve | 170:42c938a40313 | 1108 | void CAN_TX_ENC_PULSE_PER_POSITION(void) |
Lightvalve | 170:42c938a40313 | 1109 | { |
Lightvalve | 11:82d8768d7351 | 1110 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1111 | |
jobuuu | 2:a1c0a37df760 | 1112 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1113 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1114 | temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_PULSE_PER_POSITION; |
Lightvalve | 54:647072f5307a | 1115 | int temp_enc_pulse_per_position = (int) (ENC_PULSE_PER_POSITION); |
Lightvalve | 48:889798ff9329 | 1116 | temp_msg.data[1] = (uint8_t) temp_enc_pulse_per_position; |
Lightvalve | 48:889798ff9329 | 1117 | temp_msg.data[2] = (uint8_t) (temp_enc_pulse_per_position >> 8); |
jobuuu | 2:a1c0a37df760 | 1118 | |
jobuuu | 2:a1c0a37df760 | 1119 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 1120 | } |
jobuuu | 2:a1c0a37df760 | 1121 | |
Lightvalve | 170:42c938a40313 | 1122 | void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void) |
Lightvalve | 170:42c938a40313 | 1123 | { |
jobuuu | 2:a1c0a37df760 | 1124 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1125 | |
jobuuu | 2:a1c0a37df760 | 1126 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1127 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1128 | temp_msg.data[0] = (uint8_t) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE; |
Lightvalve | 240:c93d3eabff75 | 1129 | int16_t temp_torque_sensor_pulse_per_torque = (int16_t) (TORQUE_SENSOR_PULSE_PER_TORQUE * 1000.0f); |
Lightvalve | 48:889798ff9329 | 1130 | temp_msg.data[1] = (uint8_t) temp_torque_sensor_pulse_per_torque; |
Lightvalve | 48:889798ff9329 | 1131 | temp_msg.data[2] = (uint8_t) (temp_torque_sensor_pulse_per_torque >> 8); |
jobuuu | 2:a1c0a37df760 | 1132 | |
jobuuu | 2:a1c0a37df760 | 1133 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 1134 | } |
jobuuu | 2:a1c0a37df760 | 1135 | |
Lightvalve | 170:42c938a40313 | 1136 | void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void) |
Lightvalve | 170:42c938a40313 | 1137 | { |
jobuuu | 2:a1c0a37df760 | 1138 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1139 | |
jobuuu | 2:a1c0a37df760 | 1140 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1141 | temp_msg.len = 5; |
Lightvalve | 12:6f2531038ea4 | 1142 | temp_msg.data[0] = (uint8_t) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR; |
Lightvalve | 30:8d561f16383b | 1143 | temp_msg.data[1] = (uint8_t) (int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f); |
Lightvalve | 30:8d561f16383b | 1144 | temp_msg.data[2] = (uint8_t) ((int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f) >> 8); |
Lightvalve | 30:8d561f16383b | 1145 | temp_msg.data[3] = (uint8_t) (int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f); |
Lightvalve | 30:8d561f16383b | 1146 | temp_msg.data[4] = (uint8_t) ((int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f) >> 8); |
jobuuu | 2:a1c0a37df760 | 1147 | |
jobuuu | 2:a1c0a37df760 | 1148 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 1149 | } |
jobuuu | 2:a1c0a37df760 | 1150 | |
Lightvalve | 170:42c938a40313 | 1151 | void CAN_TX_FRICTION(void) |
Lightvalve | 170:42c938a40313 | 1152 | { |
Lightvalve | 11:82d8768d7351 | 1153 | CANMessage temp_msg; |
Lightvalve | 12:6f2531038ea4 | 1154 | int16_t send_friction; |
Lightvalve | 30:8d561f16383b | 1155 | send_friction = (int16_t) (FRICTION * 10.0f); |
Lightvalve | 170:42c938a40313 | 1156 | |
Lightvalve | 11:82d8768d7351 | 1157 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1158 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1159 | temp_msg.data[0] = (uint8_t) CTX_SEND_FRICTION; |
Lightvalve | 12:6f2531038ea4 | 1160 | temp_msg.data[1] = (uint8_t) send_friction; |
Lightvalve | 12:6f2531038ea4 | 1161 | temp_msg.data[2] = (uint8_t) (send_friction >> 8); |
Lightvalve | 11:82d8768d7351 | 1162 | |
Lightvalve | 11:82d8768d7351 | 1163 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1164 | } |
Lightvalve | 11:82d8768d7351 | 1165 | |
Lightvalve | 170:42c938a40313 | 1166 | void CAN_TX_VALVE_GAIN_PLUS(void) |
Lightvalve | 170:42c938a40313 | 1167 | { |
Lightvalve | 11:82d8768d7351 | 1168 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1169 | |
Lightvalve | 11:82d8768d7351 | 1170 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1171 | temp_msg.len = 6; |
Lightvalve | 12:6f2531038ea4 | 1172 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_PLUS; |
Lightvalve | 30:8d561f16383b | 1173 | temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[0] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1174 | temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[2] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1175 | temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[4] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1176 | temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[6] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1177 | temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[8] * 50.0f); |
Lightvalve | 11:82d8768d7351 | 1178 | |
Lightvalve | 11:82d8768d7351 | 1179 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1180 | } |
Lightvalve | 11:82d8768d7351 | 1181 | |
Lightvalve | 11:82d8768d7351 | 1182 | |
Lightvalve | 170:42c938a40313 | 1183 | void CAN_TX_VALVE_GAIN_MINUS(void) |
Lightvalve | 170:42c938a40313 | 1184 | { |
Lightvalve | 11:82d8768d7351 | 1185 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1186 | |
Lightvalve | 11:82d8768d7351 | 1187 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1188 | temp_msg.len = 6; |
Lightvalve | 12:6f2531038ea4 | 1189 | temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_MINUS; |
Lightvalve | 30:8d561f16383b | 1190 | temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[1] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1191 | temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[3] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1192 | temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[5] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1193 | temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[7] * 50.0f); |
Lightvalve | 30:8d561f16383b | 1194 | temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[9] * 50.0f); |
Lightvalve | 11:82d8768d7351 | 1195 | |
Lightvalve | 11:82d8768d7351 | 1196 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1197 | } |
Lightvalve | 11:82d8768d7351 | 1198 | |
Lightvalve | 170:42c938a40313 | 1199 | void CAN_TX_REFENCE_MODE(void) |
Lightvalve | 170:42c938a40313 | 1200 | { |
Lightvalve | 11:82d8768d7351 | 1201 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1202 | |
Lightvalve | 11:82d8768d7351 | 1203 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1204 | temp_msg.len = 6; |
Lightvalve | 12:6f2531038ea4 | 1205 | temp_msg.data[0] = (uint8_t) CTX_SEND_REFENCE_MODE; |
Lightvalve | 12:6f2531038ea4 | 1206 | temp_msg.data[1] = (uint8_t) REFERENCE_MODE; |
Lightvalve | 30:8d561f16383b | 1207 | temp_msg.data[2] = (uint8_t) (int) (REFERENCE_FREQ * 100.0f); |
Lightvalve | 30:8d561f16383b | 1208 | temp_msg.data[3] = (uint8_t) ((int) (REFERENCE_FREQ * 100.0f) >> 8); |
Lightvalve | 30:8d561f16383b | 1209 | temp_msg.data[4] = (uint8_t) (int) (REFERENCE_MAG * 100.0f); |
Lightvalve | 30:8d561f16383b | 1210 | temp_msg.data[5] = (uint8_t) ((int) (REFERENCE_MAG * 100.0f) >> 8); |
Lightvalve | 11:82d8768d7351 | 1211 | |
Lightvalve | 11:82d8768d7351 | 1212 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1213 | } |
Lightvalve | 11:82d8768d7351 | 1214 | |
Lightvalve | 170:42c938a40313 | 1215 | void CAN_TX_HOMEPOS_OFFSET(void) |
Lightvalve | 170:42c938a40313 | 1216 | { |
Lightvalve | 11:82d8768d7351 | 1217 | CANMessage temp_msg; |
Lightvalve | 12:6f2531038ea4 | 1218 | int16_t send_homepos_offset; |
hyhoon | 226:82a3ca333004 | 1219 | send_homepos_offset = (int16_t)HOMEPOS_OFFSET; |
Lightvalve | 170:42c938a40313 | 1220 | |
jobuuu | 2:a1c0a37df760 | 1221 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1222 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1223 | temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_OFFSET; |
Lightvalve | 12:6f2531038ea4 | 1224 | temp_msg.data[1] = (uint8_t) send_homepos_offset; |
Lightvalve | 12:6f2531038ea4 | 1225 | temp_msg.data[2] = (uint8_t) (send_homepos_offset >> 8); |
jobuuu | 2:a1c0a37df760 | 1226 | |
jobuuu | 2:a1c0a37df760 | 1227 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 1228 | } |
Lightvalve | 11:82d8768d7351 | 1229 | |
Lightvalve | 170:42c938a40313 | 1230 | void CAN_TX_HOMPOS_VALVE_OPENING(void) |
Lightvalve | 170:42c938a40313 | 1231 | { |
Lightvalve | 11:82d8768d7351 | 1232 | CANMessage temp_msg; |
Lightvalve | 12:6f2531038ea4 | 1233 | int16_t send_homepos_valve_opening; |
Lightvalve | 12:6f2531038ea4 | 1234 | send_homepos_valve_opening = (int16_t) (HOMEPOS_VALVE_OPENING); |
Lightvalve | 170:42c938a40313 | 1235 | |
Lightvalve | 11:82d8768d7351 | 1236 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1237 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1238 | temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_VALVE_OPENING; |
Lightvalve | 12:6f2531038ea4 | 1239 | temp_msg.data[1] = (uint8_t) send_homepos_valve_opening; |
Lightvalve | 12:6f2531038ea4 | 1240 | temp_msg.data[2] = (uint8_t) (send_homepos_valve_opening >> 8); |
Lightvalve | 11:82d8768d7351 | 1241 | |
Lightvalve | 11:82d8768d7351 | 1242 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1243 | } |
Lightvalve | 11:82d8768d7351 | 1244 | |
Lightvalve | 170:42c938a40313 | 1245 | void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex) |
Lightvalve | 170:42c938a40313 | 1246 | { |
Lightvalve | 11:82d8768d7351 | 1247 | CANMessage temp_msg; |
Lightvalve | 11:82d8768d7351 | 1248 | int16_t valve_pos_vs_pwm; |
Lightvalve | 170:42c938a40313 | 1249 | |
Lightvalve | 237:c2cfe349f5c1 | 1250 | if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_ELECTRIC_CENTER) { |
Lightvalve | 237:c2cfe349f5c1 | 1251 | valve_pos_vs_pwm = 10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_ELECTRIC_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_ELECTRIC_CENTER); |
Lightvalve | 49:e7bcfc244d40 | 1252 | } else { |
Lightvalve | 237:c2cfe349f5c1 | 1253 | valve_pos_vs_pwm = -10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_ELECTRIC_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_ELECTRIC_CENTER); |
Lightvalve | 49:e7bcfc244d40 | 1254 | } |
Lightvalve | 170:42c938a40313 | 1255 | |
Lightvalve | 12:6f2531038ea4 | 1256 | int16_t PWM_VALVE_ID; |
Lightvalve | 12:6f2531038ea4 | 1257 | PWM_VALVE_ID = ID_index_array[canindex] * 1000; |
Lightvalve | 170:42c938a40313 | 1258 | |
Lightvalve | 11:82d8768d7351 | 1259 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1260 | temp_msg.len = 5; |
Lightvalve | 12:6f2531038ea4 | 1261 | temp_msg.data[0] = (uint8_t) CTX_VALVE_PWM_VS_VALVE_POS; |
Lightvalve | 12:6f2531038ea4 | 1262 | temp_msg.data[1] = (uint8_t) PWM_VALVE_ID; |
Lightvalve | 12:6f2531038ea4 | 1263 | temp_msg.data[2] = (uint8_t) (PWM_VALVE_ID >> 8); |
Lightvalve | 12:6f2531038ea4 | 1264 | temp_msg.data[3] = (uint8_t) valve_pos_vs_pwm; |
Lightvalve | 12:6f2531038ea4 | 1265 | temp_msg.data[4] = (uint8_t) (valve_pos_vs_pwm >> 8); |
Lightvalve | 11:82d8768d7351 | 1266 | |
Lightvalve | 11:82d8768d7351 | 1267 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1268 | } |
Lightvalve | 11:82d8768d7351 | 1269 | |
Lightvalve | 170:42c938a40313 | 1270 | void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex) |
Lightvalve | 170:42c938a40313 | 1271 | { |
Lightvalve | 11:82d8768d7351 | 1272 | CANMessage temp_msg; |
Lightvalve | 11:82d8768d7351 | 1273 | int32_t valve_pos_vs_flowrate; |
Lightvalve | 11:82d8768d7351 | 1274 | valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]); |
Lightvalve | 11:82d8768d7351 | 1275 | |
Lightvalve | 57:f4819de54e7a | 1276 | int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + VALVE_CENTER; |
Lightvalve | 49:e7bcfc244d40 | 1277 | int16_t temp_valve_pos = 0; |
Lightvalve | 57:f4819de54e7a | 1278 | if(VALVE_POS_VALVE_ID>=VALVE_CENTER) { |
Lightvalve | 57:f4819de54e7a | 1279 | temp_valve_pos = (int16_t) (10000.0f*((double)VALVE_POS_VALVE_ID-(double)VALVE_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_CENTER)); |
Lightvalve | 49:e7bcfc244d40 | 1280 | } else { |
Lightvalve | 57:f4819de54e7a | 1281 | temp_valve_pos = (int16_t) (-10000.0f*((double)VALVE_POS_VALVE_ID-(double)VALVE_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_CENTER)); |
Lightvalve | 49:e7bcfc244d40 | 1282 | } |
Lightvalve | 170:42c938a40313 | 1283 | |
Lightvalve | 11:82d8768d7351 | 1284 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1285 | temp_msg.len = 7; |
Lightvalve | 12:6f2531038ea4 | 1286 | temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_VS_FLOWRATE; |
Lightvalve | 49:e7bcfc244d40 | 1287 | temp_msg.data[1] = (uint8_t) temp_valve_pos; |
Lightvalve | 49:e7bcfc244d40 | 1288 | temp_msg.data[2] = (uint8_t) (temp_valve_pos >> 8); |
jeongyeseong | 225:9c0becc196ba | 1289 | temp_msg.data[3] = (uint8_t) valve_pos_vs_flowrate; |
jeongyeseong | 225:9c0becc196ba | 1290 | temp_msg.data[4] = (uint8_t) (valve_pos_vs_flowrate >> 8); |
jeongyeseong | 225:9c0becc196ba | 1291 | temp_msg.data[5] = (uint8_t) (valve_pos_vs_flowrate >> 16); |
jeongyeseong | 225:9c0becc196ba | 1292 | temp_msg.data[6] = (uint8_t) (valve_pos_vs_flowrate >> 24); |
Lightvalve | 11:82d8768d7351 | 1293 | |
Lightvalve | 11:82d8768d7351 | 1294 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1295 | } |
Lightvalve | 11:82d8768d7351 | 1296 | |
Lightvalve | 170:42c938a40313 | 1297 | void CAN_TX_VALVE_POS_NUM(void) |
Lightvalve | 170:42c938a40313 | 1298 | { |
Lightvalve | 11:82d8768d7351 | 1299 | CANMessage temp_msg; |
Lightvalve | 11:82d8768d7351 | 1300 | int32_t valve_pos_num; |
Lightvalve | 11:82d8768d7351 | 1301 | valve_pos_num = (int16_t) VALVE_POS_NUM; |
Lightvalve | 170:42c938a40313 | 1302 | |
Lightvalve | 11:82d8768d7351 | 1303 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1304 | temp_msg.len = 3; |
Lightvalve | 12:6f2531038ea4 | 1305 | temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_NUM; |
Lightvalve | 12:6f2531038ea4 | 1306 | temp_msg.data[1] = (uint8_t) valve_pos_num; |
Lightvalve | 12:6f2531038ea4 | 1307 | temp_msg.data[2] = (uint8_t) (valve_pos_num >> 8); |
Lightvalve | 11:82d8768d7351 | 1308 | |
Lightvalve | 11:82d8768d7351 | 1309 | can.write(temp_msg); |
Lightvalve | 11:82d8768d7351 | 1310 | } |
Lightvalve | 11:82d8768d7351 | 1311 | |
Lightvalve | 170:42c938a40313 | 1312 | void CAN_TX_DDV_VALVE_MAX_MIN_POS(void) |
Lightvalve | 170:42c938a40313 | 1313 | { |
Lightvalve | 38:118df027d851 | 1314 | CANMessage temp_msg; |
Lightvalve | 170:42c938a40313 | 1315 | |
Lightvalve | 48:889798ff9329 | 1316 | float temp_valve_max_pos = 0.0f; |
Lightvalve | 48:889798ff9329 | 1317 | float temp_valve_min_pos = 0.0f; |
Lightvalve | 48:889798ff9329 | 1318 | float temp_ddv_center = 0.0f; |
Lightvalve | 170:42c938a40313 | 1319 | |
Lightvalve | 57:f4819de54e7a | 1320 | temp_valve_max_pos = VALVE_MAX_POS; |
Lightvalve | 57:f4819de54e7a | 1321 | temp_valve_min_pos = VALVE_MIN_POS; |
Lightvalve | 57:f4819de54e7a | 1322 | temp_ddv_center = VALVE_CENTER; |
Lightvalve | 170:42c938a40313 | 1323 | |
Lightvalve | 38:118df027d851 | 1324 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1325 | temp_msg.len = 7; |
Lightvalve | 38:118df027d851 | 1326 | temp_msg.data[0] = (uint8_t) CTX_VALVE_MAX_MIN_POS; |
Lightvalve | 48:889798ff9329 | 1327 | temp_msg.data[1] = (uint8_t) temp_valve_max_pos; |
Lightvalve | 48:889798ff9329 | 1328 | temp_msg.data[2] = (uint8_t) ((int) (temp_valve_max_pos) >> 8); |
Lightvalve | 48:889798ff9329 | 1329 | temp_msg.data[3] = (uint8_t) (temp_valve_min_pos); |
Lightvalve | 48:889798ff9329 | 1330 | temp_msg.data[4] = (uint8_t) ((int) (temp_valve_min_pos) >> 8); |
Lightvalve | 48:889798ff9329 | 1331 | temp_msg.data[5] = (uint8_t) (temp_ddv_center); |
Lightvalve | 48:889798ff9329 | 1332 | temp_msg.data[6] = (uint8_t) ((int) (temp_ddv_center) >> 8); |
Lightvalve | 38:118df027d851 | 1333 | |
Lightvalve | 38:118df027d851 | 1334 | can.write(temp_msg); |
Lightvalve | 38:118df027d851 | 1335 | } |
Lightvalve | 38:118df027d851 | 1336 | |
Lightvalve | 169:645207e160ca | 1337 | |
Lightvalve | 170:42c938a40313 | 1338 | void CAN_TX_BUFFER(int16_t t_cnt_buffer) |
Lightvalve | 170:42c938a40313 | 1339 | { |
Lightvalve | 169:645207e160ca | 1340 | CANMessage temp_msg; |
Lightvalve | 169:645207e160ca | 1341 | int16_t send_pos_array, send_ref_array; |
Lightvalve | 169:645207e160ca | 1342 | send_pos_array = (int16_t) (pos_array[t_cnt_buffer]); |
Lightvalve | 169:645207e160ca | 1343 | send_ref_array = (int16_t) (ref_array[t_cnt_buffer]); |
Lightvalve | 170:42c938a40313 | 1344 | |
Lightvalve | 169:645207e160ca | 1345 | temp_msg.id = CID_TX_INFO; |
hyhoon | 226:82a3ca333004 | 1346 | temp_msg.len = 5; |
Lightvalve | 169:645207e160ca | 1347 | temp_msg.data[0] = (uint8_t) CTX_SEND_BUFFER; |
Lightvalve | 169:645207e160ca | 1348 | temp_msg.data[1] = (uint8_t) send_pos_array; |
Lightvalve | 169:645207e160ca | 1349 | temp_msg.data[2] = (uint8_t) (send_pos_array >> 8); |
Lightvalve | 169:645207e160ca | 1350 | temp_msg.data[3] = (uint8_t) (send_ref_array); |
Lightvalve | 169:645207e160ca | 1351 | temp_msg.data[4] = (uint8_t) ((send_ref_array) >> 8); |
Lightvalve | 169:645207e160ca | 1352 | |
Lightvalve | 169:645207e160ca | 1353 | can.write(temp_msg); |
Lightvalve | 169:645207e160ca | 1354 | } |
Lightvalve | 169:645207e160ca | 1355 | |
Lightvalve | 169:645207e160ca | 1356 | |
jobuuu | 2:a1c0a37df760 | 1357 | /****************************************************************************** |
jobuuu | 2:a1c0a37df760 | 1358 | Sensor & State Transmission Functions |
jobuuu | 2:a1c0a37df760 | 1359 | *******************************************************************************/ |
jobuuu | 2:a1c0a37df760 | 1360 | |
Lightvalve | 170:42c938a40313 | 1361 | void CAN_TX_POSITION_FT(int16_t t_pos, int16_t t_vel, int16_t t_torq) |
Lightvalve | 170:42c938a40313 | 1362 | { |
Lightvalve | 52:8ea76864368a | 1363 | CANMessage temp_msg; |
Lightvalve | 52:8ea76864368a | 1364 | |
hyhoon | 227:699c3e572283 | 1365 | temp_msg.id = CID_TX_POS_VEL_TORQ; |
hyhoon | 226:82a3ca333004 | 1366 | temp_msg.len = 6; |
Lightvalve | 52:8ea76864368a | 1367 | temp_msg.data[0] = (uint8_t) t_pos; |
Lightvalve | 52:8ea76864368a | 1368 | temp_msg.data[1] = (uint8_t) (t_pos >> 8); |
Lightvalve | 52:8ea76864368a | 1369 | temp_msg.data[2] = (uint8_t) t_vel; |
Lightvalve | 52:8ea76864368a | 1370 | temp_msg.data[3] = (uint8_t) (t_vel >> 8); |
Lightvalve | 52:8ea76864368a | 1371 | temp_msg.data[4] = (uint8_t) t_torq; |
Lightvalve | 52:8ea76864368a | 1372 | temp_msg.data[5] = (uint8_t) (t_torq >> 8); |
Lightvalve | 52:8ea76864368a | 1373 | |
Lightvalve | 52:8ea76864368a | 1374 | can.write(temp_msg); |
Lightvalve | 52:8ea76864368a | 1375 | } |
Lightvalve | 52:8ea76864368a | 1376 | |
Lightvalve | 170:42c938a40313 | 1377 | void CAN_TX_POSITION_PRESSURE(int16_t t_pos, int16_t t_vel, int16_t t_pa, int16_t t_pb) |
Lightvalve | 170:42c938a40313 | 1378 | { |
Lightvalve | 170:42c938a40313 | 1379 | |
jobuuu | 2:a1c0a37df760 | 1380 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 1381 | |
hyhoon | 227:699c3e572283 | 1382 | temp_msg.id = CID_TX_POS_VEL_TORQ; |
jobuuu | 2:a1c0a37df760 | 1383 | temp_msg.len = 8; |
Lightvalve | 12:6f2531038ea4 | 1384 | temp_msg.data[0] = (uint8_t) t_pos; |
Lightvalve | 12:6f2531038ea4 | 1385 | temp_msg.data[1] = (uint8_t) (t_pos >> 8); |
Lightvalve | 41:abbd4e2af68b | 1386 | temp_msg.data[2] = (uint8_t) t_vel; |
Lightvalve | 41:abbd4e2af68b | 1387 | temp_msg.data[3] = (uint8_t) (t_vel >> 8); |
Lightvalve | 52:8ea76864368a | 1388 | temp_msg.data[4] = (uint8_t) t_pa; |
Lightvalve | 52:8ea76864368a | 1389 | temp_msg.data[5] = (uint8_t) (t_pa >> 8); |
Lightvalve | 52:8ea76864368a | 1390 | temp_msg.data[6] = (uint8_t) t_pb; |
Lightvalve | 52:8ea76864368a | 1391 | temp_msg.data[7] = (uint8_t) (t_pb >> 8); |
jobuuu | 2:a1c0a37df760 | 1392 | |
jobuuu | 2:a1c0a37df760 | 1393 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 1394 | } |
jobuuu | 2:a1c0a37df760 | 1395 | |
hyhoon | 227:699c3e572283 | 1396 | void CAN_TX_CURRENT(int16_t t_pres_a, int16_t t_pres_b) |
Lightvalve | 170:42c938a40313 | 1397 | { |
jobuuu | 2:a1c0a37df760 | 1398 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 1399 | |
hyhoon | 227:699c3e572283 | 1400 | temp_msg.id = CID_TX_CURRENT; |
hyhoon | 226:82a3ca333004 | 1401 | temp_msg.len = 4; |
Lightvalve | 12:6f2531038ea4 | 1402 | temp_msg.data[0] = (uint8_t) t_pres_a; |
Lightvalve | 12:6f2531038ea4 | 1403 | temp_msg.data[1] = (uint8_t) (t_pres_a >> 8); |
Lightvalve | 12:6f2531038ea4 | 1404 | temp_msg.data[2] = (uint8_t) t_pres_b; |
Lightvalve | 12:6f2531038ea4 | 1405 | temp_msg.data[3] = (uint8_t) (t_pres_b >> 8); |
jobuuu | 2:a1c0a37df760 | 1406 | |
jobuuu | 2:a1c0a37df760 | 1407 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 1408 | } |
jobuuu | 2:a1c0a37df760 | 1409 | |
Lightvalve | 237:c2cfe349f5c1 | 1410 | void CAN_TX_TORQUE(int16_t t_valve_pos) |
Lightvalve | 237:c2cfe349f5c1 | 1411 | { |
Lightvalve | 237:c2cfe349f5c1 | 1412 | CANMessage temp_msg; |
Lightvalve | 237:c2cfe349f5c1 | 1413 | |
Lightvalve | 237:c2cfe349f5c1 | 1414 | temp_msg.id = CID_TX_PWM; |
Lightvalve | 237:c2cfe349f5c1 | 1415 | temp_msg.len = 2; |
Lightvalve | 237:c2cfe349f5c1 | 1416 | temp_msg.data[0] = (uint8_t) t_valve_pos; |
Lightvalve | 237:c2cfe349f5c1 | 1417 | temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8); |
Lightvalve | 237:c2cfe349f5c1 | 1418 | |
Lightvalve | 237:c2cfe349f5c1 | 1419 | can.write(temp_msg); |
Lightvalve | 237:c2cfe349f5c1 | 1420 | } |
Lightvalve | 237:c2cfe349f5c1 | 1421 | |
Lightvalve | 170:42c938a40313 | 1422 | void CAN_TX_PWM(int16_t t_pwm) |
Lightvalve | 170:42c938a40313 | 1423 | { |
jobuuu | 2:a1c0a37df760 | 1424 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 1425 | |
hyhoon | 227:699c3e572283 | 1426 | temp_msg.id = CID_TX_PWM; |
hyhoon | 226:82a3ca333004 | 1427 | temp_msg.len = 2; |
Lightvalve | 12:6f2531038ea4 | 1428 | temp_msg.data[0] = (uint8_t) t_pwm; |
Lightvalve | 12:6f2531038ea4 | 1429 | temp_msg.data[1] = (uint8_t) (t_pwm >> 8); |
jobuuu | 2:a1c0a37df760 | 1430 | |
jobuuu | 2:a1c0a37df760 | 1431 | can.write(temp_msg); |
jobuuu | 2:a1c0a37df760 | 1432 | } |
jobuuu | 2:a1c0a37df760 | 1433 | |
Lightvalve | 73:f80dc3970c99 | 1434 | void CAN_TX_VALVE_POSITION(int16_t t_valve_pos_1, int16_t t_valve_pos_2, int16_t t_ref_valve_pos, int16_t t_pwm) |
Lightvalve | 27:a2254a485f23 | 1435 | { |
jobuuu | 2:a1c0a37df760 | 1436 | CANMessage temp_msg; |
jobuuu | 2:a1c0a37df760 | 1437 | |
jobuuu | 2:a1c0a37df760 | 1438 | temp_msg.id = CID_TX_VALVE_POSITION; |
Lightvalve | 73:f80dc3970c99 | 1439 | temp_msg.len = 8; |
Lightvalve | 73:f80dc3970c99 | 1440 | temp_msg.data[0] = (uint8_t) t_valve_pos_1; |
Lightvalve | 73:f80dc3970c99 | 1441 | temp_msg.data[1] = (uint8_t) (t_valve_pos_1 >> 8); |
Lightvalve | 73:f80dc3970c99 | 1442 | temp_msg.data[2] = (uint8_t) t_valve_pos_2; |
Lightvalve | 73:f80dc3970c99 | 1443 | temp_msg.data[3] = (uint8_t) (t_valve_pos_2 >> 8); |
Lightvalve | 73:f80dc3970c99 | 1444 | temp_msg.data[4] = (uint8_t) t_ref_valve_pos; |
Lightvalve | 73:f80dc3970c99 | 1445 | temp_msg.data[5] = (uint8_t) (t_ref_valve_pos >> 8); |
Lightvalve | 73:f80dc3970c99 | 1446 | temp_msg.data[6] = (uint8_t) t_pwm; |
Lightvalve | 73:f80dc3970c99 | 1447 | temp_msg.data[7] = (uint8_t) (t_pwm >> 8); |
Lightvalve | 170:42c938a40313 | 1448 | |
jobuuu | 2:a1c0a37df760 | 1449 | |
jobuuu | 2:a1c0a37df760 | 1450 | can.write(temp_msg); |
jeongyeseong | 225:9c0becc196ba | 1451 | } |
jeongyeseong | 225:9c0becc196ba | 1452 | |
jeongyeseong | 225:9c0becc196ba | 1453 | void CAN_TX_SOMETHING(int16_t t_a, int16_t t_b, int16_t t_c, int16_t t_d) |
jeongyeseong | 225:9c0becc196ba | 1454 | { |
jeongyeseong | 225:9c0becc196ba | 1455 | CANMessage temp_msg; |
jeongyeseong | 225:9c0becc196ba | 1456 | |
jeongyeseong | 225:9c0becc196ba | 1457 | temp_msg.id = CID_TX_SOMETHING; |
jeongyeseong | 225:9c0becc196ba | 1458 | temp_msg.len = 8; |
jeongyeseong | 225:9c0becc196ba | 1459 | temp_msg.data[0] = (uint8_t) t_a; |
jeongyeseong | 225:9c0becc196ba | 1460 | temp_msg.data[1] = (uint8_t) (t_a >> 8); |
jeongyeseong | 225:9c0becc196ba | 1461 | temp_msg.data[2] = (uint8_t) t_b; |
jeongyeseong | 225:9c0becc196ba | 1462 | temp_msg.data[3] = (uint8_t) (t_b >> 8); |
jeongyeseong | 225:9c0becc196ba | 1463 | temp_msg.data[4] = (uint8_t) t_c; |
jeongyeseong | 225:9c0becc196ba | 1464 | temp_msg.data[5] = (uint8_t) (t_c >> 8); |
jeongyeseong | 225:9c0becc196ba | 1465 | temp_msg.data[6] = (uint8_t) t_d; |
jeongyeseong | 225:9c0becc196ba | 1466 | temp_msg.data[7] = (uint8_t) (t_d >> 8); |
jeongyeseong | 225:9c0becc196ba | 1467 | |
jeongyeseong | 225:9c0becc196ba | 1468 | |
jeongyeseong | 225:9c0becc196ba | 1469 | can.write(temp_msg); |
Lightvalve | 237:c2cfe349f5c1 | 1470 | } |
Lightvalve | 237:c2cfe349f5c1 | 1471 | |
Lightvalve | 237:c2cfe349f5c1 | 1472 | void CAN_TX_VOUT(int16_t t_vout) |
Lightvalve | 237:c2cfe349f5c1 | 1473 | { |
Lightvalve | 237:c2cfe349f5c1 | 1474 | CANMessage temp_msg; |
Lightvalve | 237:c2cfe349f5c1 | 1475 | |
Lightvalve | 237:c2cfe349f5c1 | 1476 | temp_msg.id = CID_TX_VOUT; |
Lightvalve | 237:c2cfe349f5c1 | 1477 | temp_msg.len = 2; |
Lightvalve | 237:c2cfe349f5c1 | 1478 | temp_msg.data[0] = (uint8_t) t_vout; |
Lightvalve | 237:c2cfe349f5c1 | 1479 | temp_msg.data[1] = (uint8_t) (t_vout >> 8); |
Lightvalve | 237:c2cfe349f5c1 | 1480 | |
Lightvalve | 237:c2cfe349f5c1 | 1481 | can.write(temp_msg); |
Lightvalve | 67:c2812cf26c38 | 1482 | } |