2011

Dependencies:   mbed FastPWM

Revision:
11:82d8768d7351
Parent:
7:e9086c72bb22
Child:
12:6f2531038ea4
diff -r 83a6baa77a2e -r 82d8768d7351 CAN/function_CAN.cpp
--- a/CAN/function_CAN.cpp	Fri Aug 23 01:02:32 2019 +0000
+++ b/CAN/function_CAN.cpp	Fri Aug 23 12:28:08 2019 +0000
@@ -1,4 +1,7 @@
 #include "function_CAN.h"
+#include "setting.h"
+#include "function_utilities.h"
+#include "SPI_EEP_ENC.h"
 
 // CAN ID Setting Variables
 int CID_RX_CMD = 100;
@@ -15,26 +18,570 @@
 int CID_TX_VOUT = 1500;
 int CID_TX_VALVE_POSITION = 1600;
 
-// Board Information 
-int BNO = 0;
-int CONTROL_MODE = 0;
-double P_GAIN_JOINT_POSITION = 0.0;
-double I_GAIN_JOINT_POSITION = 0.0;
-double D_GAIN_JOINT_POSITION = 0.0;
-double P_GAIN_JOINT_TORQUE = 0.0;
-double I_GAIN_JOINT_TORQUE = 0.0;
-double D_GAIN_JOINT_TORQUE = 0.0;
+
+/*******************************************************************************
+ * CAN functions
+ ******************************************************************************/
+void CAN_ID_INIT(void) {
 
+    CID_RX_CMD = (int) (BNO + INIT_CID_RX_CMD);
+    CID_RX_REF_POSITION = (int) (BNO + INIT_CID_RX_REF_POSITION);
+    CID_RX_REF_TORQUE = (int) (BNO + INIT_CID_RX_REF_TORQUE);
+    CID_RX_REF_PRES_DIFF = (int) (BNO + INIT_CID_RX_REF_PRES_DIFF);
+    CID_RX_REF_VOUT = (int) (BNO + INIT_CID_RX_REF_VOUT);
+    CID_RX_REF_VALVE_POSITION = (int) (BNO + INIT_CID_RX_REF_VALVE_POSITION);
+
+    CID_TX_INFO = (int) (BNO + INIT_CID_TX_INFO);
+    CID_TX_POSITION = (int) (BNO + INIT_CID_TX_POSITION);
+    CID_TX_TORQUE = (int) (BNO + INIT_CID_TX_TORQUE);
+    CID_TX_PRES = (int) (BNO + INIT_CID_TX_PRES);
+    CID_TX_VOUT = (int) (BNO + INIT_CID_TX_VOUT);
+    CID_TX_VALVE_POSITION = (int) (BNO + INIT_CID_TX_VALVE_POSITION);
+}
 
 void ReadCMD(char CMD)
 {
     switch(CMD){
-    case CRX_ASK_INFO:
-//        CAN_TX_INFO();
-        break;
-    case CRX_ASK_BNO:
-//        CAN_TX_BNO();
-        break;
+        case CRX_ASK_INFO: {
+            CAN_TX_INFO();
+            break;
+        }
+        case CRX_ASK_BNO: {
+            CAN_TX_BNO();
+            break;
+        }
+        case CRX_SET_BNO: {
+            BNO = (int16_t) msg.data[1];
+            spi_eeprom_write(RID_BNO, (int16_t) BNO);
+            CAN_ID_INIT(); // can id init
+            break;
+        }
+        case CRX_ASK_OPERATING_MODE: {
+            CAN_TX_OPERATING_MODE();
+            break;
+        }
+        case CRX_SET_OPERATING_MODE: {
+            OPERATING_MODE = (int16_t) msg.data[1];
+            spi_eeprom_write(RID_OPERATING_MODE, (int16_t) OPERATING_MODE);
+            break;
+        }
+        case CRX_SET_ENC_ZERO: {
+            ENC_SET_ZERO();
+
+            break;
+        }
+        case CRX_SET_FET_ON: {
+            LAT_MOT_EN = (int16_t) msg.data[1];;
+
+            break;
+        }
+
+        case CRX_SET_REF_UPDATE_ENABLE: {
+            flag_ref_enable = (int16_t) msg.data[1];
+
+            break;
+        }
+
+        case CRX_ASK_CAN_FREQ: {
+            CAN_TX_CAN_FREQ();
+
+            break;
+        }
+
+        case CRX_SET_CAN_FREQ: {
+            CAN_FREQ = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            spi_eeprom_write(RID_CAN_FREQ, (int16_t) CAN_FREQ);
+            break;
+        }
+
+        case CRX_ASK_CONTROL_MODE: {
+            CAN_TX_CONTROL_MODE();
+
+            break;
+        }
+
+        case CRX_SET_CONTROL_MODE: {
+            CONTROL_MODE = (int16_t) (msg.data[1]);
+            if (CONTROL_MODE == MODE_FIND_HOME) {
+                FLAG_FIND_HOME = true;
+            }
+            break;
+        }
+
+        case CRX_SET_DATA_REQUEST: {
+            int request_type = msg.data[2];
+            flag_data_request[request_type] = msg.data[1];
+
+            if (flag_data_request[1] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC
+            if (flag_data_request[2] == HIGH) SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0); // set DAC
+
+            break;
+        }
+
+        case CRX_ASK_JOINT_ENC_DIR: {
+            CAN_TX_JOINT_ENC_DIR();
+
+            break;
+        }
+
+        case CRX_SET_JOINT_ENC_DIR: {
+            DIR_JOINT_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            if (DIR_JOINT_ENC >= 0)
+                DIR_JOINT_ENC = 1;
+            else
+                DIR_JOINT_ENC = -1;
+            spi_eeprom_write(RID_JOINT_ENC_DIR, (int16_t) DIR_JOINT_ENC);
+
+            break;
+        }
+
+        case CRX_ASK_VALVE_DIR: {
+            CAN_TX_VALVE_DIR();
+
+            break;
+        }
+
+        case CRX_SET_VALVE_DIR: {
+            DIR_VALVE = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            if (DIR_VALVE >= 0)
+                DIR_VALVE = 1;
+            else
+                DIR_VALVE = -1;
+            spi_eeprom_write(RID_VALVE_DIR, (int16_t) DIR_VALVE);
+
+            break;
+        }
+
+        case CRX_ASK_VALVE_ENC_DIR: {
+            CAN_TX_VALVE_ENC_DIR();
+
+            break;
+        }
+
+        case CRX_SET_VALVE_ENC_DIR: {
+            DIR_VALVE_ENC = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            if (DIR_VALVE_ENC >= 0)
+                DIR_VALVE_ENC = 1;
+            else
+                DIR_VALVE_ENC = -1;
+
+            spi_eeprom_write(RID_VALVE_ENC_DIR, (int16_t) DIR_VALVE_ENC);
+
+            break;
+        }
+
+        case CRX_ASK_VOLTAGE_SUPPLY: {
+            CAN_TX_VOLTAGE_SUPPLY();
+
+            break;
+        }
+
+        case CRX_SET_VOLTAGE_SUPPLY: {
+            SUPPLY_VOLTAGE = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.;
+            spi_eeprom_write(RID_VOLATGE_SUPPLY, (int16_t) (SUPPLY_VOLTAGE * 10.));
+
+            break;
+        }
+
+        case CRX_ASK_VOLTAGE_VALVE: {
+            CAN_TX_VOLTAGE_VALVE();
+
+            break;
+        }
+
+        case CRX_SET_VOLTAGE_VALVE: {
+            VALVE_VOLTAGE_LIMIT = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.;
+            spi_eeprom_write(RID_VOLTAGE_VALVE, (int16_t) (VALVE_VOLTAGE_LIMIT * 10.));
+
+
+            break;
+        }
+        ///////////////////////////////////////////////////////////////////////////////////////////////////////////
+        case CRX_SET_HOMEPOS: {
+            CONTROL_MODE = 22;
+            SETTING_SWITCH = (int16_t) (msg.data[1]);
+            break;
+        }
+
+        case CRX_ASK_PID_GAIN: {
+            CAN_TX_PID_GAIN(msg.data[1]);
+
+            break;
+        }
+
+        case CRX_SET_PID_GAIN: {
+            if (msg.data[1] == 0) {
+                P_GAIN_VALVE_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8);
+                I_GAIN_VALVE_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8);
+                D_GAIN_VALVE_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8);
+
+                spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION);
+                spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION);
+                spi_eeprom_write(RID_D_GAIN_VALVE_POSITION, (int16_t) D_GAIN_VALVE_POSITION);
+
+
+            } else if (msg.data[1] == 1) {
+                P_GAIN_JOINT_POSITION = (int16_t) (msg.data[2] | msg.data[3] << 8);
+                I_GAIN_JOINT_POSITION = (int16_t) (msg.data[4] | msg.data[5] << 8);
+                D_GAIN_JOINT_POSITION = (int16_t) (msg.data[6] | msg.data[7] << 8);
+
+                spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION);
+                spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION);
+                spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION);
+            } else if (msg.data[1] == 2) {
+                P_GAIN_JOINT_TORQUE = (int16_t) (msg.data[2] | msg.data[3] << 8);
+                I_GAIN_JOINT_TORQUE = (int16_t) (msg.data[4] | msg.data[5] << 8);
+                D_GAIN_JOINT_TORQUE = (int16_t) (msg.data[6] | msg.data[7] << 8);
+
+                spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE);
+                spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE);
+                spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE);
+
+
+            }
+
+            break;
+        }
+
+        case CRX_ASK_VALVE_DEADZONE: {
+            CAN_TX_VALVE_DEADZONE();
+
+            break;
+        }
+
+        case CRX_SET_VALVE_DEADZONE: {
+            VALVE_CENTER = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            VALVE_DEADZONE_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
+            VALVE_DEADZONE_MINUS = (int16_t) (msg.data[5] | msg.data[6] << 8);
+
+            spi_eeprom_write(RID_VALVE_CNETER, (int16_t) (VALVE_CENTER));
+            spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, (int16_t) (VALVE_DEADZONE_PLUS));
+            spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, (int16_t) (VALVE_DEADZONE_MINUS));
+
+            break;
+        }
+
+        case CRX_ASK_VELOCITY_COMP_GAIN: {
+            CAN_TX_VELOCITY_COMP_GAIN();
+
+            break;
+        }
+
+        case CRX_SET_VELOCITY_COMP_GAIN: {
+            VELOCITY_COMP_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_VELOCITY_COMP_GAIN, (int16_t) VELOCITY_COMP_GAIN);
+
+            break;
+        }
+
+        case CRX_ASK_COMPLIANCE_GAIN: {
+            CAN_TX_COMPLIANCE_GAIN();
+
+            break;
+        }
+
+        case CRX_SET_COMPLIANCE_GAIN: {
+            COMPLIANCE_GAIN = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_COMPLIANCE_GAIN, (int16_t) COMPLIANCE_GAIN);
+
+            break;
+        }
+
+        case CRX_ASK_VALVE_FF: {
+            CAN_TX_VALVE_FF();
+
+            break;
+        }
+
+        case CRX_SET_VALVE_FF: {
+            VALVE_FF = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_VALVE_FF, (int16_t) VALVE_FF);
+
+            break;
+        }
+
+        case CRX_ASK_BULK_MODULUS: {
+            CAN_TX_BULK_MODULUS();
+
+            break;
+        }
+
+        case CRX_SET_BULK_MODULUS: {
+            BULK_MODULUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_BULK_MODULUS, (int16_t) BULK_MODULUS);
+
+            break;
+        }
+
+        case CRX_ASK_CHAMBER_VOLUME: {
+            CAN_TX_CHAMBER_VOLUME();
+
+            break;
+        }
+
+        case CRX_SET_CHAMBER_VOLUME: {
+            CHAMBER_VOLUME_A = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            CHAMBER_VOLUME_B = (int16_t) (msg.data[3] | msg.data[4] << 8);
+
+            spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A);
+            spi_eeprom_write(RID_CHAMBER_VOLUME_B, (int16_t) CHAMBER_VOLUME_B);
+
+            break;
+        }
+
+        case CRX_ASK_PISTON_AREA: {
+            CAN_TX_PISTON_AREA();
+
+            break;
+        }
+
+        case CRX_SET_PISTON_AREA: {
+            PISTON_AREA_A = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            PISTON_AREA_B = (int16_t) (msg.data[3] | msg.data[4] << 8);
+            PISTON_AREA_alpha = (double)PISTON_AREA_B/(double)PISTON_AREA_A;
+
+            spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A);
+            spi_eeprom_write(RID_PISTON_AREA_B, (int16_t) PISTON_AREA_B);
+            break;
+        }
+
+        case CRX_ASK_PRES: {
+            CAN_TX_PRES_A_AND_B();
+            SPI_VREF_DAC_WRITE(PRES_A_VREF, PRES_B_VREF, TORQUE_VREF, 0);
+            break;
+        }
+
+        case CRX_SET_PRES: {
+            PRES_SUPPLY = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            PRES_RETURN = (int16_t) (msg.data[3] | msg.data[4] << 8);
+
+            spi_eeprom_write(RID_PRES_SUPPLY, (int16_t) PRES_SUPPLY);
+            spi_eeprom_write(RID_PRES_RETURN, (int16_t) PRES_RETURN);
+
+
+            break;
+        }
+
+        case CRX_ASK_ENC_LIMIT: {
+            CAN_TX_ENC_LIMIT();
+
+            break;
+        }
+
+        case CRX_SET_ENC_LIMIT: {
+            ENC_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            ENC_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
+
+            spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS);
+            spi_eeprom_write(RID_ENC_LIMIT_PLUS, (int16_t) ENC_LIMIT_PLUS);
+
+            break;
+        }
+
+        case CRX_ASK_STROKE: {
+            CAN_TX_STROKE();
+            break;
+        }
+
+        case CRX_SET_STROKE: {
+            STROKE = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_STROKE, (int16_t) STROKE);
+
+            break;
+        }
+
+        case CRX_ASK_VALVE_LIMIT: {
+            CAN_TX_VALVE_LIMIT();
+
+            break;
+        }
+
+        case CRX_SET_VALVE_LIMIT: {
+            VALVE_LIMIT_MINUS = (int16_t) (msg.data[1] | msg.data[2] << 8);
+            VALVE_LIMIT_PLUS = (int16_t) (msg.data[3] | msg.data[4] << 8);
+
+            spi_eeprom_write(RID_VALVE_LIMIT_MINUS, (int16_t) VALVE_LIMIT_MINUS);
+            spi_eeprom_write(RID_VALVE_LIMIT_PLUS, (int16_t) VALVE_LIMIT_PLUS);
+
+            break;
+        }
+
+        case CRX_ASK_ENC_PULSE_PER_POSITION: {
+            CAN_TX_ENC_PULSE_PER_POSITION();
+
+            break;
+        }
+
+        case CRX_SET_ENC_PULSE_PER_POSITION: {
+            ENC_PULSE_PER_POSITION = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_ENC_PULSE_PER_POSITION, (int16_t) ENC_PULSE_PER_POSITION);
+
+            break;
+        }
+
+        case CRX_ASK_TORQUE_SENSOR_PULSE_PER_TORQUE: {
+            CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE();
+
+            break;
+        }
+
+        case CRX_SET_TORQUE_SENSOR_PULSE_PER_TORQUE: {
+            TORQUE_SENSOR_PULSE_PER_TORQUE = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE, (int16_t) TORQUE_SENSOR_PULSE_PER_TORQUE);
+
+            break;
+        }
+
+        case CRX_ASK_PRES_SENSOR_PULSE_PER_PRES: {
+            CAN_TX_PRES_SENSOR_PULSE_PER_PRES();
+
+            break;
+        }
+
+        case CRX_SET_PRES_SENSOR_PULSE_PER_PRES: {
+            PRES_SENSOR_A_PULSE_PER_BAR = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) * 0.01;
+            PRES_SENSOR_B_PULSE_PER_BAR = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) * 0.01;
+
+            spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.));
+            spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.));
+
+            break;
+        }
+
+        case CRX_ASK_FRICTION: {
+            CAN_TX_FRICTION();
+
+            break;
+        }
+
+        case CRX_SET_FRICTION: {
+            FRICTION = (double) ((int16_t) (msg.data[1] | msg.data[2] << 8)) / 10.;
+
+            spi_eeprom_write(RID_FRICTION, (int16_t) (FRICTION * 10.));
+
+            break;
+        }
+
+        case CRX_ASK_VALVE_GAIN_PLUS: {
+            CAN_TX_VALVE_GAIN_PLUS();
+
+            break;
+        }
+        case CRX_SET_VALVE_GAIN_PLUS: {
+            VALVE_GAIN_LPM_PER_V[0] = (double) msg.data[1] / 50.;
+            VALVE_GAIN_LPM_PER_V[2] = (double) msg.data[2] / 50.;
+            VALVE_GAIN_LPM_PER_V[4] = (double) msg.data[3] / 50.;
+            VALVE_GAIN_LPM_PER_V[6] = (double) msg.data[4] / 50.;
+            VALVE_GAIN_LPM_PER_V[8] = (double) msg.data[5] / 50.;
+
+            spi_eeprom_write(RID_VALVE_GAIN_PLUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[0] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_PLUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[2] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_PLUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[4] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_PLUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[6] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_PLUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[8] * 100.));
+
+            break;
+        }
+
+        case CRX_ASK_VALVE_GAIN_MINUS: {
+            CAN_TX_VALVE_GAIN_MINUS();
+
+            break;
+        }
+        case CRX_SET_VALVE_GAIN_MINUS: {
+            VALVE_GAIN_LPM_PER_V[1] = (double) msg.data[1] / 50.;
+            VALVE_GAIN_LPM_PER_V[3] = (double) msg.data[2] / 50.;
+            VALVE_GAIN_LPM_PER_V[5] = (double) msg.data[3] / 50.;
+            VALVE_GAIN_LPM_PER_V[7] = (double) msg.data[4] / 50.;
+            VALVE_GAIN_LPM_PER_V[9] = (double) msg.data[5] / 50.;
+
+            spi_eeprom_write(RID_VALVE_GAIN_MINUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[1] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_MINUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[3] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_MINUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[5] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_MINUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[7] * 100.));
+            spi_eeprom_write(RID_VALVE_GAIN_MINUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[9] * 100.));
+
+            break;
+        }
+        case CRX_ASK_DDV_VALVE_DEADZONE: {
+            CAN_TX_DDV_VALVE_DEADZONE();
+            break;
+        }
+
+        case CRX_LOW_REF: {
+            REFERENCE_MODE = msg.data[1];
+
+            REF_NUM = msg.data[2];
+            REF_PERIOD = (double) ((int16_t) (msg.data[3] | msg.data[4] << 8)) / 100.;
+            if (REF_PERIOD <= 0.) REF_MOVE_TIME_5k = TMR_FREQ_5k / CAN_FREQ;
+            else REF_MOVE_TIME_5k = (int) (REF_PERIOD * (double) TMR_FREQ_5k);
+            REF_MAG = (double) ((int16_t) (msg.data[5] | msg.data[6] << 8)) / 100.;
+
+            break;
+        }
+
+        case CRX_JUMP_STATUS: {
+            MODE_JUMP_STATUS = msg.data[1];
+
+            break;
+        }
+
+        case CRX_SET_ERR_CLEAR: {
+
+            for (i = 0; i < num_err; i++) {
+                flag_err[i] = FALSE;
+                flag_err_old[i] = FALSE;
+            }
+
+            flag_err_rt = FALSE;
+
+
+            break;
+        }
+
+        case CRX_ASK_HOMEPOS_OFFSET: {
+            CAN_TX_HOMEPOS_OFFSET();
+            break;
+        }
+        case CRX_SET_HOMEPOS_OFFSET: {
+            HOMEPOS_OFFSET = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_HOMEPOS_OFFSET, (int16_t) HOMEPOS_OFFSET);
+            break;
+        }
+
+        case CRX_ASK_HOMEPOS_VALVE_OPENING: {
+            CAN_TX_HOMPOS_VALVE_OPENING();
+            break;
+        }
+        case CRX_SET_HOMEPOS_VALVE_OPENING: {
+            HOMEPOS_VALVE_OPENING = (int16_t) (msg.data[1] | msg.data[2] << 8);
+
+            spi_eeprom_write(RID_HOMEPOS_VALVE_OPENING, (int16_t) HOMEPOS_VALVE_OPENING);
+            break;
+        }
+
+        case CRX_ASK_VALVE_PWM_VS_VALVE_POS: {
+            can_index = (int16_t) msg.data[1];
+            CAN_TX_VALVE_PWM_VS_VALVE_POS(can_index);
+            break;
+        }
+        case CRX_ASK_VALVE_POS_VS_FLOWRATE: {
+            can_index = (int16_t) msg.data[1];
+            CAN_TX_VALVE_POS_VS_FLOWRATE(can_index);
+            break;
+        }
+        case CRX_ASK_VALVE_POS_NUM: {
+            CAN_TX_VALVE_POS_NUM();
+            break;
+        }
     default:
         break;
     }
