2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Mon Jun 13 08:48:55 2022 +0000
Revision:
231:30896263bd8b
Parent:
230:b235d67d25ba
Child:
232:e9c5ec04e378
220613

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