2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Fri May 15 08:38:26 2020 +0000
Revision:
67:3995ffeaa786
Parent:
66:328e1be06f5d
Child:
70:3436ce769b1e
200515_2

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