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