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