2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Wed Sep 04 11:02:57 2019 +0000
Revision:
18:b8adf1582ea3
Parent:
17:1865016ca2e7
Child:
19:23b7c1ad8683
100904

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