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