rainbow

Dependencies:   mbed FastPWM

Committer:
hyhoon
Date:
Wed Mar 03 10:56:25 2021 +0000
Revision:
226:82a3ca333004
Parent:
225:9c0becc196ba
Child:
227:699c3e572283
20210305;

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