for learning

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Thu Feb 13 05:16:15 2020 +0000
Revision:
50:3c630b5eba9f
Parent:
49:e7bcfc244d40
Child:
52:8ea76864368a
20200213

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