2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Tue May 12 11:25:00 2020 +0000
Revision:
68:328e1be06f5d
Parent:
67:c2812cf26c38
Child:
69:3995ffeaa786
200512_3

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 68:328e1be06f5d 26 extern float x_past[];
Lightvalve 68:328e1be06f5d 27 extern float f_past[];
Lightvalve 68:328e1be06f5d 28 extern float f_future[];
Lightvalve 68:328e1be06f5d 29 extern float input[];
Lightvalve 68: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 49:e7bcfc244d40 38 CID_RX_REF_VALVE_POS = (int) (BNO + INIT_CID_RX_REF_VALVE_POS);
Lightvalve 45: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 52:8ea76864368a 74 OPERATING_MODE = (uint8_t) msg.data[1];
Lightvalve 52:8ea76864368a 75 SENSING_MODE = (uint8_t) msg.data[2];
Lightvalve 52:8ea76864368a 76 CURRENT_CONTROL_MODE = (uint8_t) msg.data[3];
Lightvalve 52: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 45:35fa6884d0c6 91 case CRX_SET_POS_TORQ_TRANS: {
Lightvalve 45:35fa6884d0c6 92 MODE_POS_FT_TRANS = (int16_t) msg.data[1];
Lightvalve 45:35fa6884d0c6 93 /*
Lightvalve 45:35fa6884d0c6 94 MODE_POS_FT_TRANS == 0 : Position Control
Lightvalve 45:35fa6884d0c6 95 MODE_POS_FT_TRANS == 1 : Trasition(Position->Torque)
Lightvalve 45:35fa6884d0c6 96 MODE_POS_FT_TRANS == 2 : Torque Control (Convert to 2 automatically 3sec after transition)
Lightvalve 45:35fa6884d0c6 97 MODE_POS_FT_TRANS == 3 : Transition(Toque->Position)
Lightvalve 45: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 57:f4819de54e7a 121 //CONTROL_MODE = (int16_t) (msg.data[1]);
Lightvalve 57: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 57:f4819de54e7a 236 //CONTROL_MODE = 22;
Lightvalve 57: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 48: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 46:2694daea349b 269 } else if (msg.data[1] == 3) {
Lightvalve 67:c2812cf26c38 270 K_SPRING = (float) (((float) ((int16_t) (msg.data[2] | msg.data[3] << 8))) * 0.1f);
Lightvalve 67:c2812cf26c38 271 D_DAMPER = (float) (((float) ((int16_t) (msg.data[4] | msg.data[5] << 8))) * 0.01f);
Lightvalve 46:2694daea349b 272
Lightvalve 67: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 11:82d8768d7351 386 PISTON_AREA_alpha = (double)PISTON_AREA_B/(double)PISTON_AREA_A;
Lightvalve 57: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 57:f4819de54e7a 452 VALVE_MIN_POS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 57: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 48: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 57:f4819de54e7a 636 VALVE_CENTER_OFFSET = ((float) ((int16_t) (msg.data[1] | msg.data[2] << 8))) * 0.1f;
Lightvalve 57: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 57: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 54:647072f5307a 694 case CRX_DELAY_TEST:{
Lightvalve 54:647072f5307a 695 flag_delay_test = 1;
Lightvalve 54:647072f5307a 696 break;
Lightvalve 54:647072f5307a 697 }
Lightvalve 68:328e1be06f5d 698 case CRX_SET_NN_CONTROL_FLAG: {
Lightvalve 68:328e1be06f5d 699 NN_Control_Flag = (int16_t) msg.data[1];
Lightvalve 68:328e1be06f5d 700 CONTROL_UTILITY_MODE = 1;
Lightvalve 68:328e1be06f5d 701 break;
Lightvalve 68: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 57:f4819de54e7a 717
jobuuu 7:e9086c72bb22 718 } else if(address==CID_RX_REF_POSITION) {
Lightvalve 57:f4819de54e7a 719
Lightvalve 43:b084e5f5d0d5 720 int16_t temp_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 43:b084e5f5d0d5 721 int16_t temp_vel = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 57:f4819de54e7a 722 int16_t temp_torq = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 41:abbd4e2af68b 723
Lightvalve 57:f4819de54e7a 724 if((OPERATING_MODE&0b001)==0) { // Rotary Actuator
Lightvalve 57:f4819de54e7a 725 pos.ref = (double)temp_pos * 1.0f;
Lightvalve 57:f4819de54e7a 726 vel.ref = (double)temp_vel * 10.0f;
Lightvalve 57:f4819de54e7a 727 }
Lightvalve 57:f4819de54e7a 728 else { //Linear Actuator
Lightvalve 67:c2812cf26c38 729 pos.ref = (double)temp_pos * 10.0f;
Lightvalve 67:c2812cf26c38 730 vel.ref = (double)temp_vel * 256.0f;
Lightvalve 57:f4819de54e7a 731 }
Lightvalve 57:f4819de54e7a 732
Lightvalve 68:328e1be06f5d 733 torq.ref = (double)temp_torq * 0.1f / TORQUE_SENSOR_PULSE_PER_TORQUE; //N
Lightvalve 68:328e1be06f5d 734
Lightvalve 68:328e1be06f5d 735
Lightvalve 68:328e1be06f5d 736 ///////////////Make Data///////////////////
Lightvalve 68:328e1be06f5d 737 for(int i=0; i<num_array_x_past-1;i++){
Lightvalve 68:328e1be06f5d 738 x_past[i] = x_past[i+1];
Lightvalve 68:328e1be06f5d 739 }
Lightvalve 68:328e1be06f5d 740 x_past[num_array_x_past-1] = pos.sen / ENC_PULSE_PER_POSITION; //mm
Lightvalve 68:328e1be06f5d 741
Lightvalve 68:328e1be06f5d 742 for(int i=0; i<num_array_f_past-1;i++){
Lightvalve 68:328e1be06f5d 743 f_past[i] = f_past[i+1];
Lightvalve 68:328e1be06f5d 744 }
Lightvalve 68:328e1be06f5d 745 f_past[num_array_f_past-1] = torq.sen; //N
Lightvalve 68:328e1be06f5d 746
Lightvalve 68:328e1be06f5d 747 f_future[0] = torq.sen; //N
Lightvalve 68:328e1be06f5d 748 for(int i=1;i<num_array_f_future-1;i++){
Lightvalve 68:328e1be06f5d 749 f_future[i] = f_future[i+1];
Lightvalve 68:328e1be06f5d 750 }
Lightvalve 68:328e1be06f5d 751 f_future[num_array_f_future-1] = torq.ref; //N
Lightvalve 68:328e1be06f5d 752
Lightvalve 68:328e1be06f5d 753 int ind = 0;
Lightvalve 68:328e1be06f5d 754 for(int i=0;i<numpast_x;i++){
Lightvalve 68:328e1be06f5d 755 input[ind] = x_past[2*i] / 60.0f;
Lightvalve 68:328e1be06f5d 756 ind = ind + 1;
Lightvalve 68:328e1be06f5d 757 }
Lightvalve 68:328e1be06f5d 758 input[ind] = pos.sen / ENC_PULSE_PER_POSITION / 60.0f;
Lightvalve 68:328e1be06f5d 759 ind = ind + 1;
Lightvalve 68:328e1be06f5d 760 for(int i=0;i<numpast_f;i++){
Lightvalve 68:328e1be06f5d 761 input[ind] = f_past[2*i] / 10000.0f + 0.5f;
Lightvalve 68:328e1be06f5d 762 ind = ind + 1;
Lightvalve 68:328e1be06f5d 763 }
Lightvalve 68:328e1be06f5d 764 input[ind] = torq.sen / 10000.0f + 0.5f;
Lightvalve 68:328e1be06f5d 765 ind = ind + 1;
Lightvalve 68:328e1be06f5d 766 for(int i=0;i<numfuture_f;i++){
Lightvalve 68:328e1be06f5d 767 input[ind] = (f_future[2*i+2] - f_future[0])/10000.0f+0.5f;
Lightvalve 68:328e1be06f5d 768 ind = ind + 1;
Lightvalve 68:328e1be06f5d 769 }
Lightvalve 68:328e1be06f5d 770
Lightvalve 68:328e1be06f5d 771
Lightvalve 68:328e1be06f5d 772
Lightvalve 66:a8e6799dbce3 773
Lightvalve 49:e7bcfc244d40 774 } else if(address==CID_RX_REF_VALVE_POS) {
Lightvalve 47:fdcb8bd86fd6 775 int16_t temp_ref_valve_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 57:f4819de54e7a 776
Lightvalve 57:f4819de54e7a 777 if (((OPERATING_MODE&0b110)>>1) == 0) { //Moog Valve
Lightvalve 57:f4819de54e7a 778 valve_pos.ref = (double) temp_ref_valve_pos;
Lightvalve 57:f4819de54e7a 779 } else if (((OPERATING_MODE&0b110)>>1) == 1) { //KNR Valve
Lightvalve 57:f4819de54e7a 780 valve_pos.ref = (double) temp_ref_valve_pos;
Lightvalve 57:f4819de54e7a 781 } else { //SW Valve
Lightvalve 57:f4819de54e7a 782 if(temp_ref_valve_pos >= 0) {
Lightvalve 57:f4819de54e7a 783 valve_pos.ref = (double)VALVE_CENTER + (double)temp_ref_valve_pos * ((double)VALVE_MAX_POS-(double)VALVE_CENTER)/10000.0f;
Lightvalve 57:f4819de54e7a 784 } else {
Lightvalve 57:f4819de54e7a 785 valve_pos.ref = (double)VALVE_CENTER - (double)temp_ref_valve_pos * ((double)VALVE_MIN_POS-(double)VALVE_CENTER)/10000.0f;
Lightvalve 57:f4819de54e7a 786 }
Lightvalve 47:fdcb8bd86fd6 787 }
Lightvalve 49:e7bcfc244d40 788 } else if(address==CID_RX_REF_PWM){
Lightvalve 49:e7bcfc244d40 789 int temp_ref_pwm = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 49:e7bcfc244d40 790 Vout.ref = (double) temp_ref_pwm;
Lightvalve 45:35fa6884d0c6 791 }
jobuuu 2:a1c0a37df760 792 }
jobuuu 2:a1c0a37df760 793
jobuuu 2:a1c0a37df760 794 /******************************************************************************
jobuuu 2:a1c0a37df760 795 Information Transmission Functions
jobuuu 2:a1c0a37df760 796 *******************************************************************************/
Lightvalve 11:82d8768d7351 797
Lightvalve 11:82d8768d7351 798 void CAN_TX_INFO(void) {
Lightvalve 12:6f2531038ea4 799 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 800
jobuuu 2:a1c0a37df760 801 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 802 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 803 temp_msg.data[0] = (uint8_t) CTX_SEND_INFO;
Lightvalve 12:6f2531038ea4 804 temp_msg.data[1] = (uint8_t) BNO;
Lightvalve 12:6f2531038ea4 805 temp_msg.data[2] = (uint8_t) CAN_FREQ;
Lightvalve 12:6f2531038ea4 806 temp_msg.data[3] = (uint8_t) (CAN_FREQ >> 8);
Lightvalve 12:6f2531038ea4 807 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 808 temp_msg.data[5] = (uint8_t) CONTROL_UTILITY_MODE;
Lightvalve 12:6f2531038ea4 809 temp_msg.data[6] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 810
jobuuu 2:a1c0a37df760 811 can.write(temp_msg);
jobuuu 2:a1c0a37df760 812 }
jobuuu 2:a1c0a37df760 813
Lightvalve 11:82d8768d7351 814 void CAN_TX_BNO(void) {
Lightvalve 12:6f2531038ea4 815 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 816
jobuuu 2:a1c0a37df760 817 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 818 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 819 temp_msg.data[0] = (uint8_t) CTX_SEND_BNO;
Lightvalve 12:6f2531038ea4 820 temp_msg.data[1] = (uint8_t) BNO;
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_OPERATING_MODE(void) {
jobuuu 2:a1c0a37df760 826 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 827
jobuuu 2:a1c0a37df760 828 temp_msg.id = CID_TX_INFO;
Lightvalve 52:8ea76864368a 829 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 830 temp_msg.data[0] = (uint8_t) CTX_SEND_OPERATING_MODE;
Lightvalve 12:6f2531038ea4 831 temp_msg.data[1] = (uint8_t) OPERATING_MODE;
Lightvalve 52:8ea76864368a 832 temp_msg.data[2] = (uint8_t) SENSING_MODE;
Lightvalve 52:8ea76864368a 833 temp_msg.data[3] = (uint8_t) CURRENT_CONTROL_MODE;
Lightvalve 52:8ea76864368a 834 temp_msg.data[4] = (uint8_t) FLAG_VALVE_DEADZONE;
jobuuu 2:a1c0a37df760 835
jobuuu 2:a1c0a37df760 836 can.write(temp_msg);
jobuuu 2:a1c0a37df760 837 }
jobuuu 2:a1c0a37df760 838
Lightvalve 11:82d8768d7351 839 void CAN_TX_CAN_FREQ(void) {
jobuuu 2:a1c0a37df760 840 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 841
jobuuu 2:a1c0a37df760 842 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 843 temp_msg.len = 3;
jobuuu 2:a1c0a37df760 844 temp_msg.data[0] = (uint8_t) CTX_SEND_CAN_FREQ;
jobuuu 2:a1c0a37df760 845 temp_msg.data[1] = (uint8_t) CAN_FREQ;
jobuuu 2:a1c0a37df760 846 temp_msg.data[2] = (uint8_t) (CAN_FREQ >> 8);
jobuuu 2:a1c0a37df760 847
jobuuu 2:a1c0a37df760 848 can.write(temp_msg);
jobuuu 2:a1c0a37df760 849 }
Lightvalve 11:82d8768d7351 850
Lightvalve 11:82d8768d7351 851 void CAN_TX_CONTROL_MODE(void) {
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 = 2;
Lightvalve 12:6f2531038ea4 856 temp_msg.data[0] = (uint8_t) CTX_SEND_CONTROL_MODE;
Lightvalve 57:f4819de54e7a 857 temp_msg.data[1] = (uint8_t) CONTROL_UTILITY_MODE;
jobuuu 2:a1c0a37df760 858
jobuuu 2:a1c0a37df760 859 can.write(temp_msg);
jobuuu 2:a1c0a37df760 860 }
Lightvalve 11:82d8768d7351 861
Lightvalve 11:82d8768d7351 862 void CAN_TX_JOINT_ENC_DIR(void) {
jobuuu 2:a1c0a37df760 863 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 864
jobuuu 2:a1c0a37df760 865 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 866 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 867 temp_msg.data[0] = (uint8_t) CTX_SEND_JOINT_ENC_DIR;
Lightvalve 12:6f2531038ea4 868 temp_msg.data[1] = (uint8_t) DIR_JOINT_ENC;
Lightvalve 12:6f2531038ea4 869 temp_msg.data[2] = (uint8_t) (DIR_JOINT_ENC >> 8);
jobuuu 2:a1c0a37df760 870
jobuuu 2:a1c0a37df760 871 can.write(temp_msg);
jobuuu 2:a1c0a37df760 872 }
jobuuu 2:a1c0a37df760 873
Lightvalve 11:82d8768d7351 874 void CAN_TX_VALVE_DIR(void) {
jobuuu 2:a1c0a37df760 875 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 876
jobuuu 2:a1c0a37df760 877 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 878 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 879 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DIR;
Lightvalve 12:6f2531038ea4 880 temp_msg.data[1] = (uint8_t) DIR_VALVE;
Lightvalve 12:6f2531038ea4 881 temp_msg.data[2] = (uint8_t) (DIR_VALVE >> 8);
jobuuu 2:a1c0a37df760 882
jobuuu 2:a1c0a37df760 883 can.write(temp_msg);
jobuuu 2:a1c0a37df760 884 }
jobuuu 2:a1c0a37df760 885
Lightvalve 11:82d8768d7351 886 void CAN_TX_VALVE_ENC_DIR(void) {
jobuuu 2:a1c0a37df760 887 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 888
jobuuu 2:a1c0a37df760 889 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 890 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 891 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ENC_DIR;
Lightvalve 12:6f2531038ea4 892 temp_msg.data[1] = (uint8_t) DIR_VALVE_ENC;
Lightvalve 12:6f2531038ea4 893 temp_msg.data[2] = (uint8_t) (DIR_VALVE_ENC >> 8);
jobuuu 2:a1c0a37df760 894
jobuuu 2:a1c0a37df760 895 can.write(temp_msg);
jobuuu 2:a1c0a37df760 896 }
jobuuu 2:a1c0a37df760 897
Lightvalve 11:82d8768d7351 898 void CAN_TX_VOLTAGE_SUPPLY(void) {
Lightvalve 49:e7bcfc244d40 899 int16_t send_voltage_supply = (int16_t) (SUPPLY_VOLTAGE * 10.0f);
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 = 3;
Lightvalve 12:6f2531038ea4 905 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_SUPPLY;
Lightvalve 12:6f2531038ea4 906 temp_msg.data[1] = (uint8_t) (send_voltage_supply);
Lightvalve 12:6f2531038ea4 907 temp_msg.data[2] = (uint8_t) (send_voltage_supply >> 8);
jobuuu 2:a1c0a37df760 908
jobuuu 2:a1c0a37df760 909 can.write(temp_msg);
jobuuu 2:a1c0a37df760 910 }
jobuuu 2:a1c0a37df760 911
Lightvalve 11:82d8768d7351 912 void CAN_TX_VOLTAGE_VALVE(void) {
Lightvalve 49:e7bcfc244d40 913 int16_t send_voltage_valve = (int16_t) (VALVE_VOLTAGE_LIMIT * 10.0f);
jobuuu 2:a1c0a37df760 914
jobuuu 2:a1c0a37df760 915 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 916
jobuuu 2:a1c0a37df760 917 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 918 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 919 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_VALVE;
Lightvalve 12:6f2531038ea4 920 temp_msg.data[1] = (uint8_t) send_voltage_valve;
Lightvalve 12:6f2531038ea4 921 temp_msg.data[2] = (uint8_t) (send_voltage_valve >> 8);
jobuuu 2:a1c0a37df760 922
jobuuu 2:a1c0a37df760 923 can.write(temp_msg);
jobuuu 2:a1c0a37df760 924 }
Lightvalve 11:82d8768d7351 925
jobuuu 2:a1c0a37df760 926
Lightvalve 11:82d8768d7351 927 void CAN_TX_PID_GAIN(int t_type) {
jobuuu 2:a1c0a37df760 928 // t_type = 0 : valve position control gain
jobuuu 2:a1c0a37df760 929 // t_type = 1 : joint position control gain
jobuuu 2:a1c0a37df760 930 // t_type = 2 : joint torque control gain
jobuuu 2:a1c0a37df760 931
Lightvalve 12:6f2531038ea4 932 int16_t sendPgain=0, sendIgain=0, sendDgain=0;
jobuuu 2:a1c0a37df760 933 if (t_type == 0) {
Lightvalve 30:8d561f16383b 934 sendPgain = (int16_t) (P_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 935 sendIgain = (int16_t) (I_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 936 sendDgain = (int16_t) (D_GAIN_VALVE_POSITION);
jobuuu 2:a1c0a37df760 937 } else if (t_type == 1) {
Lightvalve 12:6f2531038ea4 938 sendPgain = (int16_t) (P_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 939 sendIgain = (int16_t) (I_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 940 sendDgain = (int16_t) (D_GAIN_JOINT_POSITION);
jobuuu 2:a1c0a37df760 941 } else if (t_type == 2) {
Lightvalve 12:6f2531038ea4 942 sendPgain = (int16_t) (P_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 943 sendIgain = (int16_t) (I_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 944 sendDgain = (int16_t) (D_GAIN_JOINT_TORQUE);
Lightvalve 46:2694daea349b 945 } else if (t_type == 3) {
Lightvalve 67:c2812cf26c38 946 sendPgain = (int16_t) (K_SPRING * 10.0f);
Lightvalve 67:c2812cf26c38 947 sendIgain = (int16_t) (D_DAMPER * 100.0f);
jobuuu 2:a1c0a37df760 948 }
jobuuu 2:a1c0a37df760 949
jobuuu 2:a1c0a37df760 950 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 951
jobuuu 2:a1c0a37df760 952 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 953 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 954 temp_msg.data[0] = (uint8_t) CTX_SEND_PID_GAIN;
Lightvalve 12:6f2531038ea4 955 temp_msg.data[1] = (uint8_t) t_type;
Lightvalve 12:6f2531038ea4 956 temp_msg.data[2] = (uint8_t) sendPgain;
Lightvalve 12:6f2531038ea4 957 temp_msg.data[3] = (uint8_t) (sendPgain >> 8);
Lightvalve 12:6f2531038ea4 958 temp_msg.data[4] = (uint8_t) sendIgain;
Lightvalve 12:6f2531038ea4 959 temp_msg.data[5] = (uint8_t) (sendIgain >> 8);
Lightvalve 12:6f2531038ea4 960 temp_msg.data[6] = (uint8_t) sendDgain;
Lightvalve 12:6f2531038ea4 961 temp_msg.data[7] = (uint8_t) (sendDgain >> 8);
jobuuu 2:a1c0a37df760 962
jobuuu 2:a1c0a37df760 963 can.write(temp_msg);
jobuuu 2:a1c0a37df760 964 }
jobuuu 2:a1c0a37df760 965
Lightvalve 11:82d8768d7351 966
Lightvalve 11:82d8768d7351 967 void CAN_TX_VALVE_DEADZONE(void) {
jobuuu 2:a1c0a37df760 968 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 969
jobuuu 2:a1c0a37df760 970 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 971 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 972 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE;
Lightvalve 57:f4819de54e7a 973 temp_msg.data[1] = (uint8_t) VALVE_CENTER;
Lightvalve 57:f4819de54e7a 974 temp_msg.data[2] = (uint8_t) (VALVE_CENTER >> 8);
Lightvalve 12:6f2531038ea4 975 temp_msg.data[3] = (uint8_t) (int) (VALVE_DEADZONE_PLUS);
Lightvalve 12:6f2531038ea4 976 temp_msg.data[4] = (uint8_t) ((int) (VALVE_DEADZONE_PLUS) >> 8);
Lightvalve 12:6f2531038ea4 977 temp_msg.data[5] = (uint8_t) (int) (VALVE_DEADZONE_MINUS);
Lightvalve 12:6f2531038ea4 978 temp_msg.data[6] = (uint8_t) ((int) (VALVE_DEADZONE_MINUS) >> 8);
jobuuu 2:a1c0a37df760 979
jobuuu 2:a1c0a37df760 980 can.write(temp_msg);
jobuuu 2:a1c0a37df760 981 }
jobuuu 2:a1c0a37df760 982
Lightvalve 11:82d8768d7351 983 void CAN_TX_VELOCITY_COMP_GAIN(void) {
Lightvalve 11:82d8768d7351 984 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 985
Lightvalve 11:82d8768d7351 986 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 987 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 988 temp_msg.data[0] = (uint8_t) CTX_SEND_VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 989 temp_msg.data[1] = (uint8_t) VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 990 temp_msg.data[2] = (uint8_t) (VELOCITY_COMP_GAIN >> 8);
Lightvalve 11:82d8768d7351 991
Lightvalve 11:82d8768d7351 992 can.write(temp_msg);
Lightvalve 11:82d8768d7351 993 }
Lightvalve 11:82d8768d7351 994
Lightvalve 11:82d8768d7351 995 void CAN_TX_COMPLIANCE_GAIN(void) {
Lightvalve 11:82d8768d7351 996 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 997
Lightvalve 11:82d8768d7351 998 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 999 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1000 temp_msg.data[0] = (uint8_t) CTX_SEND_COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 1001 temp_msg.data[1] = (uint8_t) COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 1002 temp_msg.data[2] = (uint8_t) (COMPLIANCE_GAIN >> 8);
Lightvalve 11:82d8768d7351 1003
Lightvalve 11:82d8768d7351 1004 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1005 }
Lightvalve 11:82d8768d7351 1006
Lightvalve 11:82d8768d7351 1007 void CAN_TX_VALVE_FF(void) {
Lightvalve 11:82d8768d7351 1008 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1009
Lightvalve 11:82d8768d7351 1010 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1011 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1012 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_FF;
Lightvalve 12:6f2531038ea4 1013 temp_msg.data[1] = (uint8_t) VALVE_FF;
Lightvalve 12:6f2531038ea4 1014 temp_msg.data[2] = (uint8_t) (VALVE_FF >> 8);
Lightvalve 11:82d8768d7351 1015
Lightvalve 11:82d8768d7351 1016 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1017 }
Lightvalve 11:82d8768d7351 1018
Lightvalve 11:82d8768d7351 1019 void CAN_TX_BULK_MODULUS(void) {
Lightvalve 11:82d8768d7351 1020 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1021
Lightvalve 11:82d8768d7351 1022 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1023 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1024 temp_msg.data[0] = (uint8_t) CTX_SEND_BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1025 temp_msg.data[1] = (uint8_t) BULK_MODULUS;
Lightvalve 12:6f2531038ea4 1026 temp_msg.data[2] = (uint8_t) (BULK_MODULUS >> 8);
Lightvalve 11:82d8768d7351 1027
Lightvalve 11:82d8768d7351 1028 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1029 }
Lightvalve 11:82d8768d7351 1030
Lightvalve 11:82d8768d7351 1031 void CAN_TX_CHAMBER_VOLUME(void) {
Lightvalve 11:82d8768d7351 1032 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1033
Lightvalve 11:82d8768d7351 1034 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1035 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1036 temp_msg.data[0] = (uint8_t) CTX_SEND_CHAMBER_VOLUME;
Lightvalve 12:6f2531038ea4 1037 temp_msg.data[1] = (uint8_t) CHAMBER_VOLUME_A;
Lightvalve 12:6f2531038ea4 1038 temp_msg.data[2] = (uint8_t) (CHAMBER_VOLUME_A >> 8);
Lightvalve 12:6f2531038ea4 1039 temp_msg.data[3] = (uint8_t) CHAMBER_VOLUME_B;
Lightvalve 12:6f2531038ea4 1040 temp_msg.data[4] = (uint8_t) (CHAMBER_VOLUME_B >> 8);
Lightvalve 11:82d8768d7351 1041
Lightvalve 11:82d8768d7351 1042 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1043 }
Lightvalve 11:82d8768d7351 1044
Lightvalve 11:82d8768d7351 1045 void CAN_TX_PISTON_AREA(void) {
jobuuu 2:a1c0a37df760 1046 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1047
Lightvalve 11:82d8768d7351 1048 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1049 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1050 temp_msg.data[0] = (uint8_t) CTX_SEND_PISTON_AREA;
Lightvalve 12:6f2531038ea4 1051 temp_msg.data[1] = (uint8_t) PISTON_AREA_A;
Lightvalve 12:6f2531038ea4 1052 temp_msg.data[2] = (uint8_t) (PISTON_AREA_A >> 8);
Lightvalve 12:6f2531038ea4 1053 temp_msg.data[3] = (uint8_t) PISTON_AREA_B;
Lightvalve 12:6f2531038ea4 1054 temp_msg.data[4] = (uint8_t) (PISTON_AREA_B >> 8);
jobuuu 2:a1c0a37df760 1055
Lightvalve 11:82d8768d7351 1056 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1057 }
Lightvalve 11:82d8768d7351 1058
Lightvalve 11:82d8768d7351 1059 void CAN_TX_PRES_A_AND_B(void) {
Lightvalve 11:82d8768d7351 1060 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1061
Lightvalve 11:82d8768d7351 1062 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1063 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1064 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES;
Lightvalve 12:6f2531038ea4 1065 temp_msg.data[1] = (uint8_t) PRES_SUPPLY;
Lightvalve 12:6f2531038ea4 1066 temp_msg.data[2] = (uint8_t) (PRES_SUPPLY >> 8);
Lightvalve 12:6f2531038ea4 1067 temp_msg.data[3] = (uint8_t) PRES_RETURN;
Lightvalve 12:6f2531038ea4 1068 temp_msg.data[4] = (uint8_t) (PRES_RETURN >> 8);
Lightvalve 11:82d8768d7351 1069
Lightvalve 11:82d8768d7351 1070 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1071 }
Lightvalve 11:82d8768d7351 1072
Lightvalve 11:82d8768d7351 1073 void CAN_TX_ENC_LIMIT(void) {
Lightvalve 11:82d8768d7351 1074 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1075
Lightvalve 11:82d8768d7351 1076 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1077 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1078 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_LIMIT;
Lightvalve 12:6f2531038ea4 1079 temp_msg.data[1] = (uint8_t) ENC_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 1080 temp_msg.data[2] = (uint8_t) (ENC_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 1081 temp_msg.data[3] = (uint8_t) ENC_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 1082 temp_msg.data[4] = (uint8_t) (ENC_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 1083
Lightvalve 11:82d8768d7351 1084 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1085 }
Lightvalve 11:82d8768d7351 1086
Lightvalve 11:82d8768d7351 1087 void CAN_TX_STROKE(void) {
Lightvalve 11:82d8768d7351 1088 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1089
Lightvalve 11:82d8768d7351 1090 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1091 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1092 temp_msg.data[0] = (uint8_t) CTX_SEND_STROKE;
Lightvalve 12:6f2531038ea4 1093 temp_msg.data[1] = (uint8_t) STROKE;
Lightvalve 12:6f2531038ea4 1094 temp_msg.data[2] = (uint8_t) (STROKE >> 8);
Lightvalve 11:82d8768d7351 1095
Lightvalve 11:82d8768d7351 1096 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1097 }
Lightvalve 11:82d8768d7351 1098
Lightvalve 11:82d8768d7351 1099 void CAN_TX_VALVE_LIMIT(void) {
Lightvalve 11:82d8768d7351 1100 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1101
Lightvalve 11:82d8768d7351 1102 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1103 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1104 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT;
Lightvalve 57:f4819de54e7a 1105 temp_msg.data[1] = (uint8_t) VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1106 temp_msg.data[2] = (uint8_t) (VALVE_MIN_POS >> 8);
Lightvalve 57:f4819de54e7a 1107 temp_msg.data[3] = (uint8_t) VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1108 temp_msg.data[4] = (uint8_t) (VALVE_MAX_POS >> 8);
Lightvalve 11:82d8768d7351 1109
Lightvalve 11:82d8768d7351 1110 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1111 }
Lightvalve 11:82d8768d7351 1112
Lightvalve 11:82d8768d7351 1113 void CAN_TX_ENC_PULSE_PER_POSITION(void) {
Lightvalve 11:82d8768d7351 1114 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1115
jobuuu 2:a1c0a37df760 1116 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1117 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1118 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_PULSE_PER_POSITION;
Lightvalve 54:647072f5307a 1119 int temp_enc_pulse_per_position = (int) (ENC_PULSE_PER_POSITION);
Lightvalve 48:889798ff9329 1120 temp_msg.data[1] = (uint8_t) temp_enc_pulse_per_position;
Lightvalve 48:889798ff9329 1121 temp_msg.data[2] = (uint8_t) (temp_enc_pulse_per_position >> 8);
jobuuu 2:a1c0a37df760 1122
jobuuu 2:a1c0a37df760 1123 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1124 }
jobuuu 2:a1c0a37df760 1125
Lightvalve 11:82d8768d7351 1126 void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void) {
jobuuu 2:a1c0a37df760 1127 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1128
jobuuu 2:a1c0a37df760 1129 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1130 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1131 temp_msg.data[0] = (uint8_t) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 48:889798ff9329 1132 int temp_torque_sensor_pulse_per_torque = (int) (TORQUE_SENSOR_PULSE_PER_TORQUE * 100.0f);
Lightvalve 48:889798ff9329 1133 temp_msg.data[1] = (uint8_t) temp_torque_sensor_pulse_per_torque;
Lightvalve 48:889798ff9329 1134 temp_msg.data[2] = (uint8_t) (temp_torque_sensor_pulse_per_torque >> 8);
jobuuu 2:a1c0a37df760 1135
jobuuu 2:a1c0a37df760 1136 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1137 }
jobuuu 2:a1c0a37df760 1138
Lightvalve 11:82d8768d7351 1139 void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void) {
jobuuu 2:a1c0a37df760 1140 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1141
jobuuu 2:a1c0a37df760 1142 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1143 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1144 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR;
Lightvalve 30:8d561f16383b 1145 temp_msg.data[1] = (uint8_t) (int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1146 temp_msg.data[2] = (uint8_t) ((int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1147 temp_msg.data[3] = (uint8_t) (int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1148 temp_msg.data[4] = (uint8_t) ((int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f) >> 8);
jobuuu 2:a1c0a37df760 1149
jobuuu 2:a1c0a37df760 1150 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1151 }
jobuuu 2:a1c0a37df760 1152
Lightvalve 11:82d8768d7351 1153 void CAN_TX_FRICTION(void) {
Lightvalve 11:82d8768d7351 1154 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1155 int16_t send_friction;
Lightvalve 30:8d561f16383b 1156 send_friction = (int16_t) (FRICTION * 10.0f);
Lightvalve 11:82d8768d7351 1157
Lightvalve 11:82d8768d7351 1158 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1159 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1160 temp_msg.data[0] = (uint8_t) CTX_SEND_FRICTION;
Lightvalve 12:6f2531038ea4 1161 temp_msg.data[1] = (uint8_t) send_friction;
Lightvalve 12:6f2531038ea4 1162 temp_msg.data[2] = (uint8_t) (send_friction >> 8);
Lightvalve 11:82d8768d7351 1163
Lightvalve 11:82d8768d7351 1164 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1165 }
Lightvalve 11:82d8768d7351 1166
Lightvalve 11:82d8768d7351 1167 void CAN_TX_VALVE_GAIN_PLUS(void) {
Lightvalve 11:82d8768d7351 1168 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1169
Lightvalve 11:82d8768d7351 1170 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1171 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1172 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_PLUS;
Lightvalve 30:8d561f16383b 1173 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[0] * 50.0f);
Lightvalve 30:8d561f16383b 1174 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[2] * 50.0f);
Lightvalve 30:8d561f16383b 1175 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[4] * 50.0f);
Lightvalve 30:8d561f16383b 1176 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[6] * 50.0f);
Lightvalve 30:8d561f16383b 1177 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[8] * 50.0f);
Lightvalve 11:82d8768d7351 1178
Lightvalve 11:82d8768d7351 1179 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1180 }
Lightvalve 11:82d8768d7351 1181
Lightvalve 11:82d8768d7351 1182 void CAN_TX_DDV_VALVE_DEADZONE(void) {
Lightvalve 11:82d8768d7351 1183 CANMessage temp_msg;
Lightvalve 48:889798ff9329 1184 float temp_valve_deadzone_minus = 0.0f;
Lightvalve 48:889798ff9329 1185 float temp_valve_deadzone_plus = 0.0f;
Lightvalve 48:889798ff9329 1186 float temp_ddv_center = 0.0f;
Lightvalve 48:889798ff9329 1187
Lightvalve 57:f4819de54e7a 1188 //temp_valve_deadzone_plus = 10000.0f*((double)VALVE_DEADZONE_PLUS-(double)VALVE_CENTER)/((double)VALVE_MAX_POS-(double)VALVE_CENTER);
Lightvalve 57:f4819de54e7a 1189 //temp_valve_deadzone_minus = -10000.0f*((double)VALVE_DEADZONE_MINUS-(double)VALVE_CENTER)/((double)VALVE_MIN_POS-(double)VALVE_CENTER);
Lightvalve 57:f4819de54e7a 1190 temp_valve_deadzone_plus = (double)VALVE_DEADZONE_PLUS;
Lightvalve 57:f4819de54e7a 1191 temp_valve_deadzone_minus = (double)VALVE_DEADZONE_MINUS;
Lightvalve 57:f4819de54e7a 1192 temp_ddv_center = (double)VALVE_CENTER;
Lightvalve 11:82d8768d7351 1193
Lightvalve 11:82d8768d7351 1194 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1195 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1196 temp_msg.data[0] = (uint8_t) CTX_SEND_DDV_VALVE_DEADZONE;
Lightvalve 48:889798ff9329 1197 temp_msg.data[1] = (uint8_t) temp_valve_deadzone_minus;
Lightvalve 48:889798ff9329 1198 temp_msg.data[2] = (uint8_t) ((int) (temp_valve_deadzone_minus) >> 8);
Lightvalve 48:889798ff9329 1199 temp_msg.data[3] = (uint8_t) (temp_valve_deadzone_plus);
Lightvalve 48:889798ff9329 1200 temp_msg.data[4] = (uint8_t) ((int) (temp_valve_deadzone_plus) >> 8);
Lightvalve 48:889798ff9329 1201 temp_msg.data[5] = (uint8_t) (temp_ddv_center);
Lightvalve 48:889798ff9329 1202 temp_msg.data[6] = (uint8_t) ((int) (temp_ddv_center) >> 8);
Lightvalve 11:82d8768d7351 1203
Lightvalve 11:82d8768d7351 1204 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1205 }
Lightvalve 11:82d8768d7351 1206
Lightvalve 11:82d8768d7351 1207 void CAN_TX_VALVE_GAIN_MINUS(void) {
Lightvalve 11:82d8768d7351 1208 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1209
Lightvalve 11:82d8768d7351 1210 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1211 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1212 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_MINUS;
Lightvalve 30:8d561f16383b 1213 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[1] * 50.0f);
Lightvalve 30:8d561f16383b 1214 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[3] * 50.0f);
Lightvalve 30:8d561f16383b 1215 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[5] * 50.0f);
Lightvalve 30:8d561f16383b 1216 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[7] * 50.0f);
Lightvalve 30:8d561f16383b 1217 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[9] * 50.0f);
Lightvalve 11:82d8768d7351 1218
Lightvalve 11:82d8768d7351 1219 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1220 }
Lightvalve 11:82d8768d7351 1221
Lightvalve 11:82d8768d7351 1222 void CAN_TX_REFENCE_MODE(void) {
Lightvalve 11:82d8768d7351 1223 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1224
Lightvalve 11:82d8768d7351 1225 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1226 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1227 temp_msg.data[0] = (uint8_t) CTX_SEND_REFENCE_MODE;
Lightvalve 12:6f2531038ea4 1228 temp_msg.data[1] = (uint8_t) REFERENCE_MODE;
Lightvalve 30:8d561f16383b 1229 temp_msg.data[2] = (uint8_t) (int) (REFERENCE_FREQ * 100.0f);
Lightvalve 30:8d561f16383b 1230 temp_msg.data[3] = (uint8_t) ((int) (REFERENCE_FREQ * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1231 temp_msg.data[4] = (uint8_t) (int) (REFERENCE_MAG * 100.0f);
Lightvalve 30:8d561f16383b 1232 temp_msg.data[5] = (uint8_t) ((int) (REFERENCE_MAG * 100.0f) >> 8);
Lightvalve 11:82d8768d7351 1233
Lightvalve 11:82d8768d7351 1234 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1235 }
Lightvalve 11:82d8768d7351 1236
Lightvalve 11:82d8768d7351 1237 void CAN_TX_HOMEPOS_OFFSET(void) {
Lightvalve 11:82d8768d7351 1238 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1239 int16_t send_homepos_offset;
Lightvalve 12:6f2531038ea4 1240 send_homepos_offset = (int16_t) (HOMEPOS_OFFSET);
Lightvalve 11:82d8768d7351 1241
jobuuu 2:a1c0a37df760 1242 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1243 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1244 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_OFFSET;
Lightvalve 12:6f2531038ea4 1245 temp_msg.data[1] = (uint8_t) send_homepos_offset;
Lightvalve 12:6f2531038ea4 1246 temp_msg.data[2] = (uint8_t) (send_homepos_offset >> 8);
jobuuu 2:a1c0a37df760 1247
jobuuu 2:a1c0a37df760 1248 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1249 }
Lightvalve 11:82d8768d7351 1250
Lightvalve 11:82d8768d7351 1251 void CAN_TX_HOMPOS_VALVE_OPENING(void) {
Lightvalve 11:82d8768d7351 1252 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1253 int16_t send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1254 send_homepos_valve_opening = (int16_t) (HOMEPOS_VALVE_OPENING);
Lightvalve 11:82d8768d7351 1255
Lightvalve 11:82d8768d7351 1256 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1257 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1258 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_VALVE_OPENING;
Lightvalve 12:6f2531038ea4 1259 temp_msg.data[1] = (uint8_t) send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1260 temp_msg.data[2] = (uint8_t) (send_homepos_valve_opening >> 8);
Lightvalve 11:82d8768d7351 1261
Lightvalve 11:82d8768d7351 1262 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1263 }
Lightvalve 11:82d8768d7351 1264
Lightvalve 12:6f2531038ea4 1265 void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex) {
Lightvalve 11:82d8768d7351 1266 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1267 int16_t valve_pos_vs_pwm;
Lightvalve 49:e7bcfc244d40 1268 // valve_pos_vs_pwm = (int16_t) (VALVE_POS_VS_PWM[canindex]);
Lightvalve 49:e7bcfc244d40 1269
Lightvalve 57:f4819de54e7a 1270 if(VALVE_POS_VS_PWM[canindex]>= (float) VALVE_CENTER) {
Lightvalve 57:f4819de54e7a 1271 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 1272 } else {
Lightvalve 57:f4819de54e7a 1273 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 1274 }
Lightvalve 11:82d8768d7351 1275
Lightvalve 12:6f2531038ea4 1276 int16_t PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1277 PWM_VALVE_ID = ID_index_array[canindex] * 1000;
Lightvalve 11:82d8768d7351 1278
Lightvalve 11:82d8768d7351 1279 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1280 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1281 temp_msg.data[0] = (uint8_t) CTX_VALVE_PWM_VS_VALVE_POS;
Lightvalve 12:6f2531038ea4 1282 temp_msg.data[1] = (uint8_t) PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1283 temp_msg.data[2] = (uint8_t) (PWM_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1284 temp_msg.data[3] = (uint8_t) valve_pos_vs_pwm;
Lightvalve 12:6f2531038ea4 1285 temp_msg.data[4] = (uint8_t) (valve_pos_vs_pwm >> 8);
Lightvalve 11:82d8768d7351 1286
Lightvalve 11:82d8768d7351 1287 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1288 }
Lightvalve 11:82d8768d7351 1289
Lightvalve 12:6f2531038ea4 1290 void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex) {
Lightvalve 11:82d8768d7351 1291 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1292 int32_t valve_pos_vs_flowrate;
Lightvalve 11:82d8768d7351 1293 valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]);
Lightvalve 11:82d8768d7351 1294
Lightvalve 57:f4819de54e7a 1295 int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + VALVE_CENTER;
Lightvalve 49:e7bcfc244d40 1296 int16_t temp_valve_pos = 0;
Lightvalve 57:f4819de54e7a 1297 if(VALVE_POS_VALVE_ID>=VALVE_CENTER) {
Lightvalve 57:f4819de54e7a 1298 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 1299 } else {
Lightvalve 57:f4819de54e7a 1300 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 1301 }
Lightvalve 11:82d8768d7351 1302
Lightvalve 11:82d8768d7351 1303 temp_msg.id = CID_TX_INFO;
Lightvalve 49:e7bcfc244d40 1304 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1305 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_VS_FLOWRATE;
Lightvalve 49:e7bcfc244d40 1306 temp_msg.data[1] = (uint8_t) temp_valve_pos;
Lightvalve 49:e7bcfc244d40 1307 temp_msg.data[2] = (uint8_t) (temp_valve_pos >> 8);
Lightvalve 49:e7bcfc244d40 1308 temp_msg.data[5] = (uint8_t) valve_pos_vs_flowrate;
Lightvalve 49:e7bcfc244d40 1309 temp_msg.data[6] = (uint8_t) (valve_pos_vs_flowrate >> 8);
Lightvalve 49:e7bcfc244d40 1310 temp_msg.data[7] = (uint8_t) (valve_pos_vs_flowrate >> 16);
Lightvalve 49:e7bcfc244d40 1311 temp_msg.data[7] = (uint8_t) (valve_pos_vs_flowrate >> 24);
Lightvalve 11:82d8768d7351 1312
Lightvalve 11:82d8768d7351 1313 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1314 }
Lightvalve 11:82d8768d7351 1315
Lightvalve 11:82d8768d7351 1316 void CAN_TX_VALVE_POS_NUM(void) {
Lightvalve 11:82d8768d7351 1317 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1318 int32_t valve_pos_num;
Lightvalve 11:82d8768d7351 1319 valve_pos_num = (int16_t) VALVE_POS_NUM;
Lightvalve 11:82d8768d7351 1320
Lightvalve 11:82d8768d7351 1321 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1322 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1323 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_NUM;
Lightvalve 12:6f2531038ea4 1324 temp_msg.data[1] = (uint8_t) valve_pos_num;
Lightvalve 12:6f2531038ea4 1325 temp_msg.data[2] = (uint8_t) (valve_pos_num >> 8);
Lightvalve 11:82d8768d7351 1326
Lightvalve 11:82d8768d7351 1327 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1328 }
Lightvalve 11:82d8768d7351 1329
Lightvalve 38:118df027d851 1330 void CAN_TX_DDV_VALVE_MAX_MIN_POS(void) {
Lightvalve 38:118df027d851 1331 CANMessage temp_msg;
Lightvalve 38:118df027d851 1332
Lightvalve 48:889798ff9329 1333 float temp_valve_max_pos = 0.0f;
Lightvalve 48:889798ff9329 1334 float temp_valve_min_pos = 0.0f;
Lightvalve 48:889798ff9329 1335 float temp_ddv_center = 0.0f;
Lightvalve 48:889798ff9329 1336
Lightvalve 57:f4819de54e7a 1337 temp_valve_max_pos = VALVE_MAX_POS;
Lightvalve 57:f4819de54e7a 1338 temp_valve_min_pos = VALVE_MIN_POS;
Lightvalve 57:f4819de54e7a 1339 temp_ddv_center = VALVE_CENTER;
Lightvalve 48:889798ff9329 1340
Lightvalve 38:118df027d851 1341 temp_msg.id = CID_TX_INFO;
Lightvalve 38:118df027d851 1342 temp_msg.len = 7;
Lightvalve 38:118df027d851 1343 temp_msg.data[0] = (uint8_t) CTX_VALVE_MAX_MIN_POS;
Lightvalve 48:889798ff9329 1344 temp_msg.data[1] = (uint8_t) temp_valve_max_pos;
Lightvalve 48:889798ff9329 1345 temp_msg.data[2] = (uint8_t) ((int) (temp_valve_max_pos) >> 8);
Lightvalve 48:889798ff9329 1346 temp_msg.data[3] = (uint8_t) (temp_valve_min_pos);
Lightvalve 48:889798ff9329 1347 temp_msg.data[4] = (uint8_t) ((int) (temp_valve_min_pos) >> 8);
Lightvalve 48:889798ff9329 1348 temp_msg.data[5] = (uint8_t) (temp_ddv_center);
Lightvalve 48:889798ff9329 1349 temp_msg.data[6] = (uint8_t) ((int) (temp_ddv_center) >> 8);
Lightvalve 38:118df027d851 1350
Lightvalve 38:118df027d851 1351 can.write(temp_msg);
Lightvalve 38:118df027d851 1352 }
Lightvalve 38:118df027d851 1353
jobuuu 2:a1c0a37df760 1354 /******************************************************************************
jobuuu 2:a1c0a37df760 1355 Sensor & State Transmission Functions
jobuuu 2:a1c0a37df760 1356 *******************************************************************************/
jobuuu 2:a1c0a37df760 1357
Lightvalve 52:8ea76864368a 1358 void CAN_TX_POSITION_FT(int16_t t_pos, int16_t t_vel, int16_t t_torq) {
Lightvalve 52:8ea76864368a 1359 CANMessage temp_msg;
Lightvalve 52:8ea76864368a 1360
Lightvalve 52:8ea76864368a 1361 temp_msg.id = CID_TX_POSITION;
Lightvalve 52:8ea76864368a 1362 temp_msg.len = 6;
Lightvalve 52:8ea76864368a 1363 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 52:8ea76864368a 1364 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 52:8ea76864368a 1365 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 52:8ea76864368a 1366 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1367 temp_msg.data[4] = (uint8_t) t_torq;
Lightvalve 52:8ea76864368a 1368 temp_msg.data[5] = (uint8_t) (t_torq >> 8);
Lightvalve 52:8ea76864368a 1369
Lightvalve 52:8ea76864368a 1370 can.write(temp_msg);
Lightvalve 52:8ea76864368a 1371 }
Lightvalve 52:8ea76864368a 1372
Lightvalve 52:8ea76864368a 1373 void CAN_TX_POSITION_PRESSURE(int16_t t_pos, int16_t t_vel, int16_t t_pa, int16_t t_pb) {
Lightvalve 52:8ea76864368a 1374
jobuuu 2:a1c0a37df760 1375 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1376
jobuuu 2:a1c0a37df760 1377 temp_msg.id = CID_TX_POSITION;
jobuuu 2:a1c0a37df760 1378 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1379 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 12:6f2531038ea4 1380 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 41:abbd4e2af68b 1381 temp_msg.data[2] = (uint8_t) t_vel;
Lightvalve 41:abbd4e2af68b 1382 temp_msg.data[3] = (uint8_t) (t_vel >> 8);
Lightvalve 52:8ea76864368a 1383 temp_msg.data[4] = (uint8_t) t_pa;
Lightvalve 52:8ea76864368a 1384 temp_msg.data[5] = (uint8_t) (t_pa >> 8);
Lightvalve 52:8ea76864368a 1385 temp_msg.data[6] = (uint8_t) t_pb;
Lightvalve 52:8ea76864368a 1386 temp_msg.data[7] = (uint8_t) (t_pb >> 8);
jobuuu 2:a1c0a37df760 1387
jobuuu 2:a1c0a37df760 1388 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1389 }
jobuuu 2:a1c0a37df760 1390
Lightvalve 67:c2812cf26c38 1391 //void CAN_TX_TORQUE(int16_t t_valve_pos, int16_t t_vout) {
Lightvalve 67:c2812cf26c38 1392 // CANMessage temp_msg;
Lightvalve 67:c2812cf26c38 1393 //
Lightvalve 67:c2812cf26c38 1394 // temp_msg.id = CID_TX_TORQUE;
Lightvalve 67:c2812cf26c38 1395 // temp_msg.len = 4;
Lightvalve 67:c2812cf26c38 1396 // temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 67:c2812cf26c38 1397 // temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
Lightvalve 67:c2812cf26c38 1398 // temp_msg.data[2] = (uint8_t) t_vout;
Lightvalve 67:c2812cf26c38 1399 // temp_msg.data[3] = (uint8_t) (t_vout >> 8);
Lightvalve 67:c2812cf26c38 1400 //
Lightvalve 67:c2812cf26c38 1401 // can.write(temp_msg);
Lightvalve 67:c2812cf26c38 1402 //}
Lightvalve 67:c2812cf26c38 1403
Lightvalve 67:c2812cf26c38 1404 void CAN_TX_TORQUE(int16_t t_valve_pos) {
jobuuu 2:a1c0a37df760 1405 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1406
jobuuu 2:a1c0a37df760 1407 temp_msg.id = CID_TX_TORQUE;
Lightvalve 67:c2812cf26c38 1408 temp_msg.len = 2;
Lightvalve 48:889798ff9329 1409 temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 48:889798ff9329 1410 temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
jobuuu 2:a1c0a37df760 1411
jobuuu 2:a1c0a37df760 1412 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1413 }
jobuuu 2:a1c0a37df760 1414
Lightvalve 11:82d8768d7351 1415 void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b) {
jobuuu 2:a1c0a37df760 1416 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1417
jobuuu 2:a1c0a37df760 1418 temp_msg.id = CID_TX_PRES;
Lightvalve 57:f4819de54e7a 1419 temp_msg.len = 4;
Lightvalve 12:6f2531038ea4 1420 temp_msg.data[0] = (uint8_t) t_pres_a;
Lightvalve 12:6f2531038ea4 1421 temp_msg.data[1] = (uint8_t) (t_pres_a >> 8);
Lightvalve 12:6f2531038ea4 1422 temp_msg.data[2] = (uint8_t) t_pres_b;
Lightvalve 12:6f2531038ea4 1423 temp_msg.data[3] = (uint8_t) (t_pres_b >> 8);
jobuuu 2:a1c0a37df760 1424
jobuuu 2:a1c0a37df760 1425 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1426 }
jobuuu 2:a1c0a37df760 1427
Lightvalve 11:82d8768d7351 1428 void CAN_TX_PWM(int16_t t_pwm) {
jobuuu 2:a1c0a37df760 1429 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1430
Lightvalve 57:f4819de54e7a 1431 temp_msg.id = CID_TX_VOUT;
Lightvalve 57:f4819de54e7a 1432 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 1433 temp_msg.data[0] = (uint8_t) t_pwm;
Lightvalve 12:6f2531038ea4 1434 temp_msg.data[1] = (uint8_t) (t_pwm >> 8);
jobuuu 2:a1c0a37df760 1435
jobuuu 2:a1c0a37df760 1436 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1437 }
jobuuu 2:a1c0a37df760 1438
Lightvalve 27:a2254a485f23 1439 void CAN_TX_VALVE_POSITION(int16_t t_valve_pos, int16_t t_ref_valve_pos, int16_t t_pwm)
Lightvalve 27:a2254a485f23 1440 {
jobuuu 2:a1c0a37df760 1441 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1442
jobuuu 2:a1c0a37df760 1443 temp_msg.id = CID_TX_VALVE_POSITION;
Lightvalve 48:889798ff9329 1444 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1445 temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 12:6f2531038ea4 1446 temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
Lightvalve 27:a2254a485f23 1447 temp_msg.data[2] = (uint8_t) t_ref_valve_pos;
Lightvalve 27:a2254a485f23 1448 temp_msg.data[3] = (uint8_t) (t_ref_valve_pos >> 8);
Lightvalve 27:a2254a485f23 1449 temp_msg.data[4] = (uint8_t) t_pwm;
Lightvalve 27:a2254a485f23 1450 temp_msg.data[5] = (uint8_t) (t_pwm >> 8);
Lightvalve 27:a2254a485f23 1451
jobuuu 2:a1c0a37df760 1452
jobuuu 2:a1c0a37df760 1453 can.write(temp_msg);
Lightvalve 67:c2812cf26c38 1454 }