2011

Dependencies:   mbed FastPWM

Committer:
jeongyeseong
Date:
Thu Feb 04 05:43:47 2021 +0000
Revision:
225:9c0becc196ba
Parent:
224:985dba42f261
Child:
226:82a3ca333004
20210204

Who changed what in which revision?

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