LIGHT2

Dependencies:   FastPWM mbed

Committer:
Lightvalve
Date:
Tue Dec 15 00:19:25 2020 +0000
Revision:
180:02be1711ee0b
Parent:
177:8e9cf31d63f4
Child:
192:637092202815
201215-1

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