Original Version of STM Board

Dependencies:   FastPWM mbed

Committer:
Lightvalve
Date:
Sat Sep 26 05:05:06 2020 +0000
Revision:
130:26b416050376
Parent:
122:dcb3ce3056a0
Child:
133:22ab22818e01
200926-1

Who changed what in which revision?

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