2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Tue Jul 13 01:40:56 2021 +0000
Revision:
238:4e660aa77eb7
Parent:
237:c2cfe349f5c1
Child:
240:fb5b57e3f157
210713

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 99:7bbcb3c0fb06 28 extern float u_past[];
Lightvalve 68:328e1be06f5d 29 extern float x_past[];
Lightvalve 85:a3b46118b5cd 30 extern float x_future[];
Lightvalve 68:328e1be06f5d 31 extern float f_past[];
Lightvalve 68:328e1be06f5d 32 extern float f_future[];
Lightvalve 73:f80dc3970c99 33 extern float input_NN[];
Lightvalve 68:328e1be06f5d 34
Lightvalve 11:82d8768d7351 35 /*******************************************************************************
jobuuu 230:2c3e5ecbe7e1 36 * State Class functions
jobuuu 230:2c3e5ecbe7e1 37 ******************************************************************************/
jobuuu 230:2c3e5ecbe7e1 38 void State::UpdateSen(float sen_new, float Freq_update, float f_cut) {
jobuuu 230:2c3e5ecbe7e1 39 if(f_cut<=0.0f) f_cut=0.001f;
jobuuu 230:2c3e5ecbe7e1 40
jobuuu 230:2c3e5ecbe7e1 41 this->sen_diff = (sen_new-this->sen)*Freq_update;
jobuuu 230:2c3e5ecbe7e1 42 float alpha_update = 1.0f / (1.0f + Freq_update / (2.0f * 3.14f * f_cut)); // f_cutoff : 100Hz
jobuuu 230:2c3e5ecbe7e1 43 this->sen = (1.0f - alpha_update) * this->sen + alpha_update * sen_new;
jobuuu 230:2c3e5ecbe7e1 44 }
jobuuu 230:2c3e5ecbe7e1 45
jobuuu 230:2c3e5ecbe7e1 46 void State::UpdateRef(float ref_new) {
jobuuu 230:2c3e5ecbe7e1 47 this->ref = ref_new;
jobuuu 230:2c3e5ecbe7e1 48 }
jobuuu 230:2c3e5ecbe7e1 49
jobuuu 230:2c3e5ecbe7e1 50 void State::Reset() {
jobuuu 230:2c3e5ecbe7e1 51 this->sen = 0.0f;
jobuuu 230:2c3e5ecbe7e1 52 this->sen_diff = 0.0f;
jobuuu 230:2c3e5ecbe7e1 53 this->ref = 0.0f;
jobuuu 230:2c3e5ecbe7e1 54 this->err = 0.0f;
jobuuu 230:2c3e5ecbe7e1 55 this->err_int = 0.0f;
jobuuu 230:2c3e5ecbe7e1 56 this->err_old = 0.0f;
jobuuu 230:2c3e5ecbe7e1 57 this->err_diff = 0.0f;
jobuuu 230:2c3e5ecbe7e1 58 }
jobuuu 230:2c3e5ecbe7e1 59
jobuuu 230:2c3e5ecbe7e1 60 /*******************************************************************************
Lightvalve 11:82d8768d7351 61 * CAN functions
Lightvalve 11:82d8768d7351 62 ******************************************************************************/
Lightvalve 170:42c938a40313 63 void CAN_ID_INIT(void)
Lightvalve 170: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 227:699c3e572283 68 CID_RX_REF_OPENLOOP = (int) (BNO + INIT_CID_RX_REF_OPENLOOP);
Lightvalve 45: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 227:699c3e572283 72 CID_TX_POS_VEL_TORQ = (int) (BNO + INIT_CID_TX_POS_VEL_TORQ);
hyhoon 227:699c3e572283 73 CID_TX_PWM = (int) (BNO + INIT_CID_TX_PWM);
hyhoon 227: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 225: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 170: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 170: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 52:8ea76864368a 102 OPERATING_MODE = (uint8_t) msg.data[1];
Lightvalve 52:8ea76864368a 103 SENSING_MODE = (uint8_t) msg.data[2];
Lightvalve 52:8ea76864368a 104 CURRENT_CONTROL_MODE = (uint8_t) msg.data[3];
Lightvalve 52:8ea76864368a 105 FLAG_VALVE_DEADZONE = (uint8_t) msg.data[4];
Lightvalve 170:42c938a40313 106 spi_eeprom_write(RID_OPERATING_MODE, (int16_t) OPERATING_MODE);
Lightvalve 170:42c938a40313 107 spi_eeprom_write(RID_SENSING_MODE, (int16_t) SENSING_MODE);
Lightvalve 170:42c938a40313 108 spi_eeprom_write(RID_CURRENT_CONTROL_MODE, (int16_t) CURRENT_CONTROL_MODE);
Lightvalve 170: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 45:35fa6884d0c6 122 case CRX_SET_POS_TORQ_TRANS: {
Lightvalve 45:35fa6884d0c6 123 MODE_POS_FT_TRANS = (int16_t) msg.data[1];
Lightvalve 45:35fa6884d0c6 124 /*
Lightvalve 45:35fa6884d0c6 125 MODE_POS_FT_TRANS == 0 : Position Control
Lightvalve 45:35fa6884d0c6 126 MODE_POS_FT_TRANS == 1 : Trasition(Position->Torque)
Lightvalve 45:35fa6884d0c6 127 MODE_POS_FT_TRANS == 2 : Torque Control (Convert to 2 automatically 3sec after transition)
Lightvalve 45:35fa6884d0c6 128 MODE_POS_FT_TRANS == 3 : Transition(Toque->Position)
Lightvalve 45: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 170: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 57: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 226: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 227: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 170:42c938a40313 185
Lightvalve 170: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 170:42c938a40313 203
Lightvalve 170: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 170: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 170:42c938a40313 235
Lightvalve 170:42c938a40313 236
Lightvalve 170: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 170:42c938a40313 250
Lightvalve 170: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 57:f4819de54e7a 258 CONTROL_UTILITY_MODE = 22;
Lightvalve 11:82d8768d7351 259 break;
Lightvalve 11:82d8768d7351 260 }
jobuuu 230:2c3e5ecbe7e1 261
jobuuu 230:2c3e5ecbe7e1 262 case CRX_ASK_VARIABLE_SUPPLY:
jobuuu 230:2c3e5ecbe7e1 263 {
jobuuu 230:2c3e5ecbe7e1 264 CAN_TX_VARIABLE_SUPPLY_ONOFF();
jobuuu 230:2c3e5ecbe7e1 265 break;
jobuuu 230:2c3e5ecbe7e1 266 }
jobuuu 230:2c3e5ecbe7e1 267
jobuuu 230:2c3e5ecbe7e1 268 case CRX_SET_VARIABLE_SUPPLY:
jobuuu 230:2c3e5ecbe7e1 269 {
jobuuu 230:2c3e5ecbe7e1 270 SUPPLY_PRESSURE_UPDATE = msg.data[1];
jobuuu 230:2c3e5ecbe7e1 271 break;
jobuuu 230: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 170:42c938a40313 285
Lightvalve 170:42c938a40313 286 spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION);
Lightvalve 170:42c938a40313 287 spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION);
Lightvalve 170: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 170:42c938a40313 294
Lightvalve 170:42c938a40313 295 spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION);
Lightvalve 170:42c938a40313 296 spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION);
Lightvalve 170:42c938a40313 297 spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION);
Lightvalve 170: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 170:42c938a40313 303
Lightvalve 170:42c938a40313 304 spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE);
Lightvalve 170:42c938a40313 305 spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE);
Lightvalve 170:42c938a40313 306 spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE);
Lightvalve 170:42c938a40313 307
Lightvalve 46:2694daea349b 308 } else if (msg.data[1] == 3) {
Lightvalve 67:c2812cf26c38 309 K_SPRING = (float) (((float) ((int16_t) (msg.data[2] | msg.data[3] << 8))) * 0.1f);
Lightvalve 67:c2812cf26c38 310 D_DAMPER = (float) (((float) ((int16_t) (msg.data[4] | msg.data[5] << 8))) * 0.01f);
Lightvalve 170:42c938a40313 311
Lightvalve 170:42c938a40313 312 // spi_eeprom_write(RID_K_SPRING, (int16_t) K_SPRING);
Lightvalve 170:42c938a40313 313 // spi_eeprom_write(RID_D_DAMPER, (int16_t) D_DAMPER);
Lightvalve 170:42c938a40313 314
Lightvalve 72:3436ce769b1e 315 } else if (msg.data[1] == 4) {
Lightvalve 72:3436ce769b1e 316 P_GAIN_JOINT_TORQUE_FF = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 72:3436ce769b1e 317 I_GAIN_JOINT_TORQUE_FF = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 72:3436ce769b1e 318 D_GAIN_JOINT_TORQUE_FF = (int16_t) (msg.data[6] | msg.data[7] << 8);
Lightvalve 170: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 226:82a3ca333004 333 VALVE_DEADZONE_PLUS = (int16_t)(msg.data[3] | msg.data[4] << 8);
hyhoon 226:82a3ca333004 334 VALVE_DEADZONE_MINUS = (int16_t)(msg.data[5] | msg.data[6] << 8);
Lightvalve 170:42c938a40313 335
hyhoon 226:82a3ca333004 336 spi_eeprom_write(RID_VALVE_CNETER, VALVE_CENTER);
hyhoon 226:82a3ca333004 337 spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, VALVE_DEADZONE_PLUS);
hyhoon 226: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 170:42c938a40313 351
Lightvalve 170:42c938a40313 352
Lightvalve 170: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 238:4e660aa77eb7 358 case CRX_ASK_VALVE_ELECTRIC_CENTER: {
Lightvalve 238: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 238:4e660aa77eb7 364 case CRX_SET_VALVE_ELECTRIC_CENTER: {
Lightvalve 238:4e660aa77eb7 365 VALVE_ELECTRIC_CENTER = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 366
Lightvalve 170:42c938a40313 367
Lightvalve 238: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 170:42c938a40313 381
Lightvalve 170: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 170: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 170:42c938a40313 410 spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A);
Lightvalve 170: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 69:3995ffeaa786 425 PISTON_AREA_alpha = (double)PISTON_AREA_A/(double)PISTON_AREA_B;
Lightvalve 57:f4819de54e7a 426 alpha3 = PISTON_AREA_alpha * PISTON_AREA_alpha*PISTON_AREA_alpha;
Lightvalve 170:42c938a40313 427
Lightvalve 170:42c938a40313 428 spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A);
Lightvalve 170: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 230:2c3e5ecbe7e1 433 case CRX_ASK_SUP_PRES: {
jobuuu 230:2c3e5ecbe7e1 434 CAN_TX_SUP_PRES();
Lightvalve 11:82d8768d7351 435 break;
Lightvalve 11:82d8768d7351 436 }
Lightvalve 11:82d8768d7351 437
jobuuu 230:2c3e5ecbe7e1 438 case CRX_SET_SUP_PRES: {
jobuuu 230:2c3e5ecbe7e1 439 int16_t temp = (int16_t) (msg.data[1] | msg.data[2] << 8);
jobuuu 230:2c3e5ecbe7e1 440 spi_eeprom_write(RID_PRES_SUPPLY, temp);
jobuuu 230:2c3e5ecbe7e1 441 PRES_SUPPLY_NOM = (float)temp;
jobuuu 230: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 170:42c938a40313 455 spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS);
Lightvalve 170: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 170: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 57:f4819de54e7a 480 VALVE_MIN_POS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 57:f4819de54e7a 481 VALVE_MAX_POS = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 170:42c938a40313 482
Lightvalve 170:42c938a40313 483 spi_eeprom_write(RID_VALVE_MAX_POS, (int16_t) VALVE_MAX_POS);
Lightvalve 170: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 180: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 232:2976cf1b4252 509 TORQUE_SENSOR_PULSE_PER_TORQUE = (float) ((int16_t) (msg.data[1] | msg.data[2] << 8) * 0.01f);
Lightvalve 232:2976cf1b4252 510 spi_eeprom_write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE, (int16_t) (TORQUE_SENSOR_PULSE_PER_TORQUE*100.0f));
Lightvalve 11:82d8768d7351 511
Lightvalve 11:82d8768d7351 512 break;
Lightvalve 11:82d8768d7351 513 }
Lightvalve 11:82d8768d7351 514
Lightvalve 11:82d8768d7351 515 case CRX_ASK_PRES_SENSOR_PULSE_PER_PRES: {
Lightvalve 11:82d8768d7351 516 CAN_TX_PRES_SENSOR_PULSE_PER_PRES();
Lightvalve 11:82d8768d7351 517
Lightvalve 11:82d8768d7351 518 break;
Lightvalve 11:82d8768d7351 519 }
Lightvalve 11:82d8768d7351 520
Lightvalve 11:82d8768d7351 521 case CRX_SET_PRES_SENSOR_PULSE_PER_PRES: {
Lightvalve 30:8d561f16383b 522 PRES_SENSOR_A_PULSE_PER_BAR = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) * 0.01f;
Lightvalve 30:8d561f16383b 523 PRES_SENSOR_B_PULSE_PER_BAR = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) * 0.01f;
Lightvalve 170:42c938a40313 524 spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f));
Lightvalve 170:42c938a40313 525 spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f));
Lightvalve 11:82d8768d7351 526
Lightvalve 11:82d8768d7351 527 break;
Lightvalve 11:82d8768d7351 528 }
Lightvalve 11:82d8768d7351 529
Lightvalve 11:82d8768d7351 530 case CRX_ASK_FRICTION: {
Lightvalve 11:82d8768d7351 531 CAN_TX_FRICTION();
Lightvalve 11:82d8768d7351 532
Lightvalve 11:82d8768d7351 533 break;
Lightvalve 11:82d8768d7351 534 }
Lightvalve 11:82d8768d7351 535
Lightvalve 11:82d8768d7351 536 case CRX_SET_FRICTION: {
Lightvalve 30:8d561f16383b 537 FRICTION = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.0f;
Lightvalve 170:42c938a40313 538 spi_eeprom_write(RID_FRICTION, (int16_t) (FRICTION * 10.0f));
Lightvalve 11:82d8768d7351 539
Lightvalve 11:82d8768d7351 540 break;
Lightvalve 11:82d8768d7351 541 }
Lightvalve 11:82d8768d7351 542
Lightvalve 11:82d8768d7351 543 case CRX_ASK_VALVE_GAIN_PLUS: {
Lightvalve 11:82d8768d7351 544 CAN_TX_VALVE_GAIN_PLUS();
Lightvalve 11:82d8768d7351 545
Lightvalve 11:82d8768d7351 546 break;
Lightvalve 11:82d8768d7351 547 }
Lightvalve 11:82d8768d7351 548 case CRX_SET_VALVE_GAIN_PLUS: {
Lightvalve 30:8d561f16383b 549 VALVE_GAIN_LPM_PER_V[0] = (double) msg.data[1] / 50.0f;
Lightvalve 30:8d561f16383b 550 VALVE_GAIN_LPM_PER_V[2] = (double) msg.data[2] / 50.0f;
Lightvalve 30:8d561f16383b 551 VALVE_GAIN_LPM_PER_V[4] = (double) msg.data[3] / 50.0f;
Lightvalve 30:8d561f16383b 552 VALVE_GAIN_LPM_PER_V[6] = (double) msg.data[4] / 50.0f;
Lightvalve 30:8d561f16383b 553 VALVE_GAIN_LPM_PER_V[8] = (double) msg.data[5] / 50.0f;
Lightvalve 170:42c938a40313 554 spi_eeprom_write(RID_VALVE_GAIN_PLUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[0] * 100.0f));
Lightvalve 170:42c938a40313 555 spi_eeprom_write(RID_VALVE_GAIN_PLUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[2] * 100.0f));
Lightvalve 170:42c938a40313 556 spi_eeprom_write(RID_VALVE_GAIN_PLUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[4] * 100.0f));
Lightvalve 170:42c938a40313 557 spi_eeprom_write(RID_VALVE_GAIN_PLUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[6] * 100.0f));
Lightvalve 170:42c938a40313 558 spi_eeprom_write(RID_VALVE_GAIN_PLUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[8] * 100.0f));
Lightvalve 11:82d8768d7351 559
Lightvalve 11:82d8768d7351 560 break;
Lightvalve 11:82d8768d7351 561 }
Lightvalve 11:82d8768d7351 562
Lightvalve 11:82d8768d7351 563 case CRX_ASK_VALVE_GAIN_MINUS: {
Lightvalve 11:82d8768d7351 564 CAN_TX_VALVE_GAIN_MINUS();
Lightvalve 11:82d8768d7351 565
Lightvalve 11:82d8768d7351 566 break;
Lightvalve 11:82d8768d7351 567 }
Lightvalve 11:82d8768d7351 568 case CRX_SET_VALVE_GAIN_MINUS: {
Lightvalve 30:8d561f16383b 569 VALVE_GAIN_LPM_PER_V[1] = (double) msg.data[1] / 50.0f;
Lightvalve 30:8d561f16383b 570 VALVE_GAIN_LPM_PER_V[3] = (double) msg.data[2] / 50.0f;
Lightvalve 30:8d561f16383b 571 VALVE_GAIN_LPM_PER_V[5] = (double) msg.data[3] / 50.0f;
Lightvalve 30:8d561f16383b 572 VALVE_GAIN_LPM_PER_V[7] = (double) msg.data[4] / 50.0f;
Lightvalve 30:8d561f16383b 573 VALVE_GAIN_LPM_PER_V[9] = (double) msg.data[5] / 50.0f;
Lightvalve 170:42c938a40313 574 spi_eeprom_write(RID_VALVE_GAIN_MINUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[1] * 100.0f));
Lightvalve 170:42c938a40313 575 spi_eeprom_write(RID_VALVE_GAIN_MINUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[3] * 100.0f));
Lightvalve 170:42c938a40313 576 spi_eeprom_write(RID_VALVE_GAIN_MINUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[5] * 100.0f));
Lightvalve 170:42c938a40313 577 spi_eeprom_write(RID_VALVE_GAIN_MINUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[7] * 100.0f));
Lightvalve 170:42c938a40313 578 spi_eeprom_write(RID_VALVE_GAIN_MINUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[9] * 100.0f));
Lightvalve 11:82d8768d7351 579
Lightvalve 11:82d8768d7351 580 break;
Lightvalve 11:82d8768d7351 581 }
Lightvalve 11:82d8768d7351 582
Lightvalve 11:82d8768d7351 583 case CRX_LOW_REF: {
Lightvalve 11:82d8768d7351 584 REFERENCE_MODE = msg.data[1];
Lightvalve 11:82d8768d7351 585
Lightvalve 11:82d8768d7351 586 REF_NUM = msg.data[2];
Lightvalve 30:8d561f16383b 587 REF_PERIOD = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) / 100.0f;
Lightvalve 30:8d561f16383b 588 if (REF_PERIOD <= 0.0f) REF_MOVE_TIME_5k = TMR_FREQ_5k / CAN_FREQ;
Lightvalve 11:82d8768d7351 589 else REF_MOVE_TIME_5k = (int) (REF_PERIOD * (double) TMR_FREQ_5k);
Lightvalve 30:8d561f16383b 590 REF_MAG = (double) ((int16_t) (msg.data[5] | msg.data[6] << 8)) / 100.0f;
Lightvalve 11:82d8768d7351 591
Lightvalve 11:82d8768d7351 592 break;
Lightvalve 11:82d8768d7351 593 }
Lightvalve 11:82d8768d7351 594
Lightvalve 11:82d8768d7351 595 case CRX_JUMP_STATUS: {
Lightvalve 11:82d8768d7351 596 MODE_JUMP_STATUS = msg.data[1];
Lightvalve 11:82d8768d7351 597
Lightvalve 11:82d8768d7351 598 break;
Lightvalve 11:82d8768d7351 599 }
Lightvalve 11:82d8768d7351 600
Lightvalve 11:82d8768d7351 601 case CRX_SET_ERR_CLEAR: {
Lightvalve 11:82d8768d7351 602
Lightvalve 12:6f2531038ea4 603 for (int i = 0; i < num_err; i++) {
Lightvalve 11:82d8768d7351 604 flag_err[i] = FALSE;
Lightvalve 11:82d8768d7351 605 flag_err_old[i] = FALSE;
Lightvalve 11:82d8768d7351 606 }
Lightvalve 11:82d8768d7351 607
Lightvalve 11:82d8768d7351 608 flag_err_rt = FALSE;
Lightvalve 11:82d8768d7351 609
Lightvalve 11:82d8768d7351 610
Lightvalve 11:82d8768d7351 611 break;
Lightvalve 11:82d8768d7351 612 }
Lightvalve 11:82d8768d7351 613
Lightvalve 11:82d8768d7351 614 case CRX_ASK_HOMEPOS_OFFSET: {
Lightvalve 11:82d8768d7351 615 CAN_TX_HOMEPOS_OFFSET();
Lightvalve 11:82d8768d7351 616 break;
Lightvalve 11:82d8768d7351 617 }
Lightvalve 11:82d8768d7351 618 case CRX_SET_HOMEPOS_OFFSET: {
hyhoon 226:82a3ca333004 619 HOMEPOS_OFFSET = (int16_t)(msg.data[1] | msg.data[2] << 8);
Lightvalve 170:42c938a40313 620 spi_eeprom_write(RID_HOMEPOS_OFFSET, (int16_t) HOMEPOS_OFFSET);
Lightvalve 11:82d8768d7351 621 break;
Lightvalve 11:82d8768d7351 622 }
Lightvalve 11:82d8768d7351 623
Lightvalve 11:82d8768d7351 624 case CRX_ASK_HOMEPOS_VALVE_OPENING: {
Lightvalve 11:82d8768d7351 625 CAN_TX_HOMPOS_VALVE_OPENING();
Lightvalve 11:82d8768d7351 626 break;
Lightvalve 11:82d8768d7351 627 }
Lightvalve 11:82d8768d7351 628 case CRX_SET_HOMEPOS_VALVE_OPENING: {
Lightvalve 11:82d8768d7351 629 HOMEPOS_VALVE_OPENING = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 170:42c938a40313 630 spi_eeprom_write(RID_HOMEPOS_VALVE_OPENING, (int16_t) HOMEPOS_VALVE_OPENING);
Lightvalve 11:82d8768d7351 631 break;
Lightvalve 11:82d8768d7351 632 }
Lightvalve 11:82d8768d7351 633
Lightvalve 11:82d8768d7351 634 case CRX_ASK_VALVE_PWM_VS_VALVE_POS: {
Lightvalve 11:82d8768d7351 635 can_index = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 636 CAN_TX_VALVE_PWM_VS_VALVE_POS(can_index);
Lightvalve 11:82d8768d7351 637 break;
Lightvalve 11:82d8768d7351 638 }
Lightvalve 11:82d8768d7351 639 case CRX_ASK_VALVE_POS_VS_FLOWRATE: {
Lightvalve 11:82d8768d7351 640 can_index = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 641 CAN_TX_VALVE_POS_VS_FLOWRATE(can_index);
Lightvalve 11:82d8768d7351 642 break;
Lightvalve 11:82d8768d7351 643 }
Lightvalve 11:82d8768d7351 644 case CRX_ASK_VALVE_POS_NUM: {
Lightvalve 11:82d8768d7351 645 CAN_TX_VALVE_POS_NUM();
Lightvalve 11:82d8768d7351 646 break;
Lightvalve 11:82d8768d7351 647 }
Lightvalve 170:42c938a40313 648
Lightvalve 28:2a62d73e3dd0 649 case CRX_SET_ROM: {
Lightvalve 28:2a62d73e3dd0 650 break;
Lightvalve 28:2a62d73e3dd0 651 }
Lightvalve 237:c2cfe349f5c1 652
Lightvalve 237:c2cfe349f5c1 653 case CRX_ASK_BUFFER: {
Lightvalve 237:c2cfe349f5c1 654 cnt_buffer = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 237:c2cfe349f5c1 655 CAN_TX_BUFFER(cnt_buffer);
Lightvalve 237:c2cfe349f5c1 656 break;
Lightvalve 237:c2cfe349f5c1 657 }
Lightvalve 237:c2cfe349f5c1 658 case CRX_SET_STEP_TEST: {
Lightvalve 237:c2cfe349f5c1 659 cnt_step_test = 0;
Lightvalve 237:c2cfe349f5c1 660 CONTROL_UTILITY_MODE = 37;
Lightvalve 237:c2cfe349f5c1 661 break;
Lightvalve 237:c2cfe349f5c1 662 }
Lightvalve 237:c2cfe349f5c1 663 case CRX_SET_FREQ_TEST: {
Lightvalve 237:c2cfe349f5c1 664 cnt_freq_test = 0;
Lightvalve 237:c2cfe349f5c1 665 CONTROL_UTILITY_MODE = 34;
Lightvalve 237:c2cfe349f5c1 666 break;
Lightvalve 237:c2cfe349f5c1 667 }
Lightvalve 192:637092202815 668
Lightvalve 170:42c938a40313 669 default:
Lightvalve 170:42c938a40313 670 break;
jobuuu 2:a1c0a37df760 671 }
jobuuu 2:a1c0a37df760 672 }
jobuuu 2:a1c0a37df760 673
jobuuu 2:a1c0a37df760 674 void CAN_RX_HANDLER()
jobuuu 2:a1c0a37df760 675 {
Lightvalve 170:42c938a40313 676
jobuuu 2:a1c0a37df760 677 can.read(msg);
jobuuu 2:a1c0a37df760 678 unsigned int address = msg.id;
Lightvalve 170:42c938a40313 679 if(address==CID_RX_CMD) {
jobuuu 2:a1c0a37df760 680 unsigned int CMD = msg.data[0];
jobuuu 2:a1c0a37df760 681 ReadCMD(CMD);
Lightvalve 170:42c938a40313 682
jobuuu 7:e9086c72bb22 683 } else if(address==CID_RX_REF_POSITION) {
Lightvalve 170:42c938a40313 684
jobuuu 230:2c3e5ecbe7e1 685 int16_t temp_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 43:b084e5f5d0d5 686 int16_t temp_vel = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 57:f4819de54e7a 687 int16_t temp_torq = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 170:42c938a40313 688
Lightvalve 57:f4819de54e7a 689 if((OPERATING_MODE&0b001)==0) { // Rotary Actuator
Lightvalve 232:2976cf1b4252 690 REF_POSITION = (float)temp_pos / 200.0f;
Lightvalve 232:2976cf1b4252 691 REF_VELOCITY = (float)temp_vel / 20.0f;
Lightvalve 232:2976cf1b4252 692 REF_TORQUE = (float)temp_torq * 0.1f / TORQUE_SENSOR_PULSE_PER_TORQUE; // pulse >> Nm
Lightvalve 170:42c938a40313 693 } else { //Linear Actuator
Lightvalve 232:2976cf1b4252 694 REF_POSITION = (float)temp_pos / 200.0f;
Lightvalve 232:2976cf1b4252 695 REF_VELOCITY = (float)temp_vel / 20.0f;
jobuuu 230:2c3e5ecbe7e1 696 REF_FORCE = (float)temp_torq * 0.1f / TORQUE_SENSOR_PULSE_PER_TORQUE; // pulse >> N
Lightvalve 57:f4819de54e7a 697 }
Lightvalve 170:42c938a40313 698
jobuuu 230:2c3e5ecbe7e1 699 if(SUPPLY_PRESSURE_UPDATE == 1) {
jobuuu 230:2c3e5ecbe7e1 700 int16_t temp_REF_Ps = (int16_t) (msg.data[6] | msg.data[7] << 8);
jobuuu 230:2c3e5ecbe7e1 701 PRES_SUPPLY = ((float)temp_REF_Ps) / 100.0;
jobuuu 230:2c3e5ecbe7e1 702 if(PRES_SUPPLY<35.0f) PRES_SUPPLY = 35.0f;
jobuuu 230:2c3e5ecbe7e1 703 else if(PRES_SUPPLY>210.0f) PRES_SUPPLY = 210.0f;
jobuuu 230:2c3e5ecbe7e1 704 } else {
jobuuu 230:2c3e5ecbe7e1 705 PRES_SUPPLY = PRES_SUPPLY_NOM;
jobuuu 230:2c3e5ecbe7e1 706 }
hyhoon 226:82a3ca333004 707
hyhoon 226:82a3ca333004 708 if(CAN_FREQ == -1) {
jobuuu 230:2c3e5ecbe7e1 709
hyhoon 226:82a3ca333004 710 // Position, Velocity, and Torque (ID:1200)
hyhoon 226:82a3ca333004 711 if (flag_data_request[0] == HIGH) {
hyhoon 226:82a3ca333004 712 if ((OPERATING_MODE & 0b01) == 0) { // Rotary Actuator
Lightvalve 231:e00e71ca3e80 713 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 714 } else if ((OPERATING_MODE & 0b01) == 1) { // Linear Actuator
Lightvalve 231:e00e71ca3e80 715 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 716 }
jeongyeseong 225:9c0becc196ba 717 }
hyhoon 226:82a3ca333004 718
jobuuu 230:2c3e5ecbe7e1 719 // Valve Position (ID:1300)
hyhoon 226:82a3ca333004 720 if (flag_data_request[1] == HIGH) {
jobuuu 230:2c3e5ecbe7e1 721 CAN_TX_PWM((int16_t)(cur.sen/mA_PER_pulse));
hyhoon 226:82a3ca333004 722 }
hyhoon 226:82a3ca333004 723
jobuuu 230:2c3e5ecbe7e1 724 // Others : Pressure A, B, Supply Pressure, etc. (for Debugging) (ID:1400)
hyhoon 226:82a3ca333004 725 if (flag_data_request[2] == HIGH) {
jobuuu 230:2c3e5ecbe7e1 726 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 727 }
jeongyeseong 225:9c0becc196ba 728 }
Lightvalve 68:328e1be06f5d 729
hyhoon 227:699c3e572283 730 } else if(address==CID_RX_REF_OPENLOOP) {
Lightvalve 47:fdcb8bd86fd6 731 int16_t temp_ref_valve_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 170:42c938a40313 732
Lightvalve 57:f4819de54e7a 733 if (((OPERATING_MODE&0b110)>>1) == 0) { //Moog Valve
jobuuu 230:2c3e5ecbe7e1 734 valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~10000)
Lightvalve 57:f4819de54e7a 735 } else if (((OPERATING_MODE&0b110)>>1) == 1) { //KNR Valve
jobuuu 230:2c3e5ecbe7e1 736 valve_pos.ref = (double) temp_ref_valve_pos; // Unit : pulse (0~30000)
Lightvalve 57:f4819de54e7a 737 } else { //SW Valve
Lightvalve 57:f4819de54e7a 738 if(temp_ref_valve_pos >= 0) {
Lightvalve 238:4e660aa77eb7 739 // 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 740 valve_pos.ref = (double)temp_ref_valve_pos; // -10000~10000
Lightvalve 57:f4819de54e7a 741 } else {
Lightvalve 238:4e660aa77eb7 742 // 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 743 valve_pos.ref = (double)temp_ref_valve_pos; // -10000~10000
Lightvalve 57:f4819de54e7a 744 }
Lightvalve 47:fdcb8bd86fd6 745 }
Lightvalve 170:42c938a40313 746 } else if(address==CID_RX_REF_PWM) {
Lightvalve 49:e7bcfc244d40 747 int temp_ref_pwm = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 49:e7bcfc244d40 748 Vout.ref = (double) temp_ref_pwm;
Lightvalve 170:42c938a40313 749 }
jeongyeseong 225:9c0becc196ba 750
jeongyeseong 225:9c0becc196ba 751
jobuuu 2:a1c0a37df760 752 }
jobuuu 2:a1c0a37df760 753
jobuuu 2:a1c0a37df760 754 /******************************************************************************
jobuuu 2:a1c0a37df760 755 Information Transmission Functions
jobuuu 2:a1c0a37df760 756 *******************************************************************************/
Lightvalve 11:82d8768d7351 757
Lightvalve 170:42c938a40313 758 void CAN_TX_INFO(void)
Lightvalve 170:42c938a40313 759 {
Lightvalve 12:6f2531038ea4 760 CANMessage temp_msg;
Lightvalve 170:42c938a40313 761
jobuuu 2:a1c0a37df760 762 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 763 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 764 temp_msg.data[0] = (uint8_t) CTX_SEND_INFO;
Lightvalve 12:6f2531038ea4 765 temp_msg.data[1] = (uint8_t) BNO;
Lightvalve 12:6f2531038ea4 766 temp_msg.data[2] = (uint8_t) CAN_FREQ;
Lightvalve 12:6f2531038ea4 767 temp_msg.data[3] = (uint8_t) (CAN_FREQ >> 8);
Lightvalve 12:6f2531038ea4 768 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 769 temp_msg.data[5] = (uint8_t) CONTROL_UTILITY_MODE;
Lightvalve 12:6f2531038ea4 770 temp_msg.data[6] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 771
jobuuu 2:a1c0a37df760 772 can.write(temp_msg);
jobuuu 2:a1c0a37df760 773 }
jobuuu 2:a1c0a37df760 774
Lightvalve 170:42c938a40313 775 void CAN_TX_BNO(void)
Lightvalve 170:42c938a40313 776 {
Lightvalve 12:6f2531038ea4 777 CANMessage temp_msg;
Lightvalve 170:42c938a40313 778
jobuuu 2:a1c0a37df760 779 temp_msg.id = CID_TX_INFO;
jeongyeseong 225:9c0becc196ba 780 //temp_msg.len = 2;
hyhoon 226:82a3ca333004 781 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 782 temp_msg.data[0] = (uint8_t) CTX_SEND_BNO;
Lightvalve 12:6f2531038ea4 783 temp_msg.data[1] = (uint8_t) BNO;
jobuuu 2:a1c0a37df760 784
jobuuu 2:a1c0a37df760 785 can.write(temp_msg);
jobuuu 2:a1c0a37df760 786 }
jobuuu 2:a1c0a37df760 787
Lightvalve 170:42c938a40313 788 void CAN_TX_OPERATING_MODE(void)
Lightvalve 170:42c938a40313 789 {
jobuuu 2:a1c0a37df760 790 CANMessage temp_msg;
Lightvalve 170:42c938a40313 791
jobuuu 2:a1c0a37df760 792 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 793 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 794 temp_msg.data[0] = (uint8_t) CTX_SEND_OPERATING_MODE;
Lightvalve 12:6f2531038ea4 795 temp_msg.data[1] = (uint8_t) OPERATING_MODE;
Lightvalve 52:8ea76864368a 796 temp_msg.data[2] = (uint8_t) SENSING_MODE;
Lightvalve 52:8ea76864368a 797 temp_msg.data[3] = (uint8_t) CURRENT_CONTROL_MODE;
Lightvalve 52:8ea76864368a 798 temp_msg.data[4] = (uint8_t) FLAG_VALVE_DEADZONE;
jobuuu 2:a1c0a37df760 799
jobuuu 2:a1c0a37df760 800 can.write(temp_msg);
jobuuu 2:a1c0a37df760 801 }
jobuuu 2:a1c0a37df760 802
Lightvalve 170:42c938a40313 803 void CAN_TX_CAN_FREQ(void)
Lightvalve 170:42c938a40313 804 {
jobuuu 2:a1c0a37df760 805 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 806
jobuuu 2:a1c0a37df760 807 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 808 temp_msg.len = 3;
jobuuu 2:a1c0a37df760 809 temp_msg.data[0] = (uint8_t) CTX_SEND_CAN_FREQ;
jobuuu 2:a1c0a37df760 810 temp_msg.data[1] = (uint8_t) CAN_FREQ;
jobuuu 2:a1c0a37df760 811 temp_msg.data[2] = (uint8_t) (CAN_FREQ >> 8);
jobuuu 2:a1c0a37df760 812
jobuuu 2:a1c0a37df760 813 can.write(temp_msg);
jobuuu 2:a1c0a37df760 814 }
Lightvalve 11:82d8768d7351 815
Lightvalve 170:42c938a40313 816 void CAN_TX_CONTROL_MODE(void)
Lightvalve 170:42c938a40313 817 {
jobuuu 2:a1c0a37df760 818 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 819
jobuuu 2:a1c0a37df760 820 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 821 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 822 temp_msg.data[0] = (uint8_t) CTX_SEND_CONTROL_MODE;
Lightvalve 57:f4819de54e7a 823 temp_msg.data[1] = (uint8_t) CONTROL_UTILITY_MODE;
jobuuu 2:a1c0a37df760 824
jobuuu 2:a1c0a37df760 825 can.write(temp_msg);
jobuuu 2:a1c0a37df760 826 }
Lightvalve 11:82d8768d7351 827
Lightvalve 170:42c938a40313 828 void CAN_TX_JOINT_ENC_DIR(void)
Lightvalve 170:42c938a40313 829 {
jobuuu 2:a1c0a37df760 830 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 831
jobuuu 2:a1c0a37df760 832 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 833 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 834 temp_msg.data[0] = (uint8_t) CTX_SEND_JOINT_ENC_DIR;
Lightvalve 12:6f2531038ea4 835 temp_msg.data[1] = (uint8_t) DIR_JOINT_ENC;
Lightvalve 12:6f2531038ea4 836 temp_msg.data[2] = (uint8_t) (DIR_JOINT_ENC >> 8);
jobuuu 2:a1c0a37df760 837
jobuuu 2:a1c0a37df760 838 can.write(temp_msg);
jobuuu 2:a1c0a37df760 839 }
jobuuu 2:a1c0a37df760 840
Lightvalve 170:42c938a40313 841 void CAN_TX_VALVE_DIR(void)
Lightvalve 170:42c938a40313 842 {
jobuuu 2:a1c0a37df760 843 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 844
jobuuu 2:a1c0a37df760 845 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 846 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 847 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DIR;
Lightvalve 12:6f2531038ea4 848 temp_msg.data[1] = (uint8_t) DIR_VALVE;
Lightvalve 12:6f2531038ea4 849 temp_msg.data[2] = (uint8_t) (DIR_VALVE >> 8);
jobuuu 2:a1c0a37df760 850
jobuuu 2:a1c0a37df760 851 can.write(temp_msg);
jobuuu 2:a1c0a37df760 852 }
jobuuu 2:a1c0a37df760 853
Lightvalve 170:42c938a40313 854 void CAN_TX_VALVE_ENC_DIR(void)
Lightvalve 170:42c938a40313 855 {
jobuuu 2:a1c0a37df760 856 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 857
jobuuu 2:a1c0a37df760 858 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 859 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 860 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ENC_DIR;
Lightvalve 12:6f2531038ea4 861 temp_msg.data[1] = (uint8_t) DIR_VALVE_ENC;
Lightvalve 12:6f2531038ea4 862 temp_msg.data[2] = (uint8_t) (DIR_VALVE_ENC >> 8);
jobuuu 2:a1c0a37df760 863
jobuuu 2:a1c0a37df760 864 can.write(temp_msg);
jobuuu 2:a1c0a37df760 865 }
jobuuu 2:a1c0a37df760 866
Lightvalve 170:42c938a40313 867 void CAN_TX_VOLTAGE_SUPPLY(void)
Lightvalve 170:42c938a40313 868 {
Lightvalve 49:e7bcfc244d40 869 int16_t send_voltage_supply = (int16_t) (SUPPLY_VOLTAGE * 10.0f);
jobuuu 2:a1c0a37df760 870
jobuuu 2:a1c0a37df760 871 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 872
jobuuu 2:a1c0a37df760 873 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 874 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 875 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_SUPPLY;
Lightvalve 12:6f2531038ea4 876 temp_msg.data[1] = (uint8_t) (send_voltage_supply);
Lightvalve 12:6f2531038ea4 877 temp_msg.data[2] = (uint8_t) (send_voltage_supply >> 8);
jobuuu 2:a1c0a37df760 878
jobuuu 2:a1c0a37df760 879 can.write(temp_msg);
jobuuu 2:a1c0a37df760 880 }
jobuuu 2:a1c0a37df760 881
Lightvalve 170:42c938a40313 882 void CAN_TX_VOLTAGE_VALVE(void)
Lightvalve 170:42c938a40313 883 {
Lightvalve 49:e7bcfc244d40 884 int16_t send_voltage_valve = (int16_t) (VALVE_VOLTAGE_LIMIT * 10.0f);
jobuuu 2:a1c0a37df760 885
jobuuu 2:a1c0a37df760 886 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 887
jobuuu 2:a1c0a37df760 888 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 889 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 890 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_VALVE;
Lightvalve 12:6f2531038ea4 891 temp_msg.data[1] = (uint8_t) send_voltage_valve;
Lightvalve 12:6f2531038ea4 892 temp_msg.data[2] = (uint8_t) (send_voltage_valve >> 8);
jobuuu 2:a1c0a37df760 893
jobuuu 2:a1c0a37df760 894 can.write(temp_msg);
jobuuu 2:a1c0a37df760 895 }
Lightvalve 11:82d8768d7351 896
jobuuu 230:2c3e5ecbe7e1 897 void CAN_TX_VARIABLE_SUPPLY_ONOFF(void)
jobuuu 230:2c3e5ecbe7e1 898 {
jobuuu 230:2c3e5ecbe7e1 899 CANMessage temp_msg;
jobuuu 230:2c3e5ecbe7e1 900 temp_msg.id = CID_TX_INFO;
jobuuu 230:2c3e5ecbe7e1 901 temp_msg.len = 2;
jobuuu 230:2c3e5ecbe7e1 902 temp_msg.data[0] = (uint8_t) CTX_SEND_VARIABLE_SUPPLY;
jobuuu 230:2c3e5ecbe7e1 903 temp_msg.data[1] = (uint8_t) SUPPLY_PRESSURE_UPDATE;
jobuuu 230:2c3e5ecbe7e1 904
jobuuu 230:2c3e5ecbe7e1 905 can.write(temp_msg);
jobuuu 230:2c3e5ecbe7e1 906 }
jobuuu 2:a1c0a37df760 907
Lightvalve 170:42c938a40313 908 void CAN_TX_PID_GAIN(int t_type)
Lightvalve 170:42c938a40313 909 {
jobuuu 2:a1c0a37df760 910 // t_type = 0 : valve position control gain
jobuuu 2:a1c0a37df760 911 // t_type = 1 : joint position control gain
jobuuu 2:a1c0a37df760 912 // t_type = 2 : joint torque control gain
jobuuu 2:a1c0a37df760 913
Lightvalve 12:6f2531038ea4 914 int16_t sendPgain=0, sendIgain=0, sendDgain=0;
jobuuu 2:a1c0a37df760 915 if (t_type == 0) {
Lightvalve 30:8d561f16383b 916 sendPgain = (int16_t) (P_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 917 sendIgain = (int16_t) (I_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 918 sendDgain = (int16_t) (D_GAIN_VALVE_POSITION);
jobuuu 2:a1c0a37df760 919 } else if (t_type == 1) {
Lightvalve 12:6f2531038ea4 920 sendPgain = (int16_t) (P_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 921 sendIgain = (int16_t) (I_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 922 sendDgain = (int16_t) (D_GAIN_JOINT_POSITION);
jobuuu 2:a1c0a37df760 923 } else if (t_type == 2) {
Lightvalve 12:6f2531038ea4 924 sendPgain = (int16_t) (P_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 925 sendIgain = (int16_t) (I_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 926 sendDgain = (int16_t) (D_GAIN_JOINT_TORQUE);
Lightvalve 46:2694daea349b 927 } else if (t_type == 3) {
Lightvalve 67:c2812cf26c38 928 sendPgain = (int16_t) (K_SPRING * 10.0f);
Lightvalve 67:c2812cf26c38 929 sendIgain = (int16_t) (D_DAMPER * 100.0f);
jobuuu 2:a1c0a37df760 930 }
jobuuu 2:a1c0a37df760 931
jobuuu 2:a1c0a37df760 932 CANMessage temp_msg;
Lightvalve 170:42c938a40313 933
jobuuu 2:a1c0a37df760 934 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 935 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 936 temp_msg.data[0] = (uint8_t) CTX_SEND_PID_GAIN;
Lightvalve 12:6f2531038ea4 937 temp_msg.data[1] = (uint8_t) t_type;
Lightvalve 12:6f2531038ea4 938 temp_msg.data[2] = (uint8_t) sendPgain;
Lightvalve 12:6f2531038ea4 939 temp_msg.data[3] = (uint8_t) (sendPgain >> 8);
Lightvalve 12:6f2531038ea4 940 temp_msg.data[4] = (uint8_t) sendIgain;
Lightvalve 12:6f2531038ea4 941 temp_msg.data[5] = (uint8_t) (sendIgain >> 8);
Lightvalve 12:6f2531038ea4 942 temp_msg.data[6] = (uint8_t) sendDgain;
Lightvalve 12:6f2531038ea4 943 temp_msg.data[7] = (uint8_t) (sendDgain >> 8);
jobuuu 2:a1c0a37df760 944
jobuuu 2:a1c0a37df760 945 can.write(temp_msg);
jobuuu 2:a1c0a37df760 946 }
jobuuu 2:a1c0a37df760 947
Lightvalve 11:82d8768d7351 948
Lightvalve 170:42c938a40313 949 void CAN_TX_VALVE_DEADZONE(void)
Lightvalve 170:42c938a40313 950 {
jobuuu 2:a1c0a37df760 951 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 952
jobuuu 2:a1c0a37df760 953 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 954 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 955 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE;
Lightvalve 57:f4819de54e7a 956 temp_msg.data[1] = (uint8_t) VALVE_CENTER;
Lightvalve 57:f4819de54e7a 957 temp_msg.data[2] = (uint8_t) (VALVE_CENTER >> 8);
hyhoon 226:82a3ca333004 958 temp_msg.data[3] = (uint8_t) VALVE_DEADZONE_PLUS;
hyhoon 226:82a3ca333004 959 temp_msg.data[4] = (uint8_t) (VALVE_DEADZONE_PLUS >> 8);
hyhoon 226:82a3ca333004 960 temp_msg.data[5] = (uint8_t) VALVE_DEADZONE_MINUS;
hyhoon 226:82a3ca333004 961 temp_msg.data[6] = (uint8_t) (VALVE_DEADZONE_MINUS >> 8);
jobuuu 2:a1c0a37df760 962
jobuuu 2:a1c0a37df760 963 can.write(temp_msg);
jobuuu 2:a1c0a37df760 964 }
jobuuu 2:a1c0a37df760 965
Lightvalve 170:42c938a40313 966 void CAN_TX_VELOCITY_COMP_GAIN(void)
Lightvalve 170:42c938a40313 967 {
Lightvalve 11:82d8768d7351 968 CANMessage temp_msg;
Lightvalve 170:42c938a40313 969
Lightvalve 11:82d8768d7351 970 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 971 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 972 temp_msg.data[0] = (uint8_t) CTX_SEND_VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 973 temp_msg.data[1] = (uint8_t) VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 974 temp_msg.data[2] = (uint8_t) (VELOCITY_COMP_GAIN >> 8);
Lightvalve 11:82d8768d7351 975
Lightvalve 11:82d8768d7351 976 can.write(temp_msg);
Lightvalve 11:82d8768d7351 977 }
Lightvalve 11:82d8768d7351 978
Lightvalve 238:4e660aa77eb7 979 void CAN_TX_VALVE_ELECTRIC_CENTER(void)
Lightvalve 170:42c938a40313 980 {
Lightvalve 11:82d8768d7351 981 CANMessage temp_msg;
Lightvalve 170:42c938a40313 982
Lightvalve 11:82d8768d7351 983 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 984 temp_msg.len = 3;
Lightvalve 238:4e660aa77eb7 985 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ELECTRIC_CENTER;
Lightvalve 238:4e660aa77eb7 986 temp_msg.data[1] = (uint8_t) VALVE_ELECTRIC_CENTER;
Lightvalve 238:4e660aa77eb7 987 temp_msg.data[2] = (uint8_t) (VALVE_ELECTRIC_CENTER >> 8);
Lightvalve 11:82d8768d7351 988
Lightvalve 11:82d8768d7351 989 can.write(temp_msg);
Lightvalve 11:82d8768d7351 990 }
Lightvalve 11:82d8768d7351 991
Lightvalve 170:42c938a40313 992 void CAN_TX_VALVE_FF(void)
Lightvalve 170:42c938a40313 993 {
Lightvalve 11:82d8768d7351 994 CANMessage temp_msg;
Lightvalve 170:42c938a40313 995
Lightvalve 11:82d8768d7351 996 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 997 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 998 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_FF;
Lightvalve 12:6f2531038ea4 999 temp_msg.data[1] = (uint8_t) VALVE_FF;
Lightvalve 12:6f2531038ea4 1000 temp_msg.data[2] = (uint8_t) (VALVE_FF >> 8);
Lightvalve 11:82d8768d7351 1001
Lightvalve 11:82d8768d7351 1002 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1003 }
Lightvalve 11:82d8768d7351 1004
Lightvalve 170:42c938a40313 1005 void CAN_TX_BULK_MODULUS(void)
Lightvalve 170:42c938a40313 1006 {
Lightvalve 11:82d8768d7351 1007 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1008
Lightvalve 11:82d8768d7351 1009 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1010 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1011 temp_msg.data[0] = (uint8_t) CTX_SEND_BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1012 temp_msg.data[1] = (uint8_t) BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1013 temp_msg.data[2] = (uint8_t) (BULK_MODULUS >> 8);
Lightvalve 11:82d8768d7351 1014
Lightvalve 11:82d8768d7351 1015 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1016 }
Lightvalve 11:82d8768d7351 1017
Lightvalve 170:42c938a40313 1018 void CAN_TX_CHAMBER_VOLUME(void)
Lightvalve 170:42c938a40313 1019 {
Lightvalve 11:82d8768d7351 1020 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1021
Lightvalve 11:82d8768d7351 1022 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1023 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1024 temp_msg.data[0] = (uint8_t) CTX_SEND_CHAMBER_VOLUME;
Lightvalve 12:6f2531038ea4 1025 temp_msg.data[1] = (uint8_t) CHAMBER_VOLUME_A;
Lightvalve 12:6f2531038ea4 1026 temp_msg.data[2] = (uint8_t) (CHAMBER_VOLUME_A >> 8);
Lightvalve 12:6f2531038ea4 1027 temp_msg.data[3] = (uint8_t) CHAMBER_VOLUME_B;
Lightvalve 12:6f2531038ea4 1028 temp_msg.data[4] = (uint8_t) (CHAMBER_VOLUME_B >> 8);
Lightvalve 11:82d8768d7351 1029
Lightvalve 11:82d8768d7351 1030 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1031 }
Lightvalve 11:82d8768d7351 1032
Lightvalve 170:42c938a40313 1033 void CAN_TX_PISTON_AREA(void)
Lightvalve 170:42c938a40313 1034 {
jobuuu 2:a1c0a37df760 1035 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1036
Lightvalve 11:82d8768d7351 1037 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1038 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1039 temp_msg.data[0] = (uint8_t) CTX_SEND_PISTON_AREA;
Lightvalve 12:6f2531038ea4 1040 temp_msg.data[1] = (uint8_t) PISTON_AREA_A;
Lightvalve 12:6f2531038ea4 1041 temp_msg.data[2] = (uint8_t) (PISTON_AREA_A >> 8);
Lightvalve 12:6f2531038ea4 1042 temp_msg.data[3] = (uint8_t) PISTON_AREA_B;
Lightvalve 12:6f2531038ea4 1043 temp_msg.data[4] = (uint8_t) (PISTON_AREA_B >> 8);
jobuuu 2:a1c0a37df760 1044
Lightvalve 11:82d8768d7351 1045 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1046 }
Lightvalve 11:82d8768d7351 1047
jobuuu 230:2c3e5ecbe7e1 1048 void CAN_TX_SUP_PRES(void)
Lightvalve 170:42c938a40313 1049 {
Lightvalve 11:82d8768d7351 1050 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1051
jobuuu 230:2c3e5ecbe7e1 1052 int16_t temp_PRES_SUPPLY = (int16_t) (PRES_SUPPLY);
Lightvalve 11:82d8768d7351 1053 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1054 temp_msg.len = 5;
jobuuu 230:2c3e5ecbe7e1 1055 temp_msg.data[0] = (uint8_t) CTX_SEND_SUP_PRES;
jobuuu 230:2c3e5ecbe7e1 1056 temp_msg.data[1] = (uint8_t) temp_PRES_SUPPLY;
jobuuu 230:2c3e5ecbe7e1 1057 temp_msg.data[2] = (uint8_t) (temp_PRES_SUPPLY >> 8);
jobuuu 230:2c3e5ecbe7e1 1058 temp_msg.data[3] = 0;
jobuuu 230:2c3e5ecbe7e1 1059 temp_msg.data[4] = 0;
Lightvalve 11:82d8768d7351 1060
Lightvalve 11:82d8768d7351 1061 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1062 }
Lightvalve 11:82d8768d7351 1063
Lightvalve 170:42c938a40313 1064 void CAN_TX_ENC_LIMIT(void)
Lightvalve 170:42c938a40313 1065 {
Lightvalve 11:82d8768d7351 1066 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1067
Lightvalve 11:82d8768d7351 1068 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1069 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1070 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_LIMIT;
Lightvalve 12:6f2531038ea4 1071 temp_msg.data[1] = (uint8_t) ENC_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 1072 temp_msg.data[2] = (uint8_t) (ENC_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 1073 temp_msg.data[3] = (uint8_t) ENC_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 1074 temp_msg.data[4] = (uint8_t) (ENC_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 1075
Lightvalve 11:82d8768d7351 1076 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1077 }
Lightvalve 11:82d8768d7351 1078
Lightvalve 170:42c938a40313 1079 void CAN_TX_STROKE(void)
Lightvalve 170:42c938a40313 1080 {
Lightvalve 11:82d8768d7351 1081 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1082
Lightvalve 11:82d8768d7351 1083 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1084 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1085 temp_msg.data[0] = (uint8_t) CTX_SEND_STROKE;
Lightvalve 12:6f2531038ea4 1086 temp_msg.data[1] = (uint8_t) STROKE;
Lightvalve 12:6f2531038ea4 1087 temp_msg.data[2] = (uint8_t) (STROKE >> 8);
Lightvalve 11:82d8768d7351 1088
Lightvalve 11:82d8768d7351 1089 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1090 }
Lightvalve 11:82d8768d7351 1091
Lightvalve 170:42c938a40313 1092 void CAN_TX_VALVE_LIMIT(void)
Lightvalve 170:42c938a40313 1093 {
Lightvalve 11:82d8768d7351 1094 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1095
Lightvalve 11:82d8768d7351 1096 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1097 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1098 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT;
Lightvalve 57:f4819de54e7a 1099 temp_msg.data[1] = (uint8_t) VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1100 temp_msg.data[2] = (uint8_t) (VALVE_MIN_POS >> 8);
Lightvalve 57:f4819de54e7a 1101 temp_msg.data[3] = (uint8_t) VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1102 temp_msg.data[4] = (uint8_t) (VALVE_MAX_POS >> 8);
Lightvalve 11:82d8768d7351 1103
Lightvalve 11:82d8768d7351 1104 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1105 }
Lightvalve 11:82d8768d7351 1106
Lightvalve 170:42c938a40313 1107 void CAN_TX_ENC_PULSE_PER_POSITION(void)
Lightvalve 170:42c938a40313 1108 {
Lightvalve 11:82d8768d7351 1109 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1110
jobuuu 2:a1c0a37df760 1111 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1112 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1113 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_PULSE_PER_POSITION;
Lightvalve 54:647072f5307a 1114 int temp_enc_pulse_per_position = (int) (ENC_PULSE_PER_POSITION);
Lightvalve 48:889798ff9329 1115 temp_msg.data[1] = (uint8_t) temp_enc_pulse_per_position;
Lightvalve 48:889798ff9329 1116 temp_msg.data[2] = (uint8_t) (temp_enc_pulse_per_position >> 8);
jobuuu 2:a1c0a37df760 1117
jobuuu 2:a1c0a37df760 1118 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1119 }
jobuuu 2:a1c0a37df760 1120
Lightvalve 170:42c938a40313 1121 void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void)
Lightvalve 170:42c938a40313 1122 {
jobuuu 2:a1c0a37df760 1123 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1124
jobuuu 2:a1c0a37df760 1125 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1126 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1127 temp_msg.data[0] = (uint8_t) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 232:2976cf1b4252 1128 int temp_torque_sensor_pulse_per_torque = (int) (TORQUE_SENSOR_PULSE_PER_TORQUE * 100.0f);
Lightvalve 48:889798ff9329 1129 temp_msg.data[1] = (uint8_t) temp_torque_sensor_pulse_per_torque;
Lightvalve 48:889798ff9329 1130 temp_msg.data[2] = (uint8_t) (temp_torque_sensor_pulse_per_torque >> 8);
jobuuu 2:a1c0a37df760 1131
jobuuu 2:a1c0a37df760 1132 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1133 }
jobuuu 2:a1c0a37df760 1134
Lightvalve 170:42c938a40313 1135 void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void)
Lightvalve 170:42c938a40313 1136 {
jobuuu 2:a1c0a37df760 1137 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1138
jobuuu 2:a1c0a37df760 1139 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1140 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1141 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR;
Lightvalve 30:8d561f16383b 1142 temp_msg.data[1] = (uint8_t) (int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1143 temp_msg.data[2] = (uint8_t) ((int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1144 temp_msg.data[3] = (uint8_t) (int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1145 temp_msg.data[4] = (uint8_t) ((int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f) >> 8);
jobuuu 2:a1c0a37df760 1146
jobuuu 2:a1c0a37df760 1147 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1148 }
jobuuu 2:a1c0a37df760 1149
Lightvalve 170:42c938a40313 1150 void CAN_TX_FRICTION(void)
Lightvalve 170:42c938a40313 1151 {
Lightvalve 11:82d8768d7351 1152 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1153 int16_t send_friction;
Lightvalve 30:8d561f16383b 1154 send_friction = (int16_t) (FRICTION * 10.0f);
Lightvalve 170:42c938a40313 1155
Lightvalve 11:82d8768d7351 1156 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1157 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1158 temp_msg.data[0] = (uint8_t) CTX_SEND_FRICTION;
Lightvalve 12:6f2531038ea4 1159 temp_msg.data[1] = (uint8_t) send_friction;
Lightvalve 12:6f2531038ea4 1160 temp_msg.data[2] = (uint8_t) (send_friction >> 8);
Lightvalve 11:82d8768d7351 1161
Lightvalve 11:82d8768d7351 1162 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1163 }
Lightvalve 11:82d8768d7351 1164
Lightvalve 170:42c938a40313 1165 void CAN_TX_VALVE_GAIN_PLUS(void)
Lightvalve 170:42c938a40313 1166 {
Lightvalve 11:82d8768d7351 1167 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1168
Lightvalve 11:82d8768d7351 1169 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1170 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1171 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_PLUS;
Lightvalve 30:8d561f16383b 1172 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[0] * 50.0f);
Lightvalve 30:8d561f16383b 1173 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[2] * 50.0f);
Lightvalve 30:8d561f16383b 1174 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[4] * 50.0f);
Lightvalve 30:8d561f16383b 1175 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[6] * 50.0f);
Lightvalve 30:8d561f16383b 1176 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[8] * 50.0f);
Lightvalve 11:82d8768d7351 1177
Lightvalve 11:82d8768d7351 1178 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1179 }
Lightvalve 11:82d8768d7351 1180
Lightvalve 11:82d8768d7351 1181
Lightvalve 170:42c938a40313 1182 void CAN_TX_VALVE_GAIN_MINUS(void)
Lightvalve 170:42c938a40313 1183 {
Lightvalve 11:82d8768d7351 1184 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1185
Lightvalve 11:82d8768d7351 1186 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1187 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1188 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_MINUS;
Lightvalve 30:8d561f16383b 1189 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[1] * 50.0f);
Lightvalve 30:8d561f16383b 1190 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[3] * 50.0f);
Lightvalve 30:8d561f16383b 1191 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[5] * 50.0f);
Lightvalve 30:8d561f16383b 1192 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[7] * 50.0f);
Lightvalve 30:8d561f16383b 1193 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[9] * 50.0f);
Lightvalve 11:82d8768d7351 1194
Lightvalve 11:82d8768d7351 1195 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1196 }
Lightvalve 11:82d8768d7351 1197
Lightvalve 170:42c938a40313 1198 void CAN_TX_REFENCE_MODE(void)
Lightvalve 170:42c938a40313 1199 {
Lightvalve 11:82d8768d7351 1200 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1201
Lightvalve 11:82d8768d7351 1202 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1203 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1204 temp_msg.data[0] = (uint8_t) CTX_SEND_REFENCE_MODE;
Lightvalve 12:6f2531038ea4 1205 temp_msg.data[1] = (uint8_t) REFERENCE_MODE;
Lightvalve 30:8d561f16383b 1206 temp_msg.data[2] = (uint8_t) (int) (REFERENCE_FREQ * 100.0f);
Lightvalve 30:8d561f16383b 1207 temp_msg.data[3] = (uint8_t) ((int) (REFERENCE_FREQ * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1208 temp_msg.data[4] = (uint8_t) (int) (REFERENCE_MAG * 100.0f);
Lightvalve 30:8d561f16383b 1209 temp_msg.data[5] = (uint8_t) ((int) (REFERENCE_MAG * 100.0f) >> 8);
Lightvalve 11:82d8768d7351 1210
Lightvalve 11:82d8768d7351 1211 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1212 }
Lightvalve 11:82d8768d7351 1213
Lightvalve 170:42c938a40313 1214 void CAN_TX_HOMEPOS_OFFSET(void)
Lightvalve 170:42c938a40313 1215 {
Lightvalve 11:82d8768d7351 1216 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1217 int16_t send_homepos_offset;
hyhoon 226:82a3ca333004 1218 send_homepos_offset = (int16_t)HOMEPOS_OFFSET;
Lightvalve 170:42c938a40313 1219
jobuuu 2:a1c0a37df760 1220 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1221 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1222 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_OFFSET;
Lightvalve 12:6f2531038ea4 1223 temp_msg.data[1] = (uint8_t) send_homepos_offset;
Lightvalve 12:6f2531038ea4 1224 temp_msg.data[2] = (uint8_t) (send_homepos_offset >> 8);
jobuuu 2:a1c0a37df760 1225
jobuuu 2:a1c0a37df760 1226 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1227 }
Lightvalve 11:82d8768d7351 1228
Lightvalve 170:42c938a40313 1229 void CAN_TX_HOMPOS_VALVE_OPENING(void)
Lightvalve 170:42c938a40313 1230 {
Lightvalve 11:82d8768d7351 1231 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1232 int16_t send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1233 send_homepos_valve_opening = (int16_t) (HOMEPOS_VALVE_OPENING);
Lightvalve 170:42c938a40313 1234
Lightvalve 11:82d8768d7351 1235 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1236 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1237 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_VALVE_OPENING;
Lightvalve 12:6f2531038ea4 1238 temp_msg.data[1] = (uint8_t) send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1239 temp_msg.data[2] = (uint8_t) (send_homepos_valve_opening >> 8);
Lightvalve 11:82d8768d7351 1240
Lightvalve 11:82d8768d7351 1241 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1242 }
Lightvalve 11:82d8768d7351 1243
Lightvalve 170:42c938a40313 1244 void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex)
Lightvalve 170:42c938a40313 1245 {
Lightvalve 11:82d8768d7351 1246 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1247 int16_t valve_pos_vs_pwm;
Lightvalve 170:42c938a40313 1248
Lightvalve 237:c2cfe349f5c1 1249 if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_ELECTRIC_CENTER) {
Lightvalve 237:c2cfe349f5c1 1250 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 1251 } else {
Lightvalve 237:c2cfe349f5c1 1252 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 1253 }
Lightvalve 170:42c938a40313 1254
Lightvalve 12:6f2531038ea4 1255 int16_t PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1256 PWM_VALVE_ID = ID_index_array[canindex] * 1000;
Lightvalve 170:42c938a40313 1257
Lightvalve 11:82d8768d7351 1258 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1259 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1260 temp_msg.data[0] = (uint8_t) CTX_VALVE_PWM_VS_VALVE_POS;
Lightvalve 12:6f2531038ea4 1261 temp_msg.data[1] = (uint8_t) PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1262 temp_msg.data[2] = (uint8_t) (PWM_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1263 temp_msg.data[3] = (uint8_t) valve_pos_vs_pwm;
Lightvalve 12:6f2531038ea4 1264 temp_msg.data[4] = (uint8_t) (valve_pos_vs_pwm >> 8);
Lightvalve 11:82d8768d7351 1265
Lightvalve 11:82d8768d7351 1266 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1267 }
Lightvalve 11:82d8768d7351 1268
Lightvalve 170:42c938a40313 1269 void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex)
Lightvalve 170:42c938a40313 1270 {
Lightvalve 11:82d8768d7351 1271 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1272 int32_t valve_pos_vs_flowrate;
Lightvalve 11:82d8768d7351 1273 valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]);
Lightvalve 11:82d8768d7351 1274
Lightvalve 57:f4819de54e7a 1275 int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + VALVE_CENTER;
Lightvalve 49:e7bcfc244d40 1276 int16_t temp_valve_pos = 0;
Lightvalve 57:f4819de54e7a 1277 if(VALVE_POS_VALVE_ID>=VALVE_CENTER) {
Lightvalve 57:f4819de54e7a 1278 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 1279 } else {
Lightvalve 57:f4819de54e7a 1280 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 1281 }
Lightvalve 170:42c938a40313 1282
Lightvalve 11:82d8768d7351 1283 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1284 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1285 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_VS_FLOWRATE;
Lightvalve 49:e7bcfc244d40 1286 temp_msg.data[1] = (uint8_t) temp_valve_pos;
Lightvalve 49:e7bcfc244d40 1287 temp_msg.data[2] = (uint8_t) (temp_valve_pos >> 8);
jeongyeseong 225:9c0becc196ba 1288 temp_msg.data[3] = (uint8_t) valve_pos_vs_flowrate;
jeongyeseong 225:9c0becc196ba 1289 temp_msg.data[4] = (uint8_t) (valve_pos_vs_flowrate >> 8);
jeongyeseong 225:9c0becc196ba 1290 temp_msg.data[5] = (uint8_t) (valve_pos_vs_flowrate >> 16);
jeongyeseong 225:9c0becc196ba 1291 temp_msg.data[6] = (uint8_t) (valve_pos_vs_flowrate >> 24);
Lightvalve 11:82d8768d7351 1292
Lightvalve 11:82d8768d7351 1293 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1294 }
Lightvalve 11:82d8768d7351 1295
Lightvalve 170:42c938a40313 1296 void CAN_TX_VALVE_POS_NUM(void)
Lightvalve 170:42c938a40313 1297 {
Lightvalve 11:82d8768d7351 1298 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1299 int32_t valve_pos_num;
Lightvalve 11:82d8768d7351 1300 valve_pos_num = (int16_t) VALVE_POS_NUM;
Lightvalve 170:42c938a40313 1301
Lightvalve 11:82d8768d7351 1302 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1303 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1304 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_NUM;
Lightvalve 12:6f2531038ea4 1305 temp_msg.data[1] = (uint8_t) valve_pos_num;
Lightvalve 12:6f2531038ea4 1306 temp_msg.data[2] = (uint8_t) (valve_pos_num >> 8);
Lightvalve 11:82d8768d7351 1307
Lightvalve 11:82d8768d7351 1308 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1309 }
Lightvalve 11:82d8768d7351 1310
Lightvalve 170:42c938a40313 1311 void CAN_TX_DDV_VALVE_MAX_MIN_POS(void)
Lightvalve 170:42c938a40313 1312 {
Lightvalve 38:118df027d851 1313 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1314
Lightvalve 48:889798ff9329 1315 float temp_valve_max_pos = 0.0f;
Lightvalve 48:889798ff9329 1316 float temp_valve_min_pos = 0.0f;
Lightvalve 48:889798ff9329 1317 float temp_ddv_center = 0.0f;
Lightvalve 170:42c938a40313 1318
Lightvalve 57:f4819de54e7a 1319 temp_valve_max_pos = VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1320 temp_valve_min_pos = VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1321 temp_ddv_center = VALVE_CENTER;
Lightvalve 170:42c938a40313 1322
Lightvalve 38:118df027d851 1323 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1324 temp_msg.len = 7;
Lightvalve 38:118df027d851 1325 temp_msg.data[0] = (uint8_t) CTX_VALVE_MAX_MIN_POS;
Lightvalve 48:889798ff9329 1326 temp_msg.data[1] = (uint8_t) temp_valve_max_pos;
Lightvalve 48:889798ff9329 1327 temp_msg.data[2] = (uint8_t) ((int) (temp_valve_max_pos) >> 8);
Lightvalve 48:889798ff9329 1328 temp_msg.data[3] = (uint8_t) (temp_valve_min_pos);
Lightvalve 48:889798ff9329 1329 temp_msg.data[4] = (uint8_t) ((int) (temp_valve_min_pos) >> 8);
Lightvalve 48:889798ff9329 1330 temp_msg.data[5] = (uint8_t) (temp_ddv_center);
Lightvalve 48:889798ff9329 1331 temp_msg.data[6] = (uint8_t) ((int) (temp_ddv_center) >> 8);
Lightvalve 38:118df027d851 1332
Lightvalve 38:118df027d851 1333 can.write(temp_msg);
Lightvalve 38:118df027d851 1334 }
Lightvalve 38:118df027d851 1335
Lightvalve 169:645207e160ca 1336
Lightvalve 170:42c938a40313 1337 void CAN_TX_BUFFER(int16_t t_cnt_buffer)
Lightvalve 170:42c938a40313 1338 {
Lightvalve 169:645207e160ca 1339 CANMessage temp_msg;
Lightvalve 169:645207e160ca 1340 int16_t send_pos_array, send_ref_array;
Lightvalve 169:645207e160ca 1341 send_pos_array = (int16_t) (pos_array[t_cnt_buffer]);
Lightvalve 169:645207e160ca 1342 send_ref_array = (int16_t) (ref_array[t_cnt_buffer]);
Lightvalve 170:42c938a40313 1343
Lightvalve 169:645207e160ca 1344 temp_msg.id = CID_TX_INFO;
hyhoon 226:82a3ca333004 1345 temp_msg.len = 5;
Lightvalve 169:645207e160ca 1346 temp_msg.data[0] = (uint8_t) CTX_SEND_BUFFER;
Lightvalve 169:645207e160ca 1347 temp_msg.data[1] = (uint8_t) send_pos_array;
Lightvalve 169:645207e160ca 1348 temp_msg.data[2] = (uint8_t) (send_pos_array >> 8);
Lightvalve 169:645207e160ca 1349 temp_msg.data[3] = (uint8_t) (send_ref_array);
Lightvalve 169:645207e160ca 1350 temp_msg.data[4] = (uint8_t) ((send_ref_array) >> 8);
Lightvalve 169:645207e160ca 1351
Lightvalve 169:645207e160ca 1352 can.write(temp_msg);
Lightvalve 169:645207e160ca 1353 }
Lightvalve 169:645207e160ca 1354
Lightvalve 169:645207e160ca 1355
jobuuu 2:a1c0a37df760 1356 /******************************************************************************
jobuuu 2:a1c0a37df760 1357 Sensor & State Transmission Functions
jobuuu 2:a1c0a37df760 1358 *******************************************************************************/
jobuuu 2:a1c0a37df760 1359
Lightvalve 170:42c938a40313 1360 void CAN_TX_POSITION_FT(int16_t t_pos, int16_t t_vel, int16_t t_torq)
Lightvalve 170:42c938a40313 1361 {
Lightvalve 52:8ea76864368a 1362 CANMessage temp_msg;
Lightvalve 52:8ea76864368a 1363
hyhoon 227:699c3e572283 1364 temp_msg.id = CID_TX_POS_VEL_TORQ;
hyhoon 226:82a3ca333004 1365 temp_msg.len = 6;
Lightvalve 52:8ea76864368a 1366 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 52:8ea76864368a 1367 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 52:8ea76864368a 1368 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 52:8ea76864368a 1369 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1370 temp_msg.data[4] = (uint8_t) t_torq;
Lightvalve 52:8ea76864368a 1371 temp_msg.data[5] = (uint8_t) (t_torq >> 8);
Lightvalve 52:8ea76864368a 1372
Lightvalve 52:8ea76864368a 1373 can.write(temp_msg);
Lightvalve 52:8ea76864368a 1374 }
Lightvalve 52:8ea76864368a 1375
Lightvalve 170:42c938a40313 1376 void CAN_TX_POSITION_PRESSURE(int16_t t_pos, int16_t t_vel, int16_t t_pa, int16_t t_pb)
Lightvalve 170:42c938a40313 1377 {
Lightvalve 170:42c938a40313 1378
jobuuu 2:a1c0a37df760 1379 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1380
hyhoon 227:699c3e572283 1381 temp_msg.id = CID_TX_POS_VEL_TORQ;
jobuuu 2:a1c0a37df760 1382 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1383 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 12:6f2531038ea4 1384 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 41:abbd4e2af68b 1385 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 41:abbd4e2af68b 1386 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1387 temp_msg.data[4] = (uint8_t) t_pa;
Lightvalve 52:8ea76864368a 1388 temp_msg.data[5] = (uint8_t) (t_pa >> 8);
Lightvalve 52:8ea76864368a 1389 temp_msg.data[6] = (uint8_t) t_pb;
Lightvalve 52:8ea76864368a 1390 temp_msg.data[7] = (uint8_t) (t_pb >> 8);
jobuuu 2:a1c0a37df760 1391
jobuuu 2:a1c0a37df760 1392 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1393 }
jobuuu 2:a1c0a37df760 1394
hyhoon 227:699c3e572283 1395 void CAN_TX_CURRENT(int16_t t_pres_a, int16_t t_pres_b)
Lightvalve 170:42c938a40313 1396 {
jobuuu 2:a1c0a37df760 1397 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1398
hyhoon 227:699c3e572283 1399 temp_msg.id = CID_TX_CURRENT;
hyhoon 226:82a3ca333004 1400 temp_msg.len = 4;
Lightvalve 12:6f2531038ea4 1401 temp_msg.data[0] = (uint8_t) t_pres_a;
Lightvalve 12:6f2531038ea4 1402 temp_msg.data[1] = (uint8_t) (t_pres_a >> 8);
Lightvalve 12:6f2531038ea4 1403 temp_msg.data[2] = (uint8_t) t_pres_b;
Lightvalve 12:6f2531038ea4 1404 temp_msg.data[3] = (uint8_t) (t_pres_b >> 8);
jobuuu 2:a1c0a37df760 1405
jobuuu 2:a1c0a37df760 1406 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1407 }
jobuuu 2:a1c0a37df760 1408
Lightvalve 237:c2cfe349f5c1 1409 void CAN_TX_TORQUE(int16_t t_valve_pos)
Lightvalve 237:c2cfe349f5c1 1410 {
Lightvalve 237:c2cfe349f5c1 1411 CANMessage temp_msg;
Lightvalve 237:c2cfe349f5c1 1412
Lightvalve 237:c2cfe349f5c1 1413 temp_msg.id = CID_TX_PWM;
Lightvalve 237:c2cfe349f5c1 1414 temp_msg.len = 2;
Lightvalve 237:c2cfe349f5c1 1415 temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 237:c2cfe349f5c1 1416 temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
Lightvalve 237:c2cfe349f5c1 1417
Lightvalve 237:c2cfe349f5c1 1418 can.write(temp_msg);
Lightvalve 237:c2cfe349f5c1 1419 }
Lightvalve 237:c2cfe349f5c1 1420
Lightvalve 170:42c938a40313 1421 void CAN_TX_PWM(int16_t t_pwm)
Lightvalve 170:42c938a40313 1422 {
jobuuu 2:a1c0a37df760 1423 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1424
hyhoon 227:699c3e572283 1425 temp_msg.id = CID_TX_PWM;
hyhoon 226:82a3ca333004 1426 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 1427 temp_msg.data[0] = (uint8_t) t_pwm;
Lightvalve 12:6f2531038ea4 1428 temp_msg.data[1] = (uint8_t) (t_pwm >> 8);
jobuuu 2:a1c0a37df760 1429
jobuuu 2:a1c0a37df760 1430 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1431 }
jobuuu 2:a1c0a37df760 1432
Lightvalve 73:f80dc3970c99 1433 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 1434 {
jobuuu 2:a1c0a37df760 1435 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1436
jobuuu 2:a1c0a37df760 1437 temp_msg.id = CID_TX_VALVE_POSITION;
Lightvalve 73:f80dc3970c99 1438 temp_msg.len = 8;
Lightvalve 73:f80dc3970c99 1439 temp_msg.data[0] = (uint8_t) t_valve_pos_1;
Lightvalve 73:f80dc3970c99 1440 temp_msg.data[1] = (uint8_t) (t_valve_pos_1 >> 8);
Lightvalve 73:f80dc3970c99 1441 temp_msg.data[2] = (uint8_t) t_valve_pos_2;
Lightvalve 73:f80dc3970c99 1442 temp_msg.data[3] = (uint8_t) (t_valve_pos_2 >> 8);
Lightvalve 73:f80dc3970c99 1443 temp_msg.data[4] = (uint8_t) t_ref_valve_pos;
Lightvalve 73:f80dc3970c99 1444 temp_msg.data[5] = (uint8_t) (t_ref_valve_pos >> 8);
Lightvalve 73:f80dc3970c99 1445 temp_msg.data[6] = (uint8_t) t_pwm;
Lightvalve 73:f80dc3970c99 1446 temp_msg.data[7] = (uint8_t) (t_pwm >> 8);
Lightvalve 170:42c938a40313 1447
jobuuu 2:a1c0a37df760 1448
jobuuu 2:a1c0a37df760 1449 can.write(temp_msg);
jeongyeseong 225:9c0becc196ba 1450 }
jeongyeseong 225:9c0becc196ba 1451
jeongyeseong 225:9c0becc196ba 1452 void CAN_TX_SOMETHING(int16_t t_a, int16_t t_b, int16_t t_c, int16_t t_d)
jeongyeseong 225:9c0becc196ba 1453 {
jeongyeseong 225:9c0becc196ba 1454 CANMessage temp_msg;
jeongyeseong 225:9c0becc196ba 1455
jeongyeseong 225:9c0becc196ba 1456 temp_msg.id = CID_TX_SOMETHING;
jeongyeseong 225:9c0becc196ba 1457 temp_msg.len = 8;
jeongyeseong 225:9c0becc196ba 1458 temp_msg.data[0] = (uint8_t) t_a;
jeongyeseong 225:9c0becc196ba 1459 temp_msg.data[1] = (uint8_t) (t_a >> 8);
jeongyeseong 225:9c0becc196ba 1460 temp_msg.data[2] = (uint8_t) t_b;
jeongyeseong 225:9c0becc196ba 1461 temp_msg.data[3] = (uint8_t) (t_b >> 8);
jeongyeseong 225:9c0becc196ba 1462 temp_msg.data[4] = (uint8_t) t_c;
jeongyeseong 225:9c0becc196ba 1463 temp_msg.data[5] = (uint8_t) (t_c >> 8);
jeongyeseong 225:9c0becc196ba 1464 temp_msg.data[6] = (uint8_t) t_d;
jeongyeseong 225:9c0becc196ba 1465 temp_msg.data[7] = (uint8_t) (t_d >> 8);
jeongyeseong 225:9c0becc196ba 1466
jeongyeseong 225:9c0becc196ba 1467
jeongyeseong 225:9c0becc196ba 1468 can.write(temp_msg);
Lightvalve 237:c2cfe349f5c1 1469 }
Lightvalve 237:c2cfe349f5c1 1470
Lightvalve 237:c2cfe349f5c1 1471 void CAN_TX_VOUT(int16_t t_vout)
Lightvalve 237:c2cfe349f5c1 1472 {
Lightvalve 237:c2cfe349f5c1 1473 CANMessage temp_msg;
Lightvalve 237:c2cfe349f5c1 1474
Lightvalve 237:c2cfe349f5c1 1475 temp_msg.id = CID_TX_VOUT;
Lightvalve 237:c2cfe349f5c1 1476 temp_msg.len = 2;
Lightvalve 237:c2cfe349f5c1 1477 temp_msg.data[0] = (uint8_t) t_vout;
Lightvalve 237:c2cfe349f5c1 1478 temp_msg.data[1] = (uint8_t) (t_vout >> 8);
Lightvalve 237:c2cfe349f5c1 1479
Lightvalve 237:c2cfe349f5c1 1480 can.write(temp_msg);
Lightvalve 67:c2812cf26c38 1481 }