Original Version of STM Board

Dependencies:   FastPWM mbed

Committer:
Lightvalve
Date:
Tue Aug 27 05:32:44 2019 +0000
Revision:
12:6f2531038ea4
Parent:
11:82d8768d7351
Child:
14:8e7590227d22
190827

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"
jobuuu 2:a1c0a37df760 5
jobuuu 2:a1c0a37df760 6 // CAN ID Setting Variables
jobuuu 2:a1c0a37df760 7 int CID_RX_CMD = 100;
jobuuu 2:a1c0a37df760 8 int CID_RX_REF_POSITION = 200;
jobuuu 2:a1c0a37df760 9 int CID_RX_REF_TORQUE = 300;
jobuuu 2:a1c0a37df760 10 int CID_RX_REF_PRES_DIFF = 400;
jobuuu 7:e9086c72bb22 11 int CID_RX_REF_VOUT = 500;
jobuuu 2:a1c0a37df760 12 int CID_RX_REF_VALVE_POSITION = 600;
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 12:6f2531038ea4 23
Lightvalve 11:82d8768d7351 24
Lightvalve 11:82d8768d7351 25 /*******************************************************************************
Lightvalve 11:82d8768d7351 26 * CAN functions
Lightvalve 11:82d8768d7351 27 ******************************************************************************/
Lightvalve 11:82d8768d7351 28 void CAN_ID_INIT(void) {
jobuuu 7:e9086c72bb22 29
Lightvalve 11:82d8768d7351 30 CID_RX_CMD = (int) (BNO + INIT_CID_RX_CMD);
Lightvalve 11:82d8768d7351 31 CID_RX_REF_POSITION = (int) (BNO + INIT_CID_RX_REF_POSITION);
Lightvalve 11:82d8768d7351 32 CID_RX_REF_TORQUE = (int) (BNO + INIT_CID_RX_REF_TORQUE);
Lightvalve 11:82d8768d7351 33 CID_RX_REF_PRES_DIFF = (int) (BNO + INIT_CID_RX_REF_PRES_DIFF);
Lightvalve 11:82d8768d7351 34 CID_RX_REF_VOUT = (int) (BNO + INIT_CID_RX_REF_VOUT);
Lightvalve 11:82d8768d7351 35 CID_RX_REF_VALVE_POSITION = (int) (BNO + INIT_CID_RX_REF_VALVE_POSITION);
Lightvalve 11:82d8768d7351 36
Lightvalve 11:82d8768d7351 37 CID_TX_INFO = (int) (BNO + INIT_CID_TX_INFO);
Lightvalve 11:82d8768d7351 38 CID_TX_POSITION = (int) (BNO + INIT_CID_TX_POSITION);
Lightvalve 11:82d8768d7351 39 CID_TX_TORQUE = (int) (BNO + INIT_CID_TX_TORQUE);
Lightvalve 11:82d8768d7351 40 CID_TX_PRES = (int) (BNO + INIT_CID_TX_PRES);
Lightvalve 11:82d8768d7351 41 CID_TX_VOUT = (int) (BNO + INIT_CID_TX_VOUT);
Lightvalve 11:82d8768d7351 42 CID_TX_VALVE_POSITION = (int) (BNO + INIT_CID_TX_VALVE_POSITION);
Lightvalve 11:82d8768d7351 43 }
jobuuu 2:a1c0a37df760 44
Lightvalve 12:6f2531038ea4 45 void ReadCMD(int8_t CMD)
jobuuu 2:a1c0a37df760 46 {
jobuuu 2:a1c0a37df760 47 switch(CMD){
Lightvalve 11:82d8768d7351 48 case CRX_ASK_INFO: {
Lightvalve 11:82d8768d7351 49 CAN_TX_INFO();
Lightvalve 11:82d8768d7351 50 break;
Lightvalve 11:82d8768d7351 51 }
Lightvalve 11:82d8768d7351 52 case CRX_ASK_BNO: {
Lightvalve 11:82d8768d7351 53 CAN_TX_BNO();
Lightvalve 11:82d8768d7351 54 break;
Lightvalve 11:82d8768d7351 55 }
Lightvalve 11:82d8768d7351 56 case CRX_SET_BNO: {
Lightvalve 11:82d8768d7351 57 BNO = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 58 spi_eeprom_write(RID_BNO, (int16_t) BNO);
Lightvalve 11:82d8768d7351 59 CAN_ID_INIT(); // can id init
Lightvalve 11:82d8768d7351 60 break;
Lightvalve 11:82d8768d7351 61 }
Lightvalve 11:82d8768d7351 62 case CRX_ASK_OPERATING_MODE: {
Lightvalve 11:82d8768d7351 63 CAN_TX_OPERATING_MODE();
Lightvalve 11:82d8768d7351 64 break;
Lightvalve 11:82d8768d7351 65 }
Lightvalve 11:82d8768d7351 66 case CRX_SET_OPERATING_MODE: {
Lightvalve 11:82d8768d7351 67 OPERATING_MODE = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 68 spi_eeprom_write(RID_OPERATING_MODE, (int16_t) OPERATING_MODE);
Lightvalve 11:82d8768d7351 69 break;
Lightvalve 11:82d8768d7351 70 }
Lightvalve 11:82d8768d7351 71 case CRX_SET_ENC_ZERO: {
Lightvalve 11:82d8768d7351 72 ENC_SET_ZERO();
Lightvalve 11:82d8768d7351 73
Lightvalve 11:82d8768d7351 74 break;
Lightvalve 11:82d8768d7351 75 }
Lightvalve 11:82d8768d7351 76 case CRX_SET_FET_ON: {
Lightvalve 12:6f2531038ea4 77 //LAT_MOT_EN = (int16_t) msg.data[1];;
Lightvalve 11:82d8768d7351 78
Lightvalve 11:82d8768d7351 79 break;
Lightvalve 11:82d8768d7351 80 }
Lightvalve 11:82d8768d7351 81
Lightvalve 11:82d8768d7351 82 case CRX_SET_REF_UPDATE_ENABLE: {
Lightvalve 11:82d8768d7351 83 flag_ref_enable = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 84
Lightvalve 11:82d8768d7351 85 break;
Lightvalve 11:82d8768d7351 86 }
Lightvalve 11:82d8768d7351 87
Lightvalve 11:82d8768d7351 88 case CRX_ASK_CAN_FREQ: {
Lightvalve 11:82d8768d7351 89 CAN_TX_CAN_FREQ();
Lightvalve 11:82d8768d7351 90
Lightvalve 11:82d8768d7351 91 break;
Lightvalve 11:82d8768d7351 92 }
Lightvalve 11:82d8768d7351 93
Lightvalve 11:82d8768d7351 94 case CRX_SET_CAN_FREQ: {
Lightvalve 11:82d8768d7351 95 CAN_FREQ = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 96 spi_eeprom_write(RID_CAN_FREQ, (int16_t) CAN_FREQ);
Lightvalve 11:82d8768d7351 97 break;
Lightvalve 11:82d8768d7351 98 }
Lightvalve 11:82d8768d7351 99
Lightvalve 11:82d8768d7351 100 case CRX_ASK_CONTROL_MODE: {
Lightvalve 11:82d8768d7351 101 CAN_TX_CONTROL_MODE();
Lightvalve 11:82d8768d7351 102
Lightvalve 11:82d8768d7351 103 break;
Lightvalve 11:82d8768d7351 104 }
Lightvalve 11:82d8768d7351 105
Lightvalve 11:82d8768d7351 106 case CRX_SET_CONTROL_MODE: {
Lightvalve 11:82d8768d7351 107 CONTROL_MODE = (int16_t) (msg.data[1]);
Lightvalve 12:6f2531038ea4 108 if (CONTROL_MODE == 22) { //MODE_FIND_HOME
Lightvalve 11:82d8768d7351 109 FLAG_FIND_HOME = true;
Lightvalve 11:82d8768d7351 110 }
Lightvalve 11:82d8768d7351 111 break;
Lightvalve 11:82d8768d7351 112 }
Lightvalve 11:82d8768d7351 113
Lightvalve 11:82d8768d7351 114 case CRX_SET_DATA_REQUEST: {
Lightvalve 11:82d8768d7351 115 int request_type = msg.data[2];
Lightvalve 11:82d8768d7351 116 flag_data_request[request_type] = msg.data[1];
Lightvalve 11:82d8768d7351 117
Lightvalve 12:6f2531038ea4 118 // if (flag_data_request[1] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC
Lightvalve 12:6f2531038ea4 119 if (flag_data_request[1] == HIGH) dac_1 = PRES_A_VREF/3.3;
Lightvalve 12:6f2531038ea4 120 // if (flag_data_request[2] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC
Lightvalve 12:6f2531038ea4 121 if (flag_data_request[2] == HIGH) dac_2 = PRES_B_VREF/3.3;
Lightvalve 11:82d8768d7351 122
Lightvalve 11:82d8768d7351 123 break;
Lightvalve 11:82d8768d7351 124 }
Lightvalve 11:82d8768d7351 125
Lightvalve 11:82d8768d7351 126 case CRX_ASK_JOINT_ENC_DIR: {
Lightvalve 11:82d8768d7351 127 CAN_TX_JOINT_ENC_DIR();
Lightvalve 11:82d8768d7351 128
Lightvalve 11:82d8768d7351 129 break;
Lightvalve 11:82d8768d7351 130 }
Lightvalve 11:82d8768d7351 131
Lightvalve 11:82d8768d7351 132 case CRX_SET_JOINT_ENC_DIR: {
Lightvalve 11:82d8768d7351 133 DIR_JOINT_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 134 if (DIR_JOINT_ENC >= 0)
Lightvalve 11:82d8768d7351 135 DIR_JOINT_ENC = 1;
Lightvalve 11:82d8768d7351 136 else
Lightvalve 11:82d8768d7351 137 DIR_JOINT_ENC = -1;
Lightvalve 11:82d8768d7351 138 spi_eeprom_write(RID_JOINT_ENC_DIR, (int16_t) DIR_JOINT_ENC);
Lightvalve 11:82d8768d7351 139
Lightvalve 11:82d8768d7351 140 break;
Lightvalve 11:82d8768d7351 141 }
Lightvalve 11:82d8768d7351 142
Lightvalve 11:82d8768d7351 143 case CRX_ASK_VALVE_DIR: {
Lightvalve 11:82d8768d7351 144 CAN_TX_VALVE_DIR();
Lightvalve 11:82d8768d7351 145
Lightvalve 11:82d8768d7351 146 break;
Lightvalve 11:82d8768d7351 147 }
Lightvalve 11:82d8768d7351 148
Lightvalve 11:82d8768d7351 149 case CRX_SET_VALVE_DIR: {
Lightvalve 11:82d8768d7351 150 DIR_VALVE = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 151 if (DIR_VALVE >= 0)
Lightvalve 11:82d8768d7351 152 DIR_VALVE = 1;
Lightvalve 11:82d8768d7351 153 else
Lightvalve 11:82d8768d7351 154 DIR_VALVE = -1;
Lightvalve 11:82d8768d7351 155 spi_eeprom_write(RID_VALVE_DIR, (int16_t) DIR_VALVE);
Lightvalve 11:82d8768d7351 156
Lightvalve 11:82d8768d7351 157 break;
Lightvalve 11:82d8768d7351 158 }
Lightvalve 11:82d8768d7351 159
Lightvalve 11:82d8768d7351 160 case CRX_ASK_VALVE_ENC_DIR: {
Lightvalve 11:82d8768d7351 161 CAN_TX_VALVE_ENC_DIR();
Lightvalve 11:82d8768d7351 162
Lightvalve 11:82d8768d7351 163 break;
Lightvalve 11:82d8768d7351 164 }
Lightvalve 11:82d8768d7351 165
Lightvalve 11:82d8768d7351 166 case CRX_SET_VALVE_ENC_DIR: {
Lightvalve 11:82d8768d7351 167 DIR_VALVE_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 168 if (DIR_VALVE_ENC >= 0)
Lightvalve 11:82d8768d7351 169 DIR_VALVE_ENC = 1;
Lightvalve 11:82d8768d7351 170 else
Lightvalve 11:82d8768d7351 171 DIR_VALVE_ENC = -1;
Lightvalve 11:82d8768d7351 172
Lightvalve 11:82d8768d7351 173 spi_eeprom_write(RID_VALVE_ENC_DIR, (int16_t) DIR_VALVE_ENC);
Lightvalve 11:82d8768d7351 174
Lightvalve 11:82d8768d7351 175 break;
Lightvalve 11:82d8768d7351 176 }
Lightvalve 11:82d8768d7351 177
Lightvalve 11:82d8768d7351 178 case CRX_ASK_VOLTAGE_SUPPLY: {
Lightvalve 11:82d8768d7351 179 CAN_TX_VOLTAGE_SUPPLY();
Lightvalve 11:82d8768d7351 180
Lightvalve 11:82d8768d7351 181 break;
Lightvalve 11:82d8768d7351 182 }
Lightvalve 11:82d8768d7351 183
Lightvalve 11:82d8768d7351 184 case CRX_SET_VOLTAGE_SUPPLY: {
Lightvalve 11:82d8768d7351 185 SUPPLY_VOLTAGE = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.;
Lightvalve 11:82d8768d7351 186 spi_eeprom_write(RID_VOLATGE_SUPPLY, (int16_t) (SUPPLY_VOLTAGE * 10.));
Lightvalve 11:82d8768d7351 187
Lightvalve 11:82d8768d7351 188 break;
Lightvalve 11:82d8768d7351 189 }
Lightvalve 11:82d8768d7351 190
Lightvalve 11:82d8768d7351 191 case CRX_ASK_VOLTAGE_VALVE: {
Lightvalve 11:82d8768d7351 192 CAN_TX_VOLTAGE_VALVE();
Lightvalve 11:82d8768d7351 193
Lightvalve 11:82d8768d7351 194 break;
Lightvalve 11:82d8768d7351 195 }
Lightvalve 11:82d8768d7351 196
Lightvalve 11:82d8768d7351 197 case CRX_SET_VOLTAGE_VALVE: {
Lightvalve 11:82d8768d7351 198 VALVE_VOLTAGE_LIMIT = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.;
Lightvalve 11:82d8768d7351 199 spi_eeprom_write(RID_VOLTAGE_VALVE, (int16_t) (VALVE_VOLTAGE_LIMIT * 10.));
Lightvalve 11:82d8768d7351 200
Lightvalve 11:82d8768d7351 201
Lightvalve 11:82d8768d7351 202 break;
Lightvalve 11:82d8768d7351 203 }
Lightvalve 12:6f2531038ea4 204
Lightvalve 11:82d8768d7351 205 case CRX_SET_HOMEPOS: {
Lightvalve 11:82d8768d7351 206 CONTROL_MODE = 22;
Lightvalve 11:82d8768d7351 207 SETTING_SWITCH = (int16_t) (msg.data[1]);
Lightvalve 11:82d8768d7351 208 break;
Lightvalve 11:82d8768d7351 209 }
Lightvalve 11:82d8768d7351 210
Lightvalve 11:82d8768d7351 211 case CRX_ASK_PID_GAIN: {
Lightvalve 11:82d8768d7351 212 CAN_TX_PID_GAIN(msg.data[1]);
Lightvalve 11:82d8768d7351 213
Lightvalve 11:82d8768d7351 214 break;
Lightvalve 11:82d8768d7351 215 }
Lightvalve 11:82d8768d7351 216
Lightvalve 11:82d8768d7351 217 case CRX_SET_PID_GAIN: {
Lightvalve 11:82d8768d7351 218 if (msg.data[1] == 0) {
Lightvalve 11:82d8768d7351 219 P_GAIN_VALVE_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 11:82d8768d7351 220 I_GAIN_VALVE_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 11:82d8768d7351 221 D_GAIN_VALVE_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8);
Lightvalve 11:82d8768d7351 222
Lightvalve 11:82d8768d7351 223 spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION);
Lightvalve 11:82d8768d7351 224 spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION);
Lightvalve 11:82d8768d7351 225 spi_eeprom_write(RID_D_GAIN_VALVE_POSITION, (int16_t) D_GAIN_VALVE_POSITION);
Lightvalve 11:82d8768d7351 226
Lightvalve 11:82d8768d7351 227
Lightvalve 11:82d8768d7351 228 } else if (msg.data[1] == 1) {
Lightvalve 11:82d8768d7351 229 P_GAIN_JOINT_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 11:82d8768d7351 230 I_GAIN_JOINT_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 11:82d8768d7351 231 D_GAIN_JOINT_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8);
Lightvalve 11:82d8768d7351 232
Lightvalve 11:82d8768d7351 233 spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION);
Lightvalve 11:82d8768d7351 234 spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION);
Lightvalve 11:82d8768d7351 235 spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION);
Lightvalve 11:82d8768d7351 236 } else if (msg.data[1] == 2) {
Lightvalve 11:82d8768d7351 237 P_GAIN_JOINT_TORQUE = (int16_t) (msg.data[2] | msg.data[3] << 8);
Lightvalve 11:82d8768d7351 238 I_GAIN_JOINT_TORQUE = (int16_t) (msg.data[4] | msg.data[5] << 8);
Lightvalve 11:82d8768d7351 239 D_GAIN_JOINT_TORQUE = (int16_t) (msg.data[6] | msg.data[7] << 8);
Lightvalve 11:82d8768d7351 240
Lightvalve 11:82d8768d7351 241 spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE);
Lightvalve 11:82d8768d7351 242 spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE);
Lightvalve 11:82d8768d7351 243 spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE);
Lightvalve 11:82d8768d7351 244 }
Lightvalve 11:82d8768d7351 245
Lightvalve 11:82d8768d7351 246 break;
Lightvalve 11:82d8768d7351 247 }
Lightvalve 11:82d8768d7351 248
Lightvalve 11:82d8768d7351 249 case CRX_ASK_VALVE_DEADZONE: {
Lightvalve 11:82d8768d7351 250 CAN_TX_VALVE_DEADZONE();
Lightvalve 11:82d8768d7351 251
Lightvalve 11:82d8768d7351 252 break;
Lightvalve 11:82d8768d7351 253 }
Lightvalve 11:82d8768d7351 254
Lightvalve 11:82d8768d7351 255 case CRX_SET_VALVE_DEADZONE: {
Lightvalve 11:82d8768d7351 256 VALVE_CENTER = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 257 VALVE_DEADZONE_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 258 VALVE_DEADZONE_MINUS = (int16_t) (msg.data[5] | msg.data[6] << 8);
Lightvalve 11:82d8768d7351 259
Lightvalve 11:82d8768d7351 260 spi_eeprom_write(RID_VALVE_CNETER, (int16_t) (VALVE_CENTER));
Lightvalve 11:82d8768d7351 261 spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, (int16_t) (VALVE_DEADZONE_PLUS));
Lightvalve 11:82d8768d7351 262 spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, (int16_t) (VALVE_DEADZONE_MINUS));
Lightvalve 11:82d8768d7351 263
Lightvalve 11:82d8768d7351 264 break;
Lightvalve 11:82d8768d7351 265 }
Lightvalve 11:82d8768d7351 266
Lightvalve 11:82d8768d7351 267 case CRX_ASK_VELOCITY_COMP_GAIN: {
Lightvalve 11:82d8768d7351 268 CAN_TX_VELOCITY_COMP_GAIN();
Lightvalve 11:82d8768d7351 269
Lightvalve 11:82d8768d7351 270 break;
Lightvalve 11:82d8768d7351 271 }
Lightvalve 11:82d8768d7351 272
Lightvalve 11:82d8768d7351 273 case CRX_SET_VELOCITY_COMP_GAIN: {
Lightvalve 11:82d8768d7351 274 VELOCITY_COMP_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 275
Lightvalve 11:82d8768d7351 276 spi_eeprom_write(RID_VELOCITY_COMP_GAIN, (int16_t) VELOCITY_COMP_GAIN);
Lightvalve 11:82d8768d7351 277
Lightvalve 11:82d8768d7351 278 break;
Lightvalve 11:82d8768d7351 279 }
Lightvalve 11:82d8768d7351 280
Lightvalve 11:82d8768d7351 281 case CRX_ASK_COMPLIANCE_GAIN: {
Lightvalve 11:82d8768d7351 282 CAN_TX_COMPLIANCE_GAIN();
Lightvalve 11:82d8768d7351 283
Lightvalve 11:82d8768d7351 284 break;
Lightvalve 11:82d8768d7351 285 }
Lightvalve 11:82d8768d7351 286
Lightvalve 11:82d8768d7351 287 case CRX_SET_COMPLIANCE_GAIN: {
Lightvalve 11:82d8768d7351 288 COMPLIANCE_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 289
Lightvalve 11:82d8768d7351 290 spi_eeprom_write(RID_COMPLIANCE_GAIN, (int16_t) COMPLIANCE_GAIN);
Lightvalve 11:82d8768d7351 291
Lightvalve 11:82d8768d7351 292 break;
Lightvalve 11:82d8768d7351 293 }
Lightvalve 11:82d8768d7351 294
Lightvalve 11:82d8768d7351 295 case CRX_ASK_VALVE_FF: {
Lightvalve 11:82d8768d7351 296 CAN_TX_VALVE_FF();
Lightvalve 11:82d8768d7351 297
Lightvalve 11:82d8768d7351 298 break;
Lightvalve 11:82d8768d7351 299 }
Lightvalve 11:82d8768d7351 300
Lightvalve 11:82d8768d7351 301 case CRX_SET_VALVE_FF: {
Lightvalve 11:82d8768d7351 302 VALVE_FF = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 303
Lightvalve 11:82d8768d7351 304 spi_eeprom_write(RID_VALVE_FF, (int16_t) VALVE_FF);
Lightvalve 11:82d8768d7351 305
Lightvalve 11:82d8768d7351 306 break;
Lightvalve 11:82d8768d7351 307 }
Lightvalve 11:82d8768d7351 308
Lightvalve 11:82d8768d7351 309 case CRX_ASK_BULK_MODULUS: {
Lightvalve 11:82d8768d7351 310 CAN_TX_BULK_MODULUS();
Lightvalve 11:82d8768d7351 311
Lightvalve 11:82d8768d7351 312 break;
Lightvalve 11:82d8768d7351 313 }
Lightvalve 11:82d8768d7351 314
Lightvalve 11:82d8768d7351 315 case CRX_SET_BULK_MODULUS: {
Lightvalve 11:82d8768d7351 316 BULK_MODULUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 317
Lightvalve 11:82d8768d7351 318 spi_eeprom_write(RID_BULK_MODULUS, (int16_t) BULK_MODULUS);
Lightvalve 11:82d8768d7351 319
Lightvalve 11:82d8768d7351 320 break;
Lightvalve 11:82d8768d7351 321 }
Lightvalve 11:82d8768d7351 322
Lightvalve 11:82d8768d7351 323 case CRX_ASK_CHAMBER_VOLUME: {
Lightvalve 11:82d8768d7351 324 CAN_TX_CHAMBER_VOLUME();
Lightvalve 11:82d8768d7351 325
Lightvalve 11:82d8768d7351 326 break;
Lightvalve 11:82d8768d7351 327 }
Lightvalve 11:82d8768d7351 328
Lightvalve 11:82d8768d7351 329 case CRX_SET_CHAMBER_VOLUME: {
Lightvalve 11:82d8768d7351 330 CHAMBER_VOLUME_A = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 331 CHAMBER_VOLUME_B = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 332
Lightvalve 11:82d8768d7351 333 spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A);
Lightvalve 11:82d8768d7351 334 spi_eeprom_write(RID_CHAMBER_VOLUME_B, (int16_t) CHAMBER_VOLUME_B);
Lightvalve 11:82d8768d7351 335
Lightvalve 11:82d8768d7351 336 break;
Lightvalve 11:82d8768d7351 337 }
Lightvalve 11:82d8768d7351 338
Lightvalve 11:82d8768d7351 339 case CRX_ASK_PISTON_AREA: {
Lightvalve 11:82d8768d7351 340 CAN_TX_PISTON_AREA();
Lightvalve 11:82d8768d7351 341
Lightvalve 11:82d8768d7351 342 break;
Lightvalve 11:82d8768d7351 343 }
Lightvalve 11:82d8768d7351 344
Lightvalve 11:82d8768d7351 345 case CRX_SET_PISTON_AREA: {
Lightvalve 11:82d8768d7351 346 PISTON_AREA_A = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 347 PISTON_AREA_B = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 348 PISTON_AREA_alpha = (double)PISTON_AREA_B/(double)PISTON_AREA_A;
Lightvalve 11:82d8768d7351 349
Lightvalve 11:82d8768d7351 350 spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A);
Lightvalve 11:82d8768d7351 351 spi_eeprom_write(RID_PISTON_AREA_B, (int16_t) PISTON_AREA_B);
Lightvalve 11:82d8768d7351 352 break;
Lightvalve 11:82d8768d7351 353 }
Lightvalve 11:82d8768d7351 354
Lightvalve 11:82d8768d7351 355 case CRX_ASK_PRES: {
Lightvalve 11:82d8768d7351 356 CAN_TX_PRES_A_AND_B();
Lightvalve 12:6f2531038ea4 357 // SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0);
Lightvalve 12:6f2531038ea4 358 dac_1 = PRES_A_VREF;
Lightvalve 12:6f2531038ea4 359 dac_2 = PRES_B_VREF;
Lightvalve 12:6f2531038ea4 360
Lightvalve 11:82d8768d7351 361 break;
Lightvalve 11:82d8768d7351 362 }
Lightvalve 11:82d8768d7351 363
Lightvalve 11:82d8768d7351 364 case CRX_SET_PRES: {
Lightvalve 11:82d8768d7351 365 PRES_SUPPLY = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 366 PRES_RETURN = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 367
Lightvalve 11:82d8768d7351 368 spi_eeprom_write(RID_PRES_SUPPLY, (int16_t) PRES_SUPPLY);
Lightvalve 11:82d8768d7351 369 spi_eeprom_write(RID_PRES_RETURN, (int16_t) PRES_RETURN);
Lightvalve 11:82d8768d7351 370
Lightvalve 11:82d8768d7351 371
Lightvalve 11:82d8768d7351 372 break;
Lightvalve 11:82d8768d7351 373 }
Lightvalve 11:82d8768d7351 374
Lightvalve 11:82d8768d7351 375 case CRX_ASK_ENC_LIMIT: {
Lightvalve 11:82d8768d7351 376 CAN_TX_ENC_LIMIT();
Lightvalve 11:82d8768d7351 377
Lightvalve 11:82d8768d7351 378 break;
Lightvalve 11:82d8768d7351 379 }
Lightvalve 11:82d8768d7351 380
Lightvalve 11:82d8768d7351 381 case CRX_SET_ENC_LIMIT: {
Lightvalve 11:82d8768d7351 382 ENC_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 383 ENC_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 384
Lightvalve 11:82d8768d7351 385 spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS);
Lightvalve 11:82d8768d7351 386 spi_eeprom_write(RID_ENC_LIMIT_PLUS, (int16_t) ENC_LIMIT_PLUS);
Lightvalve 11:82d8768d7351 387
Lightvalve 11:82d8768d7351 388 break;
Lightvalve 11:82d8768d7351 389 }
Lightvalve 11:82d8768d7351 390
Lightvalve 11:82d8768d7351 391 case CRX_ASK_STROKE: {
Lightvalve 11:82d8768d7351 392 CAN_TX_STROKE();
Lightvalve 11:82d8768d7351 393 break;
Lightvalve 11:82d8768d7351 394 }
Lightvalve 11:82d8768d7351 395
Lightvalve 11:82d8768d7351 396 case CRX_SET_STROKE: {
Lightvalve 11:82d8768d7351 397 STROKE = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 398
Lightvalve 11:82d8768d7351 399 spi_eeprom_write(RID_STROKE, (int16_t) STROKE);
Lightvalve 11:82d8768d7351 400
Lightvalve 11:82d8768d7351 401 break;
Lightvalve 11:82d8768d7351 402 }
Lightvalve 11:82d8768d7351 403
Lightvalve 11:82d8768d7351 404 case CRX_ASK_VALVE_LIMIT: {
Lightvalve 11:82d8768d7351 405 CAN_TX_VALVE_LIMIT();
Lightvalve 11:82d8768d7351 406
Lightvalve 11:82d8768d7351 407 break;
Lightvalve 11:82d8768d7351 408 }
Lightvalve 11:82d8768d7351 409
Lightvalve 11:82d8768d7351 410 case CRX_SET_VALVE_LIMIT: {
Lightvalve 11:82d8768d7351 411 VALVE_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 412 VALVE_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
Lightvalve 11:82d8768d7351 413
Lightvalve 11:82d8768d7351 414 spi_eeprom_write(RID_VALVE_LIMIT_MINUS, (int16_t) VALVE_LIMIT_MINUS);
Lightvalve 11:82d8768d7351 415 spi_eeprom_write(RID_VALVE_LIMIT_PLUS, (int16_t) VALVE_LIMIT_PLUS);
Lightvalve 11:82d8768d7351 416
Lightvalve 11:82d8768d7351 417 break;
Lightvalve 11:82d8768d7351 418 }
Lightvalve 11:82d8768d7351 419
Lightvalve 11:82d8768d7351 420 case CRX_ASK_ENC_PULSE_PER_POSITION: {
Lightvalve 11:82d8768d7351 421 CAN_TX_ENC_PULSE_PER_POSITION();
Lightvalve 11:82d8768d7351 422
Lightvalve 11:82d8768d7351 423 break;
Lightvalve 11:82d8768d7351 424 }
Lightvalve 11:82d8768d7351 425
Lightvalve 11:82d8768d7351 426 case CRX_SET_ENC_PULSE_PER_POSITION: {
Lightvalve 11:82d8768d7351 427 ENC_PULSE_PER_POSITION = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 428
Lightvalve 11:82d8768d7351 429 spi_eeprom_write(RID_ENC_PULSE_PER_POSITION, (int16_t) ENC_PULSE_PER_POSITION);
Lightvalve 11:82d8768d7351 430
Lightvalve 11:82d8768d7351 431 break;
Lightvalve 11:82d8768d7351 432 }
Lightvalve 11:82d8768d7351 433
Lightvalve 11:82d8768d7351 434 case CRX_ASK_TORQUE_SENSOR_PULSE_PER_TORQUE: {
Lightvalve 11:82d8768d7351 435 CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE();
Lightvalve 11:82d8768d7351 436
Lightvalve 11:82d8768d7351 437 break;
Lightvalve 11:82d8768d7351 438 }
Lightvalve 11:82d8768d7351 439
Lightvalve 11:82d8768d7351 440 case CRX_SET_TORQUE_SENSOR_PULSE_PER_TORQUE: {
Lightvalve 11:82d8768d7351 441 TORQUE_SENSOR_PULSE_PER_TORQUE = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 442
Lightvalve 11:82d8768d7351 443 spi_eeprom_write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE, (int16_t) TORQUE_SENSOR_PULSE_PER_TORQUE);
Lightvalve 11:82d8768d7351 444
Lightvalve 11:82d8768d7351 445 break;
Lightvalve 11:82d8768d7351 446 }
Lightvalve 11:82d8768d7351 447
Lightvalve 11:82d8768d7351 448 case CRX_ASK_PRES_SENSOR_PULSE_PER_PRES: {
Lightvalve 11:82d8768d7351 449 CAN_TX_PRES_SENSOR_PULSE_PER_PRES();
Lightvalve 11:82d8768d7351 450
Lightvalve 11:82d8768d7351 451 break;
Lightvalve 11:82d8768d7351 452 }
Lightvalve 11:82d8768d7351 453
Lightvalve 11:82d8768d7351 454 case CRX_SET_PRES_SENSOR_PULSE_PER_PRES: {
Lightvalve 11:82d8768d7351 455 PRES_SENSOR_A_PULSE_PER_BAR = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) * 0.01;
Lightvalve 11:82d8768d7351 456 PRES_SENSOR_B_PULSE_PER_BAR = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) * 0.01;
Lightvalve 11:82d8768d7351 457
Lightvalve 11:82d8768d7351 458 spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.));
Lightvalve 11:82d8768d7351 459 spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.));
Lightvalve 11:82d8768d7351 460
Lightvalve 11:82d8768d7351 461 break;
Lightvalve 11:82d8768d7351 462 }
Lightvalve 11:82d8768d7351 463
Lightvalve 11:82d8768d7351 464 case CRX_ASK_FRICTION: {
Lightvalve 11:82d8768d7351 465 CAN_TX_FRICTION();
Lightvalve 11:82d8768d7351 466
Lightvalve 11:82d8768d7351 467 break;
Lightvalve 11:82d8768d7351 468 }
Lightvalve 11:82d8768d7351 469
Lightvalve 11:82d8768d7351 470 case CRX_SET_FRICTION: {
Lightvalve 11:82d8768d7351 471 FRICTION = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.;
Lightvalve 11:82d8768d7351 472
Lightvalve 11:82d8768d7351 473 spi_eeprom_write(RID_FRICTION, (int16_t) (FRICTION * 10.));
Lightvalve 11:82d8768d7351 474
Lightvalve 11:82d8768d7351 475 break;
Lightvalve 11:82d8768d7351 476 }
Lightvalve 11:82d8768d7351 477
Lightvalve 11:82d8768d7351 478 case CRX_ASK_VALVE_GAIN_PLUS: {
Lightvalve 11:82d8768d7351 479 CAN_TX_VALVE_GAIN_PLUS();
Lightvalve 11:82d8768d7351 480
Lightvalve 11:82d8768d7351 481 break;
Lightvalve 11:82d8768d7351 482 }
Lightvalve 11:82d8768d7351 483 case CRX_SET_VALVE_GAIN_PLUS: {
Lightvalve 11:82d8768d7351 484 VALVE_GAIN_LPM_PER_V[0] = (double) msg.data[1] / 50.;
Lightvalve 11:82d8768d7351 485 VALVE_GAIN_LPM_PER_V[2] = (double) msg.data[2] / 50.;
Lightvalve 11:82d8768d7351 486 VALVE_GAIN_LPM_PER_V[4] = (double) msg.data[3] / 50.;
Lightvalve 11:82d8768d7351 487 VALVE_GAIN_LPM_PER_V[6] = (double) msg.data[4] / 50.;
Lightvalve 11:82d8768d7351 488 VALVE_GAIN_LPM_PER_V[8] = (double) msg.data[5] / 50.;
Lightvalve 11:82d8768d7351 489
Lightvalve 11:82d8768d7351 490 spi_eeprom_write(RID_VALVE_GAIN_PLUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[0] * 100.));
Lightvalve 11:82d8768d7351 491 spi_eeprom_write(RID_VALVE_GAIN_PLUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[2] * 100.));
Lightvalve 11:82d8768d7351 492 spi_eeprom_write(RID_VALVE_GAIN_PLUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[4] * 100.));
Lightvalve 11:82d8768d7351 493 spi_eeprom_write(RID_VALVE_GAIN_PLUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[6] * 100.));
Lightvalve 11:82d8768d7351 494 spi_eeprom_write(RID_VALVE_GAIN_PLUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[8] * 100.));
Lightvalve 11:82d8768d7351 495
Lightvalve 11:82d8768d7351 496 break;
Lightvalve 11:82d8768d7351 497 }
Lightvalve 11:82d8768d7351 498
Lightvalve 11:82d8768d7351 499 case CRX_ASK_VALVE_GAIN_MINUS: {
Lightvalve 11:82d8768d7351 500 CAN_TX_VALVE_GAIN_MINUS();
Lightvalve 11:82d8768d7351 501
Lightvalve 11:82d8768d7351 502 break;
Lightvalve 11:82d8768d7351 503 }
Lightvalve 11:82d8768d7351 504 case CRX_SET_VALVE_GAIN_MINUS: {
Lightvalve 11:82d8768d7351 505 VALVE_GAIN_LPM_PER_V[1] = (double) msg.data[1] / 50.;
Lightvalve 11:82d8768d7351 506 VALVE_GAIN_LPM_PER_V[3] = (double) msg.data[2] / 50.;
Lightvalve 11:82d8768d7351 507 VALVE_GAIN_LPM_PER_V[5] = (double) msg.data[3] / 50.;
Lightvalve 11:82d8768d7351 508 VALVE_GAIN_LPM_PER_V[7] = (double) msg.data[4] / 50.;
Lightvalve 11:82d8768d7351 509 VALVE_GAIN_LPM_PER_V[9] = (double) msg.data[5] / 50.;
Lightvalve 11:82d8768d7351 510
Lightvalve 11:82d8768d7351 511 spi_eeprom_write(RID_VALVE_GAIN_MINUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[1] * 100.));
Lightvalve 11:82d8768d7351 512 spi_eeprom_write(RID_VALVE_GAIN_MINUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[3] * 100.));
Lightvalve 11:82d8768d7351 513 spi_eeprom_write(RID_VALVE_GAIN_MINUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[5] * 100.));
Lightvalve 11:82d8768d7351 514 spi_eeprom_write(RID_VALVE_GAIN_MINUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[7] * 100.));
Lightvalve 11:82d8768d7351 515 spi_eeprom_write(RID_VALVE_GAIN_MINUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[9] * 100.));
Lightvalve 11:82d8768d7351 516
Lightvalve 11:82d8768d7351 517 break;
Lightvalve 11:82d8768d7351 518 }
Lightvalve 11:82d8768d7351 519 case CRX_ASK_DDV_VALVE_DEADZONE: {
Lightvalve 11:82d8768d7351 520 CAN_TX_DDV_VALVE_DEADZONE();
Lightvalve 11:82d8768d7351 521 break;
Lightvalve 11:82d8768d7351 522 }
Lightvalve 11:82d8768d7351 523
Lightvalve 11:82d8768d7351 524 case CRX_LOW_REF: {
Lightvalve 11:82d8768d7351 525 REFERENCE_MODE = msg.data[1];
Lightvalve 11:82d8768d7351 526
Lightvalve 11:82d8768d7351 527 REF_NUM = msg.data[2];
Lightvalve 11:82d8768d7351 528 REF_PERIOD = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) / 100.;
Lightvalve 11:82d8768d7351 529 if (REF_PERIOD <= 0.) REF_MOVE_TIME_5k = TMR_FREQ_5k / CAN_FREQ;
Lightvalve 11:82d8768d7351 530 else REF_MOVE_TIME_5k = (int) (REF_PERIOD * (double) TMR_FREQ_5k);
Lightvalve 11:82d8768d7351 531 REF_MAG = (double) ((int16_t) (msg.data[5] | msg.data[6] << 8)) / 100.;
Lightvalve 11:82d8768d7351 532
Lightvalve 11:82d8768d7351 533 break;
Lightvalve 11:82d8768d7351 534 }
Lightvalve 11:82d8768d7351 535
Lightvalve 11:82d8768d7351 536 case CRX_JUMP_STATUS: {
Lightvalve 11:82d8768d7351 537 MODE_JUMP_STATUS = msg.data[1];
Lightvalve 11:82d8768d7351 538
Lightvalve 11:82d8768d7351 539 break;
Lightvalve 11:82d8768d7351 540 }
Lightvalve 11:82d8768d7351 541
Lightvalve 11:82d8768d7351 542 case CRX_SET_ERR_CLEAR: {
Lightvalve 11:82d8768d7351 543
Lightvalve 12:6f2531038ea4 544 for (int i = 0; i < num_err; i++) {
Lightvalve 11:82d8768d7351 545 flag_err[i] = FALSE;
Lightvalve 11:82d8768d7351 546 flag_err_old[i] = FALSE;
Lightvalve 11:82d8768d7351 547 }
Lightvalve 11:82d8768d7351 548
Lightvalve 11:82d8768d7351 549 flag_err_rt = FALSE;
Lightvalve 11:82d8768d7351 550
Lightvalve 11:82d8768d7351 551
Lightvalve 11:82d8768d7351 552 break;
Lightvalve 11:82d8768d7351 553 }
Lightvalve 11:82d8768d7351 554
Lightvalve 11:82d8768d7351 555 case CRX_ASK_HOMEPOS_OFFSET: {
Lightvalve 11:82d8768d7351 556 CAN_TX_HOMEPOS_OFFSET();
Lightvalve 11:82d8768d7351 557 break;
Lightvalve 11:82d8768d7351 558 }
Lightvalve 11:82d8768d7351 559 case CRX_SET_HOMEPOS_OFFSET: {
Lightvalve 11:82d8768d7351 560 HOMEPOS_OFFSET = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 561
Lightvalve 11:82d8768d7351 562 spi_eeprom_write(RID_HOMEPOS_OFFSET, (int16_t) HOMEPOS_OFFSET);
Lightvalve 11:82d8768d7351 563 break;
Lightvalve 11:82d8768d7351 564 }
Lightvalve 11:82d8768d7351 565
Lightvalve 11:82d8768d7351 566 case CRX_ASK_HOMEPOS_VALVE_OPENING: {
Lightvalve 11:82d8768d7351 567 CAN_TX_HOMPOS_VALVE_OPENING();
Lightvalve 11:82d8768d7351 568 break;
Lightvalve 11:82d8768d7351 569 }
Lightvalve 11:82d8768d7351 570 case CRX_SET_HOMEPOS_VALVE_OPENING: {
Lightvalve 11:82d8768d7351 571 HOMEPOS_VALVE_OPENING = (int16_t) (msg.data[1] | msg.data[2] << 8);
Lightvalve 11:82d8768d7351 572
Lightvalve 11:82d8768d7351 573 spi_eeprom_write(RID_HOMEPOS_VALVE_OPENING, (int16_t) HOMEPOS_VALVE_OPENING);
Lightvalve 11:82d8768d7351 574 break;
Lightvalve 11:82d8768d7351 575 }
Lightvalve 11:82d8768d7351 576
Lightvalve 11:82d8768d7351 577 case CRX_ASK_VALVE_PWM_VS_VALVE_POS: {
Lightvalve 11:82d8768d7351 578 can_index = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 579 CAN_TX_VALVE_PWM_VS_VALVE_POS(can_index);
Lightvalve 11:82d8768d7351 580 break;
Lightvalve 11:82d8768d7351 581 }
Lightvalve 11:82d8768d7351 582 case CRX_ASK_VALVE_POS_VS_FLOWRATE: {
Lightvalve 11:82d8768d7351 583 can_index = (int16_t) msg.data[1];
Lightvalve 11:82d8768d7351 584 CAN_TX_VALVE_POS_VS_FLOWRATE(can_index);
Lightvalve 11:82d8768d7351 585 break;
Lightvalve 11:82d8768d7351 586 }
Lightvalve 11:82d8768d7351 587 case CRX_ASK_VALVE_POS_NUM: {
Lightvalve 11:82d8768d7351 588 CAN_TX_VALVE_POS_NUM();
Lightvalve 11:82d8768d7351 589 break;
Lightvalve 11:82d8768d7351 590 }
jobuuu 2:a1c0a37df760 591 default:
jobuuu 2:a1c0a37df760 592 break;
jobuuu 2:a1c0a37df760 593 }
jobuuu 2:a1c0a37df760 594 }
jobuuu 2:a1c0a37df760 595
jobuuu 2:a1c0a37df760 596 void CAN_RX_HANDLER()
jobuuu 2:a1c0a37df760 597 {
jobuuu 2:a1c0a37df760 598 can.read(msg);
jobuuu 2:a1c0a37df760 599 unsigned int address = msg.id;
jobuuu 2:a1c0a37df760 600
jobuuu 7:e9086c72bb22 601 if(address==CID_RX_CMD){
jobuuu 2:a1c0a37df760 602 unsigned int CMD = msg.data[0];
jobuuu 2:a1c0a37df760 603 ReadCMD(CMD);
jobuuu 7:e9086c72bb22 604 } else if(address==CID_RX_REF_POSITION) {
jobuuu 7:e9086c72bb22 605 int32_t temp_pos = (int32_t) (msg.data[0] | msg.data[1] << 8 | msg.data[2] << 16 | msg.data[3] << 24);
jobuuu 7:e9086c72bb22 606 int32_t temp_vel = (int32_t) (msg.data[4] | msg.data[5] << 8 | msg.data[6] << 16 | msg.data[7] << 24);
jobuuu 7:e9086c72bb22 607 pos.ref = (double)temp_pos;
jobuuu 7:e9086c72bb22 608 vel.ref = (double)temp_vel;
jobuuu 7:e9086c72bb22 609 } else if(address==CID_RX_REF_TORQUE) {
jobuuu 7:e9086c72bb22 610 int16_t temp_torq = (int16_t) (msg.data[0] | msg.data[1] << 8);
jobuuu 7:e9086c72bb22 611 torq.ref = (double)temp_torq;
jobuuu 7:e9086c72bb22 612 } else if(address==CID_RX_REF_PRES_DIFF) {
Lightvalve 11:82d8768d7351 613 int16_t temp_presdiff = (int16_t) (msg.data[0] | msg.data[1] << 8);
Lightvalve 11:82d8768d7351 614 torq.ref = (double)temp_presdiff;
jobuuu 7:e9086c72bb22 615 } else if(address==CID_RX_REF_VOUT) {
jobuuu 7:e9086c72bb22 616 int16_t temp_PWM = (int16_t) (msg.data[0] | msg.data[1] << 8);
jobuuu 7:e9086c72bb22 617 Vout.ref = (double)temp_PWM;
jobuuu 7:e9086c72bb22 618 } else if(address==CID_RX_REF_VALVE_POSITION) {
jobuuu 7:e9086c72bb22 619 int16_t temp_cur = (int16_t) (msg.data[0] | msg.data[1] << 8);
jobuuu 7:e9086c72bb22 620 cur.ref = (double)temp_cur;
jobuuu 2:a1c0a37df760 621 }
jobuuu 7:e9086c72bb22 622
jobuuu 2:a1c0a37df760 623 }
jobuuu 2:a1c0a37df760 624
jobuuu 2:a1c0a37df760 625 /******************************************************************************
jobuuu 2:a1c0a37df760 626 Information Transmission Functions
jobuuu 2:a1c0a37df760 627 *******************************************************************************/
Lightvalve 11:82d8768d7351 628
Lightvalve 11:82d8768d7351 629 void CAN_TX_INFO(void) {
Lightvalve 12:6f2531038ea4 630 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 631
jobuuu 2:a1c0a37df760 632 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 633 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 634 temp_msg.data[0] = (uint8_t) CTX_SEND_INFO;
Lightvalve 12:6f2531038ea4 635 temp_msg.data[1] = (uint8_t) BNO;
Lightvalve 12:6f2531038ea4 636 temp_msg.data[2] = (uint8_t) CAN_FREQ;
Lightvalve 12:6f2531038ea4 637 temp_msg.data[3] = (uint8_t) (CAN_FREQ >> 8);
Lightvalve 12:6f2531038ea4 638 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 639 temp_msg.data[5] = (uint8_t) CONTROL_MODE;
Lightvalve 12:6f2531038ea4 640 temp_msg.data[6] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 641
jobuuu 2:a1c0a37df760 642 can.write(temp_msg);
jobuuu 2:a1c0a37df760 643 }
jobuuu 2:a1c0a37df760 644
Lightvalve 11:82d8768d7351 645 void CAN_TX_BNO(void) {
Lightvalve 12:6f2531038ea4 646 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 647
jobuuu 2:a1c0a37df760 648 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 649 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 650 temp_msg.data[0] = (uint8_t) CTX_SEND_BNO;
Lightvalve 12:6f2531038ea4 651 temp_msg.data[1] = (uint8_t) BNO;
jobuuu 2:a1c0a37df760 652
jobuuu 2:a1c0a37df760 653 can.write(temp_msg);
jobuuu 2:a1c0a37df760 654 }
jobuuu 2:a1c0a37df760 655
Lightvalve 11:82d8768d7351 656 void CAN_TX_OPERATING_MODE(void) {
jobuuu 2:a1c0a37df760 657 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 658
jobuuu 2:a1c0a37df760 659 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 660 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 661 temp_msg.data[0] = (uint8_t) CTX_SEND_OPERATING_MODE;
Lightvalve 12:6f2531038ea4 662 temp_msg.data[1] = (uint8_t) OPERATING_MODE;
jobuuu 2:a1c0a37df760 663
jobuuu 2:a1c0a37df760 664 can.write(temp_msg);
jobuuu 2:a1c0a37df760 665 }
jobuuu 2:a1c0a37df760 666
Lightvalve 11:82d8768d7351 667 void CAN_TX_CAN_FREQ(void) {
jobuuu 2:a1c0a37df760 668 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 669
jobuuu 2:a1c0a37df760 670 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 671 temp_msg.len = 3;
jobuuu 2:a1c0a37df760 672 temp_msg.data[0] = (uint8_t) CTX_SEND_CAN_FREQ;
jobuuu 2:a1c0a37df760 673 temp_msg.data[1] = (uint8_t) CAN_FREQ;
jobuuu 2:a1c0a37df760 674 temp_msg.data[2] = (uint8_t) (CAN_FREQ >> 8);
jobuuu 2:a1c0a37df760 675
jobuuu 2:a1c0a37df760 676 can.write(temp_msg);
jobuuu 2:a1c0a37df760 677 }
Lightvalve 11:82d8768d7351 678
Lightvalve 11:82d8768d7351 679 void CAN_TX_CONTROL_MODE(void) {
jobuuu 2:a1c0a37df760 680 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 681
jobuuu 2:a1c0a37df760 682 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 683 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 684 temp_msg.data[0] = (uint8_t) CTX_SEND_CONTROL_MODE;
Lightvalve 12:6f2531038ea4 685 temp_msg.data[1] = (uint8_t) CONTROL_MODE;
jobuuu 2:a1c0a37df760 686
jobuuu 2:a1c0a37df760 687 can.write(temp_msg);
jobuuu 2:a1c0a37df760 688 }
Lightvalve 11:82d8768d7351 689
Lightvalve 11:82d8768d7351 690 void CAN_TX_JOINT_ENC_DIR(void) {
jobuuu 2:a1c0a37df760 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 = 3;
Lightvalve 12:6f2531038ea4 695 temp_msg.data[0] = (uint8_t) CTX_SEND_JOINT_ENC_DIR;
Lightvalve 12:6f2531038ea4 696 temp_msg.data[1] = (uint8_t) DIR_JOINT_ENC;
Lightvalve 12:6f2531038ea4 697 temp_msg.data[2] = (uint8_t) (DIR_JOINT_ENC >> 8);
jobuuu 2:a1c0a37df760 698
jobuuu 2:a1c0a37df760 699 can.write(temp_msg);
jobuuu 2:a1c0a37df760 700 }
jobuuu 2:a1c0a37df760 701
Lightvalve 11:82d8768d7351 702 void CAN_TX_VALVE_DIR(void) {
jobuuu 2:a1c0a37df760 703 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 704
jobuuu 2:a1c0a37df760 705 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 706 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 707 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DIR;
Lightvalve 12:6f2531038ea4 708 temp_msg.data[1] = (uint8_t) DIR_VALVE;
Lightvalve 12:6f2531038ea4 709 temp_msg.data[2] = (uint8_t) (DIR_VALVE >> 8);
jobuuu 2:a1c0a37df760 710
jobuuu 2:a1c0a37df760 711 can.write(temp_msg);
jobuuu 2:a1c0a37df760 712 }
jobuuu 2:a1c0a37df760 713
Lightvalve 11:82d8768d7351 714 void CAN_TX_VALVE_ENC_DIR(void) {
jobuuu 2:a1c0a37df760 715 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 716
jobuuu 2:a1c0a37df760 717 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 718 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 719 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_ENC_DIR;
Lightvalve 12:6f2531038ea4 720 temp_msg.data[1] = (uint8_t) DIR_VALVE_ENC;
Lightvalve 12:6f2531038ea4 721 temp_msg.data[2] = (uint8_t) (DIR_VALVE_ENC >> 8);
jobuuu 2:a1c0a37df760 722
jobuuu 2:a1c0a37df760 723 can.write(temp_msg);
jobuuu 2:a1c0a37df760 724 }
jobuuu 2:a1c0a37df760 725
Lightvalve 11:82d8768d7351 726 void CAN_TX_VOLTAGE_SUPPLY(void) {
Lightvalve 12:6f2531038ea4 727 int16_t send_voltage_supply = (int16_t) (SUPPLY_VOLTAGE * 10);
jobuuu 2:a1c0a37df760 728
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;
Lightvalve 12:6f2531038ea4 733 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_SUPPLY;
Lightvalve 12:6f2531038ea4 734 temp_msg.data[1] = (uint8_t) (send_voltage_supply);
Lightvalve 12:6f2531038ea4 735 temp_msg.data[2] = (uint8_t) (send_voltage_supply >> 8);
jobuuu 2:a1c0a37df760 736
jobuuu 2:a1c0a37df760 737 can.write(temp_msg);
jobuuu 2:a1c0a37df760 738 }
jobuuu 2:a1c0a37df760 739
Lightvalve 11:82d8768d7351 740 void CAN_TX_VOLTAGE_VALVE(void) {
Lightvalve 12:6f2531038ea4 741 int16_t send_voltage_valve = (int16_t) (VALVE_VOLTAGE_LIMIT * 10);
jobuuu 2:a1c0a37df760 742
jobuuu 2:a1c0a37df760 743 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 744
jobuuu 2:a1c0a37df760 745 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 746 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 747 temp_msg.data[0] = (uint8_t) CTX_SEND_VOLTAGE_VALVE;
Lightvalve 12:6f2531038ea4 748 temp_msg.data[1] = (uint8_t) send_voltage_valve;
Lightvalve 12:6f2531038ea4 749 temp_msg.data[2] = (uint8_t) (send_voltage_valve >> 8);
jobuuu 2:a1c0a37df760 750
jobuuu 2:a1c0a37df760 751 can.write(temp_msg);
jobuuu 2:a1c0a37df760 752 }
Lightvalve 11:82d8768d7351 753
jobuuu 2:a1c0a37df760 754
Lightvalve 11:82d8768d7351 755 void CAN_TX_PID_GAIN(int t_type) {
jobuuu 2:a1c0a37df760 756 // t_type = 0 : valve position control gain
jobuuu 2:a1c0a37df760 757 // t_type = 1 : joint position control gain
jobuuu 2:a1c0a37df760 758 // t_type = 2 : joint torque control gain
jobuuu 2:a1c0a37df760 759
Lightvalve 12:6f2531038ea4 760 int16_t sendPgain=0, sendIgain=0, sendDgain=0;
jobuuu 2:a1c0a37df760 761 if (t_type == 0) {
Lightvalve 12:6f2531038ea4 762 // sendPgain = (int16_t) (P_GAIN_VALVE_POSITION);
Lightvalve 12:6f2531038ea4 763 // sendIgain = (int16_t) (I_GAIN_VALVE_POSITION);
Lightvalve 12:6f2531038ea4 764 // sendDgain = (int16_t) (D_GAIN_VALVE_POSITION);
jobuuu 2:a1c0a37df760 765 } else if (t_type == 1) {
Lightvalve 12:6f2531038ea4 766 sendPgain = (int16_t) (P_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 767 sendIgain = (int16_t) (I_GAIN_JOINT_POSITION);
Lightvalve 12:6f2531038ea4 768 sendDgain = (int16_t) (D_GAIN_JOINT_POSITION);
jobuuu 2:a1c0a37df760 769 } else if (t_type == 2) {
Lightvalve 12:6f2531038ea4 770 sendPgain = (int16_t) (P_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 771 sendIgain = (int16_t) (I_GAIN_JOINT_TORQUE);
Lightvalve 12:6f2531038ea4 772 sendDgain = (int16_t) (D_GAIN_JOINT_TORQUE);
jobuuu 2:a1c0a37df760 773 }
jobuuu 2:a1c0a37df760 774
jobuuu 2:a1c0a37df760 775 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 776
jobuuu 2:a1c0a37df760 777 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 778 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 779 temp_msg.data[0] = (uint8_t) CTX_SEND_PID_GAIN;
Lightvalve 12:6f2531038ea4 780 temp_msg.data[1] = (uint8_t) t_type;
Lightvalve 12:6f2531038ea4 781 temp_msg.data[2] = (uint8_t) sendPgain;
Lightvalve 12:6f2531038ea4 782 temp_msg.data[3] = (uint8_t) (sendPgain >> 8);
Lightvalve 12:6f2531038ea4 783 temp_msg.data[4] = (uint8_t) sendIgain;
Lightvalve 12:6f2531038ea4 784 temp_msg.data[5] = (uint8_t) (sendIgain >> 8);
Lightvalve 12:6f2531038ea4 785 temp_msg.data[6] = (uint8_t) sendDgain;
Lightvalve 12:6f2531038ea4 786 temp_msg.data[7] = (uint8_t) (sendDgain >> 8);
jobuuu 2:a1c0a37df760 787
jobuuu 2:a1c0a37df760 788 can.write(temp_msg);
jobuuu 2:a1c0a37df760 789 }
jobuuu 2:a1c0a37df760 790
Lightvalve 11:82d8768d7351 791
Lightvalve 11:82d8768d7351 792 void CAN_TX_VALVE_DEADZONE(void) {
jobuuu 2:a1c0a37df760 793 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 794
jobuuu 2:a1c0a37df760 795 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 796 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 797 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_DEADZONE;
Lightvalve 12:6f2531038ea4 798 temp_msg.data[1] = (uint8_t) (int) (VALVE_CENTER);
Lightvalve 12:6f2531038ea4 799 temp_msg.data[2] = (uint8_t) ((int) (VALVE_CENTER) >> 8);
Lightvalve 12:6f2531038ea4 800 temp_msg.data[3] = (uint8_t) (int) (VALVE_DEADZONE_PLUS);
Lightvalve 12:6f2531038ea4 801 temp_msg.data[4] = (uint8_t) ((int) (VALVE_DEADZONE_PLUS) >> 8);
Lightvalve 12:6f2531038ea4 802 temp_msg.data[5] = (uint8_t) (int) (VALVE_DEADZONE_MINUS);
Lightvalve 12:6f2531038ea4 803 temp_msg.data[6] = (uint8_t) ((int) (VALVE_DEADZONE_MINUS) >> 8);
jobuuu 2:a1c0a37df760 804
jobuuu 2:a1c0a37df760 805 can.write(temp_msg);
jobuuu 2:a1c0a37df760 806 }
jobuuu 2:a1c0a37df760 807
Lightvalve 11:82d8768d7351 808 void CAN_TX_VELOCITY_COMP_GAIN(void) {
Lightvalve 11:82d8768d7351 809 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 810
Lightvalve 11:82d8768d7351 811 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 812 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 813 temp_msg.data[0] = (uint8_t) CTX_SEND_VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 814 temp_msg.data[1] = (uint8_t) VELOCITY_COMP_GAIN;
Lightvalve 12:6f2531038ea4 815 temp_msg.data[2] = (uint8_t) (VELOCITY_COMP_GAIN >> 8);
Lightvalve 11:82d8768d7351 816
Lightvalve 11:82d8768d7351 817 can.write(temp_msg);
Lightvalve 11:82d8768d7351 818 }
Lightvalve 11:82d8768d7351 819
Lightvalve 11:82d8768d7351 820 void CAN_TX_COMPLIANCE_GAIN(void) {
Lightvalve 11:82d8768d7351 821 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 822
Lightvalve 11:82d8768d7351 823 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 824 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 825 temp_msg.data[0] = (uint8_t) CTX_SEND_COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 826 temp_msg.data[1] = (uint8_t) COMPLIANCE_GAIN;
Lightvalve 12:6f2531038ea4 827 temp_msg.data[2] = (uint8_t) (COMPLIANCE_GAIN >> 8);
Lightvalve 11:82d8768d7351 828
Lightvalve 11:82d8768d7351 829 can.write(temp_msg);
Lightvalve 11:82d8768d7351 830 }
Lightvalve 11:82d8768d7351 831
Lightvalve 11:82d8768d7351 832 void CAN_TX_VALVE_FF(void) {
Lightvalve 11:82d8768d7351 833 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 834
Lightvalve 11:82d8768d7351 835 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 836 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 837 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_FF;
Lightvalve 12:6f2531038ea4 838 temp_msg.data[1] = (uint8_t) VALVE_FF;
Lightvalve 12:6f2531038ea4 839 temp_msg.data[2] = (uint8_t) (VALVE_FF >> 8);
Lightvalve 11:82d8768d7351 840
Lightvalve 11:82d8768d7351 841 can.write(temp_msg);
Lightvalve 11:82d8768d7351 842 }
Lightvalve 11:82d8768d7351 843
Lightvalve 11:82d8768d7351 844 void CAN_TX_BULK_MODULUS(void) {
Lightvalve 11:82d8768d7351 845 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 846
Lightvalve 11:82d8768d7351 847 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 848 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 849 temp_msg.data[0] = (uint8_t) CTX_SEND_BULK_MODULUS;
Lightvalve 12:6f2531038ea4 850 temp_msg.data[1] = (uint8_t) BULK_MODULUS;
Lightvalve 12:6f2531038ea4 851 temp_msg.data[2] = (uint8_t) (BULK_MODULUS >> 8);
Lightvalve 11:82d8768d7351 852
Lightvalve 11:82d8768d7351 853 can.write(temp_msg);
Lightvalve 11:82d8768d7351 854 }
Lightvalve 11:82d8768d7351 855
Lightvalve 11:82d8768d7351 856 void CAN_TX_CHAMBER_VOLUME(void) {
Lightvalve 11:82d8768d7351 857 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 858
Lightvalve 11:82d8768d7351 859 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 860 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 861 temp_msg.data[0] = (uint8_t) CTX_SEND_CHAMBER_VOLUME;
Lightvalve 12:6f2531038ea4 862 temp_msg.data[1] = (uint8_t) CHAMBER_VOLUME_A;
Lightvalve 12:6f2531038ea4 863 temp_msg.data[2] = (uint8_t) (CHAMBER_VOLUME_A >> 8);
Lightvalve 12:6f2531038ea4 864 temp_msg.data[3] = (uint8_t) CHAMBER_VOLUME_B;
Lightvalve 12:6f2531038ea4 865 temp_msg.data[4] = (uint8_t) (CHAMBER_VOLUME_B >> 8);
Lightvalve 11:82d8768d7351 866
Lightvalve 11:82d8768d7351 867 can.write(temp_msg);
Lightvalve 11:82d8768d7351 868 }
Lightvalve 11:82d8768d7351 869
Lightvalve 11:82d8768d7351 870 void CAN_TX_PISTON_AREA(void) {
jobuuu 2:a1c0a37df760 871 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 872
Lightvalve 11:82d8768d7351 873 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 874 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 875 temp_msg.data[0] = (uint8_t) CTX_SEND_PISTON_AREA;
Lightvalve 12:6f2531038ea4 876 temp_msg.data[1] = (uint8_t) PISTON_AREA_A;
Lightvalve 12:6f2531038ea4 877 temp_msg.data[2] = (uint8_t) (PISTON_AREA_A >> 8);
Lightvalve 12:6f2531038ea4 878 temp_msg.data[3] = (uint8_t) PISTON_AREA_B;
Lightvalve 12:6f2531038ea4 879 temp_msg.data[4] = (uint8_t) (PISTON_AREA_B >> 8);
jobuuu 2:a1c0a37df760 880
Lightvalve 11:82d8768d7351 881 can.write(temp_msg);
Lightvalve 11:82d8768d7351 882 }
Lightvalve 11:82d8768d7351 883
Lightvalve 11:82d8768d7351 884 void CAN_TX_PRES_A_AND_B(void) {
Lightvalve 11:82d8768d7351 885 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 886
Lightvalve 11:82d8768d7351 887 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 888 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 889 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES;
Lightvalve 12:6f2531038ea4 890 temp_msg.data[1] = (uint8_t) PRES_SUPPLY;
Lightvalve 12:6f2531038ea4 891 temp_msg.data[2] = (uint8_t) (PRES_SUPPLY >> 8);
Lightvalve 12:6f2531038ea4 892 temp_msg.data[3] = (uint8_t) PRES_RETURN;
Lightvalve 12:6f2531038ea4 893 temp_msg.data[4] = (uint8_t) (PRES_RETURN >> 8);
Lightvalve 11:82d8768d7351 894
Lightvalve 11:82d8768d7351 895 can.write(temp_msg);
Lightvalve 11:82d8768d7351 896 }
Lightvalve 11:82d8768d7351 897
Lightvalve 11:82d8768d7351 898 void CAN_TX_ENC_LIMIT(void) {
Lightvalve 11:82d8768d7351 899 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 900
Lightvalve 11:82d8768d7351 901 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 902 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 903 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_LIMIT;
Lightvalve 12:6f2531038ea4 904 temp_msg.data[1] = (uint8_t) ENC_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 905 temp_msg.data[2] = (uint8_t) (ENC_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 906 temp_msg.data[3] = (uint8_t) ENC_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 907 temp_msg.data[4] = (uint8_t) (ENC_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 908
Lightvalve 11:82d8768d7351 909 can.write(temp_msg);
Lightvalve 11:82d8768d7351 910 }
Lightvalve 11:82d8768d7351 911
Lightvalve 11:82d8768d7351 912 void CAN_TX_STROKE(void) {
Lightvalve 11:82d8768d7351 913 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 914
Lightvalve 11:82d8768d7351 915 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 916 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 917 temp_msg.data[0] = (uint8_t) CTX_SEND_STROKE;
Lightvalve 12:6f2531038ea4 918 temp_msg.data[1] = (uint8_t) STROKE;
Lightvalve 12:6f2531038ea4 919 temp_msg.data[2] = (uint8_t) (STROKE >> 8);
Lightvalve 11:82d8768d7351 920
Lightvalve 11:82d8768d7351 921 can.write(temp_msg);
Lightvalve 11:82d8768d7351 922 }
Lightvalve 11:82d8768d7351 923
Lightvalve 11:82d8768d7351 924 void CAN_TX_VALVE_LIMIT(void) {
Lightvalve 11:82d8768d7351 925 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 926
Lightvalve 11:82d8768d7351 927 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 928 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 929 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_LIMIT;
Lightvalve 12:6f2531038ea4 930 temp_msg.data[1] = (uint8_t) VALVE_LIMIT_MINUS;
Lightvalve 12:6f2531038ea4 931 temp_msg.data[2] = (uint8_t) (VALVE_LIMIT_MINUS >> 8);
Lightvalve 12:6f2531038ea4 932 temp_msg.data[3] = (uint8_t) VALVE_LIMIT_PLUS;
Lightvalve 12:6f2531038ea4 933 temp_msg.data[4] = (uint8_t) (VALVE_LIMIT_PLUS >> 8);
Lightvalve 11:82d8768d7351 934
Lightvalve 11:82d8768d7351 935 can.write(temp_msg);
Lightvalve 11:82d8768d7351 936 }
Lightvalve 11:82d8768d7351 937
Lightvalve 11:82d8768d7351 938 void CAN_TX_ENC_PULSE_PER_POSITION(void) {
Lightvalve 11:82d8768d7351 939 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 940
jobuuu 2:a1c0a37df760 941 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 942 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 943 temp_msg.data[0] = (uint8_t) CTX_SEND_ENC_PULSE_PER_POSITION;
Lightvalve 12:6f2531038ea4 944 temp_msg.data[1] = (uint8_t) ENC_PULSE_PER_POSITION;
Lightvalve 12:6f2531038ea4 945 temp_msg.data[2] = (uint8_t) (ENC_PULSE_PER_POSITION >> 8);
jobuuu 2:a1c0a37df760 946
jobuuu 2:a1c0a37df760 947 can.write(temp_msg);
jobuuu 2:a1c0a37df760 948 }
jobuuu 2:a1c0a37df760 949
Lightvalve 11:82d8768d7351 950 void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void) {
jobuuu 2:a1c0a37df760 951 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 952
jobuuu 2:a1c0a37df760 953 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 954 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 955 temp_msg.data[0] = (uint8_t) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 12:6f2531038ea4 956 temp_msg.data[1] = (uint8_t) TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 12:6f2531038ea4 957 temp_msg.data[2] = (uint8_t) (TORQUE_SENSOR_PULSE_PER_TORQUE >> 8);
jobuuu 2:a1c0a37df760 958
jobuuu 2:a1c0a37df760 959 can.write(temp_msg);
jobuuu 2:a1c0a37df760 960 }
jobuuu 2:a1c0a37df760 961
Lightvalve 11:82d8768d7351 962 void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void) {
jobuuu 2:a1c0a37df760 963 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 964
jobuuu 2:a1c0a37df760 965 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 966 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 967 temp_msg.data[0] = (uint8_t) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR;
Lightvalve 12:6f2531038ea4 968 temp_msg.data[1] = (uint8_t) (int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.);
Lightvalve 12:6f2531038ea4 969 temp_msg.data[2] = (uint8_t) ((int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.) >> 8);
Lightvalve 12:6f2531038ea4 970 temp_msg.data[3] = (uint8_t) (int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.);
Lightvalve 12:6f2531038ea4 971 temp_msg.data[4] = (uint8_t) ((int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.) >> 8);
jobuuu 2:a1c0a37df760 972
jobuuu 2:a1c0a37df760 973 can.write(temp_msg);
jobuuu 2:a1c0a37df760 974 }
jobuuu 2:a1c0a37df760 975
Lightvalve 11:82d8768d7351 976 void CAN_TX_FRICTION(void) {
Lightvalve 11:82d8768d7351 977 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 978 int16_t send_friction;
Lightvalve 12:6f2531038ea4 979 send_friction = (int16_t) (FRICTION * 10.);
Lightvalve 11:82d8768d7351 980
Lightvalve 11:82d8768d7351 981 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 982 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 983 temp_msg.data[0] = (uint8_t) CTX_SEND_FRICTION;
Lightvalve 12:6f2531038ea4 984 temp_msg.data[1] = (uint8_t) send_friction;
Lightvalve 12:6f2531038ea4 985 temp_msg.data[2] = (uint8_t) (send_friction >> 8);
Lightvalve 11:82d8768d7351 986
Lightvalve 11:82d8768d7351 987 can.write(temp_msg);
Lightvalve 11:82d8768d7351 988 }
Lightvalve 11:82d8768d7351 989
Lightvalve 11:82d8768d7351 990 void CAN_TX_VALVE_GAIN_PLUS(void) {
Lightvalve 11:82d8768d7351 991 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 992
Lightvalve 11:82d8768d7351 993 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 994 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 995 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_PLUS;
Lightvalve 12:6f2531038ea4 996 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[0] * 50.);
Lightvalve 12:6f2531038ea4 997 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[2] * 50.);
Lightvalve 12:6f2531038ea4 998 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[4] * 50.);
Lightvalve 12:6f2531038ea4 999 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[6] * 50.);
Lightvalve 12:6f2531038ea4 1000 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[8] * 50.);
Lightvalve 11:82d8768d7351 1001
Lightvalve 11:82d8768d7351 1002 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1003 }
Lightvalve 11:82d8768d7351 1004
Lightvalve 11:82d8768d7351 1005 void CAN_TX_DDV_VALVE_DEADZONE(void) {
Lightvalve 11:82d8768d7351 1006 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1007
Lightvalve 11:82d8768d7351 1008 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1009 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1010 temp_msg.data[0] = (uint8_t) CTX_SEND_DDV_VALVE_DEADZONE;
Lightvalve 12:6f2531038ea4 1011 temp_msg.data[1] = (uint8_t) VALVE_DEADZONE_MINUS;
Lightvalve 12:6f2531038ea4 1012 temp_msg.data[2] = (uint8_t) ((int) (VALVE_DEADZONE_MINUS) >> 8);
Lightvalve 12:6f2531038ea4 1013 temp_msg.data[3] = (uint8_t) (VALVE_DEADZONE_PLUS);
Lightvalve 12:6f2531038ea4 1014 temp_msg.data[4] = (uint8_t) ((int) (VALVE_DEADZONE_PLUS) >> 8);
Lightvalve 12:6f2531038ea4 1015 temp_msg.data[5] = (uint8_t) (DDV_CENTER);
Lightvalve 12:6f2531038ea4 1016 temp_msg.data[6] = (uint8_t) ((int) (DDV_CENTER) >> 8);
Lightvalve 11:82d8768d7351 1017
Lightvalve 11:82d8768d7351 1018 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1019 }
Lightvalve 11:82d8768d7351 1020
Lightvalve 11:82d8768d7351 1021 void CAN_TX_VALVE_GAIN_MINUS(void) {
Lightvalve 11:82d8768d7351 1022 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1023
Lightvalve 11:82d8768d7351 1024 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1025 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1026 temp_msg.data[0] = (uint8_t) CTX_SEND_VALVE_GAIN_MINUS;
Lightvalve 12:6f2531038ea4 1027 temp_msg.data[1] = (uint8_t) (VALVE_GAIN_LPM_PER_V[1] * 50.);
Lightvalve 12:6f2531038ea4 1028 temp_msg.data[2] = (uint8_t) (VALVE_GAIN_LPM_PER_V[3] * 50.);
Lightvalve 12:6f2531038ea4 1029 temp_msg.data[3] = (uint8_t) (VALVE_GAIN_LPM_PER_V[5] * 50.);
Lightvalve 12:6f2531038ea4 1030 temp_msg.data[4] = (uint8_t) (VALVE_GAIN_LPM_PER_V[7] * 50.);
Lightvalve 12:6f2531038ea4 1031 temp_msg.data[5] = (uint8_t) (VALVE_GAIN_LPM_PER_V[9] * 50.);
Lightvalve 11:82d8768d7351 1032
Lightvalve 11:82d8768d7351 1033 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1034 }
Lightvalve 11:82d8768d7351 1035
Lightvalve 11:82d8768d7351 1036 void CAN_TX_REFENCE_MODE(void) {
Lightvalve 11:82d8768d7351 1037 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1038
Lightvalve 11:82d8768d7351 1039 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1040 temp_msg.len = 6;
Lightvalve 12:6f2531038ea4 1041 temp_msg.data[0] = (uint8_t) CTX_SEND_REFENCE_MODE;
Lightvalve 12:6f2531038ea4 1042 temp_msg.data[1] = (uint8_t) REFERENCE_MODE;
Lightvalve 12:6f2531038ea4 1043 temp_msg.data[2] = (uint8_t) (int) (REFERENCE_FREQ * 100.);
Lightvalve 12:6f2531038ea4 1044 temp_msg.data[3] = (uint8_t) ((int) (REFERENCE_FREQ * 100.) >> 8);
Lightvalve 12:6f2531038ea4 1045 temp_msg.data[4] = (uint8_t) (int) (REFERENCE_MAG * 100.);
Lightvalve 12:6f2531038ea4 1046 temp_msg.data[5] = (uint8_t) ((int) (REFERENCE_MAG * 100.) >> 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_HOMEPOS_OFFSET(void) {
Lightvalve 11:82d8768d7351 1052 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1053 int16_t send_homepos_offset;
Lightvalve 12:6f2531038ea4 1054 send_homepos_offset = (int16_t) (HOMEPOS_OFFSET);
Lightvalve 11:82d8768d7351 1055
jobuuu 2:a1c0a37df760 1056 temp_msg.id = CID_TX_INFO;
jobuuu 2:a1c0a37df760 1057 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1058 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_OFFSET;
Lightvalve 12:6f2531038ea4 1059 temp_msg.data[1] = (uint8_t) send_homepos_offset;
Lightvalve 12:6f2531038ea4 1060 temp_msg.data[2] = (uint8_t) (send_homepos_offset >> 8);
jobuuu 2:a1c0a37df760 1061
jobuuu 2:a1c0a37df760 1062 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1063 }
Lightvalve 11:82d8768d7351 1064
Lightvalve 11:82d8768d7351 1065 void CAN_TX_HOMPOS_VALVE_OPENING(void) {
Lightvalve 11:82d8768d7351 1066 CANMessage temp_msg;
Lightvalve 12:6f2531038ea4 1067 int16_t send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1068 send_homepos_valve_opening = (int16_t) (HOMEPOS_VALVE_OPENING);
Lightvalve 11:82d8768d7351 1069
Lightvalve 11:82d8768d7351 1070 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1071 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1072 temp_msg.data[0] = (uint8_t) CTX_SEND_HOMEPOS_VALVE_OPENING;
Lightvalve 12:6f2531038ea4 1073 temp_msg.data[1] = (uint8_t) send_homepos_valve_opening;
Lightvalve 12:6f2531038ea4 1074 temp_msg.data[2] = (uint8_t) (send_homepos_valve_opening >> 8);
Lightvalve 11:82d8768d7351 1075
Lightvalve 11:82d8768d7351 1076 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1077 }
Lightvalve 11:82d8768d7351 1078
Lightvalve 12:6f2531038ea4 1079 void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex) {
Lightvalve 11:82d8768d7351 1080 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1081 int16_t valve_pos_vs_pwm;
Lightvalve 11:82d8768d7351 1082 valve_pos_vs_pwm = (int16_t) (VALVE_POS_VS_PWM[canindex]);
Lightvalve 11:82d8768d7351 1083
Lightvalve 12:6f2531038ea4 1084 int16_t PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1085 PWM_VALVE_ID = ID_index_array[canindex] * 1000;
Lightvalve 11:82d8768d7351 1086
Lightvalve 11:82d8768d7351 1087 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1088 temp_msg.len = 5;
Lightvalve 12:6f2531038ea4 1089 temp_msg.data[0] = (uint8_t) CTX_VALVE_PWM_VS_VALVE_POS;
Lightvalve 12:6f2531038ea4 1090 temp_msg.data[1] = (uint8_t) PWM_VALVE_ID;
Lightvalve 12:6f2531038ea4 1091 temp_msg.data[2] = (uint8_t) (PWM_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1092 temp_msg.data[3] = (uint8_t) valve_pos_vs_pwm;
Lightvalve 12:6f2531038ea4 1093 temp_msg.data[4] = (uint8_t) (valve_pos_vs_pwm >> 8);
Lightvalve 11:82d8768d7351 1094
Lightvalve 11:82d8768d7351 1095 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1096 }
Lightvalve 11:82d8768d7351 1097
Lightvalve 12:6f2531038ea4 1098 void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex) {
Lightvalve 11:82d8768d7351 1099 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1100 int32_t valve_pos_vs_flowrate;
Lightvalve 11:82d8768d7351 1101 valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]);
Lightvalve 11:82d8768d7351 1102
Lightvalve 11:82d8768d7351 1103 int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 50 + DDV_CENTER;
Lightvalve 11:82d8768d7351 1104
Lightvalve 11:82d8768d7351 1105 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1106 temp_msg.len = 7;
Lightvalve 12:6f2531038ea4 1107 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_VS_FLOWRATE;
Lightvalve 12:6f2531038ea4 1108 temp_msg.data[1] = (uint8_t) VALVE_POS_VALVE_ID;
Lightvalve 12:6f2531038ea4 1109 temp_msg.data[2] = (uint8_t) (VALVE_POS_VALVE_ID >> 8);
Lightvalve 12:6f2531038ea4 1110 temp_msg.data[3] = (uint8_t) valve_pos_vs_flowrate;
Lightvalve 12:6f2531038ea4 1111 temp_msg.data[4] = (uint8_t) (valve_pos_vs_flowrate >> 8);
Lightvalve 12:6f2531038ea4 1112 temp_msg.data[5] = (uint8_t) (valve_pos_vs_flowrate >> 16);
Lightvalve 12:6f2531038ea4 1113 temp_msg.data[6] = (uint8_t) (valve_pos_vs_flowrate >> 24);
Lightvalve 11:82d8768d7351 1114
Lightvalve 11:82d8768d7351 1115 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1116 }
Lightvalve 11:82d8768d7351 1117
Lightvalve 11:82d8768d7351 1118 void CAN_TX_VALVE_POS_NUM(void) {
Lightvalve 11:82d8768d7351 1119 CANMessage temp_msg;
Lightvalve 11:82d8768d7351 1120 int32_t valve_pos_num;
Lightvalve 11:82d8768d7351 1121 valve_pos_num = (int16_t) VALVE_POS_NUM;
Lightvalve 11:82d8768d7351 1122
Lightvalve 11:82d8768d7351 1123 temp_msg.id = CID_TX_INFO;
Lightvalve 11:82d8768d7351 1124 temp_msg.len = 3;
Lightvalve 12:6f2531038ea4 1125 temp_msg.data[0] = (uint8_t) CTX_VALVE_POS_NUM;
Lightvalve 12:6f2531038ea4 1126 temp_msg.data[1] = (uint8_t) valve_pos_num;
Lightvalve 12:6f2531038ea4 1127 temp_msg.data[2] = (uint8_t) (valve_pos_num >> 8);
Lightvalve 11:82d8768d7351 1128
Lightvalve 11:82d8768d7351 1129 can.write(temp_msg);
Lightvalve 11:82d8768d7351 1130 }
Lightvalve 11:82d8768d7351 1131
jobuuu 2:a1c0a37df760 1132 /******************************************************************************
jobuuu 2:a1c0a37df760 1133 Sensor & State Transmission Functions
jobuuu 2:a1c0a37df760 1134 *******************************************************************************/
jobuuu 2:a1c0a37df760 1135
Lightvalve 12:6f2531038ea4 1136 void CAN_TX_POSITION(int32_t t_pos, int32_t t_vel) {
jobuuu 2:a1c0a37df760 1137 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1138
jobuuu 2:a1c0a37df760 1139 temp_msg.id = CID_TX_POSITION;
jobuuu 2:a1c0a37df760 1140 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1141 temp_msg.data[0] = (uint8_t) t_pos;
Lightvalve 12:6f2531038ea4 1142 temp_msg.data[1] = (uint8_t) (t_pos >> 8);
Lightvalve 12:6f2531038ea4 1143 temp_msg.data[2] = (uint8_t) (t_pos >> 16);
Lightvalve 12:6f2531038ea4 1144 temp_msg.data[3] = (uint8_t) (t_pos >> 24);
Lightvalve 12:6f2531038ea4 1145 temp_msg.data[4] = (uint8_t) t_vel;
Lightvalve 12:6f2531038ea4 1146 temp_msg.data[5] = (uint8_t) (t_vel >> 8);
Lightvalve 12:6f2531038ea4 1147 temp_msg.data[6] = (uint8_t) (t_vel >> 16);
Lightvalve 12:6f2531038ea4 1148 temp_msg.data[7] = (uint8_t) (t_vel >> 24);
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(int16_t t_torque) {
jobuuu 2:a1c0a37df760 1154 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1155
jobuuu 2:a1c0a37df760 1156 temp_msg.id = CID_TX_TORQUE;
jobuuu 2:a1c0a37df760 1157 temp_msg.len = 2;
Lightvalve 12:6f2531038ea4 1158 temp_msg.data[0] = (uint8_t) t_torque;
Lightvalve 12:6f2531038ea4 1159 temp_msg.data[1] = (uint8_t) (t_torque >> 8);
jobuuu 2:a1c0a37df760 1160
jobuuu 2:a1c0a37df760 1161 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1162 }
jobuuu 2:a1c0a37df760 1163
Lightvalve 11:82d8768d7351 1164 void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b) {
jobuuu 2:a1c0a37df760 1165 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1166
jobuuu 2:a1c0a37df760 1167 temp_msg.id = CID_TX_PRES;
jobuuu 2:a1c0a37df760 1168 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1169 temp_msg.data[0] = (uint8_t) t_pres_a;
Lightvalve 12:6f2531038ea4 1170 temp_msg.data[1] = (uint8_t) (t_pres_a >> 8);
Lightvalve 12:6f2531038ea4 1171 temp_msg.data[2] = (uint8_t) t_pres_b;
Lightvalve 12:6f2531038ea4 1172 temp_msg.data[3] = (uint8_t) (t_pres_b >> 8);
jobuuu 2:a1c0a37df760 1173
jobuuu 2:a1c0a37df760 1174 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1175 }
jobuuu 2:a1c0a37df760 1176
Lightvalve 11:82d8768d7351 1177 void CAN_TX_PWM(int16_t t_pwm) {
jobuuu 2:a1c0a37df760 1178 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1179
jobuuu 2:a1c0a37df760 1180 temp_msg.id = CID_TX_POSITION;
jobuuu 2:a1c0a37df760 1181 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1182 temp_msg.data[0] = (uint8_t) t_pwm;
Lightvalve 12:6f2531038ea4 1183 temp_msg.data[1] = (uint8_t) (t_pwm >> 8);
jobuuu 2:a1c0a37df760 1184
jobuuu 2:a1c0a37df760 1185 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1186 }
jobuuu 2:a1c0a37df760 1187
Lightvalve 11:82d8768d7351 1188 void CAN_TX_VALVE_POSITION(int16_t t_valve_pos) {
jobuuu 2:a1c0a37df760 1189 CANMessage temp_msg;
jobuuu 2:a1c0a37df760 1190
jobuuu 2:a1c0a37df760 1191 temp_msg.id = CID_TX_VALVE_POSITION;
jobuuu 2:a1c0a37df760 1192 temp_msg.len = 8;
Lightvalve 12:6f2531038ea4 1193 temp_msg.data[0] = (uint8_t) t_valve_pos;
Lightvalve 12:6f2531038ea4 1194 temp_msg.data[1] = (uint8_t) (t_valve_pos >> 8);
jobuuu 2:a1c0a37df760 1195
jobuuu 2:a1c0a37df760 1196 can.write(temp_msg);
jobuuu 2:a1c0a37df760 1197 }