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