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