LIGHT2

Dependencies:   FastPWM mbed

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