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