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