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