for learning

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Mon Jan 20 08:05:21 2020 +0000
Revision:
46:2694daea349b
Parent:
45:35fa6884d0c6
Child:
47:fdcb8bd86fd6
20200120

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