@@ -57,8 +604,8 @@
         int16_t temp_torq = (int16_t) (msg.data[0] | msg.data[1] << 8);
         torq.ref = (double)temp_torq;
     } else if(address==CID_RX_REF_PRES_DIFF) {
-//        int16_t temp_presdiff = (int16_t) (msg.data[0] | msg.data[1] << 8);
-//        torq.ref = (double)temp_presdiff;   
+        int16_t temp_presdiff = (int16_t) (msg.data[0] | msg.data[1] << 8);
+        torq.ref = (double)temp_presdiff;   
     } else if(address==CID_RX_REF_VOUT) {
         int16_t temp_PWM = (int16_t) (msg.data[0] | msg.data[1] << 8);
         Vout.ref = (double)temp_PWM;   
@@ -72,9 +619,9 @@
 /******************************************************************************
  Information Transmission Functions
 *******************************************************************************/
-/*
-inline void CAN_TX_INFO(void) {
-    CANMessage temp_msg;
+
+void CAN_TX_INFO(void) {
+    CANmsg.data temp_msg;
     
     temp_msg.id = CID_TX_INFO;
     temp_msg.len = 7;
@@ -89,8 +636,8 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_BNO(void) {
-    CANMessage temp_msg;
+void CAN_TX_BNO(void) {
+    CANmsg.data temp_msg;
     
     temp_msg.id = CID_TX_INFO;
     temp_msg.len = 2;
@@ -100,7 +647,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_OPERATING_MODE(void) {
+void CAN_TX_OPERATING_MODE(void) {
     CANMessage temp_msg;
     
     temp_msg.id = CID_TX_INFO;
@@ -111,8 +658,7 @@
     can.write(temp_msg);
 }
 
-
-inline void CAN_TX_CAN_FREQ(void) {
+void CAN_TX_CAN_FREQ(void) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_INFO;
@@ -123,8 +669,8 @@
 
     can.write(temp_msg);
 }
-*/
-inline void CAN_TX_CONTROL_MODE(void) {
+
+void CAN_TX_CONTROL_MODE(void) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_INFO;
@@ -134,8 +680,8 @@
 
     can.write(temp_msg);
 }
-/*
-inline void CAN_TX_JOINT_ENC_DIR(void) {
+
+void CAN_TX_JOINT_ENC_DIR(void) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_INFO;
@@ -147,7 +693,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_VALVE_DIR(void) {
+void CAN_TX_VALVE_DIR(void) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_INFO;
@@ -159,7 +705,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_VALVE_ENC_DIR(void) {
+void CAN_TX_VALVE_ENC_DIR(void) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_INFO;
@@ -171,7 +717,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_VOLTAGE_SUPPLY(void) {
+void CAN_TX_VOLTAGE_SUPPLY(void) {
     long send_voltage_supply = (long) (SUPPLY_VOLTAGE * 10);
 
     CANMessage temp_msg;
@@ -185,7 +731,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_VOLTAGE_VALVE(void) {
+void CAN_TX_VOLTAGE_VALVE(void) {
     long send_voltage_valve = (long) (VALVE_VOLTAGE_LIMIT * 10);
 
     CANMessage temp_msg;
@@ -198,9 +744,9 @@
 
     can.write(temp_msg);
 }
-*/
+
 
-inline void CAN_TX_PID_GAIN(int t_type) {
+void CAN_TX_PID_GAIN(int t_type) {
     // t_type = 0 : valve position control gain
     // t_type = 1 : joint position control gain
     // t_type = 2 : joint torque control gain
@@ -236,8 +782,8 @@
     can.write(temp_msg);
 }
 
-/*
-inline void CAN_TX_VALVE_DEADZONE(void) {
+
+void CAN_TX_VALVE_DEADZONE(void) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_INFO;
@@ -253,9 +799,139 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_ENC_PULSE_PER_POSITION(void) {
+void CAN_TX_VELOCITY_COMP_GAIN(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_VELOCITY_COMP_GAIN;
+    temp_msg.data[1] = (unsigned char) VELOCITY_COMP_GAIN;
+    temp_msg.data[2] = (unsigned char) (VELOCITY_COMP_GAIN >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_COMPLIANCE_GAIN(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_COMPLIANCE_GAIN;
+    temp_msg.data[1] = (unsigned char) COMPLIANCE_GAIN;
+    temp_msg.data[2] = (unsigned char) (COMPLIANCE_GAIN >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_VALVE_FF(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_VALVE_FF;
+    temp_msg.data[1] = (unsigned char) VALVE_FF;
+    temp_msg.data[2] = (unsigned char) (VALVE_FF >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_BULK_MODULUS(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_BULK_MODULUS;
+    temp_msg.data[1] = (unsigned char) BULK_MODULUS;
+    temp_msg.data[2] = (unsigned char) (BULK_MODULUS >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_CHAMBER_VOLUME(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 5;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_CHAMBER_VOLUME;
+    temp_msg.data[1] = (unsigned char) CHAMBER_VOLUME_A;
+    temp_msg.data[2] = (unsigned char) (CHAMBER_VOLUME_A >> 8);
+    temp_msg.data[3] = (unsigned char) CHAMBER_VOLUME_B;
+    temp_msg.data[4] = (unsigned char) (CHAMBER_VOLUME_B >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_PISTON_AREA(void) {
     CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 5;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_PISTON_AREA;
+    temp_msg.data[1] = (unsigned char) PISTON_AREA_A;
+    temp_msg.data[2] = (unsigned char) (PISTON_AREA_A >> 8);
+    temp_msg.data[3] = (unsigned char) PISTON_AREA_B;
+    temp_msg.data[4] = (unsigned char) (PISTON_AREA_B >> 8);
 
+    can.write(temp_msg);
+}
+
+void CAN_TX_PRES_A_AND_B(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 5;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_PRES;
+    temp_msg.data[1] = (unsigned char) PRES_SUPPLY;
+    temp_msg.data[2] = (unsigned char) (PRES_SUPPLY >> 8);
+    temp_msg.data[3] = (unsigned char) PRES_RETURN;
+    temp_msg.data[4] = (unsigned char) (PRES_RETURN >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_ENC_LIMIT(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 5;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_ENC_LIMIT;
+    temp_msg.data[1] = (unsigned char) ENC_LIMIT_MINUS;
+    temp_msg.data[2] = (unsigned char) (ENC_LIMIT_MINUS >> 8);
+    temp_msg.data[3] = (unsigned char) ENC_LIMIT_PLUS;
+    temp_msg.data[4] = (unsigned char) (ENC_LIMIT_PLUS >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_STROKE(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_STROKE;
+    temp_msg.data[1] = (unsigned char) STROKE;
+    temp_msg.data[2] = (unsigned char) (STROKE >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_VALVE_LIMIT(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 5;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_VALVE_LIMIT;
+    temp_msg.data[1] = (unsigned char) VALVE_LIMIT_MINUS;
+    temp_msg.data[2] = (unsigned char) (VALVE_LIMIT_MINUS >> 8);
+    temp_msg.data[3] = (unsigned char) VALVE_LIMIT_PLUS;
+    temp_msg.data[4] = (unsigned char) (VALVE_LIMIT_PLUS >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_ENC_PULSE_PER_POSITION(void) {
+    CANMessage temp_msg;
+    
     temp_msg.id = CID_TX_INFO;
     temp_msg.len = 3;
     temp_msg.data[0] = (unsigned char) CTX_SEND_ENC_PULSE_PER_POSITION;
@@ -265,9 +941,9 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void) {
+void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void) {
     CANMessage temp_msg;
-
+    
     temp_msg.id = CID_TX_INFO;
     temp_msg.len = 3;
     temp_msg.data[0] = (unsigned char) CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE;
@@ -277,9 +953,9 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void) {
+void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void) {
     CANMessage temp_msg;
-
+    
     temp_msg.id = CID_TX_INFO;
     temp_msg.len = 5;
     temp_msg.data[0] = (unsigned char) CTX_SEND_PRES_SENSOR_PULSE_PER_BAR;
@@ -291,12 +967,86 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_HOMEPOS_OFFSET(void) {
+void CAN_TX_FRICTION(void) {
+    CANMessage temp_msg;
+    long send_friction;
+    send_friction = (long) (FRICTION * 10.);
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_FRICTION;
+    temp_msg.data[1] = (unsigned char) send_friction;
+    temp_msg.data[2] = (unsigned char) (send_friction >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_VALVE_GAIN_PLUS(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 6;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_VALVE_GAIN_PLUS;
+    temp_msg.data[1] = (unsigned char) (VALVE_GAIN_LPM_PER_V[0] * 50.);
+    temp_msg.data[2] = (unsigned char) (VALVE_GAIN_LPM_PER_V[2] * 50.);
+    temp_msg.data[3] = (unsigned char) (VALVE_GAIN_LPM_PER_V[4] * 50.);
+    temp_msg.data[4] = (unsigned char) (VALVE_GAIN_LPM_PER_V[6] * 50.);
+    temp_msg.data[5] = (unsigned char) (VALVE_GAIN_LPM_PER_V[8] * 50.);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_DDV_VALVE_DEADZONE(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 7;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_DDV_VALVE_DEADZONE;
+    temp_msg.data[1] = (unsigned char) VALVE_DEADZONE_MINUS;
+    temp_msg.data[2] = (unsigned char) ((int) (VALVE_DEADZONE_MINUS) >> 8);
+    temp_msg.data[3] = (unsigned char) (VALVE_DEADZONE_PLUS);
+    temp_msg.data[4] = (unsigned char) ((int) (VALVE_DEADZONE_PLUS) >> 8);
+    temp_msg.data[5] = (unsigned char) (DDV_CENTER);
+    temp_msg.data[6] = (unsigned char) ((int) (DDV_CENTER) >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_VALVE_GAIN_MINUS(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 6;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_VALVE_GAIN_MINUS;
+    temp_msg.data[1] = (unsigned char) (VALVE_GAIN_LPM_PER_V[1] * 50.);
+    temp_msg.data[2] = (unsigned char) (VALVE_GAIN_LPM_PER_V[3] * 50.);
+    temp_msg.data[3] = (unsigned char) (VALVE_GAIN_LPM_PER_V[5] * 50.);
+    temp_msg.data[4] = (unsigned char) (VALVE_GAIN_LPM_PER_V[7] * 50.);
+    temp_msg.data[5] = (unsigned char) (VALVE_GAIN_LPM_PER_V[9] * 50.);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_REFENCE_MODE(void) {
+    CANMessage temp_msg;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 6;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_REFENCE_MODE;
+    temp_msg.data[1] = (unsigned char) REFERENCE_MODE;
+    temp_msg.data[2] = (unsigned char) (int) (REFERENCE_FREQ * 100.);
+    temp_msg.data[3] = (unsigned char) ((int) (REFERENCE_FREQ * 100.) >> 8);
+    temp_msg.data[4] = (unsigned char) (int) (REFERENCE_MAG * 100.);
+    temp_msg.data[5] = (unsigned char) ((int) (REFERENCE_MAG * 100.) >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_HOMEPOS_OFFSET(void) {
+    CANMessage temp_msg;
     long send_homepos_offset;
     send_homepos_offset = (long) (HOMEPOS_OFFSET);
-
-    CANMessage temp_msg;
-
+    
     temp_msg.id = CID_TX_INFO;
     temp_msg.len = 3;
     temp_msg.data[0] = (unsigned char) CTX_SEND_HOMEPOS_OFFSET;
@@ -305,12 +1055,78 @@
 
     can.write(temp_msg);
 }
-*/
+
+void CAN_TX_HOMPOS_VALVE_OPENING(void) {
+    CANMessage temp_msg;
+    long send_homepos_valve_opening;
+    send_homepos_valve_opening = (long) (HOMEPOS_VALVE_OPENING);
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_SEND_HOMEPOS_VALVE_OPENING;
+    temp_msg.data[1] = (unsigned char) send_homepos_valve_opening;
+    temp_msg.data[2] = (unsigned char) (send_homepos_valve_opening >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_VALVE_PWM_VS_VALVE_POS(char canindex) {
+    CANMessage temp_msg;
+    int16_t valve_pos_vs_pwm;
+    valve_pos_vs_pwm = (int16_t) (VALVE_POS_VS_PWM[canindex]);
+    
+    int16_t PWM_VALVE_ID = ID_index_array[canindex] * 1000;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 5;
+    temp_msg.data[0] = (unsigned char) CTX_VALVE_PWM_VS_VALVE_POS;
+    temp_msg.data[1] = (unsigned char) PWM_VALVE_ID;
+    temp_msg.data[2] = (unsigned char) (PWM_VALVE_ID >> 8);
+    temp_msg.data[3] = (unsigned char) valve_pos_vs_pwm;
+    temp_msg.data[4] = (unsigned char) (valve_pos_vs_pwm >> 8);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_VALVE_POS_VS_FLOWRATE(char canindex) {
+    CANMessage temp_msg;
+    int32_t valve_pos_vs_flowrate;
+    valve_pos_vs_flowrate = (int32_t) (JOINT_VEL[canindex]);
+
+    int16_t VALVE_POS_VALVE_ID = ID_index_array[canindex] * 50 + DDV_CENTER;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 7;
+    temp_msg.data[0] = (unsigned char) CTX_VALVE_POS_VS_FLOWRATE;
+    temp_msg.data[1] = (unsigned char) VALVE_POS_VALVE_ID;
+    temp_msg.data[2] = (unsigned char) (VALVE_POS_VALVE_ID >> 8);
+    temp_msg.data[3] = (unsigned char) valve_pos_vs_flowrate;
+    temp_msg.data[4] = (unsigned char) (valve_pos_vs_flowrate >> 8);
+    temp_msg.data[5] = (unsigned char) (valve_pos_vs_flowrate >> 16);
+    temp_msg.data[6] = (unsigned char) (valve_pos_vs_flowrate >> 24);
+
+    can.write(temp_msg);
+}
+
+void CAN_TX_VALVE_POS_NUM(void) {
+    CANMessage temp_msg;
+    int32_t valve_pos_num;
+    valve_pos_num = (int16_t) VALVE_POS_NUM;
+    
+    temp_msg.id = CID_TX_INFO;
+    temp_msg.len = 3;
+    temp_msg.data[0] = (unsigned char) CTX_VALVE_POS_NUM;
+    temp_msg.data[1] = (unsigned char) valve_pos_num;
+    temp_msg.data[2] = (unsigned char) (valve_pos_num >> 8);
+
+    can.write(temp_msg);
+}
+
 /******************************************************************************
  Sensor & State Transmission Functions
 *******************************************************************************/
 
-inline void CAN_TX_POSITION(long t_pos, long t_vel) {
+void CAN_TX_POSITION(long t_pos, long t_vel) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_POSITION;
@@ -327,7 +1143,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_TORQUE(int16_t t_torque) {
+void CAN_TX_TORQUE(int16_t t_torque) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_TORQUE;
@@ -338,7 +1154,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b) {
+void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_PRES;
@@ -351,7 +1167,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_PWM(int16_t t_pwm) {
+void CAN_TX_PWM(int16_t t_pwm) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_POSITION;
@@ -362,7 +1178,7 @@
     can.write(temp_msg);
 }
 
-inline void CAN_TX_VALVE_POSITION(int16_t t_valve_pos) {
+void CAN_TX_VALVE_POSITION(int16_t t_valve_pos) {
     CANMessage temp_msg;
 
     temp_msg.id = CID_TX_VALVE_POSITION;