2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Mon Nov 11 09:48:00 2019 +0000
Revision:
32:4b8c0fedaf2c
Parent:
30:8d561f16383b
Child:
33:91b17819ec30
191111

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;
jobuuu 2:a1c0a37df760 11 int CID_RX_REF_TORQUE = 300;
jobuuu 2:a1c0a37df760 12 int CID_RX_REF_PRES_DIFF = 400;
jobuuu 7:e9086c72bb22 13 int CID_RX_REF_VOUT = 500;
jobuuu 2:a1c0a37df760 14 int CID_RX_REF_VALVE_POSITION = 600;
Lightvalve 14:8e7590227d22 15 int CID_RX_REF_CURRENT = 700;
jobuuu 2:a1c0a37df760 16
jobuuu 2:a1c0a37df760 17 int CID_TX_INFO = 1100;
jobuuu 2:a1c0a37df760 18 int CID_TX_POSITION = 1200;
jobuuu 2:a1c0a37df760 19 int CID_TX_TORQUE = 1300;
jobuuu 2:a1c0a37df760 20 int CID_TX_PRES = 1400;
jobuuu 7:e9086c72bb22 21 int CID_TX_VOUT = 1500;
jobuuu 2:a1c0a37df760 22 int CID_TX_VALVE_POSITION = 1600;
jobuuu 2:a1c0a37df760 23
Lightvalve 12:6f2531038ea4 24 // variables
Lightvalve 12:6f2531038ea4 25 uint8_t can_index = 0;
Lightvalve 12:6f2531038ea4 26
Lightvalve 11:82d8768d7351 27
Lightvalve 11:82d8768d7351 28 /*******************************************************************************
Lightvalve 11:82d8768d7351 29 * CAN functions
Lightvalve 11:82d8768d7351 30 ******************************************************************************/
Lightvalve 11:82d8768d7351 31 void CAN_ID_INIT(void) {
jobuuu 7:e9086c72bb22 32
Lightvalve 11:82d8768d7351 33 CID_RX_CMD = (int) (BNO + INIT_CID_RX_CMD);
Lightvalve 11:82d8768d7351 34 CID_RX_REF_POSITION = (int) (BNO + INIT_CID_RX_REF_POSITION);
Lightvalve 11:82d8768d7351 35 CID_RX_REF_TORQUE = (int) (BNO + INIT_CID_RX_REF_TORQUE);
Lightvalve 11:82d8768d7351 36 CID_RX_REF_PRES_DIFF = (int) (BNO + INIT_CID_RX_REF_PRES_DIFF);
Lightvalve 11:82d8768d7351 37 CID_RX_REF_VOUT = (int) (BNO + INIT_CID_RX_REF_VOUT);
Lightvalve 11:82d8768d7351 38 CID_RX_REF_VALVE_POSITION = (int) (BNO + INIT_CID_RX_REF_VALVE_POSITION);
Lightvalve 14:8e7590227d22 39 CID_RX_REF_CURRENT = (int) (BNO + INIT_CID_RX_REF_CURRENT);
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 11:82d8768d7351 74 OPERATING_MODE = (int16_t) msg.data[1];
Lightvalve 16:903b5a4433b4 75
Lightvalve 16:903b5a4433b4 76 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 77
Lightvalve 23:59218d4a256d 78
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 11:82d8768d7351 91 case CRX_SET_REF_UPDATE_ENABLE: {
Lightvalve 11:82d8768d7351 92 flag_ref_enable = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 93
Lightvalve 11:82d8768d7351 94 break;
Lightvalve 11:82d8768d7351 95 }
Lightvalve 11:82d8768d7351 96
Lightvalve 11:82d8768d7351 97 case CRX_ASK_CAN_FREQ: {
Lightvalve 11:82d8768d7351 98 CAN_TX_CAN_FREQ();
Lightvalve 11:82d8768d7351 99
Lightvalve 11:82d8768d7351 100 break;
Lightvalve 11:82d8768d7351 101 }
Lightvalve 11:82d8768d7351 102
Lightvalve 11:82d8768d7351 103 case CRX_SET_CAN_FREQ: {
Lightvalve 11:82d8768d7351 104 CAN_FREQ = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 16:903b5a4433b4 105
Lightvalve 16:903b5a4433b4 106 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 107
Lightvalve 16:903b5a4433b4 108 //spi_eeprom_write(RID_CAN_FREQ, (int16_t) CAN_FREQ);
Lightvalve 11:82d8768d7351 109 break;
Lightvalve 11:82d8768d7351 110 }
Lightvalve 11:82d8768d7351 111
Lightvalve 11:82d8768d7351 112 case CRX_ASK_CONTROL_MODE: {
Lightvalve 11:82d8768d7351 113 CAN_TX_CONTROL_MODE();
Lightvalve 11:82d8768d7351 114
Lightvalve 11:82d8768d7351 115 break;
Lightvalve 11:82d8768d7351 116 }
Lightvalve 11:82d8768d7351 117
Lightvalve 11:82d8768d7351 118 case CRX_SET_CONTROL_MODE: {
Lightvalve 11:82d8768d7351 119 CONTROL_MODE = (int16_t) (msg.data[1]);
Lightvalve 12:6f2531038ea4 120 if (CONTROL_MODE == 22) { //MODE_FIND_HOME
Lightvalve 11:82d8768d7351 121 FLAG_FIND_HOME = true;
Lightvalve 11:82d8768d7351 122 }
Lightvalve 11:82d8768d7351 123 break;
Lightvalve 11:82d8768d7351 124 }
Lightvalve 11:82d8768d7351 125
Lightvalve 11:82d8768d7351 126 case CRX_SET_DATA_REQUEST: {
Lightvalve 11:82d8768d7351 127 int request_type = msg.data[2];
Lightvalve 11:82d8768d7351 128 flag_data_request[request_type] = msg.data[1];
Lightvalve 14:8e7590227d22 129 //pc.printf("can middle %d\n", request_type);
Lightvalve 11:82d8768d7351 130
Lightvalve 12:6f2531038ea4 131 // if (flag_data_request[1] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC
Lightvalve 15:bd0d12728506 132 //if (flag_data_request[1] == HIGH) dac_1 = PRES_A_VREF/3.3;
Lightvalve 12:6f2531038ea4 133 // if (flag_data_request[2] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC
Lightvalve 15:bd0d12728506 134 //if (flag_data_request[2] == HIGH) dac_2 = PRES_B_VREF/3.3;
Lightvalve 11:82d8768d7351 135
Lightvalve 11:82d8768d7351 136 break;
Lightvalve 11:82d8768d7351 137 }
Lightvalve 11:82d8768d7351 138
Lightvalve 11:82d8768d7351 139 case CRX_ASK_JOINT_ENC_DIR: {
Lightvalve 11:82d8768d7351 140 CAN_TX_JOINT_ENC_DIR();
Lightvalve 11:82d8768d7351 141
Lightvalve 11:82d8768d7351 142 break;
Lightvalve 11:82d8768d7351 143 }
Lightvalve 11:82d8768d7351 144
Lightvalve 11:82d8768d7351 145 case CRX_SET_JOINT_ENC_DIR: {
Lightvalve 11:82d8768d7351 146 DIR_JOINT_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 147 if (DIR_JOINT_ENC >= 0)
Lightvalve 11:82d8768d7351 148 DIR_JOINT_ENC = 1;
Lightvalve 11:82d8768d7351 149 else
Lightvalve 11:82d8768d7351 150 DIR_JOINT_ENC = -1;
Lightvalve 16:903b5a4433b4 151
Lightvalve 16:903b5a4433b4 152 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 153
Lightvalve 16:903b5a4433b4 154 //spi_eeprom_write(RID_JOINT_ENC_DIR, (int16_t) DIR_JOINT_ENC);
Lightvalve 11:82d8768d7351 155
Lightvalve 11:82d8768d7351 156 break;
Lightvalve 11:82d8768d7351 157 }
Lightvalve 11:82d8768d7351 158
Lightvalve 11:82d8768d7351 159 case CRX_ASK_VALVE_DIR: {
Lightvalve 11:82d8768d7351 160 CAN_TX_VALVE_DIR();
Lightvalve 11:82d8768d7351 161
Lightvalve 11:82d8768d7351 162 break;
Lightvalve 11:82d8768d7351 163 }
Lightvalve 11:82d8768d7351 164
Lightvalve 11:82d8768d7351 165 case CRX_SET_VALVE_DIR: {
Lightvalve 11:82d8768d7351 166 DIR_VALVE = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 167 if (DIR_VALVE >= 0)
Lightvalve 11:82d8768d7351 168 DIR_VALVE = 1;
Lightvalve 11:82d8768d7351 169 else
Lightvalve 11:82d8768d7351 170 DIR_VALVE = -1;
Lightvalve 16:903b5a4433b4 171
Lightvalve 16:903b5a4433b4 172 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 173
Lightvalve 16:903b5a4433b4 174 //spi_eeprom_write(RID_VALVE_DIR, (int16_t) DIR_VALVE);
Lightvalve 11:82d8768d7351 175
Lightvalve 11:82d8768d7351 176 break;
Lightvalve 11:82d8768d7351 177 }
Lightvalve 11:82d8768d7351 178
Lightvalve 11:82d8768d7351 179 case CRX_ASK_VALVE_ENC_DIR: {
Lightvalve 11:82d8768d7351 180 CAN_TX_VALVE_ENC_DIR();
Lightvalve 11:82d8768d7351 181
Lightvalve 11:82d8768d7351 182 break;
Lightvalve 11:82d8768d7351 183 }
Lightvalve 11:82d8768d7351 184
Lightvalve 11:82d8768d7351 185 case CRX_SET_VALVE_ENC_DIR: {
Lightvalve 11:82d8768d7351 186 DIR_VALVE_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 187 if (DIR_VALVE_ENC >= 0)
Lightvalve 11:82d8768d7351 188 DIR_VALVE_ENC = 1;
Lightvalve 11:82d8768d7351 189 else
Lightvalve 11:82d8768d7351 190 DIR_VALVE_ENC = -1;
Lightvalve 16:903b5a4433b4 191
Lightvalve 16:903b5a4433b4 192 ROM_RESET_DATA();
Lightvalve 11:82d8768d7351 193
Lightvalve 16:903b5a4433b4 194 //spi_eeprom_write(RID_VALVE_ENC_DIR, (int16_t) DIR_VALVE_ENC);
Lightvalve 11:82d8768d7351 195
Lightvalve 11:82d8768d7351 196 break;
Lightvalve 11:82d8768d7351 197 }
Lightvalve 11:82d8768d7351 198
Lightvalve 11:82d8768d7351 199 case CRX_ASK_VOLTAGE_SUPPLY: {
Lightvalve 11:82d8768d7351 200 CAN_TX_VOLTAGE_SUPPLY();
Lightvalve 11:82d8768d7351 201
Lightvalve 11:82d8768d7351 202 break;
Lightvalve 11:82d8768d7351 203 }
Lightvalve 11:82d8768d7351 204
Lightvalve 11:82d8768d7351 205 case CRX_SET_VOLTAGE_SUPPLY: {
Lightvalve 30:8d561f16383b 206 SUPPLY_VOLTAGE = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.0f;
Lightvalve 16:903b5a4433b4 207
Lightvalve 16:903b5a4433b4 208 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 209
Lightvalve 16:903b5a4433b4 210 //spi_eeprom_write(RID_VOLATGE_SUPPLY, (int16_t) (SUPPLY_VOLTAGE * 10.));
Lightvalve 11:82d8768d7351 211
Lightvalve 11:82d8768d7351 212 break;
Lightvalve 11:82d8768d7351 213 }
Lightvalve 11:82d8768d7351 214
Lightvalve 11:82d8768d7351 215 case CRX_ASK_VOLTAGE_VALVE: {
Lightvalve 11:82d8768d7351 216 CAN_TX_VOLTAGE_VALVE();
Lightvalve 11:82d8768d7351 217
Lightvalve 11:82d8768d7351 218 break;
Lightvalve 11:82d8768d7351 219 }
Lightvalve 11:82d8768d7351 220
Lightvalve 11:82d8768d7351 221 case CRX_SET_VOLTAGE_VALVE: {
Lightvalve 30:8d561f16383b 222 VALVE_VOLTAGE_LIMIT = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.0f;
Lightvalve 16:903b5a4433b4 223
Lightvalve 16:903b5a4433b4 224 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 225
Lightvalve 16:903b5a4433b4 226 //spi_eeprom_write(RID_VOLTAGE_VALVE, (int16_t) (VALVE_VOLTAGE_LIMIT * 10.));
Lightvalve 11:82d8768d7351 227
Lightvalve 11:82d8768d7351 228
Lightvalve 11:82d8768d7351 229 break;
Lightvalve 11:82d8768d7351 230 }
Lightvalve 12:6f2531038ea4 231
Lightvalve 11:82d8768d7351 232 case CRX_SET_HOMEPOS: {
Lightvalve 11:82d8768d7351 233 CONTROL_MODE = 22;
Lightvalve 11:82d8768d7351 234 SETTING_SWITCH = (int16_t) (msg.data[1]);
Lightvalve 11:82d8768d7351 235 break;
Lightvalve 11:82d8768d7351 236 }
Lightvalve 11:82d8768d7351 237
Lightvalve 11:82d8768d7351 238 case CRX_ASK_PID_GAIN: {
Lightvalve 11:82d8768d7351 239 CAN_TX_PID_GAIN(msg.data[1]);
Lightvalve 11:82d8768d7351 240
Lightvalve 11:82d8768d7351 241 break;
Lightvalve 11:82d8768d7351 242 }
Lightvalve 11:82d8768d7351 243
Lightvalve 11:82d8768d7351 244 case CRX_SET_PID_GAIN: {
Lightvalve 11:82d8768d7351 245 if (msg.data[1] == 0) {
Lightvalve 11:82d8768d7351 246 P_GAIN_VALVE_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 11:82d8768d7351 247 I_GAIN_VALVE_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 11:82d8768d7351 248 D_GAIN_VALVE_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8);
Lightvalve 16:903b5a4433b4 249
Lightvalve 16:903b5a4433b4 250 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 251
Lightvalve 16:903b5a4433b4 252 //spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 253 //spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 254 //spi_eeprom_write(RID_D_GAIN_VALVE_POSITION, (int16_t) D_GAIN_VALVE_POSITION);
Lightvalve 11:82d8768d7351 255
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 11:82d8768d7351 263
Lightvalve 16:903b5a4433b4 264 //spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 265 //spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 266 //spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION);
Lightvalve 11:82d8768d7351 267 } else if (msg.data[1] == 2) {
Lightvalve 11:82d8768d7351 268 P_GAIN_JOINT_TORQUE = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 11:82d8768d7351 269 I_GAIN_JOINT_TORQUE = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 11:82d8768d7351 270 D_GAIN_JOINT_TORQUE = (int16_t) (msg.data[6] | msg.data[7] << 8);
Lightvalve 16:903b5a4433b4 271
Lightvalve 16:903b5a4433b4 272 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 273
Lightvalve 16:903b5a4433b4 274 //spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE);
Lightvalve 16:903b5a4433b4 275 //spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE);
Lightvalve 16:903b5a4433b4 276 //spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE);
Lightvalve 11:82d8768d7351 277 }
Lightvalve 11:82d8768d7351 278
Lightvalve 11:82d8768d7351 279 break;
Lightvalve 11:82d8768d7351 280 }
Lightvalve 11:82d8768d7351 281
Lightvalve 11:82d8768d7351 282 case CRX_ASK_VALVE_DEADZONE: {
Lightvalve 11:82d8768d7351 283 CAN_TX_VALVE_DEADZONE();
Lightvalve 11:82d8768d7351 284
Lightvalve 11:82d8768d7351 285 break;
Lightvalve 11:82d8768d7351 286 }
Lightvalve 11:82d8768d7351 287
Lightvalve 11:82d8768d7351 288 case CRX_SET_VALVE_DEADZONE: {
Lightvalve 11:82d8768d7351 289 VALVE_CENTER = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 290 VALVE_DEADZONE_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 291 VALVE_DEADZONE_MINUS = (int16_t) (msg.data[5] | msg.data[6] << 8);
Lightvalve 16:903b5a4433b4 292
Lightvalve 16:903b5a4433b4 293 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 294
Lightvalve 16:903b5a4433b4 295 //spi_eeprom_write(RID_VALVE_CNETER, (int16_t) (VALVE_CENTER));
Lightvalve 16:903b5a4433b4 296 //spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, (int16_t) (VALVE_DEADZONE_PLUS));
Lightvalve 16:903b5a4433b4 297 //spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, (int16_t) (VALVE_DEADZONE_MINUS));
Lightvalve 11:82d8768d7351 298
Lightvalve 11:82d8768d7351 299 break;
Lightvalve 11:82d8768d7351 300 }
Lightvalve 11:82d8768d7351 301
Lightvalve 11:82d8768d7351 302 case CRX_ASK_VELOCITY_COMP_GAIN: {
Lightvalve 11:82d8768d7351 303 CAN_TX_VELOCITY_COMP_GAIN();
Lightvalve 11:82d8768d7351 304
Lightvalve 11:82d8768d7351 305 break;
Lightvalve 11:82d8768d7351 306 }
Lightvalve 11:82d8768d7351 307
Lightvalve 11:82d8768d7351 308 case CRX_SET_VELOCITY_COMP_GAIN: {
Lightvalve 11:82d8768d7351 309 VELOCITY_COMP_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 16:903b5a4433b4 310
Lightvalve 16:903b5a4433b4 311 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 312
Lightvalve 16:903b5a4433b4 313 //spi_eeprom_write(RID_VELOCITY_COMP_GAIN, (int16_t) VELOCITY_COMP_GAIN);
Lightvalve 11:82d8768d7351 314
Lightvalve 11:82d8768d7351 315 break;
Lightvalve 11:82d8768d7351 316 }
Lightvalve 11:82d8768d7351 317
Lightvalve 11:82d8768d7351 318 case CRX_ASK_COMPLIANCE_GAIN: {
Lightvalve 11:82d8768d7351 319 CAN_TX_COMPLIANCE_GAIN();
Lightvalve 11:82d8768d7351 320
Lightvalve 11:82d8768d7351 321 break;
Lightvalve 11:82d8768d7351 322 }
Lightvalve 11:82d8768d7351 323
Lightvalve 11:82d8768d7351 324 case CRX_SET_COMPLIANCE_GAIN: {
Lightvalve 11:82d8768d7351 325 COMPLIANCE_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 326
Lightvalve 16:903b5a4433b4 327 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 328
Lightvalve 16:903b5a4433b4 329 //spi_eeprom_write(RID_COMPLIANCE_GAIN, (int16_t) COMPLIANCE_GAIN);
Lightvalve 11:82d8768d7351 330
Lightvalve 11:82d8768d7351 331 break;
Lightvalve 11:82d8768d7351 332 }
Lightvalve 11:82d8768d7351 333
Lightvalve 11:82d8768d7351 334 case CRX_ASK_VALVE_FF: {
Lightvalve 11:82d8768d7351 335 CAN_TX_VALVE_FF();
Lightvalve 11:82d8768d7351 336
Lightvalve 11:82d8768d7351 337 break;
Lightvalve 11:82d8768d7351 338 }
Lightvalve 11:82d8768d7351 339
Lightvalve 11:82d8768d7351 340 case CRX_SET_VALVE_FF: {
Lightvalve 11:82d8768d7351 341 VALVE_FF = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 16:903b5a4433b4 342
Lightvalve 16:903b5a4433b4 343 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 344
Lightvalve 16:903b5a4433b4 345 //spi_eeprom_write(RID_VALVE_FF, (int16_t) VALVE_FF);
Lightvalve 11:82d8768d7351 346
Lightvalve 11:82d8768d7351 347 break;
Lightvalve 11:82d8768d7351 348 }
Lightvalve 11:82d8768d7351 349
Lightvalve 11:82d8768d7351 350 case CRX_ASK_BULK_MODULUS: {
Lightvalve 11:82d8768d7351 351 CAN_TX_BULK_MODULUS();
Lightvalve 11:82d8768d7351 352
Lightvalve 11:82d8768d7351 353 break;
Lightvalve 11:82d8768d7351 354 }
Lightvalve 11:82d8768d7351 355
Lightvalve 11:82d8768d7351 356 case CRX_SET_BULK_MODULUS: {
Lightvalve 11:82d8768d7351 357 BULK_MODULUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 16:903b5a4433b4 358
Lightvalve 16:903b5a4433b4 359 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 360
Lightvalve 16:903b5a4433b4 361 //spi_eeprom_write(RID_BULK_MODULUS, (int16_t) BULK_MODULUS);
Lightvalve 11:82d8768d7351 362
Lightvalve 11:82d8768d7351 363 break;
Lightvalve 11:82d8768d7351 364 }
Lightvalve 11:82d8768d7351 365
Lightvalve 11:82d8768d7351 366 case CRX_ASK_CHAMBER_VOLUME: {
Lightvalve 11:82d8768d7351 367 CAN_TX_CHAMBER_VOLUME();
Lightvalve 11:82d8768d7351 368
Lightvalve 11:82d8768d7351 369 break;
Lightvalve 11:82d8768d7351 370 }
Lightvalve 11:82d8768d7351 371
Lightvalve 11:82d8768d7351 372 case CRX_SET_CHAMBER_VOLUME: {
Lightvalve 11:82d8768d7351 373 CHAMBER_VOLUME_A = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 374 CHAMBER_VOLUME_B = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 375
Lightvalve 16:903b5a4433b4 376 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 377
Lightvalve 16:903b5a4433b4 378 //spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A);
Lightvalve 16:903b5a4433b4 379 //spi_eeprom_write(RID_CHAMBER_VOLUME_B, (int16_t) CHAMBER_VOLUME_B);
Lightvalve 11:82d8768d7351 380
Lightvalve 11:82d8768d7351 381 break;
Lightvalve 11:82d8768d7351 382 }
Lightvalve 11:82d8768d7351 383
Lightvalve 11:82d8768d7351 384 case CRX_ASK_PISTON_AREA: {
Lightvalve 11:82d8768d7351 385 CAN_TX_PISTON_AREA();
Lightvalve 11:82d8768d7351 386
Lightvalve 11:82d8768d7351 387 break;
Lightvalve 11:82d8768d7351 388 }
Lightvalve 11:82d8768d7351 389
Lightvalve 11:82d8768d7351 390 case CRX_SET_PISTON_AREA: {
Lightvalve 11:82d8768d7351 391 PISTON_AREA_A = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 392 PISTON_AREA_B = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 393 PISTON_AREA_alpha = (double)PISTON_AREA_B/(double)PISTON_AREA_A;
Lightvalve 16:903b5a4433b4 394
Lightvalve 16:903b5a4433b4 395 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 396
Lightvalve 16:903b5a4433b4 397 //spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A);
Lightvalve 16:903b5a4433b4 398 //spi_eeprom_write(RID_PISTON_AREA_B, (int16_t) PISTON_AREA_B);
Lightvalve 11:82d8768d7351 399 break;
Lightvalve 11:82d8768d7351 400 }
Lightvalve 11:82d8768d7351 401
Lightvalve 11:82d8768d7351 402 case CRX_ASK_PRES: {
Lightvalve 11:82d8768d7351 403 CAN_TX_PRES_A_AND_B();
Lightvalve 12:6f2531038ea4 404 // SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0);
Lightvalve 16:903b5a4433b4 405 //dac_1 = PRES_A_VREF;
Lightvalve 16:903b5a4433b4 406 //dac_2 = PRES_B_VREF;
Lightvalve 12:6f2531038ea4 407
Lightvalve 11:82d8768d7351 408 break;
Lightvalve 11:82d8768d7351 409 }
Lightvalve 11:82d8768d7351 410
Lightvalve 11:82d8768d7351 411 case CRX_SET_PRES: {
Lightvalve 11:82d8768d7351 412 PRES_SUPPLY = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 413 PRES_RETURN = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 16:903b5a4433b4 414 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 415 //spi_eeprom_write(RID_PRES_SUPPLY, (int16_t) PRES_SUPPLY);
Lightvalve 16:903b5a4433b4 416 //spi_eeprom_write(RID_PRES_RETURN, (int16_t) PRES_RETURN);
Lightvalve 11:82d8768d7351 417
Lightvalve 11:82d8768d7351 418
Lightvalve 11:82d8768d7351 419 break;
Lightvalve 11:82d8768d7351 420 }
Lightvalve 11:82d8768d7351 421
Lightvalve 11:82d8768d7351 422 case CRX_ASK_ENC_LIMIT: {
Lightvalve 11:82d8768d7351 423 CAN_TX_ENC_LIMIT();
Lightvalve 11:82d8768d7351 424
Lightvalve 11:82d8768d7351 425 break;
Lightvalve 11:82d8768d7351 426 }
Lightvalve 11:82d8768d7351 427
Lightvalve 11:82d8768d7351 428 case CRX_SET_ENC_LIMIT: {
Lightvalve 11:82d8768d7351 429 ENC_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 430 ENC_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 16:903b5a4433b4 431 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 432 //spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS);
Lightvalve 16:903b5a4433b4 433 //spi_eeprom_write(RID_ENC_LIMIT_PLUS, (int16_t) ENC_LIMIT_PLUS);
Lightvalve 11:82d8768d7351 434
Lightvalve 11:82d8768d7351 435 break;
Lightvalve 11:82d8768d7351 436 }
Lightvalve 11:82d8768d7351 437
Lightvalve 11:82d8768d7351 438 case CRX_ASK_STROKE: {
Lightvalve 11:82d8768d7351 439 CAN_TX_STROKE();
Lightvalve 11:82d8768d7351 440 break;
Lightvalve 11:82d8768d7351 441 }
Lightvalve 11:82d8768d7351 442
Lightvalve 11:82d8768d7351 443 case CRX_SET_STROKE: {
Lightvalve 11:82d8768d7351 444 STROKE = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 16:903b5a4433b4 445 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 446 //spi_eeprom_write(RID_STROKE, (int16_t) STROKE);
Lightvalve 11:82d8768d7351 447
Lightvalve 11:82d8768d7351 448 break;
Lightvalve 11:82d8768d7351 449 }
Lightvalve 11:82d8768d7351 450
Lightvalve 11:82d8768d7351 451 case CRX_ASK_VALVE_LIMIT: {
Lightvalve 11:82d8768d7351 452 CAN_TX_VALVE_LIMIT();
Lightvalve 11:82d8768d7351 453
Lightvalve 11:82d8768d7351 454 break;
Lightvalve 11:82d8768d7351 455 }
Lightvalve 11:82d8768d7351 456
Lightvalve 11:82d8768d7351 457 case CRX_SET_VALVE_LIMIT: {
Lightvalve 11:82d8768d7351 458 VALVE_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 459 VALVE_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 16:903b5a4433b4 460 ROM_RESET_DATA();
Lightvalve 16:903b5a4433b4 461 //spi_eeprom_write(RID_VALVE_LIMIT_MINUS, (int16_t) VALVE_LIMIT_MINUS);
Lightvalve 16:903b5a4433b4 462 //spi_eeprom_write(RID_VALVE_LIMIT_PLUS, (int16_t) VALVE_LIMIT_PLUS);
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 11:82d8768d7351 488 TORQUE_SENSOR_PULSE_PER_TORQUE = (int16_t) (msg.data[1] | msg.data[2] << 8);
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 32:4b8c0fedaf2c 644 VALVE_CENTER_OFFSET_times10 = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 32:4b8c0fedaf2c 645 VALVE_CENTER_OFFSET = VALVE_CENTER_OFFSET_times10 * 0.1f;
Lightvalve 32:4b8c0fedaf2c 646 ROM_RESET_DATA();
Lightvalve 32:4b8c0fedaf2c 647 break;
Lightvalve 32:4b8c0fedaf2c 648 }
jobuuu 2:a1c0a37df760 649 default:
jobuuu 2:a1c0a37df760 650 break;
jobuuu 2:a1c0a37df760 651 }
jobuuu 2:a1c0a37df760 652 }
jobuuu 2:a1c0a37df760 653
jobuuu 2:a1c0a37df760 654 void CAN_RX_HANDLER()
jobuuu 2:a1c0a37df760 655 {
Lightvalve 23:59218d4a256d 656
jobuuu 2:a1c0a37df760 657 can.read(msg);
jobuuu 2:a1c0a37df760 658 unsigned int address = msg.id;
jobuuu 7:e9086c72bb22 659 if(address==CID_RX_CMD){
jobuuu 2:a1c0a37df760 660 unsigned int CMD = msg.data[0];
jobuuu 2:a1c0a37df760 661 ReadCMD(CMD);
jobuuu 7:e9086c72bb22 662 } else if(address==CID_RX_REF_POSITION) {
jobuuu 7:e9086c72bb22 663 int32_t temp_pos = (int32_t) (msg.data[0] | msg.data[1] << 8 | msg.data[2] << 16 | msg.data[3] << 24);
jobuuu 7:e9086c72bb22 664 int32_t temp_vel = (int32_t) (msg.data[4] | msg.data[5] << 8 | msg.data[6] << 16 | msg.data[7] << 24);
jobuuu 7:e9086c72bb22 665 pos.ref = (double)temp_pos;
jobuuu 7:e9086c72bb22 666 vel.ref = (double)temp_vel;
jobuuu 7:e9086c72bb22 667 } else if(address==CID_RX_REF_TORQUE) {
jobuuu 7:e9086c72bb22 668 int16_t temp_torq = (int16_t) (msg.data[0] | msg.data[1] << 8);
jobuuu 7:e9086c72bb22 669 torq.ref = (double)temp_torq;
jobuuu 7:e9086c72bb22 670 } else if(address==CID_RX_REF_PRES_DIFF) {
Lightvalve 11:82d8768d7351 671 int16_t temp_presdiff = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 11:82d8768d7351 672 torq.ref = (double)temp_presdiff;
jobuuu 7:e9086c72bb22 673 } else if(address==CID_RX_REF_VOUT) {
jobuuu 7:e9086c72bb22 674 int16_t temp_PWM = (int16_t) (msg.data[0] | msg.data[1] << 8);
jobuuu 7:e9086c72bb22 675 Vout.ref = (double)temp_PWM;
jobuuu 7:e9086c72bb22 676 } else if(address==CID_RX_REF_VALVE_POSITION) {
Lightvalve 14:8e7590227d22 677 int16_t temp_valve_pos = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 14:8e7590227d22 678 valve_pos.ref = (double)temp_valve_pos;
Lightvalve 14:8e7590227d22 679 } else if(address==CID_RX_REF_CURRENT) {
jobuuu 7:e9086c72bb22 680 int16_t temp_cur = (int16_t) (msg.data[0] | msg.data[1] << 8);
jobuuu 7:e9086c72bb22 681 cur.ref = (double)temp_cur;
jobuuu 2:a1c0a37df760 682 }
jobuuu 7:e9086c72bb22 683
jobuuu 2:a1c0a37df760 684 }
jobuuu 2:a1c0a37df760 685
jobuuu 2:a1c0a37df760 686 /******************************************************************************
jobuuu 2:a1c0a37df760 687 Information Transmission Functions
jobuuu 2:a1c0a37df760 688 *******************************************************************************/
Lightvalve 11:82d8768d7351 689
Lightvalve 11:82d8768d7351 690 void CAN_TX_INFO(void) {
Lightvalve 12:6f2531038ea4 691 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 692
jobuuu 2:a1c0a37df760 693 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 694 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 695 temp_msg.data[0] = (uint8_t) CTX_SEND_INFO;
Lightvalve 12:6f2531038ea4 696 temp_msg.data[1] = (uint8_t) BNO;
Lightvalve 12:6f2531038ea4 697 temp_msg.data[2] = (uint8_t) CAN_FREQ;
Lightvalve 12:6f2531038ea4 698 temp_msg.data[3] = (uint8_t) (CAN_FREQ >> 8);
Lightvalve 12:6f2531038ea4 699 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 12:6f2531038ea4 700 temp_msg.data[5] = (uint8_t) CONTROL_MODE;
Lightvalve 12:6f2531038ea4 701 temp_msg.data[6] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 702
jobuuu 2:a1c0a37df760 703 can.write(temp_msg);
jobuuu 2:a1c0a37df760 704 }
jobuuu 2:a1c0a37df760 705
Lightvalve 11:82d8768d7351 706 void CAN_TX_BNO(void) {
Lightvalve 12:6f2531038ea4 707 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 708
jobuuu 2:a1c0a37df760 709 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 710 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 711 temp_msg.data[0] = (uint8_t) CTX_SEND_BNO;
Lightvalve 12:6f2531038ea4 712 temp_msg.data[1] = (uint8_t) BNO;
jobuuu 2:a1c0a37df760 713
jobuuu 2:a1c0a37df760 714 can.write(temp_msg);
jobuuu 2:a1c0a37df760 715 }
jobuuu 2:a1c0a37df760 716
Lightvalve 11:82d8768d7351 717 void CAN_TX_OPERATING_MODE(void) {
jobuuu 2:a1c0a37df760 718 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 719
jobuuu 2:a1c0a37df760 720 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 721 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 722 temp_msg.data[0] = (uint8_t) CTX_SEND_OPERATING_MODE;
Lightvalve 12:6f2531038ea4 723 temp_msg.data[1] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 724
jobuuu 2:a1c0a37df760 725 can.write(temp_msg);
jobuuu 2:a1c0a37df760 726 }
jobuuu 2:a1c0a37df760 727
Lightvalve 11:82d8768d7351 728 void CAN_TX_CAN_FREQ(void) {
jobuuu 2:a1c0a37df760 729 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 730
jobuuu 2:a1c0a37df760 731 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 732 temp_msg.len = 3;
jobuuu 2:a1c0a37df760 733 temp_msg.data[0] = (uint8_t) CTX_SEND_CAN_FREQ;
jobuuu 2:a1c0a37df760 734 temp_msg.data[1] = (uint8_t) CAN_FREQ;
jobuuu 2:a1c0a37df760 735 temp_msg.data[2] = (uint8_t) (CAN_FREQ >> 8);
jobuuu 2:a1c0a37df760 736
jobuuu 2:a1c0a37df760 737 can.write(temp_msg);
jobuuu 2:a1c0a37df760 738 }
Lightvalve 11:82d8768d7351 739
Lightvalve 11:82d8768d7351 740 void CAN_TX_CONTROL_MODE(void) {
jobuuu 2:a1c0a37df760 741 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 742
jobuuu 2:a1c0a37df760 743 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 744 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 745 temp_msg.data[0] = (uint8_t) CTX_SEND_CONTROL_MODE;
Lightvalve 12:6f2531038ea4 746 temp_msg.data[1] = (uint8_t) CONTROL_MODE;
jobuuu 2:a1c0a37df760 747
jobuuu 2:a1c0a37df760 748 can.write(temp_msg);
jobuuu 2:a1c0a37df760 749 }
Lightvalve 11:82d8768d7351 750
Lightvalve 11:82d8768d7351 751 void CAN_TX_JOINT_ENC_DIR(void) {
jobuuu 2:a1c0a37df760 752 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 753
jobuuu 2:a1c0a37df760 754 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 755 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 756 temp_msg.data[0] = (uint8_t) CTX_SEND_JOINT_ENC_DIR;
Lightvalve 12:6f2531038ea4 757 temp_msg.data[1] = (uint8_t) DIR_JOINT_ENC;
Lightvalve 12:6f2531038ea4 758 temp_msg.data[2] = (uint8_t) (DIR_JOINT_ENC >> 8);
jobuuu 2:a1c0a37df760 759
jobuuu 2:a1c0a37df760 760 can.write(temp_msg);
jobuuu 2:a1c0a37df760 761 }
jobuuu 2:a1c0a37df760 762
Lightvalve 11:82d8768d7351 763 void CAN_TX_VALVE_DIR(void) {
jobuuu 2:a1c0a37df760 764 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 765
jobuuu 2:a1c0a37df760 766 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 767 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 768 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DIR;
Lightvalve 12:6f2531038ea4 769 temp_msg.data[1] = (uint8_t) DIR_VALVE;
Lightvalve 12:6f2531038ea4 770 temp_msg.data[2] = (uint8_t) (DIR_VALVE >> 8);
jobuuu 2:a1c0a37df760 771
jobuuu 2:a1c0a37df760 772 can.write(temp_msg);
jobuuu 2:a1c0a37df760 773 }
jobuuu 2:a1c0a37df760 774
Lightvalve 11:82d8768d7351 775 void CAN_TX_VALVE_ENC_DIR(void) {
jobuuu 2:a1c0a37df760 776 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 777
jobuuu 2:a1c0a37df760 778 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 779 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 780 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ENC_DIR;
Lightvalve 12:6f2531038ea4 781 temp_msg.data[1] = (uint8_t) DIR_VALVE_ENC;
Lightvalve 12:6f2531038ea4 782 temp_msg.data[2] = (uint8_t) (DIR_VALVE_ENC >> 8);
jobuuu 2:a1c0a37df760 783
jobuuu 2:a1c0a37df760 784 can.write(temp_msg);
jobuuu 2:a1c0a37df760 785 }
jobuuu 2:a1c0a37df760 786
Lightvalve 11:82d8768d7351 787 void CAN_TX_VOLTAGE_SUPPLY(void) {
Lightvalve 12:6f2531038ea4 788 int16_t send_voltage_supply = (int16_t) (SUPPLY_VOLTAGE * 10);
jobuuu 2:a1c0a37df760 789
jobuuu 2:a1c0a37df760 790 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 791
jobuuu 2:a1c0a37df760 792 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 793 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 794 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_SUPPLY;
Lightvalve 12:6f2531038ea4 795 temp_msg.data[1] = (uint8_t) (send_voltage_supply);
Lightvalve 12:6f2531038ea4 796 temp_msg.data[2] = (uint8_t) (send_voltage_supply >> 8);
jobuuu 2:a1c0a37df760 797
jobuuu 2:a1c0a37df760 798 can.write(temp_msg);
jobuuu 2:a1c0a37df760 799 }
jobuuu 2:a1c0a37df760 800
Lightvalve 11:82d8768d7351 801 void CAN_TX_VOLTAGE_VALVE(void) {
Lightvalve 12:6f2531038ea4 802 int16_t send_voltage_valve = (int16_t) (VALVE_VOLTAGE_LIMIT * 10);
jobuuu 2:a1c0a37df760 803
jobuuu 2:a1c0a37df760 804 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 805
jobuuu 2:a1c0a37df760 806 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 807 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 808 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_VALVE;
Lightvalve 12:6f2531038ea4 809 temp_msg.data[1] = (uint8_t) send_voltage_valve;
Lightvalve 12:6f2531038ea4 810 temp_msg.data[2] = (uint8_t) (send_voltage_valve >> 8);
jobuuu 2:a1c0a37df760 811
jobuuu 2:a1c0a37df760 812 can.write(temp_msg);
jobuuu 2:a1c0a37df760 813 }
Lightvalve 11:82d8768d7351 814
jobuuu 2:a1c0a37df760 815
Lightvalve 11:82d8768d7351 816 void CAN_TX_PID_GAIN(int t_type) {
jobuuu 2:a1c0a37df760 817 // t_type = 0 : valve position control gain
jobuuu 2:a1c0a37df760 818 // t_type = 1 : joint position control gain
jobuuu 2:a1c0a37df760 819 // t_type = 2 : joint torque control gain
jobuuu 2:a1c0a37df760 820
Lightvalve 12:6f2531038ea4 821 int16_t sendPgain=0, sendIgain=0, sendDgain=0;
jobuuu 2:a1c0a37df760 822 if (t_type == 0) {
Lightvalve 30:8d561f16383b 823 sendPgain = (int16_t) (P_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 824 sendIgain = (int16_t) (I_GAIN_VALVE_POSITION);
Lightvalve 30:8d561f16383b 825 sendDgain = (int16_t) (D_GAIN_VALVE_POSITION);
jobuuu 2:a1c0a37df760 826 } else if (t_type == 1) {
Lightvalve 12:6f2531038ea4 827 sendPgain = (int16_t) (P_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 828 sendIgain = (int16_t) (I_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 829 sendDgain = (int16_t) (D_GAIN_JOINT_POSITION);
jobuuu 2:a1c0a37df760 830 } else if (t_type == 2) {
Lightvalve 12:6f2531038ea4 831 sendPgain = (int16_t) (P_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 832 sendIgain = (int16_t) (I_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 833 sendDgain = (int16_t) (D_GAIN_JOINT_TORQUE);
jobuuu 2:a1c0a37df760 834 }
jobuuu 2:a1c0a37df760 835
jobuuu 2:a1c0a37df760 836 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 837
jobuuu 2:a1c0a37df760 838 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 839 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 840 temp_msg.data[0] = (uint8_t) CTX_SEND_PID_GAIN;
Lightvalve 12:6f2531038ea4 841 temp_msg.data[1] = (uint8_t) t_type;
Lightvalve 12:6f2531038ea4 842 temp_msg.data[2] = (uint8_t) sendPgain;
Lightvalve 12:6f2531038ea4 843 temp_msg.data[3] = (uint8_t) (sendPgain >> 8);
Lightvalve 12:6f2531038ea4 844 temp_msg.data[4] = (uint8_t) sendIgain;
Lightvalve 12:6f2531038ea4 845 temp_msg.data[5] = (uint8_t) (sendIgain >> 8);
Lightvalve 12:6f2531038ea4 846 temp_msg.data[6] = (uint8_t) sendDgain;
Lightvalve 12:6f2531038ea4 847 temp_msg.data[7] = (uint8_t) (sendDgain >> 8);
jobuuu 2:a1c0a37df760 848
jobuuu 2:a1c0a37df760 849 can.write(temp_msg);
jobuuu 2:a1c0a37df760 850 }
jobuuu 2:a1c0a37df760 851
Lightvalve 11:82d8768d7351 852
Lightvalve 11:82d8768d7351 853 void CAN_TX_VALVE_DEADZONE(void) {
jobuuu 2:a1c0a37df760 854 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 855
jobuuu 2:a1c0a37df760 856 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 857 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 858 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE;
Lightvalve 12:6f2531038ea4 859 temp_msg.data[1] = (uint8_t) (int) (VALVE_CENTER);
Lightvalve 12:6f2531038ea4 860 temp_msg.data[2] = (uint8_t) ((int) (VALVE_CENTER) >> 8);
Lightvalve 12:6f2531038ea4 861 temp_msg.data[3] = (uint8_t) (int) (VALVE_DEADZONE_PLUS);
Lightvalve 12:6f2531038ea4 862 temp_msg.data[4] = (uint8_t) ((int) (VALVE_DEADZONE_PLUS) >> 8);
Lightvalve 12:6f2531038ea4 863 temp_msg.data[5] = (uint8_t) (int) (VALVE_DEADZONE_MINUS);
Lightvalve 12:6f2531038ea4 864 temp_msg.data[6] = (uint8_t) ((int) (VALVE_DEADZONE_MINUS) >> 8);
jobuuu 2:a1c0a37df760 865
jobuuu 2:a1c0a37df760 866 can.write(temp_msg);
jobuuu 2:a1c0a37df760 867 }
jobuuu 2:a1c0a37df760 868
Lightvalve 11:82d8768d7351 869 void CAN_TX_VELOCITY_COMP_GAIN(void) {
Lightvalve 11:82d8768d7351 870 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 871
Lightvalve 11:82d8768d7351 872 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 873 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 874 temp_msg.data[0] = (uint8_t) CTX_SEND_VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 875 temp_msg.data[1] = (uint8_t) VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 876 temp_msg.data[2] = (uint8_t) (VELOCITY_COMP_GAIN >> 8);
Lightvalve 11:82d8768d7351 877
Lightvalve 11:82d8768d7351 878 can.write(temp_msg);
Lightvalve 11:82d8768d7351 879 }
Lightvalve 11:82d8768d7351 880
Lightvalve 11:82d8768d7351 881 void CAN_TX_COMPLIANCE_GAIN(void) {
Lightvalve 11:82d8768d7351 882 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 883
Lightvalve 11:82d8768d7351 884 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 885 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 886 temp_msg.data[0] = (uint8_t) CTX_SEND_COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 887 temp_msg.data[1] = (uint8_t) COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 888 temp_msg.data[2] = (uint8_t) (COMPLIANCE_GAIN >> 8);
Lightvalve 11:82d8768d7351 889
Lightvalve 11:82d8768d7351 890 can.write(temp_msg);
Lightvalve 11:82d8768d7351 891 }
Lightvalve 11:82d8768d7351 892
Lightvalve 11:82d8768d7351 893 void CAN_TX_VALVE_FF(void) {
Lightvalve 11:82d8768d7351 894 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 895
Lightvalve 11:82d8768d7351 896 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 897 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 898 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_FF;
Lightvalve 12:6f2531038ea4 899 temp_msg.data[1] = (uint8_t) VALVE_FF;
Lightvalve 12:6f2531038ea4 900 temp_msg.data[2] = (uint8_t) (VALVE_FF >> 8);
Lightvalve 11:82d8768d7351 901
Lightvalve 11:82d8768d7351 902 can.write(temp_msg);
Lightvalve 11:82d8768d7351 903 }
Lightvalve 11:82d8768d7351 904
Lightvalve 11:82d8768d7351 905 void CAN_TX_BULK_MODULUS(void) {
Lightvalve 11:82d8768d7351 906 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 907
Lightvalve 11:82d8768d7351 908 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 909 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 910 temp_msg.data[0] = (uint8_t) CTX_SEND_BULK_MODULUS;
Lightvalve 12:6f2531038ea4 911 temp_msg.data[1] = (uint8_t) BULK_MODULUS;
Lightvalve 12:6f2531038ea4 912 temp_msg.data[2] = (uint8_t) (BULK_MODULUS >> 8);
Lightvalve 11:82d8768d7351 913
Lightvalve 11:82d8768d7351 914 can.write(temp_msg);
Lightvalve 11:82d8768d7351 915 }
Lightvalve 11:82d8768d7351 916
Lightvalve 11:82d8768d7351 917 void CAN_TX_CHAMBER_VOLUME(void) {
Lightvalve 11:82d8768d7351 918 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 919
Lightvalve 11:82d8768d7351 920 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 921 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 922 temp_msg.data[0] = (uint8_t) CTX_SEND_CHAMBER_VOLUME;
Lightvalve 12:6f2531038ea4 923 temp_msg.data[1] = (uint8_t) CHAMBER_VOLUME_A;
Lightvalve 12:6f2531038ea4 924 temp_msg.data[2] = (uint8_t) (CHAMBER_VOLUME_A >> 8);
Lightvalve 12:6f2531038ea4 925 temp_msg.data[3] = (uint8_t) CHAMBER_VOLUME_B;
Lightvalve 12:6f2531038ea4 926 temp_msg.data[4] = (uint8_t) (CHAMBER_VOLUME_B >> 8);
Lightvalve 11:82d8768d7351 927
Lightvalve 11:82d8768d7351 928 can.write(temp_msg);
Lightvalve 11:82d8768d7351 929 }
Lightvalve 11:82d8768d7351 930
Lightvalve 11:82d8768d7351 931 void CAN_TX_PISTON_AREA(void) {
jobuuu 2:a1c0a37df760 932 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 933
Lightvalve 11:82d8768d7351 934 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 935 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 936 temp_msg.data[0] = (uint8_t) CTX_SEND_PISTON_AREA;
Lightvalve 12:6f2531038ea4 937 temp_msg.data[1] = (uint8_t) PISTON_AREA_A;
Lightvalve 12:6f2531038ea4 938 temp_msg.data[2] = (uint8_t) (PISTON_AREA_A >> 8);
Lightvalve 12:6f2531038ea4 939 temp_msg.data[3] = (uint8_t) PISTON_AREA_B;
Lightvalve 12:6f2531038ea4 940 temp_msg.data[4] = (uint8_t) (PISTON_AREA_B >> 8);
jobuuu 2:a1c0a37df760 941
Lightvalve 11:82d8768d7351 942 can.write(temp_msg);
Lightvalve 11:82d8768d7351 943 }
Lightvalve 11:82d8768d7351 944
Lightvalve 11:82d8768d7351 945 void CAN_TX_PRES_A_AND_B(void) {
Lightvalve 11:82d8768d7351 946 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 947
Lightvalve 11:82d8768d7351 948 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 949 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 950 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES;
Lightvalve 12:6f2531038ea4 951 temp_msg.data[1] = (uint8_t) PRES_SUPPLY;
Lightvalve 12:6f2531038ea4 952 temp_msg.data[2] = (uint8_t) (PRES_SUPPLY >> 8);
Lightvalve 12:6f2531038ea4 953 temp_msg.data[3] = (uint8_t) PRES_RETURN;
Lightvalve 12:6f2531038ea4 954 temp_msg.data[4] = (uint8_t) (PRES_RETURN >> 8);
Lightvalve 11:82d8768d7351 955
Lightvalve 11:82d8768d7351 956 can.write(temp_msg);
Lightvalve 11:82d8768d7351 957 }
Lightvalve 11:82d8768d7351 958
Lightvalve 11:82d8768d7351 959 void CAN_TX_ENC_LIMIT(void) {
Lightvalve 11:82d8768d7351 960 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 961
Lightvalve 11:82d8768d7351 962 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 963 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 964 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_LIMIT;
Lightvalve 12:6f2531038ea4 965 temp_msg.data[1] = (uint8_t) ENC_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 966 temp_msg.data[2] = (uint8_t) (ENC_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 967 temp_msg.data[3] = (uint8_t) ENC_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 968 temp_msg.data[4] = (uint8_t) (ENC_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 969
Lightvalve 11:82d8768d7351 970 can.write(temp_msg);
Lightvalve 11:82d8768d7351 971 }
Lightvalve 11:82d8768d7351 972
Lightvalve 11:82d8768d7351 973 void CAN_TX_STROKE(void) {
Lightvalve 11:82d8768d7351 974 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 975
Lightvalve 11:82d8768d7351 976 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 977 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 978 temp_msg.data[0] = (uint8_t) CTX_SEND_STROKE;
Lightvalve 12:6f2531038ea4 979 temp_msg.data[1] = (uint8_t) STROKE;
Lightvalve 12:6f2531038ea4 980 temp_msg.data[2] = (uint8_t) (STROKE >> 8);
Lightvalve 11:82d8768d7351 981
Lightvalve 11:82d8768d7351 982 can.write(temp_msg);
Lightvalve 11:82d8768d7351 983 }
Lightvalve 11:82d8768d7351 984
Lightvalve 11:82d8768d7351 985 void CAN_TX_VALVE_LIMIT(void) {
Lightvalve 11:82d8768d7351 986 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 987
Lightvalve 11:82d8768d7351 988 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 989 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 990 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT;
Lightvalve 12:6f2531038ea4 991 temp_msg.data[1] = (uint8_t) VALVE_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 992 temp_msg.data[2] = (uint8_t) (VALVE_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 993 temp_msg.data[3] = (uint8_t) VALVE_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 994 temp_msg.data[4] = (uint8_t) (VALVE_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 995
Lightvalve 11:82d8768d7351 996 can.write(temp_msg);
Lightvalve 11:82d8768d7351 997 }
Lightvalve 11:82d8768d7351 998
Lightvalve 11:82d8768d7351 999 void CAN_TX_ENC_PULSE_PER_POSITION(void) {
Lightvalve 11:82d8768d7351 1000 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1001
jobuuu 2:a1c0a37df760 1002 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1003 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1004 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_PULSE_PER_POSITION;
Lightvalve 12:6f2531038ea4 1005 temp_msg.data[1] = (uint8_t) ENC_PULSE_PER_POSITION;
Lightvalve 12:6f2531038ea4 1006 temp_msg.data[2] = (uint8_t) (ENC_PULSE_PER_POSITION >> 8);
jobuuu 2:a1c0a37df760 1007
jobuuu 2:a1c0a37df760 1008 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1009 }
jobuuu 2:a1c0a37df760 1010
Lightvalve 11:82d8768d7351 1011 void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void) {
jobuuu 2:a1c0a37df760 1012 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1013
jobuuu 2:a1c0a37df760 1014 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1015 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1016 temp_msg.data[0] = (uint8_t) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 12:6f2531038ea4 1017 temp_msg.data[1] = (uint8_t) TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 12:6f2531038ea4 1018 temp_msg.data[2] = (uint8_t) (TORQUE_SENSOR_PULSE_PER_TORQUE >> 8);
jobuuu 2:a1c0a37df760 1019
jobuuu 2:a1c0a37df760 1020 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1021 }
jobuuu 2:a1c0a37df760 1022
Lightvalve 11:82d8768d7351 1023 void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void) {
jobuuu 2:a1c0a37df760 1024 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1025
jobuuu 2:a1c0a37df760 1026 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1027 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1028 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR;
Lightvalve 30:8d561f16383b 1029 temp_msg.data[1] = (uint8_t) (int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1030 temp_msg.data[2] = (uint8_t) ((int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1031 temp_msg.data[3] = (uint8_t) (int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f);
Lightvalve 30:8d561f16383b 1032 temp_msg.data[4] = (uint8_t) ((int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f) >> 8);
jobuuu 2:a1c0a37df760 1033
jobuuu 2:a1c0a37df760 1034 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1035 }
jobuuu 2:a1c0a37df760 1036
Lightvalve 11:82d8768d7351 1037 void CAN_TX_FRICTION(void) {
Lightvalve 11:82d8768d7351 1038 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1039 int16_t send_friction;
Lightvalve 30:8d561f16383b 1040 send_friction = (int16_t) (FRICTION * 10.0f);
Lightvalve 11:82d8768d7351 1041
Lightvalve 11:82d8768d7351 1042 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1043 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1044 temp_msg.data[0] = (uint8_t) CTX_SEND_FRICTION;
Lightvalve 12:6f2531038ea4 1045 temp_msg.data[1] = (uint8_t) send_friction;
Lightvalve 12:6f2531038ea4 1046 temp_msg.data[2] = (uint8_t) (send_friction >> 8);
Lightvalve 11:82d8768d7351 1047
Lightvalve 11:82d8768d7351 1048 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1049 }
Lightvalve 11:82d8768d7351 1050
Lightvalve 11:82d8768d7351 1051 void CAN_TX_VALVE_GAIN_PLUS(void) {
Lightvalve 11:82d8768d7351 1052 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1053
Lightvalve 11:82d8768d7351 1054 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1055 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1056 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_PLUS;
Lightvalve 30:8d561f16383b 1057 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[0] * 50.0f);
Lightvalve 30:8d561f16383b 1058 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[2] * 50.0f);
Lightvalve 30:8d561f16383b 1059 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[4] * 50.0f);
Lightvalve 30:8d561f16383b 1060 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[6] * 50.0f);
Lightvalve 30:8d561f16383b 1061 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[8] * 50.0f);
Lightvalve 11:82d8768d7351 1062
Lightvalve 11:82d8768d7351 1063 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1064 }
Lightvalve 11:82d8768d7351 1065
Lightvalve 11:82d8768d7351 1066 void CAN_TX_DDV_VALVE_DEADZONE(void) {
Lightvalve 11:82d8768d7351 1067 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1068
Lightvalve 11:82d8768d7351 1069 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1070 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1071 temp_msg.data[0] = (uint8_t) CTX_SEND_DDV_VALVE_DEADZONE;
Lightvalve 12:6f2531038ea4 1072 temp_msg.data[1] = (uint8_t) VALVE_DEADZONE_MINUS;
Lightvalve 12:6f2531038ea4 1073 temp_msg.data[2] = (uint8_t) ((int) (VALVE_DEADZONE_MINUS) >> 8);
Lightvalve 12:6f2531038ea4 1074 temp_msg.data[3] = (uint8_t) (VALVE_DEADZONE_PLUS);
Lightvalve 12:6f2531038ea4 1075 temp_msg.data[4] = (uint8_t) ((int) (VALVE_DEADZONE_PLUS) >> 8);
Lightvalve 12:6f2531038ea4 1076 temp_msg.data[5] = (uint8_t) (DDV_CENTER);
Lightvalve 12:6f2531038ea4 1077 temp_msg.data[6] = (uint8_t) ((int) (DDV_CENTER) >> 8);
Lightvalve 11:82d8768d7351 1078
Lightvalve 11:82d8768d7351 1079 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1080 }
Lightvalve 11:82d8768d7351 1081
Lightvalve 11:82d8768d7351 1082 void CAN_TX_VALVE_GAIN_MINUS(void) {
Lightvalve 11:82d8768d7351 1083 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1084
Lightvalve 11:82d8768d7351 1085 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1086 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1087 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_MINUS;
Lightvalve 30:8d561f16383b 1088 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[1] * 50.0f);
Lightvalve 30:8d561f16383b 1089 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[3] * 50.0f);
Lightvalve 30:8d561f16383b 1090 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[5] * 50.0f);
Lightvalve 30:8d561f16383b 1091 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[7] * 50.0f);
Lightvalve 30:8d561f16383b 1092 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[9] * 50.0f);
Lightvalve 11:82d8768d7351 1093
Lightvalve 11:82d8768d7351 1094 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1095 }
Lightvalve 11:82d8768d7351 1096
Lightvalve 11:82d8768d7351 1097 void CAN_TX_REFENCE_MODE(void) {
Lightvalve 11:82d8768d7351 1098 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1099
Lightvalve 11:82d8768d7351 1100 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1101 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1102 temp_msg.data[0] = (uint8_t) CTX_SEND_REFENCE_MODE;
Lightvalve 12:6f2531038ea4 1103 temp_msg.data[1] = (uint8_t) REFERENCE_MODE;
Lightvalve 30:8d561f16383b 1104 temp_msg.data[2] = (uint8_t) (int) (REFERENCE_FREQ * 100.0f);
Lightvalve 30:8d561f16383b 1105 temp_msg.data[3] = (uint8_t) ((int) (REFERENCE_FREQ * 100.0f) >> 8);
Lightvalve 30:8d561f16383b 1106 temp_msg.data[4] = (uint8_t) (int) (REFERENCE_MAG * 100.0f);
Lightvalve 30:8d561f16383b 1107 temp_msg.data[5] = (uint8_t) ((int) (REFERENCE_MAG * 100.0f) >> 8);
Lightvalve 11:82d8768d7351 1108
Lightvalve 11:82d8768d7351 1109 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1110 }
Lightvalve 11:82d8768d7351 1111
Lightvalve 11:82d8768d7351 1112 void CAN_TX_HOMEPOS_OFFSET(void) {
Lightvalve 11:82d8768d7351 1113 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1114 int16_t send_homepos_offset;
Lightvalve 12:6f2531038ea4 1115 send_homepos_offset = (int16_t) (HOMEPOS_OFFSET);
Lightvalve 11:82d8768d7351 1116
jobuuu 2:a1c0a37df760 1117 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1118 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1119 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_OFFSET;
Lightvalve 12:6f2531038ea4 1120 temp_msg.data[1] = (uint8_t) send_homepos_offset;
Lightvalve 12:6f2531038ea4 1121 temp_msg.data[2] = (uint8_t) (send_homepos_offset >> 8);
jobuuu 2:a1c0a37df760 1122
jobuuu 2:a1c0a37df760 1123 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1124 }
Lightvalve 11:82d8768d7351 1125
Lightvalve 11:82d8768d7351 1126 void CAN_TX_HOMPOS_VALVE_OPENING(void) {
Lightvalve 11:82d8768d7351 1127 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1128 int16_t send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1129 send_homepos_valve_opening = (int16_t) (HOMEPOS_VALVE_OPENING);
Lightvalve 11:82d8768d7351 1130
Lightvalve 11:82d8768d7351 1131 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1132 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1133 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_VALVE_OPENING;
Lightvalve 12:6f2531038ea4 1134 temp_msg.data[1] = (uint8_t) send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1135 temp_msg.data[2] = (uint8_t) (send_homepos_valve_opening >> 8);
Lightvalve 11:82d8768d7351 1136
Lightvalve 11:82d8768d7351 1137 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1138 }
Lightvalve 11:82d8768d7351 1139
Lightvalve 12:6f2531038ea4 1140 void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex) {
Lightvalve 11:82d8768d7351 1141 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1142 int16_t valve_pos_vs_pwm;
Lightvalve 11:82d8768d7351 1143 valve_pos_vs_pwm = (int16_t) (VALVE_POS_VS_PWM[canindex]);
Lightvalve 11:82d8768d7351 1144
Lightvalve 12:6f2531038ea4 1145 int16_t PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1146 PWM_VALVE_ID = ID_index_array[canindex] * 1000;
Lightvalve 11:82d8768d7351 1147
Lightvalve 11:82d8768d7351 1148 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1149 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1150 temp_msg.data[0] = (uint8_t) CTX_VALVE_PWM_VS_VALVE_POS;
Lightvalve 12:6f2531038ea4 1151 temp_msg.data[1] = (uint8_t) PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1152 temp_msg.data[2] = (uint8_t) (PWM_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1153 temp_msg.data[3] = (uint8_t) valve_pos_vs_pwm;
Lightvalve 12:6f2531038ea4 1154 temp_msg.data[4] = (uint8_t) (valve_pos_vs_pwm >> 8);
Lightvalve 11:82d8768d7351 1155
Lightvalve 11:82d8768d7351 1156 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1157 }
Lightvalve 11:82d8768d7351 1158
Lightvalve 12:6f2531038ea4 1159 void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex) {
Lightvalve 11:82d8768d7351 1160 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1161 int32_t valve_pos_vs_flowrate;
Lightvalve 11:82d8768d7351 1162 valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]);
Lightvalve 11:82d8768d7351 1163
Lightvalve 19:23b7c1ad8683 1164 int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 10 + DDV_CENTER;
Lightvalve 11:82d8768d7351 1165
Lightvalve 11:82d8768d7351 1166 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1167 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1168 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_VS_FLOWRATE;
Lightvalve 12:6f2531038ea4 1169 temp_msg.data[1] = (uint8_t) VALVE_POS_VALVE_ID;
Lightvalve 12:6f2531038ea4 1170 temp_msg.data[2] = (uint8_t) (VALVE_POS_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1171 temp_msg.data[3] = (uint8_t) valve_pos_vs_flowrate;
Lightvalve 12:6f2531038ea4 1172 temp_msg.data[4] = (uint8_t) (valve_pos_vs_flowrate >> 8);
Lightvalve 12:6f2531038ea4 1173 temp_msg.data[5] = (uint8_t) (valve_pos_vs_flowrate >> 16);
Lightvalve 12:6f2531038ea4 1174 temp_msg.data[6] = (uint8_t) (valve_pos_vs_flowrate >> 24);
Lightvalve 11:82d8768d7351 1175
Lightvalve 11:82d8768d7351 1176 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1177 }
Lightvalve 11:82d8768d7351 1178
Lightvalve 11:82d8768d7351 1179 void CAN_TX_VALVE_POS_NUM(void) {
Lightvalve 11:82d8768d7351 1180 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1181 int32_t valve_pos_num;
Lightvalve 11:82d8768d7351 1182 valve_pos_num = (int16_t) VALVE_POS_NUM;
Lightvalve 11:82d8768d7351 1183
Lightvalve 11:82d8768d7351 1184 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1185 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1186 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_NUM;
Lightvalve 12:6f2531038ea4 1187 temp_msg.data[1] = (uint8_t) valve_pos_num;
Lightvalve 12:6f2531038ea4 1188 temp_msg.data[2] = (uint8_t) (valve_pos_num >> 8);
Lightvalve 11:82d8768d7351 1189
Lightvalve 11:82d8768d7351 1190 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1191 }
Lightvalve 11:82d8768d7351 1192
jobuuu 2:a1c0a37df760 1193 /******************************************************************************
jobuuu 2:a1c0a37df760 1194 Sensor & State Transmission Functions
jobuuu 2:a1c0a37df760 1195 *******************************************************************************/
jobuuu 2:a1c0a37df760 1196
Lightvalve 12:6f2531038ea4 1197 void CAN_TX_POSITION(int32_t t_pos, int32_t t_vel) {
jobuuu 2:a1c0a37df760 1198 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1199
jobuuu 2:a1c0a37df760 1200 temp_msg.id = CID_TX_POSITION;
jobuuu 2:a1c0a37df760 1201 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1202 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 12:6f2531038ea4 1203 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 12:6f2531038ea4 1204 temp_msg.data[2] = (uint8_t) (t_pos >> 16);
Lightvalve 12:6f2531038ea4 1205 temp_msg.data[3] = (uint8_t) (t_pos >> 24);
Lightvalve 12:6f2531038ea4 1206 temp_msg.data[4] = (uint8_t) t_vel;
Lightvalve 12:6f2531038ea4 1207 temp_msg.data[5] = (uint8_t) (t_vel >> 8);
Lightvalve 12:6f2531038ea4 1208 temp_msg.data[6] = (uint8_t) (t_vel >> 16);
Lightvalve 12:6f2531038ea4 1209 temp_msg.data[7] = (uint8_t) (t_vel >> 24);
jobuuu 2:a1c0a37df760 1210
jobuuu 2:a1c0a37df760 1211 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1212 }
jobuuu 2:a1c0a37df760 1213
Lightvalve 11:82d8768d7351 1214 void CAN_TX_TORQUE(int16_t t_torque) {
jobuuu 2:a1c0a37df760 1215 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1216
jobuuu 2:a1c0a37df760 1217 temp_msg.id = CID_TX_TORQUE;
jobuuu 2:a1c0a37df760 1218 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 1219 temp_msg.data[0] = (uint8_t) t_torque;
Lightvalve 12:6f2531038ea4 1220 temp_msg.data[1] = (uint8_t) (t_torque >> 8);
jobuuu 2:a1c0a37df760 1221
jobuuu 2:a1c0a37df760 1222 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1223 }
jobuuu 2:a1c0a37df760 1224
Lightvalve 11:82d8768d7351 1225 void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b) {
jobuuu 2:a1c0a37df760 1226 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1227
jobuuu 2:a1c0a37df760 1228 temp_msg.id = CID_TX_PRES;
jobuuu 2:a1c0a37df760 1229 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1230 temp_msg.data[0] = (uint8_t) t_pres_a;
Lightvalve 12:6f2531038ea4 1231 temp_msg.data[1] = (uint8_t) (t_pres_a >> 8);
Lightvalve 12:6f2531038ea4 1232 temp_msg.data[2] = (uint8_t) t_pres_b;
Lightvalve 12:6f2531038ea4 1233 temp_msg.data[3] = (uint8_t) (t_pres_b >> 8);
jobuuu 2:a1c0a37df760 1234
jobuuu 2:a1c0a37df760 1235 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1236 }
jobuuu 2:a1c0a37df760 1237
Lightvalve 11:82d8768d7351 1238 void CAN_TX_PWM(int16_t t_pwm) {
jobuuu 2:a1c0a37df760 1239 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1240
jobuuu 2:a1c0a37df760 1241 temp_msg.id = CID_TX_POSITION;
jobuuu 2:a1c0a37df760 1242 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1243 temp_msg.data[0] = (uint8_t) t_pwm;
Lightvalve 12:6f2531038ea4 1244 temp_msg.data[1] = (uint8_t) (t_pwm >> 8);
jobuuu 2:a1c0a37df760 1245
jobuuu 2:a1c0a37df760 1246 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1247 }
jobuuu 2:a1c0a37df760 1248
Lightvalve 27:a2254a485f23 1249 void CAN_TX_VALVE_POSITION(int16_t t_valve_pos, int16_t t_ref_valve_pos, int16_t t_pwm)
Lightvalve 27:a2254a485f23 1250 {
jobuuu 2:a1c0a37df760 1251 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1252
jobuuu 2:a1c0a37df760 1253 temp_msg.id = CID_TX_VALVE_POSITION;
jobuuu 2:a1c0a37df760 1254 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1255 temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 12:6f2531038ea4 1256 temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
Lightvalve 27:a2254a485f23 1257 temp_msg.data[2] = (uint8_t) t_ref_valve_pos;
Lightvalve 27:a2254a485f23 1258 temp_msg.data[3] = (uint8_t) (t_ref_valve_pos >> 8);
Lightvalve 27:a2254a485f23 1259 temp_msg.data[4] = (uint8_t) t_pwm;
Lightvalve 27:a2254a485f23 1260 temp_msg.data[5] = (uint8_t) (t_pwm >> 8);
Lightvalve 27:a2254a485f23 1261
jobuuu 2:a1c0a37df760 1262
jobuuu 2:a1c0a37df760 1263 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1264 }
Lightvalve 23:59218d4a256d 1265
Lightvalve 23:59218d4a256d 1266
Lightvalve 32:4b8c0fedaf2c 1267