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