for learning

Dependencies:   mbed FastPWM

Revision:
7:e9086c72bb22
Parent:
4:58c8081de776
Child:
11:82d8768d7351
diff -r df07d3491e3a -r e9086c72bb22 CAN/function_CAN.h
--- a/CAN/function_CAN.h	Tue Aug 20 10:40:27 2019 +0000
+++ b/CAN/function_CAN.h	Tue Aug 20 12:27:19 2019 +0000
@@ -3,6 +3,9 @@
 
 #include "mbed.h"
 
+extern CAN can;
+extern CANMessage msg;
+
 // CID_RX_CMD - RX CMD type
 #define             CRX_ASK_INFO                    0
 #define             CRX_ASK_BNO                     1
@@ -72,6 +75,41 @@
 #define             CRX_SET_ERR_CLEAR               150
 #define             CRX_JUMP_STATUS                 255
 
+// CID_TX_INFO - TX INFO type
+
+#define             CTX_SEND_INFO                               0
+#define             CTX_SEND_BNO                                1
+#define             CTX_SEND_OPERATING_MODE                     2
+#define             CTX_SEND_CAN_FREQ                           6
+#define             CTX_SEND_CONTROL_MODE                       7
+#define             CTX_SEND_JOINT_ENC_DIR                      9
+#define             CTX_SEND_VALVE_DIR                          10
+#define             CTX_SEND_VALVE_ENC_DIR                      11
+#define             CTX_SEND_VOLTAGE_SUPPLY                     12
+#define             CTX_SEND_VOLTAGE_VALVE                      13
+#define             CTX_SEND_PID_GAIN                           20
+#define             CTX_SEND_VALVE_DEADZONE                     21
+#define             CTX_SEND_VELOCITY_COMP_GAIN                 22
+#define             CTX_SEND_COMPLIANCE_GAIN                    23
+#define             CTX_SEND_VALVE_CNETER                       24
+#define             CTX_SEND_VALVE_FF                           25
+#define             CTX_SEND_BULK_MODULUS                       26
+#define             CTX_SEND_CHAMBER_VOLUME                     27
+#define             CTX_SEND_PISTON_AREA                        28
+#define             CTX_SEND_PRES                               29
+#define             CTX_SEND_ENC_LIMIT                          30
+#define             CTX_SEND_STROKE                             31
+#define             CTX_SEND_VALVE_LIMIT                        32
+#define             CTX_SEND_ENC_PULSE_PER_POSITION             33
+#define             CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE     34
+#define             CTX_SEND_PRES_SENSOR_PULSE_PER_BAR          35
+#define             CTX_SEND_FRICTION                           36
+#define             CTX_SEND_VALVE_GAIN_PLUS                    37
+#define             CTX_SEND_VALVE_GAIN_MINUS                   38
+#define             CTX_SEND_REFENCE_MODE                       39
+#define             CTX_SEND_HOMEPOS_OFFSET                     40
+#define             CTX_SEND_HOMEPOS_VALVE_OPENING              41
+
 // Information Transmission
 //inline void CAN_TX_INFO(void);
 //inline void CAN_TX_BNO(void);
@@ -97,6 +135,48 @@
 inline void CAN_TX_PWM(int16_t t_pwm);
 inline void CAN_TX_VALVE_POSITION(int16_t t_valve_pos);
 
+// Board Information Variables
+extern int BNO;
+extern int CONTROL_MODE;
+extern double P_GAIN_JOINT_POSITION;
+extern double I_GAIN_JOINT_POSITION;
+extern double D_GAIN_JOINT_POSITION;
+extern double P_GAIN_JOINT_TORQUE;
+extern double I_GAIN_JOINT_TORQUE;
+extern double D_GAIN_JOINT_TORQUE;
+
+class State 
+{
+    public:
+        double sen;
+        double ref;
+        double ref_old;
+        double ref_diff;
+        double err;
+        double err_int;
+        double err_old;
+        double err_diff;
+    public:
+        State(){
+            sen = 0.0;
+            ref = 0.0;
+            ref_old = 0.0;
+            ref_diff = 0.0;
+            err = 0.0;
+            err_int = 0.0;
+            err_old = 0.0;
+            err_diff = 0.0;
+        }
+};
+
+extern State pos;
+extern State vel;
+extern State Vout;
+extern State torq;
+extern State pres_A;
+extern State pres_B;
+extern State cur;
+
 // CAN Receive Functions
 void ReadCMD();
 void CAN_RX_HANDLER();