2011

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Tue Nov 12 11:29:36 2019 +0000
Revision:
33:91b17819ec30
Parent:
32:4b8c0fedaf2c
Child:
36:a46e63505ed8
191112

Who changed what in which revision?

UserRevisionLine numberNew 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
Lightvalve 11:82d8768d7351 9 // INIT_CID
Lightvalve 11:82d8768d7351 10 #define INIT_CID_RX_CMD 100
Lightvalve 11:82d8768d7351 11 #define INIT_CID_RX_REF_POSITION 200
Lightvalve 11:82d8768d7351 12 #define INIT_CID_RX_REF_TORQUE 300
Lightvalve 11:82d8768d7351 13 #define INIT_CID_RX_REF_PRES_DIFF 400
Lightvalve 11:82d8768d7351 14 #define INIT_CID_RX_REF_VOUT 500
Lightvalve 11:82d8768d7351 15 #define INIT_CID_RX_REF_VALVE_POSITION 600
Lightvalve 14:8e7590227d22 16 #define INIT_CID_RX_REF_CURRENT 700
Lightvalve 11:82d8768d7351 17
Lightvalve 11:82d8768d7351 18 #define INIT_CID_TX_INFO 1100
Lightvalve 11:82d8768d7351 19 #define INIT_CID_TX_POSITION 1200
Lightvalve 11:82d8768d7351 20 #define INIT_CID_TX_TORQUE 1300
Lightvalve 11:82d8768d7351 21 #define INIT_CID_TX_PRES 1400
Lightvalve 11:82d8768d7351 22 #define INIT_CID_TX_VOUT 1500
Lightvalve 11:82d8768d7351 23 #define INIT_CID_TX_VALVE_POSITION 1600
Lightvalve 11:82d8768d7351 24
Lightvalve 11:82d8768d7351 25
jobuuu 2:a1c0a37df760 26 // CID_RX_CMD - RX CMD type
jobuuu 2:a1c0a37df760 27 #define CRX_ASK_INFO 0
jobuuu 2:a1c0a37df760 28 #define CRX_ASK_BNO 1
jobuuu 2:a1c0a37df760 29 #define CRX_SET_BNO 101
jobuuu 2:a1c0a37df760 30 #define CRX_ASK_OPERATING_MODE 2
jobuuu 2:a1c0a37df760 31 #define CRX_SET_OPERATING_MODE 102
jobuuu 2:a1c0a37df760 32 #define CRX_SET_ENC_ZERO 103
jobuuu 2:a1c0a37df760 33 #define CRX_SET_FET_ON 104
jobuuu 2:a1c0a37df760 34 #define CRX_SET_REF_UPDATE_ENABLE 105
jobuuu 2:a1c0a37df760 35 #define CRX_ASK_CAN_FREQ 6
jobuuu 2:a1c0a37df760 36 #define CRX_SET_CAN_FREQ 106
jobuuu 2:a1c0a37df760 37 #define CRX_ASK_CONTROL_MODE 7
jobuuu 2:a1c0a37df760 38 #define CRX_SET_CONTROL_MODE 107
jobuuu 2:a1c0a37df760 39 #define CRX_SET_DATA_REQUEST 108
jobuuu 2:a1c0a37df760 40 #define CRX_ASK_JOINT_ENC_DIR 9
jobuuu 2:a1c0a37df760 41 #define CRX_SET_JOINT_ENC_DIR 109
jobuuu 2:a1c0a37df760 42 #define CRX_ASK_VALVE_DIR 10
jobuuu 2:a1c0a37df760 43 #define CRX_SET_VALVE_DIR 110
jobuuu 2:a1c0a37df760 44 #define CRX_ASK_VALVE_ENC_DIR 11
jobuuu 2:a1c0a37df760 45 #define CRX_SET_VALVE_ENC_DIR 111
jobuuu 2:a1c0a37df760 46 #define CRX_ASK_VOLTAGE_SUPPLY 12
jobuuu 2:a1c0a37df760 47 #define CRX_SET_VOLTAGE_SUPPLY 112
jobuuu 2:a1c0a37df760 48 #define CRX_ASK_VOLTAGE_VALVE 13
jobuuu 2:a1c0a37df760 49 #define CRX_SET_VOLTAGE_VALVE 113
jobuuu 2:a1c0a37df760 50 #define CRX_SET_HOMEPOS 114
jobuuu 2:a1c0a37df760 51 #define CRX_ASK_PID_GAIN 20
jobuuu 2:a1c0a37df760 52 #define CRX_SET_PID_GAIN 120
jobuuu 2:a1c0a37df760 53 #define CRX_ASK_VALVE_DEADZONE 21
jobuuu 2:a1c0a37df760 54 #define CRX_SET_VALVE_DEADZONE 121
jobuuu 2:a1c0a37df760 55 #define CRX_ASK_VELOCITY_COMP_GAIN 22
jobuuu 2:a1c0a37df760 56 #define CRX_SET_VELOCITY_COMP_GAIN 122
jobuuu 2:a1c0a37df760 57 #define CRX_ASK_COMPLIANCE_GAIN 23
jobuuu 2:a1c0a37df760 58 #define CRX_SET_COMPLIANCE_GAIN 123
jobuuu 2:a1c0a37df760 59 #define CRX_ASK_VALVE_FF 25
jobuuu 2:a1c0a37df760 60 #define CRX_SET_VALVE_FF 125
jobuuu 2:a1c0a37df760 61 #define CRX_ASK_BULK_MODULUS 26
jobuuu 2:a1c0a37df760 62 #define CRX_SET_BULK_MODULUS 126
jobuuu 2:a1c0a37df760 63 #define CRX_ASK_CHAMBER_VOLUME 27
jobuuu 2:a1c0a37df760 64 #define CRX_SET_CHAMBER_VOLUME 127
jobuuu 2:a1c0a37df760 65 #define CRX_ASK_PISTON_AREA 28
jobuuu 2:a1c0a37df760 66 #define CRX_SET_PISTON_AREA 128
jobuuu 2:a1c0a37df760 67 #define CRX_ASK_PRES 29
jobuuu 2:a1c0a37df760 68 #define CRX_SET_PRES 129
jobuuu 2:a1c0a37df760 69 #define CRX_ASK_ENC_LIMIT 30
jobuuu 2:a1c0a37df760 70 #define CRX_SET_ENC_LIMIT 130
jobuuu 2:a1c0a37df760 71 #define CRX_ASK_STROKE 31
jobuuu 2:a1c0a37df760 72 #define CRX_SET_STROKE 131
jobuuu 2:a1c0a37df760 73 #define CRX_ASK_VALVE_LIMIT 32
jobuuu 2:a1c0a37df760 74 #define CRX_SET_VALVE_LIMIT 132
jobuuu 2:a1c0a37df760 75 #define CRX_ASK_ENC_PULSE_PER_POSITION 33
jobuuu 2:a1c0a37df760 76 #define CRX_SET_ENC_PULSE_PER_POSITION 133
jobuuu 2:a1c0a37df760 77 #define CRX_ASK_TORQUE_SENSOR_PULSE_PER_TORQUE 34
jobuuu 2:a1c0a37df760 78 #define CRX_SET_TORQUE_SENSOR_PULSE_PER_TORQUE 134
jobuuu 2:a1c0a37df760 79 #define CRX_ASK_PRES_SENSOR_PULSE_PER_PRES 35
jobuuu 2:a1c0a37df760 80 #define CRX_SET_PRES_SENSOR_PULSE_PER_PRES 135
jobuuu 2:a1c0a37df760 81 #define CRX_ASK_FRICTION 36
jobuuu 2:a1c0a37df760 82 #define CRX_SET_FRICTION 136
jobuuu 2:a1c0a37df760 83 #define CRX_ASK_VALVE_GAIN_PLUS 37
jobuuu 2:a1c0a37df760 84 #define CRX_SET_VALVE_GAIN_PLUS 137
jobuuu 2:a1c0a37df760 85 #define CRX_ASK_VALVE_GAIN_MINUS 38
jobuuu 2:a1c0a37df760 86 #define CRX_SET_VALVE_GAIN_MINUS 138
jobuuu 2:a1c0a37df760 87 #define CRX_LOW_REF 139
jobuuu 2:a1c0a37df760 88 #define CRX_ASK_HOMEPOS_OFFSET 40
jobuuu 2:a1c0a37df760 89 #define CRX_SET_HOMEPOS_OFFSET 140
jobuuu 2:a1c0a37df760 90 #define CRX_ASK_HOMEPOS_VALVE_OPENING 41
jobuuu 2:a1c0a37df760 91 #define CRX_SET_HOMEPOS_VALVE_OPENING 141
Lightvalve 11:82d8768d7351 92 #define CRX_ASK_DDV_VALVE_DEADZONE 42
Lightvalve 11:82d8768d7351 93 #define CRX_SET_DDV_VALVE_DEADZONE 142
Lightvalve 11:82d8768d7351 94 #define CRX_ASK_VALVE_PWM_VS_VALVE_POS 43
Lightvalve 11:82d8768d7351 95 #define CRX_ASK_VALVE_POS_VS_FLOWRATE 44
Lightvalve 11:82d8768d7351 96 #define CRX_ASK_VALVE_POS_NUM 45
jobuuu 2:a1c0a37df760 97 #define CRX_SET_ERR_CLEAR 150
Lightvalve 27:a2254a485f23 98 #define CRX_SET_ROM 146
Lightvalve 32:4b8c0fedaf2c 99 #define CRX_SET_VALVE_CENTER_OFFSET 147
Lightvalve 33:91b17819ec30 100 #define CRX_SET_VALVE_DZ_MINUS_OFFSET 148
Lightvalve 33:91b17819ec30 101 #define CRX_SET_VALVE_DZ_PLUS_OFFSET 149
jobuuu 2:a1c0a37df760 102 #define CRX_JUMP_STATUS 255
jobuuu 2:a1c0a37df760 103
jobuuu 7:e9086c72bb22 104 // CID_TX_INFO - TX INFO type
jobuuu 7:e9086c72bb22 105
jobuuu 7:e9086c72bb22 106 #define CTX_SEND_INFO 0
jobuuu 7:e9086c72bb22 107 #define CTX_SEND_BNO 1
jobuuu 7:e9086c72bb22 108 #define CTX_SEND_OPERATING_MODE 2
jobuuu 7:e9086c72bb22 109 #define CTX_SEND_CAN_FREQ 6
jobuuu 7:e9086c72bb22 110 #define CTX_SEND_CONTROL_MODE 7
jobuuu 7:e9086c72bb22 111 #define CTX_SEND_JOINT_ENC_DIR 9
jobuuu 7:e9086c72bb22 112 #define CTX_SEND_VALVE_DIR 10
jobuuu 7:e9086c72bb22 113 #define CTX_SEND_VALVE_ENC_DIR 11
jobuuu 7:e9086c72bb22 114 #define CTX_SEND_VOLTAGE_SUPPLY 12
jobuuu 7:e9086c72bb22 115 #define CTX_SEND_VOLTAGE_VALVE 13
jobuuu 7:e9086c72bb22 116 #define CTX_SEND_PID_GAIN 20
jobuuu 7:e9086c72bb22 117 #define CTX_SEND_VALVE_DEADZONE 21
jobuuu 7:e9086c72bb22 118 #define CTX_SEND_VELOCITY_COMP_GAIN 22
jobuuu 7:e9086c72bb22 119 #define CTX_SEND_COMPLIANCE_GAIN 23
jobuuu 7:e9086c72bb22 120 #define CTX_SEND_VALVE_CNETER 24
jobuuu 7:e9086c72bb22 121 #define CTX_SEND_VALVE_FF 25
jobuuu 7:e9086c72bb22 122 #define CTX_SEND_BULK_MODULUS 26
jobuuu 7:e9086c72bb22 123 #define CTX_SEND_CHAMBER_VOLUME 27
jobuuu 7:e9086c72bb22 124 #define CTX_SEND_PISTON_AREA 28
jobuuu 7:e9086c72bb22 125 #define CTX_SEND_PRES 29
jobuuu 7:e9086c72bb22 126 #define CTX_SEND_ENC_LIMIT 30
jobuuu 7:e9086c72bb22 127 #define CTX_SEND_STROKE 31
jobuuu 7:e9086c72bb22 128 #define CTX_SEND_VALVE_LIMIT 32
jobuuu 7:e9086c72bb22 129 #define CTX_SEND_ENC_PULSE_PER_POSITION 33
jobuuu 7:e9086c72bb22 130 #define CTX_SEND_TORQUE_SENSOR_PULSE_PER_TORQUE 34
jobuuu 7:e9086c72bb22 131 #define CTX_SEND_PRES_SENSOR_PULSE_PER_BAR 35
jobuuu 7:e9086c72bb22 132 #define CTX_SEND_FRICTION 36
jobuuu 7:e9086c72bb22 133 #define CTX_SEND_VALVE_GAIN_PLUS 37
jobuuu 7:e9086c72bb22 134 #define CTX_SEND_VALVE_GAIN_MINUS 38
jobuuu 7:e9086c72bb22 135 #define CTX_SEND_REFENCE_MODE 39
jobuuu 7:e9086c72bb22 136 #define CTX_SEND_HOMEPOS_OFFSET 40
jobuuu 7:e9086c72bb22 137 #define CTX_SEND_HOMEPOS_VALVE_OPENING 41
Lightvalve 11:82d8768d7351 138 #define CTX_SEND_DDV_VALVE_DEADZONE 42
Lightvalve 11:82d8768d7351 139 #define CTX_VALVE_PWM_VS_VALVE_POS 43
Lightvalve 11:82d8768d7351 140 #define CTX_VALVE_POS_VS_FLOWRATE 44
Lightvalve 11:82d8768d7351 141 #define CTX_VALVE_POS_NUM 45
Lightvalve 11:82d8768d7351 142
Lightvalve 11:82d8768d7351 143 // Sensor & State Transmission
Lightvalve 12:6f2531038ea4 144 void CAN_TX_POSITION(int32_t t_pos, int32_t t_vel);
Lightvalve 11:82d8768d7351 145 void CAN_TX_TORQUE(int16_t t_torque);
Lightvalve 11:82d8768d7351 146 void CAN_TX_PRES(int16_t t_pres_a, int16_t t_pres_b);
Lightvalve 11:82d8768d7351 147 void CAN_TX_PWM(int16_t t_pwm);
Lightvalve 27:a2254a485f23 148 void CAN_TX_VALVE_POSITION(int16_t t_valve_pos, int16_t t_ref_valve_pos, int16_t t_pwm);
jobuuu 7:e9086c72bb22 149
jobuuu 2:a1c0a37df760 150 // Information Transmission
Lightvalve 11:82d8768d7351 151 void CAN_TX_INFO(void);
Lightvalve 11:82d8768d7351 152 void CAN_TX_BNO(void);
Lightvalve 11:82d8768d7351 153 void CAN_TX_OPERATING_MODE(void);
Lightvalve 11:82d8768d7351 154 void CAN_TX_CAN_FREQ(void);
Lightvalve 11:82d8768d7351 155 void CAN_TX_CONTROL_MODE(void);
Lightvalve 11:82d8768d7351 156 void CAN_TX_JOINT_ENC_DIR(void);
Lightvalve 11:82d8768d7351 157 void CAN_TX_VALVE_DIR(void);
Lightvalve 11:82d8768d7351 158 void CAN_TX_VALVE_ENC_DIR(void);
Lightvalve 11:82d8768d7351 159 void CAN_TX_VOLTAGE_SUPPLY(void);
Lightvalve 11:82d8768d7351 160 void CAN_TX_VOLTAGE_VALVE(void);
Lightvalve 11:82d8768d7351 161 void CAN_TX_PID_GAIN(int t_type);
Lightvalve 11:82d8768d7351 162 void CAN_TX_VALVE_DEADZONE(void);
Lightvalve 11:82d8768d7351 163 void CAN_TX_VELOCITY_COMP_GAIN(void);
Lightvalve 11:82d8768d7351 164 void CAN_TX_COMPLIANCE_GAIN(void);
Lightvalve 11:82d8768d7351 165 void CAN_TX_VALVE_FF(void);
Lightvalve 11:82d8768d7351 166 void CAN_TX_BULK_MODULUS(void);
Lightvalve 11:82d8768d7351 167 void CAN_TX_CHAMBER_VOLUME(void);
Lightvalve 11:82d8768d7351 168 void CAN_TX_PISTON_AREA(void);
Lightvalve 11:82d8768d7351 169 void CAN_TX_PRES_A_AND_B(void);
Lightvalve 11:82d8768d7351 170 void CAN_TX_ENC_LIMIT(void);
Lightvalve 11:82d8768d7351 171 void CAN_TX_STROKE(void);
Lightvalve 11:82d8768d7351 172 void CAN_TX_VALVE_LIMIT(void);
Lightvalve 11:82d8768d7351 173 void CAN_TX_ENC_PULSE_PER_POSITION(void);
Lightvalve 11:82d8768d7351 174 void CAN_TX_TORQUE_SENSOR_PULSE_PER_TORQUE(void);
Lightvalve 11:82d8768d7351 175 void CAN_TX_PRES_SENSOR_PULSE_PER_PRES(void);
Lightvalve 11:82d8768d7351 176 void CAN_TX_FRICTION(void);
Lightvalve 11:82d8768d7351 177 void CAN_TX_VALVE_GAIN_PLUS(void);
Lightvalve 11:82d8768d7351 178 void CAN_TX_VALVE_GAIN_MINUS(void);
Lightvalve 11:82d8768d7351 179 void CAN_TX_REFENCE_MODE(void);
Lightvalve 11:82d8768d7351 180 void CAN_TX_HOMEPOS_OFFSET(void);
Lightvalve 11:82d8768d7351 181 void CAN_TX_HOMPOS_VALVE_OPENING(void);
Lightvalve 12:6f2531038ea4 182 void CAN_TX_VALVE_PWM_VS_VALVE_POS(int8_t canindex);
Lightvalve 11:82d8768d7351 183 void CAN_TX_DDV_VALVE_DEADZONE(void);
Lightvalve 12:6f2531038ea4 184 void CAN_TX_VALVE_POS_VS_FLOWRATE(int8_t canindex);
Lightvalve 11:82d8768d7351 185 void CAN_TX_VALVE_POS_NUM(void);
jobuuu 7:e9086c72bb22 186
jobuuu 7:e9086c72bb22 187 class State
jobuuu 7:e9086c72bb22 188 {
jobuuu 7:e9086c72bb22 189 public:
Lightvalve 30:8d561f16383b 190 float sen;
Lightvalve 30:8d561f16383b 191 float ref;
Lightvalve 30:8d561f16383b 192 float ref_old;
Lightvalve 30:8d561f16383b 193 float ref_diff;
Lightvalve 30:8d561f16383b 194 float ref_home_pos;
Lightvalve 30:8d561f16383b 195 float err;
Lightvalve 30:8d561f16383b 196 float err_int;
Lightvalve 30:8d561f16383b 197 float err_old;
Lightvalve 30:8d561f16383b 198 float err_diff;
Lightvalve 30:8d561f16383b 199 float err_sum;
jobuuu 7:e9086c72bb22 200 public:
jobuuu 7:e9086c72bb22 201 State(){
Lightvalve 30:8d561f16383b 202 sen = 0.0f;
Lightvalve 30:8d561f16383b 203 ref = 0.0f;
Lightvalve 30:8d561f16383b 204 ref_old = 0.0f;
Lightvalve 30:8d561f16383b 205 ref_diff = 0.0f;
Lightvalve 30:8d561f16383b 206 ref_home_pos = 0.0f;
Lightvalve 30:8d561f16383b 207 err = 0.0f;
Lightvalve 30:8d561f16383b 208 err_int = 0.0f;
Lightvalve 30:8d561f16383b 209 err_old = 0.0f;
Lightvalve 30:8d561f16383b 210 err_diff = 0.0f;
jobuuu 7:e9086c72bb22 211 }
jobuuu 7:e9086c72bb22 212 };
jobuuu 7:e9086c72bb22 213
jobuuu 7:e9086c72bb22 214 extern State pos;
jobuuu 7:e9086c72bb22 215 extern State vel;
jobuuu 7:e9086c72bb22 216 extern State Vout;
jobuuu 7:e9086c72bb22 217 extern State torq;
jobuuu 7:e9086c72bb22 218 extern State pres_A;
jobuuu 7:e9086c72bb22 219 extern State pres_B;
jobuuu 7:e9086c72bb22 220 extern State cur;
Lightvalve 14:8e7590227d22 221 extern State valve_pos;
Lightvalve 14:8e7590227d22 222
Lightvalve 14:8e7590227d22 223 extern State INIT_Vout;
Lightvalve 14:8e7590227d22 224 extern State INIT_Valve_Pos;
Lightvalve 14:8e7590227d22 225 extern State INIT_Pos;
Lightvalve 14:8e7590227d22 226 extern State INIT_torq;
jobuuu 7:e9086c72bb22 227
jobuuu 2:a1c0a37df760 228 // CAN Receive Functions
jobuuu 2:a1c0a37df760 229 void ReadCMD();
jobuuu 2:a1c0a37df760 230 void CAN_RX_HANDLER();
Lightvalve 11:82d8768d7351 231 void CAN_ID_INIT(void);
Lightvalve 11:82d8768d7351 232
Lightvalve 19:23b7c1ad8683 233 extern int ID_index_array[50];
jobuuu 2:a1c0a37df760 234
jobuuu 2:a1c0a37df760 235 #endif
Lightvalve 19:23b7c1ad8683 236
Lightvalve 30:8d561f16383b 237