2011

Dependencies:   mbed FastPWM

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