2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Mon Nov 16 02:23:23 2020 +0000
Revision:
164:645207e160ca
Parent:
158:9dd4f35e9de8
Child:
165:42c938a40313
201116_1

Who changed what in which revision?

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