Sungwoo Kim
/
HydraulicControlBoard_Learning
for learning
CAN/function_CAN.h@7:e9086c72bb22, 2019-08-20 (annotated)
- Committer:
- jobuuu
- Date:
- Tue Aug 20 12:27:19 2019 +0000
- Revision:
- 7:e9086c72bb22
- Parent:
- 4:58c8081de776
- Child:
- 11:82d8768d7351
Updated : 20190820;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jobuuu | 2:a1c0a37df760 | 1 | #ifndef _FUNCTION_CAN_H_ |
jobuuu | 2:a1c0a37df760 | 2 | #define _FUNCTION_CAN_H_ |
jobuuu | 2:a1c0a37df760 | 3 | |
jobuuu | 2:a1c0a37df760 | 4 | #include "mbed.h" |
jobuuu | 2:a1c0a37df760 | 5 | |
jobuuu | 7:e9086c72bb22 | 6 | extern CAN can; |
jobuuu | 7:e9086c72bb22 | 7 | extern CANMessage msg; |
jobuuu | 7:e9086c72bb22 | 8 | |
jobuuu | 2:a1c0a37df760 | 9 | // CID_RX_CMD - RX CMD type |
jobuuu | 2:a1c0a37df760 | 10 | #define CRX_ASK_INFO 0 |
jobuuu | 2:a1c0a37df760 | 11 | #define CRX_ASK_BNO 1 |
jobuuu | 2:a1c0a37df760 | 12 | #define CRX_SET_BNO 101 |
jobuuu | 2:a1c0a37df760 | 13 | #define CRX_ASK_OPERATING_MODE 2 |
jobuuu | 2:a1c0a37df760 | 14 | #define CRX_SET_OPERATING_MODE 102 |
jobuuu | 2:a1c0a37df760 | 15 | #define CRX_SET_ENC_ZERO 103 |
jobuuu | 2:a1c0a37df760 | 16 | #define CRX_SET_FET_ON 104 |
jobuuu | 2:a1c0a37df760 | 17 | #define CRX_SET_REF_UPDATE_ENABLE 105 |
jobuuu | 2:a1c0a37df760 | 18 | #define CRX_ASK_CAN_FREQ 6 |
jobuuu | 2:a1c0a37df760 | 19 | #define CRX_SET_CAN_FREQ 106 |
jobuuu | 2:a1c0a37df760 | 20 | #define CRX_ASK_CONTROL_MODE 7 |
jobuuu | 2:a1c0a37df760 | 21 | #define CRX_SET_CONTROL_MODE 107 |
jobuuu | 2:a1c0a37df760 | 22 | #define CRX_SET_DATA_REQUEST 108 |
jobuuu | 2:a1c0a37df760 | 23 | #define CRX_ASK_JOINT_ENC_DIR 9 |
jobuuu | 2:a1c0a37df760 | 24 | #define CRX_SET_JOINT_ENC_DIR 109 |
jobuuu | 2:a1c0a37df760 | 25 | #define CRX_ASK_VALVE_DIR 10 |
jobuuu | 2:a1c0a37df760 | 26 | #define CRX_SET_VALVE_DIR 110 |
jobuuu | 2:a1c0a37df760 | 27 | #define CRX_ASK_VALVE_ENC_DIR 11 |
jobuuu | 2:a1c0a37df760 | 28 | #define CRX_SET_VALVE_ENC_DIR 111 |
jobuuu | 2:a1c0a37df760 | 29 | #define CRX_ASK_VOLTAGE_SUPPLY 12 |
jobuuu | 2:a1c0a37df760 | 30 | #define CRX_SET_VOLTAGE_SUPPLY 112 |
jobuuu | 2:a1c0a37df760 | 31 | #define CRX_ASK_VOLTAGE_VALVE 13 |
jobuuu | 2:a1c0a37df760 | 32 | #define CRX_SET_VOLTAGE_VALVE 113 |
jobuuu | 2:a1c0a37df760 | 33 | #define CRX_SET_HOMEPOS 114 |
jobuuu | 2:a1c0a37df760 | 34 | #define CRX_ASK_PID_GAIN 20 |
jobuuu | 2:a1c0a37df760 | 35 | #define CRX_SET_PID_GAIN 120 |
jobuuu | 2:a1c0a37df760 | 36 | #define CRX_ASK_VALVE_DEADZONE 21 |
jobuuu | 2:a1c0a37df760 | 37 | #define CRX_SET_VALVE_DEADZONE 121 |
jobuuu | 2:a1c0a37df760 | 38 | #define CRX_ASK_VELOCITY_COMP_GAIN 22 |
jobuuu | 2:a1c0a37df760 | 39 | #define CRX_SET_VELOCITY_COMP_GAIN 122 |
jobuuu | 2:a1c0a37df760 | 40 | #define CRX_ASK_COMPLIANCE_GAIN 23 |
jobuuu | 2:a1c0a37df760 | 41 | #define CRX_SET_COMPLIANCE_GAIN 123 |
jobuuu | 2:a1c0a37df760 | 42 | #define CRX_ASK_VALVE_FF 25 |
jobuuu | 2:a1c0a37df760 | 43 | #define CRX_SET_VALVE_FF 125 |
jobuuu | 2:a1c0a37df760 | 44 | #define CRX_ASK_BULK_MODULUS 26 |
jobuuu | 2:a1c0a37df760 | 45 | #define CRX_SET_BULK_MODULUS 126 |
jobuuu | 2:a1c0a37df760 | 46 | #define CRX_ASK_CHAMBER_VOLUME 27 |
jobuuu | 2:a1c0a37df760 | 47 | #define CRX_SET_CHAMBER_VOLUME 127 |
jobuuu | 2:a1c0a37df760 | 48 | #define CRX_ASK_PISTON_AREA 28 |
jobuuu | 2:a1c0a37df760 | 49 | #define CRX_SET_PISTON_AREA 128 |
jobuuu | 2:a1c0a37df760 | 50 | #define CRX_ASK_PRES 29 |
jobuuu | 2:a1c0a37df760 | 51 | #define CRX_SET_PRES 129 |
jobuuu | 2:a1c0a37df760 | 52 | #define CRX_ASK_ENC_LIMIT 30 |
jobuuu | 2:a1c0a37df760 | 53 | #define CRX_SET_ENC_LIMIT 130 |
jobuuu | 2:a1c0a37df760 | 54 | #define CRX_ASK_STROKE 31 |
jobuuu | 2:a1c0a37df760 | 55 | #define CRX_SET_STROKE 131 |
jobuuu | 2:a1c0a37df760 | 56 | #define CRX_ASK_VALVE_LIMIT 32 |
jobuuu | 2:a1c0a37df760 | 57 | #define CRX_SET_VALVE_LIMIT 132 |
jobuuu | 2:a1c0a37df760 | 58 | #define CRX_ASK_ENC_PULSE_PER_POSITION 33 |
jobuuu | 2:a1c0a37df760 | 59 | #define CRX_SET_ENC_PULSE_PER_POSITION 133 |
jobuuu | 2:a1c0a37df760 | 60 | #define CRX_ASK_TORQUE_SENSOR_PULSE_PER_TORQUE 34 |
jobuuu | 2:a1c0a37df760 | 61 | #define CRX_SET_TORQUE_SENSOR_PULSE_PER_TORQUE 134 |
jobuuu | 2:a1c0a37df760 | 62 | #define CRX_ASK_PRES_SENSOR_PULSE_PER_PRES 35 |
jobuuu | 2:a1c0a37df760 | 63 | #define CRX_SET_PRES_SENSOR_PULSE_PER_PRES 135 |
jobuuu | 2:a1c0a37df760 | 64 | #define CRX_ASK_FRICTION 36 |
jobuuu | 2:a1c0a37df760 | 65 | #define CRX_SET_FRICTION 136 |
jobuuu | 2:a1c0a37df760 | 66 | #define CRX_ASK_VALVE_GAIN_PLUS 37 |
jobuuu | 2:a1c0a37df760 | 67 | #define CRX_SET_VALVE_GAIN_PLUS 137 |
jobuuu | 2:a1c0a37df760 | 68 | #define CRX_ASK_VALVE_GAIN_MINUS 38 |
jobuuu | 2:a1c0a37df760 | 69 | #define CRX_SET_VALVE_GAIN_MINUS 138 |
jobuuu | 2:a1c0a37df760 | 70 | #define CRX_LOW_REF 139 |
jobuuu | 2:a1c0a37df760 | 71 | #define CRX_ASK_HOMEPOS_OFFSET 40 |
jobuuu | 2:a1c0a37df760 | 72 | #define CRX_SET_HOMEPOS_OFFSET 140 |
jobuuu | 2:a1c0a37df760 | 73 | #define CRX_ASK_HOMEPOS_VALVE_OPENING 41 |
jobuuu | 2:a1c0a37df760 | 74 | #define CRX_SET_HOMEPOS_VALVE_OPENING 141 |
jobuuu | 2:a1c0a37df760 | 75 | #define CRX_SET_ERR_CLEAR 150 |
jobuuu | 2:a1c0a37df760 | 76 | #define CRX_JUMP_STATUS 255 |
jobuuu | 2:a1c0a37df760 | 77 | |
jobuuu | 7:e9086c72bb22 | 78 | // CID_TX_INFO - TX INFO type |
jobuuu | 7:e9086c72bb22 | 79 | |
jobuuu | 7:e9086c72bb22 | 80 | #define CTX_SEND_INFO 0 |
jobuuu | 7:e9086c72bb22 | 81 | #define CTX_SEND_BNO 1 |
jobuuu | 7:e9086c72bb22 | 82 | #define CTX_SEND_OPERATING_MODE 2 |
jobuuu | 7:e9086c72bb22 | 83 | #define CTX_SEND_CAN_FREQ 6 |
jobuuu | 7:e9086c72bb22 | 84 | #define CTX_SEND_CONTROL_MODE 7 |
jobuuu | 7:e9086c72bb22 | 85 | #define CTX_SEND_JOINT_ENC_DIR 9 |
jobuuu | 7:e9086c72bb22 | 86 | #define CTX_SEND_VALVE_DIR 10 |
jobuuu | 7:e9086c72bb22 | 87 | #define CTX_SEND_VALVE_ENC_DIR 11 |
jobuuu | 7:e9086c72bb22 | 88 | #define CTX_SEND_VOLTAGE_SUPPLY 12 |
jobuuu | 7:e9086c72bb22 | 89 | #define CTX_SEND_VOLTAGE_VALVE 13 |
jobuuu | 7:e9086c72bb22 | 90 | #define CTX_SEND_PID_GAIN 20 |
jobuuu | 7:e9086c72bb22 | 91 | #define CTX_SEND_VALVE_DEADZONE 21 |
jobuuu | 7:e9086c72bb22 | 92 | #define CTX_SEND_VELOCITY_COMP_GAIN 22 |
jobuuu | 7:e9086c72bb22 | 93 | #define CTX_SEND_COMPLIANCE_GAIN 23 |
jobuuu | 7:e9086c72bb22 | 94 | #define CTX_SEND_VALVE_CNETER 24 |
jobuuu | 7:e9086c72bb22 | 95 | #define CTX_SEND_VALVE_FF 25 |
jobuuu | 7:e9086c72bb22 | 96 | #define CTX_SEND_BULK_MODULUS 26 |
jobuuu | 7:e9086c72bb22 | 97 | #define CTX_SEND_CHAMBER_VOLUME 27 |
jobuuu | 7:e9086c72bb22 | 98 | #define CTX_SEND_PISTON_AREA 28 |
jobuuu | 7:e9086c72bb22 | 99 | #define CTX_SEND_PRES 29 |
jobuuu | 7:e9086c72bb22 | 100 | #define CTX_SEND_ENC_LIMIT 30 |
jobuuu | 7:e9086c72bb22 | 101 | #define CTX_SEND_STROKE 31 |
jobuuu | 7:e9086c72bb22 | 102 | #define CTX_SEND_VALVE_LIMIT 32 |
jobuuu | 7:e9086c72bb22 | 103 | #define CTX_SEND_ENC_PULSE_PER_POSITION 33 |
jobuuu | 7:e9086c72bb22 | 104 | #define CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE 34 |
jobuuu | 7:e9086c72bb22 | 105 | #define CTX_SEND_PRES_SENSOR_PULSE_PER_BAR 35 |
jobuuu | 7:e9086c72bb22 | 106 | #define CTX_SEND_FRICTION 36 |
jobuuu | 7:e9086c72bb22 | 107 | #define CTX_SEND_VALVE_GAIN_PLUS 37 |
jobuuu | 7:e9086c72bb22 | 108 | #define CTX_SEND_VALVE_GAIN_MINUS 38 |
jobuuu | 7:e9086c72bb22 | 109 | #define CTX_SEND_REFENCE_MODE 39 |
jobuuu | 7:e9086c72bb22 | 110 | #define CTX_SEND_HOMEPOS_OFFSET 40 |
jobuuu | 7:e9086c72bb22 | 111 | #define CTX_SEND_HOMEPOS_VALVE_OPENING 41 |
jobuuu | 7:e9086c72bb22 | 112 | |
jobuuu | 2:a1c0a37df760 | 113 | // Information Transmission |
jobuuu | 4:58c8081de776 | 114 | //inline void CAN_TX_INFO(void); |
jobuuu | 4:58c8081de776 | 115 | //inline void CAN_TX_BNO(void); |
jobuuu | 4:58c8081de776 | 116 | //inline void CAN_TX_OPERATING_MODE(void); |
jobuuu | 4:58c8081de776 | 117 | //inline void CAN_TX_CAN_FREQ(void); |
jobuuu | 4:58c8081de776 | 118 | //inline void CAN_TX_CONTROL_MODE(void); |
jobuuu | 4:58c8081de776 | 119 | //inline void CAN_TX_JOINT_ENC_DIR(void); |
jobuuu | 4:58c8081de776 | 120 | //inline void CAN_TX_VALVE_DIR(void); |
jobuuu | 4:58c8081de776 | 121 | //inline void CAN_TX_VALVE_ENC_DIR(void); |
jobuuu | 4:58c8081de776 | 122 | //inline void CAN_TX_VOLTAGE_SUPPLY(void); |
jobuuu | 4:58c8081de776 | 123 | //inline void CAN_TX_VOLTAGE_VALVE(void); |
jobuuu | 4:58c8081de776 | 124 | //inline void CAN_TX_PID_GAIN(int t_type); |
jobuuu | 4:58c8081de776 | 125 | //inline void CAN_TX_VALVE_DEADZONE(void); |
jobuuu | 4:58c8081de776 | 126 | //inline void CAN_TX_ENC_PULSE_PER_POSITION(void); |
jobuuu | 4:58c8081de776 | 127 | //inline void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void); |
jobuuu | 4:58c8081de776 | 128 | //inline void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void); |
jobuuu | 4:58c8081de776 | 129 | //inline void CAN_TX_HOMEPOS_OFFSET(void); |
jobuuu | 2:a1c0a37df760 | 130 | |
jobuuu | 2:a1c0a37df760 | 131 | // Sensor & State Transmission |
jobuuu | 2:a1c0a37df760 | 132 | inline void CAN_TX_POSITION(long t_pos, long t_vel); |
jobuuu | 2:a1c0a37df760 | 133 | inline void CAN_TX_TORQUE(int16_t t_torque); |
jobuuu | 2:a1c0a37df760 | 134 | inline void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b); |
jobuuu | 2:a1c0a37df760 | 135 | inline void CAN_TX_PWM(int16_t t_pwm); |
jobuuu | 2:a1c0a37df760 | 136 | inline void CAN_TX_VALVE_POSITION(int16_t t_valve_pos); |
jobuuu | 2:a1c0a37df760 | 137 | |
jobuuu | 7:e9086c72bb22 | 138 | // Board Information Variables |
jobuuu | 7:e9086c72bb22 | 139 | extern int BNO; |
jobuuu | 7:e9086c72bb22 | 140 | extern int CONTROL_MODE; |
jobuuu | 7:e9086c72bb22 | 141 | extern double P_GAIN_JOINT_POSITION; |
jobuuu | 7:e9086c72bb22 | 142 | extern double I_GAIN_JOINT_POSITION; |
jobuuu | 7:e9086c72bb22 | 143 | extern double D_GAIN_JOINT_POSITION; |
jobuuu | 7:e9086c72bb22 | 144 | extern double P_GAIN_JOINT_TORQUE; |
jobuuu | 7:e9086c72bb22 | 145 | extern double I_GAIN_JOINT_TORQUE; |
jobuuu | 7:e9086c72bb22 | 146 | extern double D_GAIN_JOINT_TORQUE; |
jobuuu | 7:e9086c72bb22 | 147 | |
jobuuu | 7:e9086c72bb22 | 148 | class State |
jobuuu | 7:e9086c72bb22 | 149 | { |
jobuuu | 7:e9086c72bb22 | 150 | public: |
jobuuu | 7:e9086c72bb22 | 151 | double sen; |
jobuuu | 7:e9086c72bb22 | 152 | double ref; |
jobuuu | 7:e9086c72bb22 | 153 | double ref_old; |
jobuuu | 7:e9086c72bb22 | 154 | double ref_diff; |
jobuuu | 7:e9086c72bb22 | 155 | double err; |
jobuuu | 7:e9086c72bb22 | 156 | double err_int; |
jobuuu | 7:e9086c72bb22 | 157 | double err_old; |
jobuuu | 7:e9086c72bb22 | 158 | double err_diff; |
jobuuu | 7:e9086c72bb22 | 159 | public: |
jobuuu | 7:e9086c72bb22 | 160 | State(){ |
jobuuu | 7:e9086c72bb22 | 161 | sen = 0.0; |
jobuuu | 7:e9086c72bb22 | 162 | ref = 0.0; |
jobuuu | 7:e9086c72bb22 | 163 | ref_old = 0.0; |
jobuuu | 7:e9086c72bb22 | 164 | ref_diff = 0.0; |
jobuuu | 7:e9086c72bb22 | 165 | err = 0.0; |
jobuuu | 7:e9086c72bb22 | 166 | err_int = 0.0; |
jobuuu | 7:e9086c72bb22 | 167 | err_old = 0.0; |
jobuuu | 7:e9086c72bb22 | 168 | err_diff = 0.0; |
jobuuu | 7:e9086c72bb22 | 169 | } |
jobuuu | 7:e9086c72bb22 | 170 | }; |
jobuuu | 7:e9086c72bb22 | 171 | |
jobuuu | 7:e9086c72bb22 | 172 | extern State pos; |
jobuuu | 7:e9086c72bb22 | 173 | extern State vel; |
jobuuu | 7:e9086c72bb22 | 174 | extern State Vout; |
jobuuu | 7:e9086c72bb22 | 175 | extern State torq; |
jobuuu | 7:e9086c72bb22 | 176 | extern State pres_A; |
jobuuu | 7:e9086c72bb22 | 177 | extern State pres_B; |
jobuuu | 7:e9086c72bb22 | 178 | extern State cur; |
jobuuu | 7:e9086c72bb22 | 179 | |
jobuuu | 2:a1c0a37df760 | 180 | // CAN Receive Functions |
jobuuu | 2:a1c0a37df760 | 181 | void ReadCMD(); |
jobuuu | 2:a1c0a37df760 | 182 | void CAN_RX_HANDLER(); |
jobuuu | 2:a1c0a37df760 | 183 | |
jobuuu | 2:a1c0a37df760 | 184 | #endif |