2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Fri Jun 17 06:06:53 2022 +0000
Revision:
244:e9c5ec04e378
Parent:
243:30896263bd8b
Child:
247:bfdf0f479a38
220617

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
jobuuu 230:2c3e5ecbe7e1 730 valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~10000)
Lightvalve 57:f4819de54e7a 731 } else if (((OPERATING_MODE&0b110)>>1) == 1) { //KNR Valve
jobuuu 230:2c3e5ecbe7e1 732 valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~30000)
Lightvalve 57:f4819de54e7a 733 } else { //SW Valve
Lightvalve 57:f4819de54e7a 734 if(temp_ref_valve_pos >= 0) {
Lightvalve 238:4e660aa77eb7 735 // valve_pos.ref = (double)VALVE_ELECTRIC_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_ELECTRIC_CENTER)/10000.0f;
Lightvalve 238:4e660aa77eb7 736 valve_pos.ref = (double)temp_ref_valve_pos; // -10000~10000
Lightvalve 57:f4819de54e7a 737 } else {
Lightvalve 238:4e660aa77eb7 738 // valve_pos.ref = (double)VALVE_ELECTRIC_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_ELECTRIC_CENTER)/10000.0f;
Lightvalve 238:4e660aa77eb7 739 valve_pos.ref = (double)temp_ref_valve_pos; // -10000~10000
Lightvalve 57:f4819de54e7a 740 }
Lightvalve 47:fdcb8bd86fd6 741 }
Lightvalve 170:42c938a40313 742 } else if(address==CID_RX_REF_PWM) {
Lightvalve 49:e7bcfc244d40 743 int temp_ref_pwm = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 49:e7bcfc244d40 744 Vout.ref = (double) temp_ref_pwm;
Lightvalve 170:42c938a40313 745 }
jeongyeseong 225:9c0becc196ba 746
jobuuu 2:a1c0a37df760 747 }
jobuuu 2:a1c0a37df760 748
jobuuu 2:a1c0a37df760 749 /******************************************************************************
jobuuu 2:a1c0a37df760 750 Information Transmission Functions
jobuuu 2:a1c0a37df760 751 *******************************************************************************/
Lightvalve 11:82d8768d7351 752
Lightvalve 170:42c938a40313 753 void CAN_TX_INFO(void)
Lightvalve 170:42c938a40313 754 {
Lightvalve 12:6f2531038ea4 755 CANMessage temp_msg;
Lightvalve 170:42c938a40313 756
jobuuu 2:a1c0a37df760 757 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 758 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 759 temp_msg.data[0] = (uint8_t) CTX_SEND_INFO;
Lightvalve 12:6f2531038ea4 760 temp_msg.data[1] = (uint8_t) BNO;
Lightvalve 12:6f2531038ea4 761 temp_msg.data[2] = (uint8_t) CAN_FREQ;
Lightvalve 12:6f2531038ea4 762 temp_msg.data[3] = (uint8_t) (CAN_FREQ >> 8);
Lightvalve 12:6f2531038ea4 763 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 764 temp_msg.data[5] = (uint8_t) CONTROL_UTILITY_MODE;
Lightvalve 12:6f2531038ea4 765 temp_msg.data[6] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 766
jobuuu 2:a1c0a37df760 767 can.write(temp_msg);
jobuuu 2:a1c0a37df760 768 }
jobuuu 2:a1c0a37df760 769
Lightvalve 170:42c938a40313 770 void CAN_TX_BNO(void)
Lightvalve 170:42c938a40313 771 {
Lightvalve 12:6f2531038ea4 772 CANMessage temp_msg;
Lightvalve 170:42c938a40313 773
jobuuu 2:a1c0a37df760 774 temp_msg.id = CID_TX_INFO;
jeongyeseong 225:9c0becc196ba 775 //temp_msg.len = 2;
hyhoon 226:82a3ca333004 776 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 777 temp_msg.data[0] = (uint8_t) CTX_SEND_BNO;
Lightvalve 12:6f2531038ea4 778 temp_msg.data[1] = (uint8_t) BNO;
jobuuu 2:a1c0a37df760 779
jobuuu 2:a1c0a37df760 780 can.write(temp_msg);
jobuuu 2:a1c0a37df760 781 }
jobuuu 2:a1c0a37df760 782
Lightvalve 170:42c938a40313 783 void CAN_TX_OPERATING_MODE(void)
Lightvalve 170:42c938a40313 784 {
jobuuu 2:a1c0a37df760 785 CANMessage temp_msg;
Lightvalve 170:42c938a40313 786
jobuuu 2:a1c0a37df760 787 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 788 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 789 temp_msg.data[0] = (uint8_t) CTX_SEND_OPERATING_MODE;
Lightvalve 12:6f2531038ea4 790 temp_msg.data[1] = (uint8_t) OPERATING_MODE;
Lightvalve 52:8ea76864368a 791 temp_msg.data[2] = (uint8_t) SENSING_MODE;
Lightvalve 52:8ea76864368a 792 temp_msg.data[3] = (uint8_t) CURRENT_CONTROL_MODE;
Lightvalve 52:8ea76864368a 793 temp_msg.data[4] = (uint8_t) FLAG_VALVE_DEADZONE;
jobuuu 2:a1c0a37df760 794
jobuuu 2:a1c0a37df760 795 can.write(temp_msg);
jobuuu 2:a1c0a37df760 796 }
jobuuu 2:a1c0a37df760 797
Lightvalve 170:42c938a40313 798 void CAN_TX_CAN_FREQ(void)
Lightvalve 170:42c938a40313 799 {
jobuuu 2:a1c0a37df760 800 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 801
jobuuu 2:a1c0a37df760 802 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 803 temp_msg.len = 3;
jobuuu 2:a1c0a37df760 804 temp_msg.data[0] = (uint8_t) CTX_SEND_CAN_FREQ;
jobuuu 2:a1c0a37df760 805 temp_msg.data[1] = (uint8_t) CAN_FREQ;
jobuuu 2:a1c0a37df760 806 temp_msg.data[2] = (uint8_t) (CAN_FREQ >> 8);
jobuuu 2:a1c0a37df760 807
jobuuu 2:a1c0a37df760 808 can.write(temp_msg);
jobuuu 2:a1c0a37df760 809 }
Lightvalve 11:82d8768d7351 810
Lightvalve 170:42c938a40313 811 void CAN_TX_CONTROL_MODE(void)
Lightvalve 170:42c938a40313 812 {
jobuuu 2:a1c0a37df760 813 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 814
jobuuu 2:a1c0a37df760 815 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 816 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 817 temp_msg.data[0] = (uint8_t) CTX_SEND_CONTROL_MODE;
Lightvalve 57:f4819de54e7a 818 temp_msg.data[1] = (uint8_t) CONTROL_UTILITY_MODE;
jobuuu 2:a1c0a37df760 819
jobuuu 2:a1c0a37df760 820 can.write(temp_msg);
jobuuu 2:a1c0a37df760 821 }
Lightvalve 11:82d8768d7351 822
Lightvalve 170:42c938a40313 823 void CAN_TX_JOINT_ENC_DIR(void)
Lightvalve 170:42c938a40313 824 {
jobuuu 2:a1c0a37df760 825 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 826
jobuuu 2:a1c0a37df760 827 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 828 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 829 temp_msg.data[0] = (uint8_t) CTX_SEND_JOINT_ENC_DIR;
Lightvalve 12:6f2531038ea4 830 temp_msg.data[1] = (uint8_t) DIR_JOINT_ENC;
Lightvalve 12:6f2531038ea4 831 temp_msg.data[2] = (uint8_t) (DIR_JOINT_ENC >> 8);
jobuuu 2:a1c0a37df760 832
jobuuu 2:a1c0a37df760 833 can.write(temp_msg);
jobuuu 2:a1c0a37df760 834 }
jobuuu 2:a1c0a37df760 835
Lightvalve 170:42c938a40313 836 void CAN_TX_VALVE_DIR(void)
Lightvalve 170:42c938a40313 837 {
jobuuu 2:a1c0a37df760 838 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 839
jobuuu 2:a1c0a37df760 840 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 841 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 842 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DIR;
Lightvalve 12:6f2531038ea4 843 temp_msg.data[1] = (uint8_t) DIR_VALVE;
Lightvalve 12:6f2531038ea4 844 temp_msg.data[2] = (uint8_t) (DIR_VALVE >> 8);
jobuuu 2:a1c0a37df760 845
jobuuu 2:a1c0a37df760 846 can.write(temp_msg);
jobuuu 2:a1c0a37df760 847 }
jobuuu 2:a1c0a37df760 848
Lightvalve 170:42c938a40313 849 void CAN_TX_VALVE_ENC_DIR(void)
Lightvalve 170:42c938a40313 850 {
jobuuu 2:a1c0a37df760 851 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 852
jobuuu 2:a1c0a37df760 853 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 854 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 855 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ENC_DIR;
Lightvalve 12:6f2531038ea4 856 temp_msg.data[1] = (uint8_t) DIR_VALVE_ENC;
Lightvalve 12:6f2531038ea4 857 temp_msg.data[2] = (uint8_t) (DIR_VALVE_ENC >> 8);
jobuuu 2:a1c0a37df760 858
jobuuu 2:a1c0a37df760 859 can.write(temp_msg);
jobuuu 2:a1c0a37df760 860 }
jobuuu 2:a1c0a37df760 861
Lightvalve 170:42c938a40313 862 void CAN_TX_VOLTAGE_SUPPLY(void)
Lightvalve 170:42c938a40313 863 {
Lightvalve 49:e7bcfc244d40 864 int16_t send_voltage_supply = (int16_t) (SUPPLY_VOLTAGE * 10.0f);
jobuuu 2:a1c0a37df760 865
jobuuu 2:a1c0a37df760 866 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 867
jobuuu 2:a1c0a37df760 868 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 869 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 870 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_SUPPLY;
Lightvalve 12:6f2531038ea4 871 temp_msg.data[1] = (uint8_t) (send_voltage_supply);
Lightvalve 12:6f2531038ea4 872 temp_msg.data[2] = (uint8_t) (send_voltage_supply >> 8);
jobuuu 2:a1c0a37df760 873
jobuuu 2:a1c0a37df760 874 can.write(temp_msg);
jobuuu 2:a1c0a37df760 875 }
jobuuu 2:a1c0a37df760 876
Lightvalve 170:42c938a40313 877 void CAN_TX_VOLTAGE_VALVE(void)
Lightvalve 170:42c938a40313 878 {
Lightvalve 49:e7bcfc244d40 879 int16_t send_voltage_valve = (int16_t) (VALVE_VOLTAGE_LIMIT * 10.0f);
jobuuu 2:a1c0a37df760 880
jobuuu 2:a1c0a37df760 881 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 882
jobuuu 2:a1c0a37df760 883 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 884 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 885 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_VALVE;
Lightvalve 12:6f2531038ea4 886 temp_msg.data[1] = (uint8_t) send_voltage_valve;
Lightvalve 12:6f2531038ea4 887 temp_msg.data[2] = (uint8_t) (send_voltage_valve >> 8);
jobuuu 2:a1c0a37df760 888
jobuuu 2:a1c0a37df760 889 can.write(temp_msg);
jobuuu 2:a1c0a37df760 890 }
Lightvalve 11:82d8768d7351 891
jobuuu 230:2c3e5ecbe7e1 892 void CAN_TX_VARIABLE_SUPPLY_ONOFF(void)
jobuuu 230:2c3e5ecbe7e1 893 {
jobuuu 230:2c3e5ecbe7e1 894 CANMessage temp_msg;
jobuuu 230:2c3e5ecbe7e1 895 temp_msg.id = CID_TX_INFO;
jobuuu 230:2c3e5ecbe7e1 896 temp_msg.len = 2;
jobuuu 230:2c3e5ecbe7e1 897 temp_msg.data[0] = (uint8_t) CTX_SEND_VARIABLE_SUPPLY;
jobuuu 230:2c3e5ecbe7e1 898 temp_msg.data[1] = (uint8_t) SUPPLY_PRESSURE_UPDATE;
jobuuu 230:2c3e5ecbe7e1 899
jobuuu 230:2c3e5ecbe7e1 900 can.write(temp_msg);
jobuuu 230:2c3e5ecbe7e1 901 }
jobuuu 2:a1c0a37df760 902
Lightvalve 170:42c938a40313 903 void CAN_TX_PID_GAIN(int t_type)
Lightvalve 170:42c938a40313 904 {
jobuuu 2:a1c0a37df760 905 // t_type = 0 : valve position control gain
jobuuu 2:a1c0a37df760 906 // t_type = 1 : joint position control gain
jobuuu 2:a1c0a37df760 907 // t_type = 2 : joint torque control gain
jobuuu 2:a1c0a37df760 908
Lightvalve 12:6f2531038ea4 909 int16_t sendPgain=0, sendIgain=0, sendDgain=0;
jobuuu 2:a1c0a37df760 910 if (t_type == 0) {
Lightvalve 30:8d561f16383b 911 sendPgain = (int16_t) (P_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 912 sendIgain = (int16_t) (I_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 913 sendDgain = (int16_t) (D_GAIN_VALVE_POSITION);
jobuuu 2:a1c0a37df760 914 } else if (t_type == 1) {
Lightvalve 12:6f2531038ea4 915 sendPgain = (int16_t) (P_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 916 sendIgain = (int16_t) (I_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 917 sendDgain = (int16_t) (D_GAIN_JOINT_POSITION);
jobuuu 2:a1c0a37df760 918 } else if (t_type == 2) {
Lightvalve 12:6f2531038ea4 919 sendPgain = (int16_t) (P_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 920 sendIgain = (int16_t) (I_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 921 sendDgain = (int16_t) (D_GAIN_JOINT_TORQUE);
Lightvalve 46:2694daea349b 922 } else if (t_type == 3) {
Lightvalve 67:c2812cf26c38 923 sendPgain = (int16_t) (K_SPRING * 10.0f);
Lightvalve 67:c2812cf26c38 924 sendIgain = (int16_t) (D_DAMPER * 100.0f);
jobuuu 2:a1c0a37df760 925 }
jobuuu 2:a1c0a37df760 926
jobuuu 2:a1c0a37df760 927 CANMessage temp_msg;
Lightvalve 170:42c938a40313 928
jobuuu 2:a1c0a37df760 929 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 930 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 931 temp_msg.data[0] = (uint8_t) CTX_SEND_PID_GAIN;
Lightvalve 12:6f2531038ea4 932 temp_msg.data[1] = (uint8_t) t_type;
Lightvalve 12:6f2531038ea4 933 temp_msg.data[2] = (uint8_t) sendPgain;
Lightvalve 12:6f2531038ea4 934 temp_msg.data[3] = (uint8_t) (sendPgain >> 8);
Lightvalve 12:6f2531038ea4 935 temp_msg.data[4] = (uint8_t) sendIgain;
Lightvalve 12:6f2531038ea4 936 temp_msg.data[5] = (uint8_t) (sendIgain >> 8);
Lightvalve 12:6f2531038ea4 937 temp_msg.data[6] = (uint8_t) sendDgain;
Lightvalve 12:6f2531038ea4 938 temp_msg.data[7] = (uint8_t) (sendDgain >> 8);
jobuuu 2:a1c0a37df760 939
jobuuu 2:a1c0a37df760 940 can.write(temp_msg);
jobuuu 2:a1c0a37df760 941 }
jobuuu 2:a1c0a37df760 942
Lightvalve 11:82d8768d7351 943
Lightvalve 170:42c938a40313 944 void CAN_TX_VALVE_DEADZONE(void)
Lightvalve 170:42c938a40313 945 {
jobuuu 2:a1c0a37df760 946 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 947
jobuuu 2:a1c0a37df760 948 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 949 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 950 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE;
Lightvalve 57:f4819de54e7a 951 temp_msg.data[1] = (uint8_t) VALVE_CENTER;
Lightvalve 57:f4819de54e7a 952 temp_msg.data[2] = (uint8_t) (VALVE_CENTER >> 8);
hyhoon 226:82a3ca333004 953 temp_msg.data[3] = (uint8_t) VALVE_DEADZONE_PLUS;
hyhoon 226:82a3ca333004 954 temp_msg.data[4] = (uint8_t) (VALVE_DEADZONE_PLUS >> 8);
hyhoon 226:82a3ca333004 955 temp_msg.data[5] = (uint8_t) VALVE_DEADZONE_MINUS;
hyhoon 226:82a3ca333004 956 temp_msg.data[6] = (uint8_t) (VALVE_DEADZONE_MINUS >> 8);
jobuuu 2:a1c0a37df760 957
jobuuu 2:a1c0a37df760 958 can.write(temp_msg);
jobuuu 2:a1c0a37df760 959 }
jobuuu 2:a1c0a37df760 960
Lightvalve 170:42c938a40313 961 void CAN_TX_VELOCITY_COMP_GAIN(void)
Lightvalve 170:42c938a40313 962 {
Lightvalve 11:82d8768d7351 963 CANMessage temp_msg;
Lightvalve 170:42c938a40313 964
Lightvalve 11:82d8768d7351 965 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 966 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 967 temp_msg.data[0] = (uint8_t) CTX_SEND_VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 968 temp_msg.data[1] = (uint8_t) VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 969 temp_msg.data[2] = (uint8_t) (VELOCITY_COMP_GAIN >> 8);
Lightvalve 11:82d8768d7351 970
Lightvalve 11:82d8768d7351 971 can.write(temp_msg);
Lightvalve 11:82d8768d7351 972 }
Lightvalve 11:82d8768d7351 973
Lightvalve 238:4e660aa77eb7 974 void CAN_TX_VALVE_ELECTRIC_CENTER(void)
Lightvalve 170:42c938a40313 975 {
Lightvalve 11:82d8768d7351 976 CANMessage temp_msg;
Lightvalve 170:42c938a40313 977
Lightvalve 11:82d8768d7351 978 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 979 temp_msg.len = 3;
Lightvalve 238:4e660aa77eb7 980 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ELECTRIC_CENTER;
Lightvalve 238:4e660aa77eb7 981 temp_msg.data[1] = (uint8_t) VALVE_ELECTRIC_CENTER;
Lightvalve 238:4e660aa77eb7 982 temp_msg.data[2] = (uint8_t) (VALVE_ELECTRIC_CENTER >> 8);
Lightvalve 11:82d8768d7351 983
Lightvalve 11:82d8768d7351 984 can.write(temp_msg);
Lightvalve 11:82d8768d7351 985 }
Lightvalve 11:82d8768d7351 986
Lightvalve 170:42c938a40313 987 void CAN_TX_VALVE_FF(void)
Lightvalve 170:42c938a40313 988 {
Lightvalve 11:82d8768d7351 989 CANMessage temp_msg;
Lightvalve 170:42c938a40313 990
Lightvalve 11:82d8768d7351 991 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 992 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 993 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_FF;
Lightvalve 12:6f2531038ea4 994 temp_msg.data[1] = (uint8_t) VALVE_FF;
Lightvalve 12:6f2531038ea4 995 temp_msg.data[2] = (uint8_t) (VALVE_FF >> 8);
Lightvalve 11:82d8768d7351 996
Lightvalve 11:82d8768d7351 997 can.write(temp_msg);
Lightvalve 11:82d8768d7351 998 }
Lightvalve 11:82d8768d7351 999
Lightvalve 170:42c938a40313 1000 void CAN_TX_BULK_MODULUS(void)
Lightvalve 170:42c938a40313 1001 {
Lightvalve 11:82d8768d7351 1002 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1003
Lightvalve 11:82d8768d7351 1004 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1005 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1006 temp_msg.data[0] = (uint8_t) CTX_SEND_BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1007 temp_msg.data[1] = (uint8_t) BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1008 temp_msg.data[2] = (uint8_t) (BULK_MODULUS >> 8);
Lightvalve 11:82d8768d7351 1009
Lightvalve 11:82d8768d7351 1010 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1011 }
Lightvalve 11:82d8768d7351 1012
Lightvalve 170:42c938a40313 1013 void CAN_TX_CHAMBER_VOLUME(void)
Lightvalve 170:42c938a40313 1014 {
Lightvalve 11:82d8768d7351 1015 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1016
Lightvalve 11:82d8768d7351 1017 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1018 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1019 temp_msg.data[0] = (uint8_t) CTX_SEND_CHAMBER_VOLUME;
Lightvalve 12:6f2531038ea4 1020 temp_msg.data[1] = (uint8_t) CHAMBER_VOLUME_A;
Lightvalve 12:6f2531038ea4 1021 temp_msg.data[2] = (uint8_t) (CHAMBER_VOLUME_A >> 8);
Lightvalve 12:6f2531038ea4 1022 temp_msg.data[3] = (uint8_t) CHAMBER_VOLUME_B;
Lightvalve 12:6f2531038ea4 1023 temp_msg.data[4] = (uint8_t) (CHAMBER_VOLUME_B >> 8);
Lightvalve 11:82d8768d7351 1024
Lightvalve 11:82d8768d7351 1025 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1026 }
Lightvalve 11:82d8768d7351 1027
Lightvalve 170:42c938a40313 1028 void CAN_TX_PISTON_AREA(void)
Lightvalve 170:42c938a40313 1029 {
jobuuu 2:a1c0a37df760 1030 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1031
Lightvalve 11:82d8768d7351 1032 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1033 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1034 temp_msg.data[0] = (uint8_t) CTX_SEND_PISTON_AREA;
Lightvalve 12:6f2531038ea4 1035 temp_msg.data[1] = (uint8_t) PISTON_AREA_A;
Lightvalve 12:6f2531038ea4 1036 temp_msg.data[2] = (uint8_t) (PISTON_AREA_A >> 8);
Lightvalve 12:6f2531038ea4 1037 temp_msg.data[3] = (uint8_t) PISTON_AREA_B;
Lightvalve 12:6f2531038ea4 1038 temp_msg.data[4] = (uint8_t) (PISTON_AREA_B >> 8);
jobuuu 2:a1c0a37df760 1039
Lightvalve 11:82d8768d7351 1040 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1041 }
Lightvalve 11:82d8768d7351 1042
jobuuu 230:2c3e5ecbe7e1 1043 void CAN_TX_SUP_PRES(void)
Lightvalve 170:42c938a40313 1044 {
Lightvalve 11:82d8768d7351 1045 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1046
jobuuu 230:2c3e5ecbe7e1 1047 int16_t temp_PRES_SUPPLY = (int16_t) (PRES_SUPPLY);
Lightvalve 11:82d8768d7351 1048 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1049 temp_msg.len = 5;
jobuuu 230:2c3e5ecbe7e1 1050 temp_msg.data[0] = (uint8_t) CTX_SEND_SUP_PRES;
jobuuu 230:2c3e5ecbe7e1 1051 temp_msg.data[1] = (uint8_t) temp_PRES_SUPPLY;
jobuuu 230:2c3e5ecbe7e1 1052 temp_msg.data[2] = (uint8_t) (temp_PRES_SUPPLY >> 8);
jobuuu 230:2c3e5ecbe7e1 1053 temp_msg.data[3] = 0;
jobuuu 230:2c3e5ecbe7e1 1054 temp_msg.data[4] = 0;
Lightvalve 11:82d8768d7351 1055
Lightvalve 11:82d8768d7351 1056 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1057 }
Lightvalve 11:82d8768d7351 1058
Lightvalve 170:42c938a40313 1059 void CAN_TX_ENC_LIMIT(void)
Lightvalve 170:42c938a40313 1060 {
Lightvalve 11:82d8768d7351 1061 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1062
Lightvalve 11:82d8768d7351 1063 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1064 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1065 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_LIMIT;
Lightvalve 12:6f2531038ea4 1066 temp_msg.data[1] = (uint8_t) ENC_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 1067 temp_msg.data[2] = (uint8_t) (ENC_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 1068 temp_msg.data[3] = (uint8_t) ENC_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 1069 temp_msg.data[4] = (uint8_t) (ENC_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 1070
Lightvalve 11:82d8768d7351 1071 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1072 }
Lightvalve 11:82d8768d7351 1073
Lightvalve 170:42c938a40313 1074 void CAN_TX_STROKE(void)
Lightvalve 170:42c938a40313 1075 {
Lightvalve 11:82d8768d7351 1076 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1077
Lightvalve 11:82d8768d7351 1078 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1079 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1080 temp_msg.data[0] = (uint8_t) CTX_SEND_STROKE;
Lightvalve 12:6f2531038ea4 1081 temp_msg.data[1] = (uint8_t) STROKE;
Lightvalve 12:6f2531038ea4 1082 temp_msg.data[2] = (uint8_t) (STROKE >> 8);
Lightvalve 11:82d8768d7351 1083
Lightvalve 11:82d8768d7351 1084 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1085 }
Lightvalve 11:82d8768d7351 1086
Lightvalve 170:42c938a40313 1087 void CAN_TX_VALVE_LIMIT(void)
Lightvalve 170:42c938a40313 1088 {
Lightvalve 11:82d8768d7351 1089 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1090
Lightvalve 11:82d8768d7351 1091 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1092 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1093 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT;
Lightvalve 57:f4819de54e7a 1094 temp_msg.data[1] = (uint8_t) VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1095 temp_msg.data[2] = (uint8_t) (VALVE_MIN_POS >> 8);
Lightvalve 57:f4819de54e7a 1096 temp_msg.data[3] = (uint8_t) VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1097 temp_msg.data[4] = (uint8_t) (VALVE_MAX_POS >> 8);
Lightvalve 11:82d8768d7351 1098
Lightvalve 11:82d8768d7351 1099 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1100 }
Lightvalve 11:82d8768d7351 1101
Lightvalve 170:42c938a40313 1102 void CAN_TX_ENC_PULSE_PER_POSITION(void)
Lightvalve 170:42c938a40313 1103 {
Lightvalve 11:82d8768d7351 1104 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1105
jobuuu 2:a1c0a37df760 1106 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1107 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1108 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_PULSE_PER_POSITION;
Lightvalve 54:647072f5307a 1109 int temp_enc_pulse_per_position = (int) (ENC_PULSE_PER_POSITION);
Lightvalve 48:889798ff9329 1110 temp_msg.data[1] = (uint8_t) temp_enc_pulse_per_position;
Lightvalve 48:889798ff9329 1111 temp_msg.data[2] = (uint8_t) (temp_enc_pulse_per_position >> 8);
jobuuu 2:a1c0a37df760 1112
jobuuu 2:a1c0a37df760 1113 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1114 }
jobuuu 2:a1c0a37df760 1115
Lightvalve 170:42c938a40313 1116 void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void)
Lightvalve 170:42c938a40313 1117 {
jobuuu 2:a1c0a37df760 1118 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1119
jobuuu 2:a1c0a37df760 1120 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1121 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1122 temp_msg.data[0] = (uint8_t) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 240:fb5b57e3f157 1123 int16_t temp_torque_sensor_pulse_per_torque = (int16_t) (TORQUE_SENSOR_PULSE_PER_TORQUE * 1000.0f);
Lightvalve 48:889798ff9329 1124 temp_msg.data[1] = (uint8_t) temp_torque_sensor_pulse_per_torque;
Lightvalve 48:889798ff9329 1125 temp_msg.data[2] = (uint8_t) (temp_torque_sensor_pulse_per_torque >> 8);
jobuuu 2:a1c0a37df760 1126
jobuuu 2:a1c0a37df760 1127 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1128 }
jobuuu 2:a1c0a37df760 1129
Lightvalve 170:42c938a40313 1130 void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void)
Lightvalve 170:42c938a40313 1131 {
jobuuu 2:a1c0a37df760 1132 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1133
jobuuu 2:a1c0a37df760 1134 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1135 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1136 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR;
Lightvalve 30:8d561f16383b 1137 temp_msg.data[1] = (uint8_t) (int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1138 temp_msg.data[2] = (uint8_t) ((int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1139 temp_msg.data[3] = (uint8_t) (int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1140 temp_msg.data[4] = (uint8_t) ((int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f) >> 8);
jobuuu 2:a1c0a37df760 1141
jobuuu 2:a1c0a37df760 1142 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1143 }
jobuuu 2:a1c0a37df760 1144
Lightvalve 170:42c938a40313 1145 void CAN_TX_FRICTION(void)
Lightvalve 170:42c938a40313 1146 {
Lightvalve 11:82d8768d7351 1147 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1148 int16_t send_friction;
Lightvalve 30:8d561f16383b 1149 send_friction = (int16_t) (FRICTION * 10.0f);
Lightvalve 170:42c938a40313 1150
Lightvalve 11:82d8768d7351 1151 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1152 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1153 temp_msg.data[0] = (uint8_t) CTX_SEND_FRICTION;
Lightvalve 12:6f2531038ea4 1154 temp_msg.data[1] = (uint8_t) send_friction;
Lightvalve 12:6f2531038ea4 1155 temp_msg.data[2] = (uint8_t) (send_friction >> 8);
Lightvalve 11:82d8768d7351 1156
Lightvalve 11:82d8768d7351 1157 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1158 }
Lightvalve 11:82d8768d7351 1159
Lightvalve 170:42c938a40313 1160 void CAN_TX_VALVE_GAIN_PLUS(void)
Lightvalve 170:42c938a40313 1161 {
Lightvalve 11:82d8768d7351 1162 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1163
Lightvalve 11:82d8768d7351 1164 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1165 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1166 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_PLUS;
Lightvalve 30:8d561f16383b 1167 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[0] * 50.0f);
Lightvalve 30:8d561f16383b 1168 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[2] * 50.0f);
Lightvalve 30:8d561f16383b 1169 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[4] * 50.0f);
Lightvalve 30:8d561f16383b 1170 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[6] * 50.0f);
Lightvalve 30:8d561f16383b 1171 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[8] * 50.0f);
Lightvalve 11:82d8768d7351 1172
Lightvalve 11:82d8768d7351 1173 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1174 }
Lightvalve 11:82d8768d7351 1175
Lightvalve 11:82d8768d7351 1176
Lightvalve 170:42c938a40313 1177 void CAN_TX_VALVE_GAIN_MINUS(void)
Lightvalve 170:42c938a40313 1178 {
Lightvalve 11:82d8768d7351 1179 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1180
Lightvalve 11:82d8768d7351 1181 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1182 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1183 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_MINUS;
Lightvalve 30:8d561f16383b 1184 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[1] * 50.0f);
Lightvalve 30:8d561f16383b 1185 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[3] * 50.0f);
Lightvalve 30:8d561f16383b 1186 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[5] * 50.0f);
Lightvalve 30:8d561f16383b 1187 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[7] * 50.0f);
Lightvalve 30:8d561f16383b 1188 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[9] * 50.0f);
Lightvalve 11:82d8768d7351 1189
Lightvalve 11:82d8768d7351 1190 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1191 }
Lightvalve 11:82d8768d7351 1192
Lightvalve 170:42c938a40313 1193 void CAN_TX_REFENCE_MODE(void)
Lightvalve 170:42c938a40313 1194 {
Lightvalve 11:82d8768d7351 1195 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1196
Lightvalve 11:82d8768d7351 1197 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1198 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1199 temp_msg.data[0] = (uint8_t) CTX_SEND_REFENCE_MODE;
Lightvalve 12:6f2531038ea4 1200 temp_msg.data[1] = (uint8_t) REFERENCE_MODE;
Lightvalve 30:8d561f16383b 1201 temp_msg.data[2] = (uint8_t) (int) (REFERENCE_FREQ * 100.0f);
Lightvalve 30:8d561f16383b 1202 temp_msg.data[3] = (uint8_t) ((int) (REFERENCE_FREQ * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1203 temp_msg.data[4] = (uint8_t) (int) (REFERENCE_MAG * 100.0f);
Lightvalve 30:8d561f16383b 1204 temp_msg.data[5] = (uint8_t) ((int) (REFERENCE_MAG * 100.0f) >> 8);
Lightvalve 11:82d8768d7351 1205
Lightvalve 11:82d8768d7351 1206 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1207 }
Lightvalve 11:82d8768d7351 1208
Lightvalve 170:42c938a40313 1209 void CAN_TX_HOMEPOS_OFFSET(void)
Lightvalve 170:42c938a40313 1210 {
Lightvalve 11:82d8768d7351 1211 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1212 int16_t send_homepos_offset;
hyhoon 226:82a3ca333004 1213 send_homepos_offset = (int16_t)HOMEPOS_OFFSET;
Lightvalve 170:42c938a40313 1214
jobuuu 2:a1c0a37df760 1215 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1216 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1217 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_OFFSET;
Lightvalve 12:6f2531038ea4 1218 temp_msg.data[1] = (uint8_t) send_homepos_offset;
Lightvalve 12:6f2531038ea4 1219 temp_msg.data[2] = (uint8_t) (send_homepos_offset >> 8);
jobuuu 2:a1c0a37df760 1220
jobuuu 2:a1c0a37df760 1221 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1222 }
Lightvalve 11:82d8768d7351 1223
Lightvalve 170:42c938a40313 1224 void CAN_TX_HOMPOS_VALVE_OPENING(void)
Lightvalve 170:42c938a40313 1225 {
Lightvalve 11:82d8768d7351 1226 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1227 int16_t send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1228 send_homepos_valve_opening = (int16_t) (HOMEPOS_VALVE_OPENING);
Lightvalve 170:42c938a40313 1229
Lightvalve 11:82d8768d7351 1230 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1231 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1232 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_VALVE_OPENING;
Lightvalve 12:6f2531038ea4 1233 temp_msg.data[1] = (uint8_t) send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1234 temp_msg.data[2] = (uint8_t) (send_homepos_valve_opening >> 8);
Lightvalve 11:82d8768d7351 1235
Lightvalve 11:82d8768d7351 1236 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1237 }
Lightvalve 11:82d8768d7351 1238
Lightvalve 170:42c938a40313 1239 void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex)
Lightvalve 170:42c938a40313 1240 {
Lightvalve 11:82d8768d7351 1241 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1242 int16_t valve_pos_vs_pwm;
Lightvalve 170:42c938a40313 1243
Lightvalve 237:c2cfe349f5c1 1244 if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_ELECTRIC_CENTER) {
Lightvalve 237:c2cfe349f5c1 1245 valve_pos_vs_pwm = 10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_ELECTRIC_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_ELECTRIC_CENTER);
Lightvalve 49:e7bcfc244d40 1246 } else {
Lightvalve 237:c2cfe349f5c1 1247 valve_pos_vs_pwm = -10000.0f*((double)VALVE_POS_VS_PWM[canindex]-(double)VALVE_ELECTRIC_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_ELECTRIC_CENTER);
Lightvalve 49:e7bcfc244d40 1248 }
Lightvalve 170:42c938a40313 1249
Lightvalve 12:6f2531038ea4 1250 int16_t PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1251 PWM_VALVE_ID = ID_index_array[canindex] * 1000;
Lightvalve 170:42c938a40313 1252
Lightvalve 11:82d8768d7351 1253 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1254 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1255 temp_msg.data[0] = (uint8_t) CTX_VALVE_PWM_VS_VALVE_POS;
Lightvalve 12:6f2531038ea4 1256 temp_msg.data[1] = (uint8_t) PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1257 temp_msg.data[2] = (uint8_t) (PWM_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1258 temp_msg.data[3] = (uint8_t) valve_pos_vs_pwm;
Lightvalve 12:6f2531038ea4 1259 temp_msg.data[4] = (uint8_t) (valve_pos_vs_pwm >> 8);
Lightvalve 11:82d8768d7351 1260
Lightvalve 11:82d8768d7351 1261 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1262 }
Lightvalve 11:82d8768d7351 1263
Lightvalve 170:42c938a40313 1264 void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex)
Lightvalve 170:42c938a40313 1265 {
Lightvalve 11:82d8768d7351 1266 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1267 int32_t valve_pos_vs_flowrate;
Lightvalve 11:82d8768d7351 1268 valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]);
Lightvalve 11:82d8768d7351 1269
Lightvalve 57:f4819de54e7a 1270 int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + VALVE_CENTER;
Lightvalve 49:e7bcfc244d40 1271 int16_t temp_valve_pos = 0;
Lightvalve 57:f4819de54e7a 1272 if(VALVE_POS_VALVE_ID>=VALVE_CENTER) {
Lightvalve 57:f4819de54e7a 1273 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 1274 } else {
Lightvalve 57:f4819de54e7a 1275 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 1276 }
Lightvalve 170:42c938a40313 1277
Lightvalve 11:82d8768d7351 1278 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1279 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1280 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_VS_FLOWRATE;
Lightvalve 49:e7bcfc244d40 1281 temp_msg.data[1] = (uint8_t) temp_valve_pos;
Lightvalve 49:e7bcfc244d40 1282 temp_msg.data[2] = (uint8_t) (temp_valve_pos >> 8);
jeongyeseong 225:9c0becc196ba 1283 temp_msg.data[3] = (uint8_t) valve_pos_vs_flowrate;
jeongyeseong 225:9c0becc196ba 1284 temp_msg.data[4] = (uint8_t) (valve_pos_vs_flowrate >> 8);
jeongyeseong 225:9c0becc196ba 1285 temp_msg.data[5] = (uint8_t) (valve_pos_vs_flowrate >> 16);
jeongyeseong 225:9c0becc196ba 1286 temp_msg.data[6] = (uint8_t) (valve_pos_vs_flowrate >> 24);
Lightvalve 11:82d8768d7351 1287
Lightvalve 11:82d8768d7351 1288 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1289 }
Lightvalve 11:82d8768d7351 1290
Lightvalve 170:42c938a40313 1291 void CAN_TX_VALVE_POS_NUM(void)
Lightvalve 170:42c938a40313 1292 {
Lightvalve 11:82d8768d7351 1293 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1294 int32_t valve_pos_num;
Lightvalve 11:82d8768d7351 1295 valve_pos_num = (int16_t) VALVE_POS_NUM;
Lightvalve 170:42c938a40313 1296
Lightvalve 11:82d8768d7351 1297 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1298 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1299 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_NUM;
Lightvalve 12:6f2531038ea4 1300 temp_msg.data[1] = (uint8_t) valve_pos_num;
Lightvalve 12:6f2531038ea4 1301 temp_msg.data[2] = (uint8_t) (valve_pos_num >> 8);
Lightvalve 11:82d8768d7351 1302
Lightvalve 11:82d8768d7351 1303 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1304 }
Lightvalve 11:82d8768d7351 1305
Lightvalve 170:42c938a40313 1306 void CAN_TX_DDV_VALVE_MAX_MIN_POS(void)
Lightvalve 170:42c938a40313 1307 {
Lightvalve 38:118df027d851 1308 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1309
Lightvalve 48:889798ff9329 1310 float temp_valve_max_pos = 0.0f;
Lightvalve 48:889798ff9329 1311 float temp_valve_min_pos = 0.0f;
Lightvalve 48:889798ff9329 1312 float temp_ddv_center = 0.0f;
Lightvalve 170:42c938a40313 1313
Lightvalve 57:f4819de54e7a 1314 temp_valve_max_pos = VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1315 temp_valve_min_pos = VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1316 temp_ddv_center = VALVE_CENTER;
Lightvalve 170:42c938a40313 1317
Lightvalve 38:118df027d851 1318 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1319 temp_msg.len = 7;
Lightvalve 38:118df027d851 1320 temp_msg.data[0] = (uint8_t) CTX_VALVE_MAX_MIN_POS;
Lightvalve 48:889798ff9329 1321 temp_msg.data[1] = (uint8_t) temp_valve_max_pos;
Lightvalve 48:889798ff9329 1322 temp_msg.data[2] = (uint8_t) ((int) (temp_valve_max_pos) >> 8);
Lightvalve 48:889798ff9329 1323 temp_msg.data[3] = (uint8_t) (temp_valve_min_pos);
Lightvalve 48:889798ff9329 1324 temp_msg.data[4] = (uint8_t) ((int) (temp_valve_min_pos) >> 8);
Lightvalve 48:889798ff9329 1325 temp_msg.data[5] = (uint8_t) (temp_ddv_center);
Lightvalve 48:889798ff9329 1326 temp_msg.data[6] = (uint8_t) ((int) (temp_ddv_center) >> 8);
Lightvalve 38:118df027d851 1327
Lightvalve 38:118df027d851 1328 can.write(temp_msg);
Lightvalve 38:118df027d851 1329 }
Lightvalve 38:118df027d851 1330
Lightvalve 169:645207e160ca 1331
Lightvalve 170:42c938a40313 1332 void CAN_TX_BUFFER(int16_t t_cnt_buffer)
Lightvalve 170:42c938a40313 1333 {
Lightvalve 169:645207e160ca 1334 CANMessage temp_msg;
Lightvalve 169:645207e160ca 1335 int16_t send_pos_array, send_ref_array;
Lightvalve 169:645207e160ca 1336 send_pos_array = (int16_t) (pos_array[t_cnt_buffer]);
Lightvalve 169:645207e160ca 1337 send_ref_array = (int16_t) (ref_array[t_cnt_buffer]);
Lightvalve 170:42c938a40313 1338
Lightvalve 169:645207e160ca 1339 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1340 temp_msg.len = 5;
Lightvalve 169:645207e160ca 1341 temp_msg.data[0] = (uint8_t) CTX_SEND_BUFFER;
Lightvalve 169:645207e160ca 1342 temp_msg.data[1] = (uint8_t) send_pos_array;
Lightvalve 169:645207e160ca 1343 temp_msg.data[2] = (uint8_t) (send_pos_array >> 8);
Lightvalve 169:645207e160ca 1344 temp_msg.data[3] = (uint8_t) (send_ref_array);
Lightvalve 169:645207e160ca 1345 temp_msg.data[4] = (uint8_t) ((send_ref_array) >> 8);
Lightvalve 169:645207e160ca 1346
Lightvalve 169:645207e160ca 1347 can.write(temp_msg);
Lightvalve 169:645207e160ca 1348 }
Lightvalve 169:645207e160ca 1349
Lightvalve 169:645207e160ca 1350
jobuuu 2:a1c0a37df760 1351 /******************************************************************************
jobuuu 2:a1c0a37df760 1352 Sensor & State Transmission Functions
jobuuu 2:a1c0a37df760 1353 *******************************************************************************/
jobuuu 2:a1c0a37df760 1354
Lightvalve 170:42c938a40313 1355 void CAN_TX_POSITION_FT(int16_t t_pos, int16_t t_vel, int16_t t_torq)
Lightvalve 170:42c938a40313 1356 {
Lightvalve 52:8ea76864368a 1357 CANMessage temp_msg;
Lightvalve 52:8ea76864368a 1358
hyhoon 227:699c3e572283 1359 temp_msg.id = CID_TX_POS_VEL_TORQ;
hyhoon 226:82a3ca333004 1360 temp_msg.len = 6;
Lightvalve 52:8ea76864368a 1361 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 52:8ea76864368a 1362 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 52:8ea76864368a 1363 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 52:8ea76864368a 1364 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1365 temp_msg.data[4] = (uint8_t) t_torq;
Lightvalve 52:8ea76864368a 1366 temp_msg.data[5] = (uint8_t) (t_torq >> 8);
Lightvalve 52:8ea76864368a 1367
Lightvalve 52:8ea76864368a 1368 can.write(temp_msg);
Lightvalve 52:8ea76864368a 1369 }
Lightvalve 52:8ea76864368a 1370
Lightvalve 170:42c938a40313 1371 void CAN_TX_POSITION_PRESSURE(int16_t t_pos, int16_t t_vel, int16_t t_pa, int16_t t_pb)
Lightvalve 170:42c938a40313 1372 {
Lightvalve 170:42c938a40313 1373
jobuuu 2:a1c0a37df760 1374 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1375
hyhoon 227:699c3e572283 1376 temp_msg.id = CID_TX_POS_VEL_TORQ;
jobuuu 2:a1c0a37df760 1377 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1378 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 12:6f2531038ea4 1379 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 41:abbd4e2af68b 1380 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 41:abbd4e2af68b 1381 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1382 temp_msg.data[4] = (uint8_t) t_pa;
Lightvalve 52:8ea76864368a 1383 temp_msg.data[5] = (uint8_t) (t_pa >> 8);
Lightvalve 52:8ea76864368a 1384 temp_msg.data[6] = (uint8_t) t_pb;
Lightvalve 52:8ea76864368a 1385 temp_msg.data[7] = (uint8_t) (t_pb >> 8);
jobuuu 2:a1c0a37df760 1386
jobuuu 2:a1c0a37df760 1387 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1388 }
jobuuu 2:a1c0a37df760 1389
hyhoon 227:699c3e572283 1390 void CAN_TX_CURRENT(int16_t t_pres_a, int16_t t_pres_b)
Lightvalve 170:42c938a40313 1391 {
jobuuu 2:a1c0a37df760 1392 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1393
hyhoon 227:699c3e572283 1394 temp_msg.id = CID_TX_CURRENT;
hyhoon 226:82a3ca333004 1395 temp_msg.len = 4;
Lightvalve 12:6f2531038ea4 1396 temp_msg.data[0] = (uint8_t) t_pres_a;
Lightvalve 12:6f2531038ea4 1397 temp_msg.data[1] = (uint8_t) (t_pres_a >> 8);
Lightvalve 12:6f2531038ea4 1398 temp_msg.data[2] = (uint8_t) t_pres_b;
Lightvalve 12:6f2531038ea4 1399 temp_msg.data[3] = (uint8_t) (t_pres_b >> 8);
jobuuu 2:a1c0a37df760 1400
jobuuu 2:a1c0a37df760 1401 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1402 }
jobuuu 2:a1c0a37df760 1403
Lightvalve 237:c2cfe349f5c1 1404 void CAN_TX_TORQUE(int16_t t_valve_pos)
Lightvalve 237:c2cfe349f5c1 1405 {
Lightvalve 237:c2cfe349f5c1 1406 CANMessage temp_msg;
Lightvalve 237:c2cfe349f5c1 1407
Lightvalve 237:c2cfe349f5c1 1408 temp_msg.id = CID_TX_PWM;
Lightvalve 237:c2cfe349f5c1 1409 temp_msg.len = 2;
Lightvalve 237:c2cfe349f5c1 1410 temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 237:c2cfe349f5c1 1411 temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
Lightvalve 237:c2cfe349f5c1 1412
Lightvalve 237:c2cfe349f5c1 1413 can.write(temp_msg);
Lightvalve 237:c2cfe349f5c1 1414 }
Lightvalve 237:c2cfe349f5c1 1415
Lightvalve 170:42c938a40313 1416 void CAN_TX_PWM(int16_t t_pwm)
Lightvalve 170:42c938a40313 1417 {
jobuuu 2:a1c0a37df760 1418 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1419
hyhoon 227:699c3e572283 1420 temp_msg.id = CID_TX_PWM;
hyhoon 226:82a3ca333004 1421 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 1422 temp_msg.data[0] = (uint8_t) t_pwm;
Lightvalve 12:6f2531038ea4 1423 temp_msg.data[1] = (uint8_t) (t_pwm >> 8);
jobuuu 2:a1c0a37df760 1424
jobuuu 2:a1c0a37df760 1425 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1426 }
jobuuu 2:a1c0a37df760 1427
Lightvalve 73:f80dc3970c99 1428 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 1429 {
jobuuu 2:a1c0a37df760 1430 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1431
jobuuu 2:a1c0a37df760 1432 temp_msg.id = CID_TX_VALVE_POSITION;
Lightvalve 73:f80dc3970c99 1433 temp_msg.len = 8;
Lightvalve 73:f80dc3970c99 1434 temp_msg.data[0] = (uint8_t) t_valve_pos_1;
Lightvalve 73:f80dc3970c99 1435 temp_msg.data[1] = (uint8_t) (t_valve_pos_1 >> 8);
Lightvalve 73:f80dc3970c99 1436 temp_msg.data[2] = (uint8_t) t_valve_pos_2;
Lightvalve 73:f80dc3970c99 1437 temp_msg.data[3] = (uint8_t) (t_valve_pos_2 >> 8);
Lightvalve 73:f80dc3970c99 1438 temp_msg.data[4] = (uint8_t) t_ref_valve_pos;
Lightvalve 73:f80dc3970c99 1439 temp_msg.data[5] = (uint8_t) (t_ref_valve_pos >> 8);
Lightvalve 73:f80dc3970c99 1440 temp_msg.data[6] = (uint8_t) t_pwm;
Lightvalve 73:f80dc3970c99 1441 temp_msg.data[7] = (uint8_t) (t_pwm >> 8);
Lightvalve 170:42c938a40313 1442
jobuuu 2:a1c0a37df760 1443
jobuuu 2:a1c0a37df760 1444 can.write(temp_msg);
jeongyeseong 225:9c0becc196ba 1445 }
jeongyeseong 225:9c0becc196ba 1446
jeongyeseong 225:9c0becc196ba 1447 void CAN_TX_SOMETHING(int16_t t_a, int16_t t_b, int16_t t_c, int16_t t_d)
jeongyeseong 225:9c0becc196ba 1448 {
jeongyeseong 225:9c0becc196ba 1449 CANMessage temp_msg;
jeongyeseong 225:9c0becc196ba 1450
jeongyeseong 225:9c0becc196ba 1451 temp_msg.id = CID_TX_SOMETHING;
jeongyeseong 225:9c0becc196ba 1452 temp_msg.len = 8;
jeongyeseong 225:9c0becc196ba 1453 temp_msg.data[0] = (uint8_t) t_a;
jeongyeseong 225:9c0becc196ba 1454 temp_msg.data[1] = (uint8_t) (t_a >> 8);
jeongyeseong 225:9c0becc196ba 1455 temp_msg.data[2] = (uint8_t) t_b;
jeongyeseong 225:9c0becc196ba 1456 temp_msg.data[3] = (uint8_t) (t_b >> 8);
jeongyeseong 225:9c0becc196ba 1457 temp_msg.data[4] = (uint8_t) t_c;
jeongyeseong 225:9c0becc196ba 1458 temp_msg.data[5] = (uint8_t) (t_c >> 8);
jeongyeseong 225:9c0becc196ba 1459 temp_msg.data[6] = (uint8_t) t_d;
jeongyeseong 225:9c0becc196ba 1460 temp_msg.data[7] = (uint8_t) (t_d >> 8);
jeongyeseong 225:9c0becc196ba 1461
jeongyeseong 225:9c0becc196ba 1462
jeongyeseong 225:9c0becc196ba 1463 can.write(temp_msg);
Lightvalve 237:c2cfe349f5c1 1464 }
Lightvalve 237:c2cfe349f5c1 1465
Lightvalve 237:c2cfe349f5c1 1466 void CAN_TX_VOUT(int16_t t_vout)
Lightvalve 237:c2cfe349f5c1 1467 {
Lightvalve 237:c2cfe349f5c1 1468 CANMessage temp_msg;
Lightvalve 237:c2cfe349f5c1 1469
Lightvalve 237:c2cfe349f5c1 1470 temp_msg.id = CID_TX_VOUT;
Lightvalve 237:c2cfe349f5c1 1471 temp_msg.len = 2;
Lightvalve 237:c2cfe349f5c1 1472 temp_msg.data[0] = (uint8_t) t_vout;
Lightvalve 237:c2cfe349f5c1 1473 temp_msg.data[1] = (uint8_t) (t_vout >> 8);
Lightvalve 237:c2cfe349f5c1 1474
Lightvalve 237:c2cfe349f5c1 1475 can.write(temp_msg);
Lightvalve 67:c2812cf26c38 1476 }