for learning

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Wed Dec 23 00:39:47 2020 +0000
Revision:
209:ebc69d6ee6f1
Parent:
192:637092202815
Child:
224:985dba42f261
Child:
233:0a37cdd59651
201223-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 192:637092202815 757 case CRX_SET_CHANGE_EVERY_REFERNCE: {
Lightvalve 192:637092202815 758 flag_every_reference = 1;
Lightvalve 192:637092202815 759 break;
Lightvalve 192:637092202815 760 }
Lightvalve 192:637092202815 761
Lightvalve 170:42c938a40313 762 default:
Lightvalve 170:42c938a40313 763 break;
jobuuu 2:a1c0a37df760 764 }
jobuuu 2:a1c0a37df760 765 }
jobuuu 2:a1c0a37df760 766
jobuuu 2:a1c0a37df760 767 void CAN_RX_HANDLER()
jobuuu 2:a1c0a37df760 768 {
Lightvalve 170:42c938a40313 769
jobuuu 2:a1c0a37df760 770 can.read(msg);
jobuuu 2:a1c0a37df760 771 unsigned int address = msg.id;
Lightvalve 170:42c938a40313 772 if(address==CID_RX_CMD) {
jobuuu 2:a1c0a37df760 773 unsigned int CMD = msg.data[0];
jobuuu 2:a1c0a37df760 774 ReadCMD(CMD);
Lightvalve 170:42c938a40313 775
jobuuu 7:e9086c72bb22 776 } else if(address==CID_RX_REF_POSITION) {
Lightvalve 170:42c938a40313 777
Lightvalve 43:b084e5f5d0d5 778 int16_t temp_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 43:b084e5f5d0d5 779 int16_t temp_vel = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 57:f4819de54e7a 780 int16_t temp_torq = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 170:42c938a40313 781
Lightvalve 57:f4819de54e7a 782 if((OPERATING_MODE&0b001)==0) { // Rotary Actuator
Lightvalve 57:f4819de54e7a 783 pos.ref = (double)temp_pos * 1.0f;
Lightvalve 57:f4819de54e7a 784 vel.ref = (double)temp_vel * 10.0f;
Lightvalve 170:42c938a40313 785 } else { //Linear Actuator
Lightvalve 67:c2812cf26c38 786 pos.ref = (double)temp_pos * 10.0f;
Lightvalve 67:c2812cf26c38 787 vel.ref = (double)temp_vel * 256.0f;
Lightvalve 57:f4819de54e7a 788 }
Lightvalve 170:42c938a40313 789
Lightvalve 68:328e1be06f5d 790 torq.ref = (double)temp_torq * 0.1f / TORQUE_SENSOR_PULSE_PER_TORQUE; //N
Lightvalve 133:22ab22818e01 791 torq.ref_diff = torq.ref - torq.ref_old;
Lightvalve 209:ebc69d6ee6f1 792 torq_dot.sen = torq.sen-totq_sen_past;
Lightvalve 133:22ab22818e01 793 torq.ref_old = torq.ref;
Lightvalve 209:ebc69d6ee6f1 794 totq_sen_past = torq.sen;
Lightvalve 170:42c938a40313 795
Lightvalve 68:328e1be06f5d 796 ///////////////Make Data///////////////////
Lightvalve 170:42c938a40313 797 for(int i=0; i<num_array_u_past-1; i++) {
Lightvalve 99:7bbcb3c0fb06 798 u_past[i] = u_past[i+1];
Lightvalve 99:7bbcb3c0fb06 799 }
Lightvalve 99:7bbcb3c0fb06 800 u_past[num_array_u_past-1] = output_normalized;
Lightvalve 170:42c938a40313 801
Lightvalve 170:42c938a40313 802 for(int i=0; i<num_array_x_past-1; i++) {
Lightvalve 68:328e1be06f5d 803 x_past[i] = x_past[i+1];
Lightvalve 68:328e1be06f5d 804 }
Lightvalve 68:328e1be06f5d 805 x_past[num_array_x_past-1] = pos.sen / ENC_PULSE_PER_POSITION; //mm
Lightvalve 170:42c938a40313 806
Lightvalve 122:dcb3ce3056a0 807 // for(int i=0;i<num_array_x_future-1;i++){
Lightvalve 122:dcb3ce3056a0 808 // x_future[i] = x_future[i+1];
Lightvalve 122:dcb3ce3056a0 809 // }
Lightvalve 122:dcb3ce3056a0 810 // x_future[num_array_x_future-1] = pos.sen / ENC_PULSE_PER_POSITION; //mm
Lightvalve 170:42c938a40313 811
Lightvalve 170:42c938a40313 812 for(int i=0; i<num_array_f_past-1; i++) {
Lightvalve 68:328e1be06f5d 813 f_past[i] = f_past[i+1];
Lightvalve 68:328e1be06f5d 814 }
Lightvalve 101:50159049a518 815 f_past[num_array_f_past-1] = torq.sen; //N
Lightvalve 170:42c938a40313 816
Lightvalve 68:328e1be06f5d 817 f_future[0] = torq.sen; //N
Lightvalve 192:637092202815 818
Lightvalve 192:637092202815 819 if(flag_every_reference == 1) {
Lightvalve 192:637092202815 820 for(int i=1; i<num_array_f_future-1; i++) {
Lightvalve 192:637092202815 821 f_future[i] = 500.0f;
Lightvalve 192:637092202815 822 }
Lightvalve 192:637092202815 823 f_future[num_array_f_future-1] = 500.0f; //N
Lightvalve 192:637092202815 824 } else {
Lightvalve 192:637092202815 825 for(int i=1; i<num_array_f_future-1; i++) {
Lightvalve 192:637092202815 826 f_future[i] = f_future[i+1];
Lightvalve 192:637092202815 827 }
Lightvalve 192:637092202815 828 f_future[num_array_f_future-1] = torq.ref; //N
Lightvalve 68:328e1be06f5d 829 }
Lightvalve 68:328e1be06f5d 830
Lightvalve 101:50159049a518 831
Lightvalve 49:e7bcfc244d40 832 } else if(address==CID_RX_REF_VALVE_POS) {
Lightvalve 47:fdcb8bd86fd6 833 int16_t temp_ref_valve_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 170:42c938a40313 834
Lightvalve 57:f4819de54e7a 835 if (((OPERATING_MODE&0b110)>>1) == 0) { //Moog Valve
Lightvalve 57:f4819de54e7a 836 valve_pos.ref = (double) temp_ref_valve_pos;
Lightvalve 57:f4819de54e7a 837 } else if (((OPERATING_MODE&0b110)>>1) == 1) { //KNR Valve
Lightvalve 57:f4819de54e7a 838 valve_pos.ref = (double) temp_ref_valve_pos;
Lightvalve 57:f4819de54e7a 839 } else { //SW Valve
Lightvalve 57:f4819de54e7a 840 if(temp_ref_valve_pos >= 0) {
Lightvalve 57:f4819de54e7a 841 valve_pos.ref = (double)VALVE_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_CENTER)/10000.0f;
Lightvalve 57:f4819de54e7a 842 } else {
Lightvalve 57:f4819de54e7a 843 valve_pos.ref = (double)VALVE_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_CENTER)/10000.0f;
Lightvalve 57:f4819de54e7a 844 }
Lightvalve 47:fdcb8bd86fd6 845 }
Lightvalve 170:42c938a40313 846 } else if(address==CID_RX_REF_PWM) {
Lightvalve 49:e7bcfc244d40 847 int temp_ref_pwm = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 49:e7bcfc244d40 848 Vout.ref = (double) temp_ref_pwm;
Lightvalve 170:42c938a40313 849 }
jobuuu 2:a1c0a37df760 850 }
jobuuu 2:a1c0a37df760 851
jobuuu 2:a1c0a37df760 852 /******************************************************************************
jobuuu 2:a1c0a37df760 853 Information Transmission Functions
jobuuu 2:a1c0a37df760 854 *******************************************************************************/
Lightvalve 11:82d8768d7351 855
Lightvalve 170:42c938a40313 856 void CAN_TX_INFO(void)
Lightvalve 170:42c938a40313 857 {
Lightvalve 12:6f2531038ea4 858 CANMessage temp_msg;
Lightvalve 170:42c938a40313 859
jobuuu 2:a1c0a37df760 860 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 861 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 862 temp_msg.data[0] = (uint8_t) CTX_SEND_INFO;
Lightvalve 12:6f2531038ea4 863 temp_msg.data[1] = (uint8_t) BNO;
Lightvalve 12:6f2531038ea4 864 temp_msg.data[2] = (uint8_t) CAN_FREQ;
Lightvalve 12:6f2531038ea4 865 temp_msg.data[3] = (uint8_t) (CAN_FREQ >> 8);
Lightvalve 12:6f2531038ea4 866 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 867 temp_msg.data[5] = (uint8_t) CONTROL_UTILITY_MODE;
Lightvalve 12:6f2531038ea4 868 temp_msg.data[6] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 869
jobuuu 2:a1c0a37df760 870 can.write(temp_msg);
jobuuu 2:a1c0a37df760 871 }
jobuuu 2:a1c0a37df760 872
Lightvalve 170:42c938a40313 873 void CAN_TX_BNO(void)
Lightvalve 170:42c938a40313 874 {
Lightvalve 12:6f2531038ea4 875 CANMessage temp_msg;
Lightvalve 170:42c938a40313 876
jobuuu 2:a1c0a37df760 877 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 878 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 879 temp_msg.data[0] = (uint8_t) CTX_SEND_BNO;
Lightvalve 12:6f2531038ea4 880 temp_msg.data[1] = (uint8_t) BNO;
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_OPERATING_MODE(void)
Lightvalve 170:42c938a40313 886 {
jobuuu 2:a1c0a37df760 887 CANMessage temp_msg;
Lightvalve 170:42c938a40313 888
jobuuu 2:a1c0a37df760 889 temp_msg.id = CID_TX_INFO;
Lightvalve 52:8ea76864368a 890 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 891 temp_msg.data[0] = (uint8_t) CTX_SEND_OPERATING_MODE;
Lightvalve 12:6f2531038ea4 892 temp_msg.data[1] = (uint8_t) OPERATING_MODE;
Lightvalve 52:8ea76864368a 893 temp_msg.data[2] = (uint8_t) SENSING_MODE;
Lightvalve 52:8ea76864368a 894 temp_msg.data[3] = (uint8_t) CURRENT_CONTROL_MODE;
Lightvalve 52:8ea76864368a 895 temp_msg.data[4] = (uint8_t) FLAG_VALVE_DEADZONE;
jobuuu 2:a1c0a37df760 896
jobuuu 2:a1c0a37df760 897 can.write(temp_msg);
jobuuu 2:a1c0a37df760 898 }
jobuuu 2:a1c0a37df760 899
Lightvalve 170:42c938a40313 900 void CAN_TX_CAN_FREQ(void)
Lightvalve 170:42c938a40313 901 {
jobuuu 2:a1c0a37df760 902 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 903
jobuuu 2:a1c0a37df760 904 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 905 temp_msg.len = 3;
jobuuu 2:a1c0a37df760 906 temp_msg.data[0] = (uint8_t) CTX_SEND_CAN_FREQ;
jobuuu 2:a1c0a37df760 907 temp_msg.data[1] = (uint8_t) CAN_FREQ;
jobuuu 2:a1c0a37df760 908 temp_msg.data[2] = (uint8_t) (CAN_FREQ >> 8);
jobuuu 2:a1c0a37df760 909
jobuuu 2:a1c0a37df760 910 can.write(temp_msg);
jobuuu 2:a1c0a37df760 911 }
Lightvalve 11:82d8768d7351 912
Lightvalve 170:42c938a40313 913 void CAN_TX_CONTROL_MODE(void)
Lightvalve 170:42c938a40313 914 {
jobuuu 2:a1c0a37df760 915 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 916
jobuuu 2:a1c0a37df760 917 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 918 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 919 temp_msg.data[0] = (uint8_t) CTX_SEND_CONTROL_MODE;
Lightvalve 57:f4819de54e7a 920 temp_msg.data[1] = (uint8_t) CONTROL_UTILITY_MODE;
jobuuu 2:a1c0a37df760 921
jobuuu 2:a1c0a37df760 922 can.write(temp_msg);
jobuuu 2:a1c0a37df760 923 }
Lightvalve 11:82d8768d7351 924
Lightvalve 170:42c938a40313 925 void CAN_TX_JOINT_ENC_DIR(void)
Lightvalve 170:42c938a40313 926 {
jobuuu 2:a1c0a37df760 927 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 928
jobuuu 2:a1c0a37df760 929 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 930 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 931 temp_msg.data[0] = (uint8_t) CTX_SEND_JOINT_ENC_DIR;
Lightvalve 12:6f2531038ea4 932 temp_msg.data[1] = (uint8_t) DIR_JOINT_ENC;
Lightvalve 12:6f2531038ea4 933 temp_msg.data[2] = (uint8_t) (DIR_JOINT_ENC >> 8);
jobuuu 2:a1c0a37df760 934
jobuuu 2:a1c0a37df760 935 can.write(temp_msg);
jobuuu 2:a1c0a37df760 936 }
jobuuu 2:a1c0a37df760 937
Lightvalve 170:42c938a40313 938 void CAN_TX_VALVE_DIR(void)
Lightvalve 170:42c938a40313 939 {
jobuuu 2:a1c0a37df760 940 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 941
jobuuu 2:a1c0a37df760 942 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 943 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 944 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DIR;
Lightvalve 12:6f2531038ea4 945 temp_msg.data[1] = (uint8_t) DIR_VALVE;
Lightvalve 12:6f2531038ea4 946 temp_msg.data[2] = (uint8_t) (DIR_VALVE >> 8);
jobuuu 2:a1c0a37df760 947
jobuuu 2:a1c0a37df760 948 can.write(temp_msg);
jobuuu 2:a1c0a37df760 949 }
jobuuu 2:a1c0a37df760 950
Lightvalve 170:42c938a40313 951 void CAN_TX_VALVE_ENC_DIR(void)
Lightvalve 170:42c938a40313 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_VALVE_ENC_DIR;
Lightvalve 12:6f2531038ea4 958 temp_msg.data[1] = (uint8_t) DIR_VALVE_ENC;
Lightvalve 12:6f2531038ea4 959 temp_msg.data[2] = (uint8_t) (DIR_VALVE_ENC >> 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_SUPPLY(void)
Lightvalve 170:42c938a40313 965 {
Lightvalve 49:e7bcfc244d40 966 int16_t send_voltage_supply = (int16_t) (SUPPLY_VOLTAGE * 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_SUPPLY;
Lightvalve 12:6f2531038ea4 973 temp_msg.data[1] = (uint8_t) (send_voltage_supply);
Lightvalve 12:6f2531038ea4 974 temp_msg.data[2] = (uint8_t) (send_voltage_supply >> 8);
jobuuu 2:a1c0a37df760 975
jobuuu 2:a1c0a37df760 976 can.write(temp_msg);
jobuuu 2:a1c0a37df760 977 }
jobuuu 2:a1c0a37df760 978
Lightvalve 170:42c938a40313 979 void CAN_TX_VOLTAGE_VALVE(void)
Lightvalve 170:42c938a40313 980 {
Lightvalve 49:e7bcfc244d40 981 int16_t send_voltage_valve = (int16_t) (VALVE_VOLTAGE_LIMIT * 10.0f);
jobuuu 2:a1c0a37df760 982
jobuuu 2:a1c0a37df760 983 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 984
jobuuu 2:a1c0a37df760 985 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 986 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 987 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_VALVE;
Lightvalve 12:6f2531038ea4 988 temp_msg.data[1] = (uint8_t) send_voltage_valve;
Lightvalve 12:6f2531038ea4 989 temp_msg.data[2] = (uint8_t) (send_voltage_valve >> 8);
jobuuu 2:a1c0a37df760 990
jobuuu 2:a1c0a37df760 991 can.write(temp_msg);
jobuuu 2:a1c0a37df760 992 }
Lightvalve 11:82d8768d7351 993
jobuuu 2:a1c0a37df760 994
Lightvalve 170:42c938a40313 995 void CAN_TX_PID_GAIN(int t_type)
Lightvalve 170:42c938a40313 996 {
jobuuu 2:a1c0a37df760 997 // t_type = 0 : valve position control gain
jobuuu 2:a1c0a37df760 998 // t_type = 1 : joint position control gain
jobuuu 2:a1c0a37df760 999 // t_type = 2 : joint torque control gain
jobuuu 2:a1c0a37df760 1000
Lightvalve 12:6f2531038ea4 1001 int16_t sendPgain=0, sendIgain=0, sendDgain=0;
jobuuu 2:a1c0a37df760 1002 if (t_type == 0) {
Lightvalve 30:8d561f16383b 1003 sendPgain = (int16_t) (P_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 1004 sendIgain = (int16_t) (I_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 1005 sendDgain = (int16_t) (D_GAIN_VALVE_POSITION);
jobuuu 2:a1c0a37df760 1006 } else if (t_type == 1) {
Lightvalve 12:6f2531038ea4 1007 sendPgain = (int16_t) (P_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 1008 sendIgain = (int16_t) (I_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 1009 sendDgain = (int16_t) (D_GAIN_JOINT_POSITION);
jobuuu 2:a1c0a37df760 1010 } else if (t_type == 2) {
Lightvalve 12:6f2531038ea4 1011 sendPgain = (int16_t) (P_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 1012 sendIgain = (int16_t) (I_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 1013 sendDgain = (int16_t) (D_GAIN_JOINT_TORQUE);
Lightvalve 46:2694daea349b 1014 } else if (t_type == 3) {
Lightvalve 67:c2812cf26c38 1015 sendPgain = (int16_t) (K_SPRING * 10.0f);
Lightvalve 67:c2812cf26c38 1016 sendIgain = (int16_t) (D_DAMPER * 100.0f);
jobuuu 2:a1c0a37df760 1017 }
jobuuu 2:a1c0a37df760 1018
jobuuu 2:a1c0a37df760 1019 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1020
jobuuu 2:a1c0a37df760 1021 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1022 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1023 temp_msg.data[0] = (uint8_t) CTX_SEND_PID_GAIN;
Lightvalve 12:6f2531038ea4 1024 temp_msg.data[1] = (uint8_t) t_type;
Lightvalve 12:6f2531038ea4 1025 temp_msg.data[2] = (uint8_t) sendPgain;
Lightvalve 12:6f2531038ea4 1026 temp_msg.data[3] = (uint8_t) (sendPgain >> 8);
Lightvalve 12:6f2531038ea4 1027 temp_msg.data[4] = (uint8_t) sendIgain;
Lightvalve 12:6f2531038ea4 1028 temp_msg.data[5] = (uint8_t) (sendIgain >> 8);
Lightvalve 12:6f2531038ea4 1029 temp_msg.data[6] = (uint8_t) sendDgain;
Lightvalve 12:6f2531038ea4 1030 temp_msg.data[7] = (uint8_t) (sendDgain >> 8);
jobuuu 2:a1c0a37df760 1031
jobuuu 2:a1c0a37df760 1032 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1033 }
jobuuu 2:a1c0a37df760 1034
Lightvalve 11:82d8768d7351 1035
Lightvalve 170:42c938a40313 1036 void CAN_TX_VALVE_DEADZONE(void)
Lightvalve 170:42c938a40313 1037 {
jobuuu 2:a1c0a37df760 1038 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1039
jobuuu 2:a1c0a37df760 1040 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1041 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1042 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE;
Lightvalve 57:f4819de54e7a 1043 temp_msg.data[1] = (uint8_t) VALVE_CENTER;
Lightvalve 57:f4819de54e7a 1044 temp_msg.data[2] = (uint8_t) (VALVE_CENTER >> 8);
Lightvalve 12:6f2531038ea4 1045 temp_msg.data[3] = (uint8_t) (int) (VALVE_DEADZONE_PLUS);
Lightvalve 12:6f2531038ea4 1046 temp_msg.data[4] = (uint8_t) ((int) (VALVE_DEADZONE_PLUS) >> 8);
Lightvalve 12:6f2531038ea4 1047 temp_msg.data[5] = (uint8_t) (int) (VALVE_DEADZONE_MINUS);
Lightvalve 12:6f2531038ea4 1048 temp_msg.data[6] = (uint8_t) ((int) (VALVE_DEADZONE_MINUS) >> 8);
jobuuu 2:a1c0a37df760 1049
jobuuu 2:a1c0a37df760 1050 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1051 }
jobuuu 2:a1c0a37df760 1052
Lightvalve 170:42c938a40313 1053 void CAN_TX_VELOCITY_COMP_GAIN(void)
Lightvalve 170:42c938a40313 1054 {
Lightvalve 11:82d8768d7351 1055 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1056
Lightvalve 11:82d8768d7351 1057 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1058 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1059 temp_msg.data[0] = (uint8_t) CTX_SEND_VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 1060 temp_msg.data[1] = (uint8_t) VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 1061 temp_msg.data[2] = (uint8_t) (VELOCITY_COMP_GAIN >> 8);
Lightvalve 11:82d8768d7351 1062
Lightvalve 11:82d8768d7351 1063 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1064 }
Lightvalve 11:82d8768d7351 1065
Lightvalve 170:42c938a40313 1066 void CAN_TX_COMPLIANCE_GAIN(void)
Lightvalve 170:42c938a40313 1067 {
Lightvalve 11:82d8768d7351 1068 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1069
Lightvalve 11:82d8768d7351 1070 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1071 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1072 temp_msg.data[0] = (uint8_t) CTX_SEND_COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 1073 temp_msg.data[1] = (uint8_t) COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 1074 temp_msg.data[2] = (uint8_t) (COMPLIANCE_GAIN >> 8);
Lightvalve 11:82d8768d7351 1075
Lightvalve 11:82d8768d7351 1076 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1077 }
Lightvalve 11:82d8768d7351 1078
Lightvalve 170:42c938a40313 1079 void CAN_TX_VALVE_FF(void)
Lightvalve 170:42c938a40313 1080 {
Lightvalve 11:82d8768d7351 1081 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1082
Lightvalve 11:82d8768d7351 1083 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1084 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1085 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_FF;
Lightvalve 12:6f2531038ea4 1086 temp_msg.data[1] = (uint8_t) VALVE_FF;
Lightvalve 12:6f2531038ea4 1087 temp_msg.data[2] = (uint8_t) (VALVE_FF >> 8);
Lightvalve 11:82d8768d7351 1088
Lightvalve 11:82d8768d7351 1089 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1090 }
Lightvalve 11:82d8768d7351 1091
Lightvalve 170:42c938a40313 1092 void CAN_TX_BULK_MODULUS(void)
Lightvalve 170:42c938a40313 1093 {
Lightvalve 11:82d8768d7351 1094 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1095
Lightvalve 11:82d8768d7351 1096 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1097 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1098 temp_msg.data[0] = (uint8_t) CTX_SEND_BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1099 temp_msg.data[1] = (uint8_t) BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1100 temp_msg.data[2] = (uint8_t) (BULK_MODULUS >> 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_CHAMBER_VOLUME(void)
Lightvalve 170:42c938a40313 1106 {
Lightvalve 11:82d8768d7351 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_CHAMBER_VOLUME;
Lightvalve 12:6f2531038ea4 1112 temp_msg.data[1] = (uint8_t) CHAMBER_VOLUME_A;
Lightvalve 12:6f2531038ea4 1113 temp_msg.data[2] = (uint8_t) (CHAMBER_VOLUME_A >> 8);
Lightvalve 12:6f2531038ea4 1114 temp_msg.data[3] = (uint8_t) CHAMBER_VOLUME_B;
Lightvalve 12:6f2531038ea4 1115 temp_msg.data[4] = (uint8_t) (CHAMBER_VOLUME_B >> 8);
Lightvalve 11:82d8768d7351 1116
Lightvalve 11:82d8768d7351 1117 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1118 }
Lightvalve 11:82d8768d7351 1119
Lightvalve 170:42c938a40313 1120 void CAN_TX_PISTON_AREA(void)
Lightvalve 170:42c938a40313 1121 {
jobuuu 2:a1c0a37df760 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_PISTON_AREA;
Lightvalve 12:6f2531038ea4 1127 temp_msg.data[1] = (uint8_t) PISTON_AREA_A;
Lightvalve 12:6f2531038ea4 1128 temp_msg.data[2] = (uint8_t) (PISTON_AREA_A >> 8);
Lightvalve 12:6f2531038ea4 1129 temp_msg.data[3] = (uint8_t) PISTON_AREA_B;
Lightvalve 12:6f2531038ea4 1130 temp_msg.data[4] = (uint8_t) (PISTON_AREA_B >> 8);
jobuuu 2:a1c0a37df760 1131
Lightvalve 11:82d8768d7351 1132 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1133 }
Lightvalve 11:82d8768d7351 1134
Lightvalve 170:42c938a40313 1135 void CAN_TX_PRES_A_AND_B(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_PRES;
Lightvalve 12:6f2531038ea4 1142 temp_msg.data[1] = (uint8_t) PRES_SUPPLY;
Lightvalve 12:6f2531038ea4 1143 temp_msg.data[2] = (uint8_t) (PRES_SUPPLY >> 8);
Lightvalve 12:6f2531038ea4 1144 temp_msg.data[3] = (uint8_t) PRES_RETURN;
Lightvalve 12:6f2531038ea4 1145 temp_msg.data[4] = (uint8_t) (PRES_RETURN >> 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_ENC_LIMIT(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 = 5;
Lightvalve 12:6f2531038ea4 1156 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_LIMIT;
Lightvalve 12:6f2531038ea4 1157 temp_msg.data[1] = (uint8_t) ENC_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 1158 temp_msg.data[2] = (uint8_t) (ENC_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 1159 temp_msg.data[3] = (uint8_t) ENC_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 1160 temp_msg.data[4] = (uint8_t) (ENC_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 1161
Lightvalve 11:82d8768d7351 1162 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1163 }
Lightvalve 11:82d8768d7351 1164
Lightvalve 170:42c938a40313 1165 void CAN_TX_STROKE(void)
Lightvalve 170:42c938a40313 1166 {
Lightvalve 11:82d8768d7351 1167 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1168
Lightvalve 11:82d8768d7351 1169 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1170 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1171 temp_msg.data[0] = (uint8_t) CTX_SEND_STROKE;
Lightvalve 12:6f2531038ea4 1172 temp_msg.data[1] = (uint8_t) STROKE;
Lightvalve 12:6f2531038ea4 1173 temp_msg.data[2] = (uint8_t) (STROKE >> 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_VALVE_LIMIT(void)
Lightvalve 170:42c938a40313 1179 {
Lightvalve 11:82d8768d7351 1180 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1181
Lightvalve 11:82d8768d7351 1182 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1183 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1184 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT;
Lightvalve 57:f4819de54e7a 1185 temp_msg.data[1] = (uint8_t) VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1186 temp_msg.data[2] = (uint8_t) (VALVE_MIN_POS >> 8);
Lightvalve 57:f4819de54e7a 1187 temp_msg.data[3] = (uint8_t) VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1188 temp_msg.data[4] = (uint8_t) (VALVE_MAX_POS >> 8);
Lightvalve 11:82d8768d7351 1189
Lightvalve 11:82d8768d7351 1190 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1191 }
Lightvalve 11:82d8768d7351 1192
Lightvalve 170:42c938a40313 1193 void CAN_TX_ENC_PULSE_PER_POSITION(void)
Lightvalve 170:42c938a40313 1194 {
Lightvalve 11:82d8768d7351 1195 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1196
jobuuu 2:a1c0a37df760 1197 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1198 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1199 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_PULSE_PER_POSITION;
Lightvalve 54:647072f5307a 1200 int temp_enc_pulse_per_position = (int) (ENC_PULSE_PER_POSITION);
Lightvalve 48:889798ff9329 1201 temp_msg.data[1] = (uint8_t) temp_enc_pulse_per_position;
Lightvalve 48:889798ff9329 1202 temp_msg.data[2] = (uint8_t) (temp_enc_pulse_per_position >> 8);
jobuuu 2:a1c0a37df760 1203
jobuuu 2:a1c0a37df760 1204 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1205 }
jobuuu 2:a1c0a37df760 1206
Lightvalve 170:42c938a40313 1207 void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void)
Lightvalve 170:42c938a40313 1208 {
jobuuu 2:a1c0a37df760 1209 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1210
jobuuu 2:a1c0a37df760 1211 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1212 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1213 temp_msg.data[0] = (uint8_t) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 139:15621998925b 1214 int temp_torque_sensor_pulse_per_torque = (int) (TORQUE_SENSOR_PULSE_PER_TORQUE * 10000.0f);
Lightvalve 48:889798ff9329 1215 temp_msg.data[1] = (uint8_t) temp_torque_sensor_pulse_per_torque;
Lightvalve 48:889798ff9329 1216 temp_msg.data[2] = (uint8_t) (temp_torque_sensor_pulse_per_torque >> 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_PRES_SENSOR_PULSE_PER_PRES(void)
Lightvalve 170:42c938a40313 1222 {
jobuuu 2:a1c0a37df760 1223 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1224
jobuuu 2:a1c0a37df760 1225 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1226 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1227 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR;
Lightvalve 30:8d561f16383b 1228 temp_msg.data[1] = (uint8_t) (int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1229 temp_msg.data[2] = (uint8_t) ((int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1230 temp_msg.data[3] = (uint8_t) (int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1231 temp_msg.data[4] = (uint8_t) ((int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f) >> 8);
jobuuu 2:a1c0a37df760 1232
jobuuu 2:a1c0a37df760 1233 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1234 }
jobuuu 2:a1c0a37df760 1235
Lightvalve 170:42c938a40313 1236 void CAN_TX_FRICTION(void)
Lightvalve 170:42c938a40313 1237 {
Lightvalve 11:82d8768d7351 1238 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1239 int16_t send_friction;
Lightvalve 30:8d561f16383b 1240 send_friction = (int16_t) (FRICTION * 10.0f);
Lightvalve 170:42c938a40313 1241
Lightvalve 11:82d8768d7351 1242 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1243 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1244 temp_msg.data[0] = (uint8_t) CTX_SEND_FRICTION;
Lightvalve 12:6f2531038ea4 1245 temp_msg.data[1] = (uint8_t) send_friction;
Lightvalve 12:6f2531038ea4 1246 temp_msg.data[2] = (uint8_t) (send_friction >> 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_GAIN_PLUS(void)
Lightvalve 170:42c938a40313 1252 {
Lightvalve 11:82d8768d7351 1253 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1254
Lightvalve 11:82d8768d7351 1255 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1256 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1257 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_PLUS;
Lightvalve 30:8d561f16383b 1258 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[0] * 50.0f);
Lightvalve 30:8d561f16383b 1259 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[2] * 50.0f);
Lightvalve 30:8d561f16383b 1260 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[4] * 50.0f);
Lightvalve 30:8d561f16383b 1261 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[6] * 50.0f);
Lightvalve 30:8d561f16383b 1262 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[8] * 50.0f);
Lightvalve 11:82d8768d7351 1263
Lightvalve 11:82d8768d7351 1264 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1265 }
Lightvalve 11:82d8768d7351 1266
Lightvalve 170:42c938a40313 1267 void CAN_TX_DDV_VALVE_DEADZONE(void)
Lightvalve 170:42c938a40313 1268 {
Lightvalve 11:82d8768d7351 1269 CANMessage temp_msg;
Lightvalve 48:889798ff9329 1270 float temp_valve_deadzone_minus = 0.0f;
Lightvalve 48:889798ff9329 1271 float temp_valve_deadzone_plus = 0.0f;
Lightvalve 48:889798ff9329 1272 float temp_ddv_center = 0.0f;
Lightvalve 170:42c938a40313 1273
Lightvalve 57:f4819de54e7a 1274 //temp_valve_deadzone_plus = 10000.0f*((double)VALVE_DEADZONE_PLUS-(double)VALVE_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_CENTER);
Lightvalve 57:f4819de54e7a 1275 //temp_valve_deadzone_minus = -10000.0f*((double)VALVE_DEADZONE_MINUS-(double)VALVE_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_CENTER);
Lightvalve 57:f4819de54e7a 1276 temp_valve_deadzone_plus = (double)VALVE_DEADZONE_PLUS;
Lightvalve 57:f4819de54e7a 1277 temp_valve_deadzone_minus = (double)VALVE_DEADZONE_MINUS;
Lightvalve 57:f4819de54e7a 1278 temp_ddv_center = (double)VALVE_CENTER;
Lightvalve 170:42c938a40313 1279
Lightvalve 11:82d8768d7351 1280 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1281 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1282 temp_msg.data[0] = (uint8_t) CTX_SEND_DDV_VALVE_DEADZONE;
Lightvalve 48:889798ff9329 1283 temp_msg.data[1] = (uint8_t) temp_valve_deadzone_minus;
Lightvalve 48:889798ff9329 1284 temp_msg.data[2] = (uint8_t) ((int) (temp_valve_deadzone_minus) >> 8);
Lightvalve 48:889798ff9329 1285 temp_msg.data[3] = (uint8_t) (temp_valve_deadzone_plus);
Lightvalve 48:889798ff9329 1286 temp_msg.data[4] = (uint8_t) ((int) (temp_valve_deadzone_plus) >> 8);
Lightvalve 48:889798ff9329 1287 temp_msg.data[5] = (uint8_t) (temp_ddv_center);
Lightvalve 48:889798ff9329 1288 temp_msg.data[6] = (uint8_t) ((int) (temp_ddv_center) >> 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_VALVE_GAIN_MINUS(void)
Lightvalve 170:42c938a40313 1294 {
Lightvalve 11:82d8768d7351 1295 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1296
Lightvalve 11:82d8768d7351 1297 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1298 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1299 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_MINUS;
Lightvalve 30:8d561f16383b 1300 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[1] * 50.0f);
Lightvalve 30:8d561f16383b 1301 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[3] * 50.0f);
Lightvalve 30:8d561f16383b 1302 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[5] * 50.0f);
Lightvalve 30:8d561f16383b 1303 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[7] * 50.0f);
Lightvalve 30:8d561f16383b 1304 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[9] * 50.0f);
Lightvalve 11:82d8768d7351 1305
Lightvalve 11:82d8768d7351 1306 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1307 }
Lightvalve 11:82d8768d7351 1308
Lightvalve 170:42c938a40313 1309 void CAN_TX_REFENCE_MODE(void)
Lightvalve 170:42c938a40313 1310 {
Lightvalve 11:82d8768d7351 1311 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1312
Lightvalve 11:82d8768d7351 1313 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1314 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1315 temp_msg.data[0] = (uint8_t) CTX_SEND_REFENCE_MODE;
Lightvalve 12:6f2531038ea4 1316 temp_msg.data[1] = (uint8_t) REFERENCE_MODE;
Lightvalve 30:8d561f16383b 1317 temp_msg.data[2] = (uint8_t) (int) (REFERENCE_FREQ * 100.0f);
Lightvalve 30:8d561f16383b 1318 temp_msg.data[3] = (uint8_t) ((int) (REFERENCE_FREQ * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1319 temp_msg.data[4] = (uint8_t) (int) (REFERENCE_MAG * 100.0f);
Lightvalve 30:8d561f16383b 1320 temp_msg.data[5] = (uint8_t) ((int) (REFERENCE_MAG * 100.0f) >> 8);
Lightvalve 11:82d8768d7351 1321
Lightvalve 11:82d8768d7351 1322 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1323 }
Lightvalve 11:82d8768d7351 1324
Lightvalve 170:42c938a40313 1325 void CAN_TX_HOMEPOS_OFFSET(void)
Lightvalve 170:42c938a40313 1326 {
Lightvalve 11:82d8768d7351 1327 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1328 int16_t send_homepos_offset;
Lightvalve 12:6f2531038ea4 1329 send_homepos_offset = (int16_t) (HOMEPOS_OFFSET);
Lightvalve 170:42c938a40313 1330
jobuuu 2:a1c0a37df760 1331 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1332 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1333 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_OFFSET;
Lightvalve 12:6f2531038ea4 1334 temp_msg.data[1] = (uint8_t) send_homepos_offset;
Lightvalve 12:6f2531038ea4 1335 temp_msg.data[2] = (uint8_t) (send_homepos_offset >> 8);
jobuuu 2:a1c0a37df760 1336
jobuuu 2:a1c0a37df760 1337 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1338 }
Lightvalve 11:82d8768d7351 1339
Lightvalve 170:42c938a40313 1340 void CAN_TX_HOMPOS_VALVE_OPENING(void)
Lightvalve 170:42c938a40313 1341 {
Lightvalve 11:82d8768d7351 1342 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1343 int16_t send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1344 send_homepos_valve_opening = (int16_t) (HOMEPOS_VALVE_OPENING);
Lightvalve 170:42c938a40313 1345
Lightvalve 11:82d8768d7351 1346 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1347 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1348 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_VALVE_OPENING;
Lightvalve 12:6f2531038ea4 1349 temp_msg.data[1] = (uint8_t) send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1350 temp_msg.data[2] = (uint8_t) (send_homepos_valve_opening >> 8);
Lightvalve 11:82d8768d7351 1351
Lightvalve 11:82d8768d7351 1352 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1353 }
Lightvalve 11:82d8768d7351 1354
Lightvalve 170:42c938a40313 1355 void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex)
Lightvalve 170:42c938a40313 1356 {
Lightvalve 11:82d8768d7351 1357 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1358 int16_t valve_pos_vs_pwm;
Lightvalve 49:e7bcfc244d40 1359 // valve_pos_vs_pwm = (int16_t) (VALVE_POS_VS_PWM[canindex]);
Lightvalve 170:42c938a40313 1360
Lightvalve 57:f4819de54e7a 1361 if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_CENTER) {
Lightvalve 57:f4819de54e7a 1362 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 1363 } else {
Lightvalve 57:f4819de54e7a 1364 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 1365 }
Lightvalve 170:42c938a40313 1366
Lightvalve 12:6f2531038ea4 1367 int16_t PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1368 PWM_VALVE_ID = ID_index_array[canindex] * 1000;
Lightvalve 170:42c938a40313 1369
Lightvalve 11:82d8768d7351 1370 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1371 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1372 temp_msg.data[0] = (uint8_t) CTX_VALVE_PWM_VS_VALVE_POS;
Lightvalve 12:6f2531038ea4 1373 temp_msg.data[1] = (uint8_t) PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1374 temp_msg.data[2] = (uint8_t) (PWM_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1375 temp_msg.data[3] = (uint8_t) valve_pos_vs_pwm;
Lightvalve 12:6f2531038ea4 1376 temp_msg.data[4] = (uint8_t) (valve_pos_vs_pwm >> 8);
Lightvalve 11:82d8768d7351 1377
Lightvalve 11:82d8768d7351 1378 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1379 }
Lightvalve 11:82d8768d7351 1380
Lightvalve 170:42c938a40313 1381 void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex)
Lightvalve 170:42c938a40313 1382 {
Lightvalve 11:82d8768d7351 1383 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1384 int32_t valve_pos_vs_flowrate;
Lightvalve 11:82d8768d7351 1385 valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]);
Lightvalve 11:82d8768d7351 1386
Lightvalve 57:f4819de54e7a 1387 int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + VALVE_CENTER;
Lightvalve 49:e7bcfc244d40 1388 int16_t temp_valve_pos = 0;
Lightvalve 57:f4819de54e7a 1389 if(VALVE_POS_VALVE_ID>=VALVE_CENTER) {
Lightvalve 57:f4819de54e7a 1390 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 1391 } else {
Lightvalve 57:f4819de54e7a 1392 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 1393 }
Lightvalve 170:42c938a40313 1394
Lightvalve 11:82d8768d7351 1395 temp_msg.id = CID_TX_INFO;
Lightvalve 49:e7bcfc244d40 1396 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1397 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_VS_FLOWRATE;
Lightvalve 49:e7bcfc244d40 1398 temp_msg.data[1] = (uint8_t) temp_valve_pos;
Lightvalve 49:e7bcfc244d40 1399 temp_msg.data[2] = (uint8_t) (temp_valve_pos >> 8);
Lightvalve 49:e7bcfc244d40 1400 temp_msg.data[5] = (uint8_t) valve_pos_vs_flowrate;
Lightvalve 49:e7bcfc244d40 1401 temp_msg.data[6] = (uint8_t) (valve_pos_vs_flowrate >> 8);
Lightvalve 49:e7bcfc244d40 1402 temp_msg.data[7] = (uint8_t) (valve_pos_vs_flowrate >> 16);
Lightvalve 49:e7bcfc244d40 1403 temp_msg.data[7] = (uint8_t) (valve_pos_vs_flowrate >> 24);
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_VALVE_POS_NUM(void)
Lightvalve 170:42c938a40313 1409 {
Lightvalve 11:82d8768d7351 1410 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1411 int32_t valve_pos_num;
Lightvalve 11:82d8768d7351 1412 valve_pos_num = (int16_t) VALVE_POS_NUM;
Lightvalve 170:42c938a40313 1413
Lightvalve 11:82d8768d7351 1414 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1415 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1416 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_NUM;
Lightvalve 12:6f2531038ea4 1417 temp_msg.data[1] = (uint8_t) valve_pos_num;
Lightvalve 12:6f2531038ea4 1418 temp_msg.data[2] = (uint8_t) (valve_pos_num >> 8);
Lightvalve 11:82d8768d7351 1419
Lightvalve 11:82d8768d7351 1420 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1421 }
Lightvalve 11:82d8768d7351 1422
Lightvalve 170:42c938a40313 1423 void CAN_TX_DDV_VALVE_MAX_MIN_POS(void)
Lightvalve 170:42c938a40313 1424 {
Lightvalve 38:118df027d851 1425 CANMessage temp_msg;
Lightvalve 170:42c938a40313 1426
Lightvalve 48:889798ff9329 1427 float temp_valve_max_pos = 0.0f;
Lightvalve 48:889798ff9329 1428 float temp_valve_min_pos = 0.0f;
Lightvalve 48:889798ff9329 1429 float temp_ddv_center = 0.0f;
Lightvalve 170:42c938a40313 1430
Lightvalve 57:f4819de54e7a 1431 temp_valve_max_pos = VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1432 temp_valve_min_pos = VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1433 temp_ddv_center = VALVE_CENTER;
Lightvalve 170:42c938a40313 1434
Lightvalve 38:118df027d851 1435 temp_msg.id = CID_TX_INFO;
Lightvalve 38:118df027d851 1436 temp_msg.len = 7;
Lightvalve 38:118df027d851 1437 temp_msg.data[0] = (uint8_t) CTX_VALVE_MAX_MIN_POS;
Lightvalve 48:889798ff9329 1438 temp_msg.data[1] = (uint8_t) temp_valve_max_pos;
Lightvalve 48:889798ff9329 1439 temp_msg.data[2] = (uint8_t) ((int) (temp_valve_max_pos) >> 8);
Lightvalve 48:889798ff9329 1440 temp_msg.data[3] = (uint8_t) (temp_valve_min_pos);
Lightvalve 48:889798ff9329 1441 temp_msg.data[4] = (uint8_t) ((int) (temp_valve_min_pos) >> 8);
Lightvalve 48:889798ff9329 1442 temp_msg.data[5] = (uint8_t) (temp_ddv_center);
Lightvalve 48:889798ff9329 1443 temp_msg.data[6] = (uint8_t) ((int) (temp_ddv_center) >> 8);
Lightvalve 38:118df027d851 1444
Lightvalve 38:118df027d851 1445 can.write(temp_msg);
Lightvalve 38:118df027d851 1446 }
Lightvalve 38:118df027d851 1447
Lightvalve 169:645207e160ca 1448
Lightvalve 170:42c938a40313 1449 void CAN_TX_BUFFER(int16_t t_cnt_buffer)
Lightvalve 170:42c938a40313 1450 {
Lightvalve 169:645207e160ca 1451 CANMessage temp_msg;
Lightvalve 169:645207e160ca 1452 int16_t send_pos_array, send_ref_array;
Lightvalve 169:645207e160ca 1453 send_pos_array = (int16_t) (pos_array[t_cnt_buffer]);
Lightvalve 169:645207e160ca 1454 send_ref_array = (int16_t) (ref_array[t_cnt_buffer]);
Lightvalve 170:42c938a40313 1455
Lightvalve 169:645207e160ca 1456 temp_msg.id = CID_TX_INFO;
Lightvalve 169:645207e160ca 1457 temp_msg.len = 5;
Lightvalve 169:645207e160ca 1458 temp_msg.data[0] = (uint8_t) CTX_SEND_BUFFER;
Lightvalve 169:645207e160ca 1459 temp_msg.data[1] = (uint8_t) send_pos_array;
Lightvalve 169:645207e160ca 1460 temp_msg.data[2] = (uint8_t) (send_pos_array >> 8);
Lightvalve 169:645207e160ca 1461 temp_msg.data[3] = (uint8_t) (send_ref_array);
Lightvalve 169:645207e160ca 1462 temp_msg.data[4] = (uint8_t) ((send_ref_array) >> 8);
Lightvalve 169:645207e160ca 1463
Lightvalve 169:645207e160ca 1464 can.write(temp_msg);
Lightvalve 169:645207e160ca 1465 }
Lightvalve 169:645207e160ca 1466
Lightvalve 169:645207e160ca 1467
jobuuu 2:a1c0a37df760 1468 /******************************************************************************
jobuuu 2:a1c0a37df760 1469 Sensor & State Transmission Functions
jobuuu 2:a1c0a37df760 1470 *******************************************************************************/
jobuuu 2:a1c0a37df760 1471
Lightvalve 170:42c938a40313 1472 void CAN_TX_POSITION_FT(int16_t t_pos, int16_t t_vel, int16_t t_torq)
Lightvalve 170:42c938a40313 1473 {
Lightvalve 52:8ea76864368a 1474 CANMessage temp_msg;
Lightvalve 52:8ea76864368a 1475
Lightvalve 52:8ea76864368a 1476 temp_msg.id = CID_TX_POSITION;
Lightvalve 52:8ea76864368a 1477 temp_msg.len = 6;
Lightvalve 52:8ea76864368a 1478 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 52:8ea76864368a 1479 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 52:8ea76864368a 1480 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 52:8ea76864368a 1481 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1482 temp_msg.data[4] = (uint8_t) t_torq;
Lightvalve 52:8ea76864368a 1483 temp_msg.data[5] = (uint8_t) (t_torq >> 8);
Lightvalve 52:8ea76864368a 1484
Lightvalve 52:8ea76864368a 1485 can.write(temp_msg);
Lightvalve 52:8ea76864368a 1486 }
Lightvalve 52:8ea76864368a 1487
Lightvalve 170:42c938a40313 1488 void CAN_TX_POSITION_PRESSURE(int16_t t_pos, int16_t t_vel, int16_t t_pa, int16_t t_pb)
Lightvalve 170:42c938a40313 1489 {
Lightvalve 170:42c938a40313 1490
jobuuu 2:a1c0a37df760 1491 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1492
jobuuu 2:a1c0a37df760 1493 temp_msg.id = CID_TX_POSITION;
jobuuu 2:a1c0a37df760 1494 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1495 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 12:6f2531038ea4 1496 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 41:abbd4e2af68b 1497 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 41:abbd4e2af68b 1498 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1499 temp_msg.data[4] = (uint8_t) t_pa;
Lightvalve 52:8ea76864368a 1500 temp_msg.data[5] = (uint8_t) (t_pa >> 8);
Lightvalve 52:8ea76864368a 1501 temp_msg.data[6] = (uint8_t) t_pb;
Lightvalve 52:8ea76864368a 1502 temp_msg.data[7] = (uint8_t) (t_pb >> 8);
jobuuu 2:a1c0a37df760 1503
jobuuu 2:a1c0a37df760 1504 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1505 }
jobuuu 2:a1c0a37df760 1506
Lightvalve 67:c2812cf26c38 1507 //void CAN_TX_TORQUE(int16_t t_valve_pos, int16_t t_vout) {
Lightvalve 67:c2812cf26c38 1508 // CANMessage temp_msg;
Lightvalve 67:c2812cf26c38 1509 //
Lightvalve 67:c2812cf26c38 1510 // temp_msg.id = CID_TX_TORQUE;
Lightvalve 67:c2812cf26c38 1511 // temp_msg.len = 4;
Lightvalve 67:c2812cf26c38 1512 // temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 67:c2812cf26c38 1513 // temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
Lightvalve 67:c2812cf26c38 1514 // temp_msg.data[2] = (uint8_t) t_vout;
Lightvalve 67:c2812cf26c38 1515 // temp_msg.data[3] = (uint8_t) (t_vout >> 8);
Lightvalve 67:c2812cf26c38 1516 //
Lightvalve 67:c2812cf26c38 1517 // can.write(temp_msg);
Lightvalve 67:c2812cf26c38 1518 //}
Lightvalve 67:c2812cf26c38 1519
Lightvalve 170:42c938a40313 1520 void CAN_TX_TORQUE(int16_t t_valve_pos)
Lightvalve 170:42c938a40313 1521 {
jobuuu 2:a1c0a37df760 1522 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1523
jobuuu 2:a1c0a37df760 1524 temp_msg.id = CID_TX_TORQUE;
Lightvalve 67:c2812cf26c38 1525 temp_msg.len = 2;
Lightvalve 48:889798ff9329 1526 temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 48:889798ff9329 1527 temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
jobuuu 2:a1c0a37df760 1528
jobuuu 2:a1c0a37df760 1529 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1530 }
jobuuu 2:a1c0a37df760 1531
Lightvalve 170:42c938a40313 1532 void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b)
Lightvalve 170:42c938a40313 1533 {
jobuuu 2:a1c0a37df760 1534 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1535
jobuuu 2:a1c0a37df760 1536 temp_msg.id = CID_TX_PRES;
Lightvalve 57:f4819de54e7a 1537 temp_msg.len = 4;
Lightvalve 12:6f2531038ea4 1538 temp_msg.data[0] = (uint8_t) t_pres_a;
Lightvalve 12:6f2531038ea4 1539 temp_msg.data[1] = (uint8_t) (t_pres_a >> 8);
Lightvalve 12:6f2531038ea4 1540 temp_msg.data[2] = (uint8_t) t_pres_b;
Lightvalve 12:6f2531038ea4 1541 temp_msg.data[3] = (uint8_t) (t_pres_b >> 8);
jobuuu 2:a1c0a37df760 1542
jobuuu 2:a1c0a37df760 1543 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1544 }
jobuuu 2:a1c0a37df760 1545
Lightvalve 170:42c938a40313 1546 void CAN_TX_PWM(int16_t t_pwm)
Lightvalve 170:42c938a40313 1547 {
jobuuu 2:a1c0a37df760 1548 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1549
Lightvalve 57:f4819de54e7a 1550 temp_msg.id = CID_TX_VOUT;
Lightvalve 57:f4819de54e7a 1551 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 1552 temp_msg.data[0] = (uint8_t) t_pwm;
Lightvalve 12:6f2531038ea4 1553 temp_msg.data[1] = (uint8_t) (t_pwm >> 8);
jobuuu 2:a1c0a37df760 1554
jobuuu 2:a1c0a37df760 1555 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1556 }
jobuuu 2:a1c0a37df760 1557
Lightvalve 73:f80dc3970c99 1558 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 1559 {
jobuuu 2:a1c0a37df760 1560 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1561
jobuuu 2:a1c0a37df760 1562 temp_msg.id = CID_TX_VALVE_POSITION;
Lightvalve 73:f80dc3970c99 1563 temp_msg.len = 8;
Lightvalve 73:f80dc3970c99 1564 temp_msg.data[0] = (uint8_t) t_valve_pos_1;
Lightvalve 73:f80dc3970c99 1565 temp_msg.data[1] = (uint8_t) (t_valve_pos_1 >> 8);
Lightvalve 73:f80dc3970c99 1566 temp_msg.data[2] = (uint8_t) t_valve_pos_2;
Lightvalve 73:f80dc3970c99 1567 temp_msg.data[3] = (uint8_t) (t_valve_pos_2 >> 8);
Lightvalve 73:f80dc3970c99 1568 temp_msg.data[4] = (uint8_t) t_ref_valve_pos;
Lightvalve 73:f80dc3970c99 1569 temp_msg.data[5] = (uint8_t) (t_ref_valve_pos >> 8);
Lightvalve 73:f80dc3970c99 1570 temp_msg.data[6] = (uint8_t) t_pwm;
Lightvalve 73:f80dc3970c99 1571 temp_msg.data[7] = (uint8_t) (t_pwm >> 8);
Lightvalve 170:42c938a40313 1572
jobuuu 2:a1c0a37df760 1573
jobuuu 2:a1c0a37df760 1574 can.write(temp_msg);
Lightvalve 67:c2812cf26c38 1575 }