2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Wed Jul 06 08:08:15 2022 +0000
Revision:
251:a08f301231f1
Parent:
250:91d3ec3a087e
220706

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