rainbow

Dependencies:   mbed FastPWM

Committer:
jobuuu
Date:
Wed Apr 21 04:20:39 2021 +0000
Revision:
230:2c3e5ecbe7e1
Parent:
227:699c3e572283
Child:
231:e00e71ca3e80
Synchronize to HCB_210420 (MZ-board)

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