![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
2011
function_utilities/function_utilities.cpp@13:747daba9cf59, 2019-08-27 (annotated)
- Committer:
- Lightvalve
- Date:
- Tue Aug 27 06:50:54 2019 +0000
- Revision:
- 13:747daba9cf59
- Parent:
- 12:6f2531038ea4
- Child:
- 14:8e7590227d22
1908271550
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lightvalve | 11:82d8768d7351 | 1 | #include "setting.h" |
Lightvalve | 11:82d8768d7351 | 2 | #include "SPI_EEP_ENC.h" |
Lightvalve | 11:82d8768d7351 | 3 | #include "function_utilities.h" |
Lightvalve | 11:82d8768d7351 | 4 | |
Lightvalve | 11:82d8768d7351 | 5 | /******************************************************************************* |
Lightvalve | 11:82d8768d7351 | 6 | * VARIABLE |
Lightvalve | 11:82d8768d7351 | 7 | ******************************************************************************/ |
Lightvalve | 11:82d8768d7351 | 8 | |
Lightvalve | 11:82d8768d7351 | 9 | // Board Information |
Lightvalve | 11:82d8768d7351 | 10 | uint8_t BNO = 0; |
Lightvalve | 11:82d8768d7351 | 11 | uint8_t CONTROL_MODE = 0; |
Lightvalve | 11:82d8768d7351 | 12 | uint8_t OPERATING_MODE = 0; |
Lightvalve | 11:82d8768d7351 | 13 | uint8_t SETTING_SWITCH = 0; |
Lightvalve | 11:82d8768d7351 | 14 | uint8_t SETTING_SWITCH_OLD = 0; |
Lightvalve | 11:82d8768d7351 | 15 | uint8_t REFERENCE_MODE = 0; |
Lightvalve | 11:82d8768d7351 | 16 | uint16_t CAN_FREQ = 5000; |
Lightvalve | 11:82d8768d7351 | 17 | uint8_t DIR_JOINT_ENC = 0; |
Lightvalve | 11:82d8768d7351 | 18 | uint8_t DIR_VALVE = 0; |
Lightvalve | 11:82d8768d7351 | 19 | uint8_t DIR_VALVE_ENC = 0; |
Lightvalve | 11:82d8768d7351 | 20 | |
Lightvalve | 11:82d8768d7351 | 21 | double SUPPLY_VOLTAGE = 12.0; |
Lightvalve | 11:82d8768d7351 | 22 | double VALVE_VOLTAGE_LIMIT = 5.0; |
Lightvalve | 11:82d8768d7351 | 23 | |
Lightvalve | 11:82d8768d7351 | 24 | double P_GAIN_VALVE_POSITION = 0.0; |
Lightvalve | 11:82d8768d7351 | 25 | double I_GAIN_VALVE_POSITION= 0.0; |
Lightvalve | 11:82d8768d7351 | 26 | double D_GAIN_VALVE_POSITION= 0.0; |
Lightvalve | 11:82d8768d7351 | 27 | double P_GAIN_JOINT_POSITION = 0.0; |
Lightvalve | 11:82d8768d7351 | 28 | double I_GAIN_JOINT_POSITION = 0.0; |
Lightvalve | 11:82d8768d7351 | 29 | double D_GAIN_JOINT_POSITION = 0.0; |
Lightvalve | 11:82d8768d7351 | 30 | double P_GAIN_JOINT_TORQUE = 0.0; |
Lightvalve | 11:82d8768d7351 | 31 | double I_GAIN_JOINT_TORQUE = 0.0; |
Lightvalve | 11:82d8768d7351 | 32 | double D_GAIN_JOINT_TORQUE = 0.0; |
Lightvalve | 11:82d8768d7351 | 33 | |
Lightvalve | 11:82d8768d7351 | 34 | int16_t VALVE_DEADZONE_PLUS; |
Lightvalve | 11:82d8768d7351 | 35 | int16_t VALVE_DEADZONE_MINUS; |
Lightvalve | 11:82d8768d7351 | 36 | |
Lightvalve | 11:82d8768d7351 | 37 | int16_t VELOCITY_COMP_GAIN; |
Lightvalve | 11:82d8768d7351 | 38 | int16_t COMPLIANCE_GAIN; |
Lightvalve | 11:82d8768d7351 | 39 | |
Lightvalve | 11:82d8768d7351 | 40 | int16_t VALVE_CENTER; |
Lightvalve | 11:82d8768d7351 | 41 | |
Lightvalve | 11:82d8768d7351 | 42 | int16_t VALVE_FF; |
Lightvalve | 11:82d8768d7351 | 43 | |
Lightvalve | 11:82d8768d7351 | 44 | int16_t BULK_MODULUS; |
Lightvalve | 11:82d8768d7351 | 45 | |
Lightvalve | 11:82d8768d7351 | 46 | int16_t CHAMBER_VOLUME_A; |
Lightvalve | 11:82d8768d7351 | 47 | int16_t CHAMBER_VOLUME_B; |
Lightvalve | 11:82d8768d7351 | 48 | |
Lightvalve | 11:82d8768d7351 | 49 | int16_t PISTON_AREA_A; |
Lightvalve | 11:82d8768d7351 | 50 | int16_t PISTON_AREA_B; |
Lightvalve | 11:82d8768d7351 | 51 | double PISTON_AREA_alpha; |
Lightvalve | 11:82d8768d7351 | 52 | |
Lightvalve | 11:82d8768d7351 | 53 | |
Lightvalve | 11:82d8768d7351 | 54 | int16_t PRES_SUPPLY; |
Lightvalve | 11:82d8768d7351 | 55 | int16_t PRES_RETURN; |
Lightvalve | 11:82d8768d7351 | 56 | |
Lightvalve | 11:82d8768d7351 | 57 | int16_t ENC_LIMIT_PLUS; |
Lightvalve | 11:82d8768d7351 | 58 | int16_t ENC_LIMIT_MINUS; |
Lightvalve | 11:82d8768d7351 | 59 | |
Lightvalve | 11:82d8768d7351 | 60 | int16_t STROKE; |
Lightvalve | 11:82d8768d7351 | 61 | |
Lightvalve | 11:82d8768d7351 | 62 | |
Lightvalve | 11:82d8768d7351 | 63 | int16_t VALVE_LIMIT_PLUS; |
Lightvalve | 11:82d8768d7351 | 64 | int16_t VALVE_LIMIT_MINUS; |
Lightvalve | 11:82d8768d7351 | 65 | |
Lightvalve | 11:82d8768d7351 | 66 | int16_t ENC_PULSE_PER_POSITION; |
Lightvalve | 11:82d8768d7351 | 67 | int16_t TORQUE_SENSOR_PULSE_PER_TORQUE; |
Lightvalve | 11:82d8768d7351 | 68 | double PRES_SENSOR_A_PULSE_PER_BAR; |
Lightvalve | 11:82d8768d7351 | 69 | double PRES_SENSOR_B_PULSE_PER_BAR; |
Lightvalve | 11:82d8768d7351 | 70 | |
Lightvalve | 11:82d8768d7351 | 71 | int HOMEPOS_OFFSET; |
Lightvalve | 11:82d8768d7351 | 72 | int HOMEPOS_VALVE_OPENING; |
Lightvalve | 11:82d8768d7351 | 73 | |
Lightvalve | 11:82d8768d7351 | 74 | double FRICTION; |
Lightvalve | 11:82d8768d7351 | 75 | double REF_PERIOD; |
Lightvalve | 11:82d8768d7351 | 76 | double REF_MAG; |
Lightvalve | 11:82d8768d7351 | 77 | int REF_NUM; |
Lightvalve | 11:82d8768d7351 | 78 | |
Lightvalve | 11:82d8768d7351 | 79 | |
Lightvalve | 11:82d8768d7351 | 80 | double DAC_REF; |
Lightvalve | 11:82d8768d7351 | 81 | double DAC_RESOL; |
Lightvalve | 11:82d8768d7351 | 82 | double PWM_RESOL; |
Lightvalve | 11:82d8768d7351 | 83 | |
Lightvalve | 11:82d8768d7351 | 84 | int REF_POSITION; |
Lightvalve | 11:82d8768d7351 | 85 | int REF_VELOCITY; |
Lightvalve | 11:82d8768d7351 | 86 | int16_t REF_TORQUE; |
Lightvalve | 11:82d8768d7351 | 87 | int16_t REF_PRES_DIFF; |
Lightvalve | 11:82d8768d7351 | 88 | int16_t REF_PWM; |
Lightvalve | 11:82d8768d7351 | 89 | int16_t REF_VALVE_POSITION; |
Lightvalve | 11:82d8768d7351 | 90 | |
Lightvalve | 11:82d8768d7351 | 91 | int REF_MOVE_TIME_5k; |
Lightvalve | 11:82d8768d7351 | 92 | int INIT_REF_PWM; |
Lightvalve | 11:82d8768d7351 | 93 | int INIT_REF_VALVE_POS; |
Lightvalve | 11:82d8768d7351 | 94 | int INIT_REF_POS; |
Lightvalve | 11:82d8768d7351 | 95 | int INIT_REF_VEL; |
Lightvalve | 11:82d8768d7351 | 96 | int INIT_REF_TORQUE; |
Lightvalve | 11:82d8768d7351 | 97 | int INIT_REF_PRES_DIFF; |
Lightvalve | 11:82d8768d7351 | 98 | |
Lightvalve | 11:82d8768d7351 | 99 | int CUR_POSITION; |
Lightvalve | 11:82d8768d7351 | 100 | int CUR_VELOCITY; |
Lightvalve | 11:82d8768d7351 | 101 | double CUR_TORQUE; |
Lightvalve | 11:82d8768d7351 | 102 | double CUR_PRES_A; |
Lightvalve | 11:82d8768d7351 | 103 | double CUR_PRES_B; |
Lightvalve | 11:82d8768d7351 | 104 | int CUR_PWM; |
Lightvalve | 11:82d8768d7351 | 105 | int CUR_VALVE_POSITION; |
Lightvalve | 11:82d8768d7351 | 106 | |
Lightvalve | 11:82d8768d7351 | 107 | unsigned int TMR2_COUNT_LED1; |
Lightvalve | 11:82d8768d7351 | 108 | unsigned int TMR2_COUNT_LED2; |
Lightvalve | 11:82d8768d7351 | 109 | unsigned int TMR2_COUNT_CAN_TX; |
Lightvalve | 11:82d8768d7351 | 110 | |
Lightvalve | 11:82d8768d7351 | 111 | int num_err; |
Lightvalve | 11:82d8768d7351 | 112 | int flag_err[8]; |
Lightvalve | 11:82d8768d7351 | 113 | int flag_err_old[8]; |
Lightvalve | 11:82d8768d7351 | 114 | int flag_err_rt; |
Lightvalve | 11:82d8768d7351 | 115 | |
Lightvalve | 11:82d8768d7351 | 116 | int flag_ref_enable; |
Lightvalve | 11:82d8768d7351 | 117 | |
Lightvalve | 11:82d8768d7351 | 118 | int flag_data_request[5]; |
Lightvalve | 11:82d8768d7351 | 119 | |
Lightvalve | 11:82d8768d7351 | 120 | //////////////////////////////////////////////////////////////////////////////// |
Lightvalve | 11:82d8768d7351 | 121 | ////////////////////////////// SEUNGHOON ADD /////////////////////////////////// |
Lightvalve | 11:82d8768d7351 | 122 | //////////////////////////////////////////////////////////////////////////////// |
Lightvalve | 11:82d8768d7351 | 123 | |
Lightvalve | 11:82d8768d7351 | 124 | double CUR_PRES_A_BAR; |
Lightvalve | 11:82d8768d7351 | 125 | double CUR_PRES_B_BAR; |
Lightvalve | 11:82d8768d7351 | 126 | double CUR_TORQUE_NM; |
Lightvalve | 11:82d8768d7351 | 127 | double CUR_TORQUE_NM_PRESS; |
Lightvalve | 11:82d8768d7351 | 128 | |
Lightvalve | 11:82d8768d7351 | 129 | double PRES_A_VREF; |
Lightvalve | 11:82d8768d7351 | 130 | double PRES_B_VREF; |
Lightvalve | 11:82d8768d7351 | 131 | double TORQUE_VREF; |
Lightvalve | 11:82d8768d7351 | 132 | |
Lightvalve | 11:82d8768d7351 | 133 | double VALVE_PWM_RAW; |
Lightvalve | 11:82d8768d7351 | 134 | double VALVE_PWM_RAW_FB; |
Lightvalve | 11:82d8768d7351 | 135 | double VALVE_PWM_RAW_FF; |
Lightvalve | 11:82d8768d7351 | 136 | int VALVE_PWM_VALVE_DZ; |
Lightvalve | 11:82d8768d7351 | 137 | int VALVE_INPUT_PWM; |
Lightvalve | 11:82d8768d7351 | 138 | |
Lightvalve | 11:82d8768d7351 | 139 | double VALVE_GAIN_LPM_PER_V[10]; |
Lightvalve | 11:82d8768d7351 | 140 | double VALVE_POS_VS_PWM[18]; |
Lightvalve | 11:82d8768d7351 | 141 | long JOINT_VEL[100]; |
Lightvalve | 11:82d8768d7351 | 142 | |
Lightvalve | 11:82d8768d7351 | 143 | int VALVE_MAX_POS; |
Lightvalve | 11:82d8768d7351 | 144 | int VALVE_MIN_POS; |
Lightvalve | 11:82d8768d7351 | 145 | int DDV_CENTER; |
Lightvalve | 11:82d8768d7351 | 146 | int VALVE_POS_NUM; |
Lightvalve | 11:82d8768d7351 | 147 | |
Lightvalve | 11:82d8768d7351 | 148 | int TMR2_COUNT_FINDHOME; |
Lightvalve | 11:82d8768d7351 | 149 | int TMR2_COUNT_FLOWRATE; |
Lightvalve | 11:82d8768d7351 | 150 | int TMR2_COUNT_DEADZONE; |
Lightvalve | 11:82d8768d7351 | 151 | int TMR2_COUNT_PRES_NULL; |
Lightvalve | 11:82d8768d7351 | 152 | int TMR2_COUNT_TORQUE_NULL; |
Lightvalve | 11:82d8768d7351 | 153 | int TMR2_COUNT_PRES_CALIB; |
Lightvalve | 11:82d8768d7351 | 154 | int TMR2_COUNT_REFERENCE; |
Lightvalve | 11:82d8768d7351 | 155 | int TMR2_COUNT_JOINT; |
Lightvalve | 11:82d8768d7351 | 156 | int TMR2_COUNT_ROTARY_FRIC_TUNE; |
Lightvalve | 11:82d8768d7351 | 157 | |
Lightvalve | 11:82d8768d7351 | 158 | bool FLAG_REFERENCE_VALVE_PWM; |
Lightvalve | 11:82d8768d7351 | 159 | bool FLAG_REFERENCE_VALVE_POSITION; |
Lightvalve | 11:82d8768d7351 | 160 | bool FLAG_REFERENCE_JOINT_POSITION; |
Lightvalve | 11:82d8768d7351 | 161 | bool FLAG_REFERENCE_JOINT_TORQUE; |
Lightvalve | 11:82d8768d7351 | 162 | bool FLAG_REFERENCE_PRES_DIFF; |
Lightvalve | 11:82d8768d7351 | 163 | |
Lightvalve | 11:82d8768d7351 | 164 | double TUNING_TIME; |
Lightvalve | 11:82d8768d7351 | 165 | |
Lightvalve | 11:82d8768d7351 | 166 | double REFERENCE_FREQ; |
Lightvalve | 11:82d8768d7351 | 167 | double REFERENCE_MAG; |
Lightvalve | 11:82d8768d7351 | 168 | |
Lightvalve | 11:82d8768d7351 | 169 | bool FLAG_FIND_HOME; |
Lightvalve | 11:82d8768d7351 | 170 | |
Lightvalve | 11:82d8768d7351 | 171 | int MODE_JUMP_STATUS; |
Lightvalve | 11:82d8768d7351 | 172 | enum _JUMP_STATUS { |
Lightvalve | 11:82d8768d7351 | 173 | JUMP_NO_ACT = 0, //0 |
Lightvalve | 11:82d8768d7351 | 174 | JUMP_START, //1 |
Lightvalve | 11:82d8768d7351 | 175 | JUMP_TAKEOFF, //2 |
Lightvalve | 11:82d8768d7351 | 176 | JUMP_FLYING, //3 |
Lightvalve | 11:82d8768d7351 | 177 | JUMP_LANDING, //4 |
Lightvalve | 11:82d8768d7351 | 178 | }; |
Lightvalve | 11:82d8768d7351 | 179 | |
Lightvalve | 13:747daba9cf59 | 180 | double CUR_PRES_DIFF_BAR = 0.0; |
Lightvalve | 13:747daba9cf59 | 181 | double CUR_PRES_A_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 182 | double CUR_PRES_B_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 183 | double CUR_PRES_A_mean = 0.0; |
Lightvalve | 13:747daba9cf59 | 184 | double CUR_PRES_B_mean = 0.0; |
Lightvalve | 13:747daba9cf59 | 185 | double CUR_TORQUE_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 186 | double CUR_TORQUE_mean = 0.0; |
Lightvalve | 13:747daba9cf59 | 187 | double PRES_A_NULL = 200.0; |
Lightvalve | 13:747daba9cf59 | 188 | double PRES_B_NULL = 200.0; |
Lightvalve | 13:747daba9cf59 | 189 | double TORQUE_NULL = 3900; |
Lightvalve | 11:82d8768d7351 | 190 | |
Lightvalve | 13:747daba9cf59 | 191 | double Ref_PWM = 0.0; |
Lightvalve | 13:747daba9cf59 | 192 | double Ref_Valve_Pos = 0.0; |
Lightvalve | 13:747daba9cf59 | 193 | double Ref_Joint_Pos = 0.0; |
Lightvalve | 13:747daba9cf59 | 194 | double Ref_Joint_Vel = 0.0; |
Lightvalve | 13:747daba9cf59 | 195 | double Ref_Joint_Torq = 0.0; |
Lightvalve | 13:747daba9cf59 | 196 | double Ref_Valve_Pos_Old = 0.0; |
Lightvalve | 11:82d8768d7351 | 197 | |
Lightvalve | 13:747daba9cf59 | 198 | int VALVE_ID_timer = 0; |
Lightvalve | 13:747daba9cf59 | 199 | int VALVE_DZ_timer = 0; |
Lightvalve | 13:747daba9cf59 | 200 | int VALVE_FR_timer = 0; |
Lightvalve | 13:747daba9cf59 | 201 | int VALVE_POS_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 202 | int JOINT_VEL_TMP = 0; |
Lightvalve | 13:747daba9cf59 | 203 | int DDV_POS_AVG = 0; |
Lightvalve | 13:747daba9cf59 | 204 | int VALVE_POS_AVG[100] = {0}; |
Lightvalve | 13:747daba9cf59 | 205 | int VALVE_POS_AVG_OLD = 0; |
Lightvalve | 13:747daba9cf59 | 206 | int data_num = 0; |
Lightvalve | 13:747daba9cf59 | 207 | int ID_index = 0; |
Lightvalve | 13:747daba9cf59 | 208 | int DZ_index = 1; |
Lightvalve | 13:747daba9cf59 | 209 | int ID_index_array[100] = {0}; |
Lightvalve | 13:747daba9cf59 | 210 | int FR_index_array[100] = {0}; |
Lightvalve | 13:747daba9cf59 | 211 | int first_check = 0; |
Lightvalve | 13:747daba9cf59 | 212 | double init_time = 0.0; |
Lightvalve | 13:747daba9cf59 | 213 | int VEL_POINT = 0; |
Lightvalve | 13:747daba9cf59 | 214 | int DZ_case = 0; |
Lightvalve | 13:747daba9cf59 | 215 | int START_POS = 0; |
Lightvalve | 13:747daba9cf59 | 216 | int FINAL_POS = 0; |
Lightvalve | 13:747daba9cf59 | 217 | int DZ_DIRECTION = 0; |
Lightvalve | 13:747daba9cf59 | 218 | int FIRST_DZ = 0; |
Lightvalve | 13:747daba9cf59 | 219 | int SECOND_DZ = 0; |
Lightvalve | 13:747daba9cf59 | 220 | int DZ_NUM = 0; |
Lightvalve | 13:747daba9cf59 | 221 | int one_period_end = 0; |
Lightvalve | 13:747daba9cf59 | 222 | double Ref_Vel_Test = 0.0; |
Lightvalve | 13:747daba9cf59 | 223 | long TMR2_FOR_SLOW_LOGGING = 0; |
Lightvalve | 13:747daba9cf59 | 224 | int velcount = 0; |
Lightvalve | 13:747daba9cf59 | 225 | char max_check = 0; |
Lightvalve | 13:747daba9cf59 | 226 | char min_check = 0; |
Lightvalve | 13:747daba9cf59 | 227 | |
Lightvalve | 13:747daba9cf59 | 228 | double valve_pos_err = 0.0, valve_pos_err_old = 0.0, valve_pos_err_diff = 0.0, valve_pos_err_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 229 | double joint_pos_err = 0.0, joint_pos_err_old = 0.0, joint_pos_err_diff = 0.0, joint_pos_err_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 230 | double joint_torq_err = 0.0, joint_torq_err_old = 0.0, joint_torq_err_diff = 0.0, joint_torq_err_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 231 | double VALVE_PWM_RAW_POS = 0.0, VALVE_PWM_RAW_TORQ = 0.0; |
Lightvalve | 13:747daba9cf59 | 232 | |
Lightvalve | 13:747daba9cf59 | 233 | double CUR_FLOWRATE = 0.0; |
Lightvalve | 13:747daba9cf59 | 234 | double VALVE_FF_VOLTAGE = 0.0; |
Lightvalve | 13:747daba9cf59 | 235 | |
Lightvalve | 13:747daba9cf59 | 236 | int pos_plus_end = 0; |
Lightvalve | 13:747daba9cf59 | 237 | int pos_minus_end = 0; |
Lightvalve | 13:747daba9cf59 | 238 | |
Lightvalve | 13:747daba9cf59 | 239 | bool need_enc_init = false; |
Lightvalve | 13:747daba9cf59 | 240 | |
Lightvalve | 13:747daba9cf59 | 241 | int temp_time = 0; |
Lightvalve | 13:747daba9cf59 | 242 | |
Lightvalve | 13:747daba9cf59 | 243 | double CUR_VELOCITY_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 244 | double temp_vel_sum = 0.0; |
Lightvalve | 13:747daba9cf59 | 245 | |
Lightvalve | 13:747daba9cf59 | 246 | int DZ_dir = 0; |
Lightvalve | 13:747daba9cf59 | 247 | int DZ_temp_cnt = 0; |
Lightvalve | 13:747daba9cf59 | 248 | int DZ_temp_cnt2 = 0; |
Lightvalve | 13:747daba9cf59 | 249 | int DZ_end = 2; |
Lightvalve | 13:747daba9cf59 | 250 | int flag_flowrate = 0; |
Lightvalve | 13:747daba9cf59 | 251 | int fl_temp_cnt = 0; |
Lightvalve | 13:747daba9cf59 | 252 | int fl_temp_cnt2 = 0; |
Lightvalve | 13:747daba9cf59 | 253 | int cur_vel_sum = 0; |
Lightvalve | 13:747daba9cf59 | 254 | |
Lightvalve | 13:747daba9cf59 | 255 | // find home |
Lightvalve | 13:747daba9cf59 | 256 | int CUR_VELOCITY_OLD = 0; |
Lightvalve | 13:747daba9cf59 | 257 | int cnt_findhome = 0; |
Lightvalve | 13:747daba9cf59 | 258 | int cnt_vel_findhome = 0; |
Lightvalve | 13:747daba9cf59 | 259 | int FINDHOME_VELOCITY = 0; |
Lightvalve | 13:747daba9cf59 | 260 | int FINDHOME_VELOCITY_OLD = 0; |
Lightvalve | 13:747daba9cf59 | 261 | int FINDHOME_POSITION = 0; |
Lightvalve | 13:747daba9cf59 | 262 | int FINDHOME_POSITION_OLD = 0; |
Lightvalve | 13:747daba9cf59 | 263 | |
Lightvalve | 13:747daba9cf59 | 264 | // valve gain |
Lightvalve | 13:747daba9cf59 | 265 | int check_vel_pos_init = 0; |
Lightvalve | 13:747daba9cf59 | 266 | int check_vel_pos_fin = 0; |
Lightvalve | 13:747daba9cf59 | 267 | int check_vel_pos_interv = 0; |
Lightvalve | 13:747daba9cf59 | 268 | int valve_gain_repeat_cnt = 0; |
Lightvalve | 13:747daba9cf59 | 269 | double VALVE_VOLTAGE = 0.0; |
Lightvalve | 13:747daba9cf59 | 270 | |
Lightvalve | 13:747daba9cf59 | 271 | double freq_fric_tune = 1.0; |
Lightvalve | 13:747daba9cf59 | 272 | |
Lightvalve | 13:747daba9cf59 | 273 | bool FLAG_VALVE_OUTPUT_CALIB = false; |
Lightvalve | 11:82d8768d7351 | 274 | |
Lightvalve | 11:82d8768d7351 | 275 | /******************************************************************************* |
Lightvalve | 11:82d8768d7351 | 276 | * General math functions |
Lightvalve | 11:82d8768d7351 | 277 | ******************************************************************************/ |
Lightvalve | 11:82d8768d7351 | 278 | |
Lightvalve | 11:82d8768d7351 | 279 | |
Lightvalve | 11:82d8768d7351 | 280 | double dabs(double tx) { |
Lightvalve | 11:82d8768d7351 | 281 | if (tx >= 0.0) |
Lightvalve | 11:82d8768d7351 | 282 | return tx; |
Lightvalve | 11:82d8768d7351 | 283 | else |
Lightvalve | 11:82d8768d7351 | 284 | return -tx; |
Lightvalve | 11:82d8768d7351 | 285 | } |
Lightvalve | 11:82d8768d7351 | 286 | |
Lightvalve | 11:82d8768d7351 | 287 | double change_int_to_efloat(int input) { |
Lightvalve | 11:82d8768d7351 | 288 | int i = 0; |
Lightvalve | 11:82d8768d7351 | 289 | |
Lightvalve | 11:82d8768d7351 | 290 | double output = 0; |
Lightvalve | 11:82d8768d7351 | 291 | int vn = (int) ((double) input / 10.); |
Lightvalve | 11:82d8768d7351 | 292 | int en = input % 10; |
Lightvalve | 11:82d8768d7351 | 293 | |
Lightvalve | 11:82d8768d7351 | 294 | double temp = 1.; |
Lightvalve | 11:82d8768d7351 | 295 | for (i = 0; i < en; i++) |
Lightvalve | 11:82d8768d7351 | 296 | temp *= 0.1; |
Lightvalve | 11:82d8768d7351 | 297 | |
Lightvalve | 11:82d8768d7351 | 298 | output = (double) vn*temp; |
Lightvalve | 11:82d8768d7351 | 299 | return output; |
Lightvalve | 11:82d8768d7351 | 300 | } |
Lightvalve | 11:82d8768d7351 | 301 | |
Lightvalve | 11:82d8768d7351 | 302 | void make_delay(void) { |
Lightvalve | 11:82d8768d7351 | 303 | int i = 0; |
Lightvalve | 11:82d8768d7351 | 304 | |
Lightvalve | 11:82d8768d7351 | 305 | for (i = 0; i < 100000; i++) { |
Lightvalve | 11:82d8768d7351 | 306 | ; |
Lightvalve | 11:82d8768d7351 | 307 | } |
Lightvalve | 11:82d8768d7351 | 308 | |
Lightvalve | 11:82d8768d7351 | 309 | } |
Lightvalve | 11:82d8768d7351 | 310 | |
Lightvalve | 11:82d8768d7351 | 311 | |
Lightvalve | 11:82d8768d7351 | 312 | /******************************************************************************* |
Lightvalve | 11:82d8768d7351 | 313 | * ROM functions |
Lightvalve | 11:82d8768d7351 | 314 | ******************************************************************************/ |
Lightvalve | 11:82d8768d7351 | 315 | void ROM_INIT_DATA(void) { |
Lightvalve | 11:82d8768d7351 | 316 | static int16_t temp_check_num = LATEST_VERSION; |
Lightvalve | 11:82d8768d7351 | 317 | spi_eeprom_ready(); |
Lightvalve | 11:82d8768d7351 | 318 | if (spi_eeprom_read(RID_IS_FIRST) != temp_check_num) { |
Lightvalve | 11:82d8768d7351 | 319 | spi_eeprom_ready(); |
Lightvalve | 11:82d8768d7351 | 320 | spi_eeprom_write(RID_IS_FIRST, temp_check_num); |
Lightvalve | 11:82d8768d7351 | 321 | ROM_RESET_DATA(); |
Lightvalve | 11:82d8768d7351 | 322 | } |
Lightvalve | 11:82d8768d7351 | 323 | ROM_CALL_DATA(); |
Lightvalve | 11:82d8768d7351 | 324 | } |
Lightvalve | 11:82d8768d7351 | 325 | |
Lightvalve | 11:82d8768d7351 | 326 | void ROM_RESET_DATA(void) { |
Lightvalve | 11:82d8768d7351 | 327 | |
Lightvalve | 11:82d8768d7351 | 328 | spi_eeprom_write(RID_BNO, (int16_t) BNO); |
Lightvalve | 11:82d8768d7351 | 329 | spi_eeprom_write(RID_OPERATING_MODE, (int16_t) OPERATING_MODE); |
Lightvalve | 11:82d8768d7351 | 330 | spi_eeprom_write(RID_CAN_FREQ, (int16_t) CAN_FREQ); |
Lightvalve | 11:82d8768d7351 | 331 | spi_eeprom_write(RID_JOINT_ENC_DIR, (int16_t) DIR_JOINT_ENC); |
Lightvalve | 11:82d8768d7351 | 332 | spi_eeprom_write(RID_VALVE_DIR, (int16_t) DIR_VALVE); |
Lightvalve | 11:82d8768d7351 | 333 | spi_eeprom_write(RID_VALVE_ENC_DIR, (int16_t) DIR_VALVE_ENC); |
Lightvalve | 11:82d8768d7351 | 334 | spi_eeprom_write(RID_VOLATGE_SUPPLY, (int16_t) (SUPPLY_VOLTAGE * 10.)); |
Lightvalve | 11:82d8768d7351 | 335 | spi_eeprom_write(RID_VOLTAGE_VALVE, (int16_t) (VALVE_VOLTAGE_LIMIT * 10.)); |
Lightvalve | 11:82d8768d7351 | 336 | spi_eeprom_write(RID_P_GAIN_VALVE_POSITION, (int16_t) P_GAIN_VALVE_POSITION); |
Lightvalve | 11:82d8768d7351 | 337 | spi_eeprom_write(RID_I_GAIN_VALVE_POSITION, (int16_t) I_GAIN_VALVE_POSITION); |
Lightvalve | 11:82d8768d7351 | 338 | spi_eeprom_write(RID_D_GAIN_VALVE_POSITION, (int16_t) D_GAIN_VALVE_POSITION); |
Lightvalve | 11:82d8768d7351 | 339 | spi_eeprom_write(RID_P_GAIN_JOINT_POSITION, (int16_t) P_GAIN_JOINT_POSITION); |
Lightvalve | 11:82d8768d7351 | 340 | spi_eeprom_write(RID_I_GAIN_JOINT_POSITION, (int16_t) I_GAIN_JOINT_POSITION); |
Lightvalve | 11:82d8768d7351 | 341 | spi_eeprom_write(RID_D_GAIN_JOINT_POSITION, (int16_t) D_GAIN_JOINT_POSITION); |
Lightvalve | 11:82d8768d7351 | 342 | spi_eeprom_write(RID_P_GAIN_JOINT_TORQUE, (int16_t) P_GAIN_JOINT_TORQUE); |
Lightvalve | 11:82d8768d7351 | 343 | spi_eeprom_write(RID_I_GAIN_JOINT_TORQUE, (int16_t) I_GAIN_JOINT_TORQUE); |
Lightvalve | 11:82d8768d7351 | 344 | spi_eeprom_write(RID_D_GAIN_JOINT_TORQUE, (int16_t) D_GAIN_JOINT_TORQUE); |
Lightvalve | 11:82d8768d7351 | 345 | spi_eeprom_write(RID_VALVE_DEADZONE_PLUS, (int16_t) (VALVE_DEADZONE_PLUS)); |
Lightvalve | 11:82d8768d7351 | 346 | spi_eeprom_write(RID_VALVE_DEADZONE_MINUS, (int16_t) (VALVE_DEADZONE_MINUS)); |
Lightvalve | 11:82d8768d7351 | 347 | spi_eeprom_write(RID_VELOCITY_COMP_GAIN, (int16_t) VELOCITY_COMP_GAIN); |
Lightvalve | 11:82d8768d7351 | 348 | spi_eeprom_write(RID_COMPLIANCE_GAIN, (int16_t) COMPLIANCE_GAIN); |
Lightvalve | 11:82d8768d7351 | 349 | spi_eeprom_write(RID_VALVE_CNETER, (int16_t) VALVE_CENTER); |
Lightvalve | 11:82d8768d7351 | 350 | spi_eeprom_write(RID_VALVE_FF, (int16_t) VALVE_FF); |
Lightvalve | 11:82d8768d7351 | 351 | spi_eeprom_write(RID_BULK_MODULUS, (int16_t) BULK_MODULUS); |
Lightvalve | 11:82d8768d7351 | 352 | spi_eeprom_write(RID_CHAMBER_VOLUME_A, (int16_t) CHAMBER_VOLUME_A); |
Lightvalve | 11:82d8768d7351 | 353 | spi_eeprom_write(RID_CHAMBER_VOLUME_B, (int16_t) CHAMBER_VOLUME_B); |
Lightvalve | 11:82d8768d7351 | 354 | spi_eeprom_write(RID_PISTON_AREA_A, (int16_t) PISTON_AREA_A); |
Lightvalve | 11:82d8768d7351 | 355 | spi_eeprom_write(RID_PISTON_AREA_B, (int16_t) PISTON_AREA_B); |
Lightvalve | 11:82d8768d7351 | 356 | spi_eeprom_write(RID_PRES_SUPPLY, (int16_t) PRES_SUPPLY); |
Lightvalve | 11:82d8768d7351 | 357 | spi_eeprom_write(RID_PRES_RETURN, (int16_t) PRES_RETURN); |
Lightvalve | 11:82d8768d7351 | 358 | spi_eeprom_write(RID_ENC_LIMIT_MINUS, (int16_t) ENC_LIMIT_MINUS); |
Lightvalve | 11:82d8768d7351 | 359 | spi_eeprom_write(RID_ENC_LIMIT_PLUS, (int16_t) ENC_LIMIT_PLUS); |
Lightvalve | 11:82d8768d7351 | 360 | spi_eeprom_write(RID_STROKE, (int16_t) STROKE); |
Lightvalve | 11:82d8768d7351 | 361 | spi_eeprom_write(RID_VALVE_LIMIT_MINUS, (int16_t) VALVE_LIMIT_MINUS); |
Lightvalve | 11:82d8768d7351 | 362 | spi_eeprom_write(RID_VALVE_LIMIT_PLUS, (int16_t) VALVE_LIMIT_PLUS); |
Lightvalve | 11:82d8768d7351 | 363 | spi_eeprom_write(RID_ENC_PULSE_PER_POSITION, (int16_t) ENC_PULSE_PER_POSITION); |
Lightvalve | 11:82d8768d7351 | 364 | spi_eeprom_write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE, (int16_t) TORQUE_SENSOR_PULSE_PER_TORQUE); |
Lightvalve | 11:82d8768d7351 | 365 | spi_eeprom_write(RID_PRES_SENSOR_A_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_A_PULSE_PER_BAR * 100.)); |
Lightvalve | 11:82d8768d7351 | 366 | spi_eeprom_write(RID_PRES_SENSOR_B_PULSE_PER_BAR, (int16_t) (PRES_SENSOR_B_PULSE_PER_BAR * 100.)); |
Lightvalve | 11:82d8768d7351 | 367 | spi_eeprom_write(RID_FRICTION, (int16_t) (FRICTION * 10.)); |
Lightvalve | 11:82d8768d7351 | 368 | spi_eeprom_write(RID_HOMEPOS_OFFSET, (int16_t) HOMEPOS_OFFSET); |
Lightvalve | 11:82d8768d7351 | 369 | spi_eeprom_write(RID_HOMEPOS_VALVE_OPENING, (int16_t) HOMEPOS_VALVE_OPENING); |
Lightvalve | 11:82d8768d7351 | 370 | spi_eeprom_write(RID_TORQUE_SENSOR_VREF, (int16_t) (TORQUE_VREF * 1000.)); |
Lightvalve | 11:82d8768d7351 | 371 | spi_eeprom_write(RID_PRES_A_SENSOR_VREF, (int16_t) (PRES_A_VREF * 1000.)); |
Lightvalve | 11:82d8768d7351 | 372 | spi_eeprom_write(RID_PRES_B_SENSOR_VREF, (int16_t) (PRES_B_VREF * 1000.)); |
Lightvalve | 11:82d8768d7351 | 373 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[0] * 100.)); |
Lightvalve | 11:82d8768d7351 | 374 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[2] * 100.)); |
Lightvalve | 11:82d8768d7351 | 375 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[4] * 100.)); |
Lightvalve | 11:82d8768d7351 | 376 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[6] * 100.)); |
Lightvalve | 11:82d8768d7351 | 377 | spi_eeprom_write(RID_VALVE_GAIN_PLUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[8] * 100.)); |
Lightvalve | 11:82d8768d7351 | 378 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_1, (int16_t) (VALVE_GAIN_LPM_PER_V[1] * 100.)); |
Lightvalve | 11:82d8768d7351 | 379 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_2, (int16_t) (VALVE_GAIN_LPM_PER_V[3] * 100.)); |
Lightvalve | 11:82d8768d7351 | 380 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_3, (int16_t) (VALVE_GAIN_LPM_PER_V[5] * 100.)); |
Lightvalve | 11:82d8768d7351 | 381 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_4, (int16_t) (VALVE_GAIN_LPM_PER_V[7] * 100.)); |
Lightvalve | 11:82d8768d7351 | 382 | spi_eeprom_write(RID_VALVE_GAIN_MINUS_5, (int16_t) (VALVE_GAIN_LPM_PER_V[9] * 100.)); |
Lightvalve | 11:82d8768d7351 | 383 | |
Lightvalve | 11:82d8768d7351 | 384 | |
Lightvalve | 11:82d8768d7351 | 385 | } |
Lightvalve | 11:82d8768d7351 | 386 | |
Lightvalve | 11:82d8768d7351 | 387 | void ROM_CALL_DATA(void) { |
Lightvalve | 11:82d8768d7351 | 388 | int i = 0; |
Lightvalve | 11:82d8768d7351 | 389 | BNO = spi_eeprom_read(RID_BNO); |
Lightvalve | 11:82d8768d7351 | 390 | BNO = 10; |
Lightvalve | 11:82d8768d7351 | 391 | OPERATING_MODE = spi_eeprom_read(RID_OPERATING_MODE); |
Lightvalve | 11:82d8768d7351 | 392 | CAN_FREQ = spi_eeprom_read(RID_CAN_FREQ); |
Lightvalve | 11:82d8768d7351 | 393 | |
Lightvalve | 11:82d8768d7351 | 394 | DIR_JOINT_ENC = spi_eeprom_read(RID_JOINT_ENC_DIR); |
Lightvalve | 11:82d8768d7351 | 395 | DIR_VALVE = spi_eeprom_read(RID_VALVE_DIR); |
Lightvalve | 11:82d8768d7351 | 396 | DIR_VALVE_ENC = spi_eeprom_read(RID_VALVE_ENC_DIR); |
Lightvalve | 11:82d8768d7351 | 397 | |
Lightvalve | 11:82d8768d7351 | 398 | SUPPLY_VOLTAGE = (double) spi_eeprom_read(RID_VOLATGE_SUPPLY) / 10.; |
Lightvalve | 11:82d8768d7351 | 399 | VALVE_VOLTAGE_LIMIT = (double) spi_eeprom_read(RID_VOLTAGE_VALVE) / 10.; |
Lightvalve | 11:82d8768d7351 | 400 | |
Lightvalve | 11:82d8768d7351 | 401 | P_GAIN_VALVE_POSITION = spi_eeprom_read(RID_P_GAIN_VALVE_POSITION); |
Lightvalve | 11:82d8768d7351 | 402 | I_GAIN_VALVE_POSITION = spi_eeprom_read(RID_I_GAIN_VALVE_POSITION); |
Lightvalve | 11:82d8768d7351 | 403 | D_GAIN_VALVE_POSITION = spi_eeprom_read(RID_D_GAIN_VALVE_POSITION); |
Lightvalve | 11:82d8768d7351 | 404 | |
Lightvalve | 11:82d8768d7351 | 405 | P_GAIN_JOINT_POSITION = spi_eeprom_read(RID_P_GAIN_JOINT_POSITION); |
Lightvalve | 11:82d8768d7351 | 406 | I_GAIN_JOINT_POSITION = spi_eeprom_read(RID_I_GAIN_JOINT_POSITION); |
Lightvalve | 11:82d8768d7351 | 407 | D_GAIN_JOINT_POSITION = spi_eeprom_read(RID_D_GAIN_JOINT_POSITION); |
Lightvalve | 11:82d8768d7351 | 408 | |
Lightvalve | 11:82d8768d7351 | 409 | P_GAIN_JOINT_TORQUE = spi_eeprom_read(RID_P_GAIN_JOINT_TORQUE); |
Lightvalve | 11:82d8768d7351 | 410 | I_GAIN_JOINT_TORQUE = spi_eeprom_read(RID_I_GAIN_JOINT_TORQUE); |
Lightvalve | 11:82d8768d7351 | 411 | D_GAIN_JOINT_TORQUE = spi_eeprom_read(RID_D_GAIN_JOINT_TORQUE); |
Lightvalve | 11:82d8768d7351 | 412 | |
Lightvalve | 11:82d8768d7351 | 413 | VALVE_DEADZONE_PLUS = spi_eeprom_read(RID_VALVE_DEADZONE_PLUS); |
Lightvalve | 11:82d8768d7351 | 414 | VALVE_DEADZONE_MINUS = spi_eeprom_read(RID_VALVE_DEADZONE_MINUS); |
Lightvalve | 11:82d8768d7351 | 415 | |
Lightvalve | 11:82d8768d7351 | 416 | VELOCITY_COMP_GAIN = spi_eeprom_read(RID_VELOCITY_COMP_GAIN); |
Lightvalve | 11:82d8768d7351 | 417 | COMPLIANCE_GAIN = spi_eeprom_read(RID_COMPLIANCE_GAIN); |
Lightvalve | 11:82d8768d7351 | 418 | |
Lightvalve | 11:82d8768d7351 | 419 | VALVE_CENTER = spi_eeprom_read(RID_VALVE_CNETER); |
Lightvalve | 11:82d8768d7351 | 420 | VALVE_FF = spi_eeprom_read(RID_VALVE_FF); |
Lightvalve | 11:82d8768d7351 | 421 | BULK_MODULUS = spi_eeprom_read(RID_BULK_MODULUS); |
Lightvalve | 11:82d8768d7351 | 422 | |
Lightvalve | 11:82d8768d7351 | 423 | CHAMBER_VOLUME_A = spi_eeprom_read(RID_CHAMBER_VOLUME_A); |
Lightvalve | 11:82d8768d7351 | 424 | CHAMBER_VOLUME_B = spi_eeprom_read(RID_CHAMBER_VOLUME_B); |
Lightvalve | 11:82d8768d7351 | 425 | |
Lightvalve | 11:82d8768d7351 | 426 | PISTON_AREA_A = spi_eeprom_read(RID_PISTON_AREA_A); |
Lightvalve | 11:82d8768d7351 | 427 | PISTON_AREA_B = spi_eeprom_read(RID_PISTON_AREA_B); |
Lightvalve | 11:82d8768d7351 | 428 | PISTON_AREA_alpha = (double)PISTON_AREA_B/(double)PISTON_AREA_A; |
Lightvalve | 11:82d8768d7351 | 429 | |
Lightvalve | 11:82d8768d7351 | 430 | PRES_SUPPLY = spi_eeprom_read(RID_PRES_SUPPLY); |
Lightvalve | 11:82d8768d7351 | 431 | PRES_RETURN = spi_eeprom_read(RID_PRES_RETURN); |
Lightvalve | 11:82d8768d7351 | 432 | |
Lightvalve | 11:82d8768d7351 | 433 | ENC_LIMIT_MINUS = spi_eeprom_read(RID_ENC_LIMIT_MINUS); |
Lightvalve | 11:82d8768d7351 | 434 | ENC_LIMIT_PLUS = spi_eeprom_read(RID_ENC_LIMIT_PLUS); |
Lightvalve | 11:82d8768d7351 | 435 | |
Lightvalve | 11:82d8768d7351 | 436 | STROKE = spi_eeprom_read(RID_STROKE); |
Lightvalve | 11:82d8768d7351 | 437 | |
Lightvalve | 11:82d8768d7351 | 438 | VALVE_LIMIT_MINUS = spi_eeprom_read(RID_VALVE_LIMIT_MINUS); |
Lightvalve | 11:82d8768d7351 | 439 | VALVE_LIMIT_PLUS = spi_eeprom_read(RID_VALVE_LIMIT_PLUS); |
Lightvalve | 11:82d8768d7351 | 440 | |
Lightvalve | 11:82d8768d7351 | 441 | ENC_PULSE_PER_POSITION = spi_eeprom_read(RID_ENC_PULSE_PER_POSITION); |
Lightvalve | 11:82d8768d7351 | 442 | TORQUE_SENSOR_PULSE_PER_TORQUE = spi_eeprom_read(RID_TORQUE_SENSOR_PULSE_PER_TORQUE); |
Lightvalve | 11:82d8768d7351 | 443 | PRES_SENSOR_A_PULSE_PER_BAR = (double) spi_eeprom_read(RID_PRES_SENSOR_A_PULSE_PER_BAR) * 0.01; |
Lightvalve | 11:82d8768d7351 | 444 | PRES_SENSOR_B_PULSE_PER_BAR = (double) spi_eeprom_read(RID_PRES_SENSOR_B_PULSE_PER_BAR) * 0.01; |
Lightvalve | 11:82d8768d7351 | 445 | |
Lightvalve | 11:82d8768d7351 | 446 | FRICTION = (double) spi_eeprom_read(RID_FRICTION) / 10.; |
Lightvalve | 11:82d8768d7351 | 447 | HOMEPOS_OFFSET = (int) spi_eeprom_read(RID_HOMEPOS_OFFSET); |
Lightvalve | 11:82d8768d7351 | 448 | HOMEPOS_VALVE_OPENING = (int) spi_eeprom_read(RID_HOMEPOS_VALVE_OPENING); |
Lightvalve | 11:82d8768d7351 | 449 | |
Lightvalve | 11:82d8768d7351 | 450 | TORQUE_VREF = (double) spi_eeprom_read(RID_TORQUE_SENSOR_VREF) / 1000.; |
Lightvalve | 11:82d8768d7351 | 451 | |
Lightvalve | 11:82d8768d7351 | 452 | PRES_A_VREF = (double) spi_eeprom_read(RID_PRES_A_SENSOR_VREF) / 1000.; |
Lightvalve | 11:82d8768d7351 | 453 | PRES_B_VREF = (double) spi_eeprom_read(RID_PRES_B_SENSOR_VREF) / 1000.; |
Lightvalve | 11:82d8768d7351 | 454 | |
Lightvalve | 11:82d8768d7351 | 455 | VALVE_GAIN_LPM_PER_V[0] = (double) spi_eeprom_read(RID_VALVE_GAIN_PLUS_1) / 100.; |
Lightvalve | 11:82d8768d7351 | 456 | VALVE_GAIN_LPM_PER_V[2] = (double) spi_eeprom_read(RID_VALVE_GAIN_PLUS_2) / 100.; |
Lightvalve | 11:82d8768d7351 | 457 | VALVE_GAIN_LPM_PER_V[4] = (double) spi_eeprom_read(RID_VALVE_GAIN_PLUS_3) / 100.; |
Lightvalve | 11:82d8768d7351 | 458 | VALVE_GAIN_LPM_PER_V[6] = (double) spi_eeprom_read(RID_VALVE_GAIN_PLUS_4) / 100.; |
Lightvalve | 11:82d8768d7351 | 459 | VALVE_GAIN_LPM_PER_V[8] = (double) spi_eeprom_read(RID_VALVE_GAIN_PLUS_5) / 100.; |
Lightvalve | 11:82d8768d7351 | 460 | VALVE_GAIN_LPM_PER_V[1] = (double) spi_eeprom_read(RID_VALVE_GAIN_MINUS_1) / 100.; |
Lightvalve | 11:82d8768d7351 | 461 | VALVE_GAIN_LPM_PER_V[3] = (double) spi_eeprom_read(RID_VALVE_GAIN_MINUS_2) / 100.; |
Lightvalve | 11:82d8768d7351 | 462 | VALVE_GAIN_LPM_PER_V[5] = (double) spi_eeprom_read(RID_VALVE_GAIN_MINUS_3) / 100.; |
Lightvalve | 11:82d8768d7351 | 463 | VALVE_GAIN_LPM_PER_V[7] = (double) spi_eeprom_read(RID_VALVE_GAIN_MINUS_4) / 100.; |
Lightvalve | 11:82d8768d7351 | 464 | VALVE_GAIN_LPM_PER_V[9] = (double) spi_eeprom_read(RID_VALVE_GAIN_MINUS_5) / 100.; |
Lightvalve | 11:82d8768d7351 | 465 | |
Lightvalve | 11:82d8768d7351 | 466 | for(i=0; i<18; i++) |
Lightvalve | 11:82d8768d7351 | 467 | { |
Lightvalve | 11:82d8768d7351 | 468 | VALVE_POS_VS_PWM[i] = (double) spi_eeprom_read(RID_VALVE_POS_VS_PWM_0 + i); |
Lightvalve | 11:82d8768d7351 | 469 | } |
Lightvalve | 11:82d8768d7351 | 470 | for(i=0; i<100; i++) |
Lightvalve | 11:82d8768d7351 | 471 | { |
Lightvalve | 12:6f2531038ea4 | 472 | JOINT_VEL[i] = (int32_t) ( (spi_eeprom_read(RID_VALVE_POS_VS_FLOWRATE_0 + i) & 0xFFFF) | ((spi_eeprom_read(RID_VALVE_POS_VS_FLOWRATE_0_1 + i) & 0xFFFF) << 16)); |
Lightvalve | 11:82d8768d7351 | 473 | } |
Lightvalve | 11:82d8768d7351 | 474 | |
Lightvalve | 11:82d8768d7351 | 475 | VALVE_MAX_POS = (int) spi_eeprom_read(RID_VALVE_MAX_POS); |
Lightvalve | 11:82d8768d7351 | 476 | VALVE_MIN_POS = (int) spi_eeprom_read(RID_VALVE_MIN_POS); |
Lightvalve | 11:82d8768d7351 | 477 | DDV_CENTER = (int) spi_eeprom_read(RID_DDV_CNETER); |
Lightvalve | 11:82d8768d7351 | 478 | |
Lightvalve | 11:82d8768d7351 | 479 | VALVE_POS_NUM = (int) spi_eeprom_read(RID_VALVE_POS_NUM); |
Lightvalve | 11:82d8768d7351 | 480 | |
Lightvalve | 11:82d8768d7351 | 481 | } |
Lightvalve | 11:82d8768d7351 | 482 | |
Lightvalve | 11:82d8768d7351 | 483 | /******************************************************************************* |
Lightvalve | 11:82d8768d7351 | 484 | * ENCODER functions |
Lightvalve | 11:82d8768d7351 | 485 | ******************************************************************************/ |
Lightvalve | 11:82d8768d7351 | 486 | // A-KHA |
Lightvalve | 11:82d8768d7351 | 487 | #define KF_G1_11 0.083920206005350 |
Lightvalve | 11:82d8768d7351 | 488 | #define KF_G1_12 0.000013905329560 |
Lightvalve | 11:82d8768d7351 | 489 | #define KF_G1_21 -0.000575742328210 |
Lightvalve | 11:82d8768d7351 | 490 | #define KF_G1_22 0.799999939711725 |
Lightvalve | 11:82d8768d7351 | 491 | // K |
Lightvalve | 11:82d8768d7351 | 492 | #define KF_G2_11 0.916079793994650 |
Lightvalve | 11:82d8768d7351 | 493 | #define KF_G2_12 0.000002878711641 |
Lightvalve | 11:82d8768d7351 | 494 | #define KF_G2_21 0.000575742328210 |
Lightvalve | 11:82d8768d7351 | 495 | #define KF_G2_22 0.199999945139809 |
Lightvalve | 11:82d8768d7351 | 496 | |
Lightvalve | 11:82d8768d7351 | 497 | double KF_Y_11 = 0.; |
Lightvalve | 11:82d8768d7351 | 498 | double KF_Y_21 = 0.; |
Lightvalve | 11:82d8768d7351 | 499 | double KF_X_11 = 0.; |
Lightvalve | 11:82d8768d7351 | 500 | double KF_X_21 = 0.; |
Lightvalve | 11:82d8768d7351 | 501 | |
Lightvalve | 11:82d8768d7351 | 502 | long ENC_pos_old = 0, ENC_pos_cur = 0, ENC_pos_diff = 0; |
Lightvalve | 11:82d8768d7351 | 503 | long ENC_RAW = 0, ENC_VEL_RAW = 0, ENC_VEL_KF = 0; |
Lightvalve | 11:82d8768d7351 | 504 | long enc_offset = 0; |
Lightvalve | 11:82d8768d7351 | 505 | |
Lightvalve | 11:82d8768d7351 | 506 | void ENC_UPDATE(void) { |
Lightvalve | 11:82d8768d7351 | 507 | |
Lightvalve | 11:82d8768d7351 | 508 | ENC_pos_cur = spi_enc_read(); |
Lightvalve | 11:82d8768d7351 | 509 | ENC_pos_diff = ENC_pos_cur - ENC_pos_old; |
Lightvalve | 11:82d8768d7351 | 510 | |
Lightvalve | 11:82d8768d7351 | 511 | if (ENC_pos_diff > 1300 || ENC_pos_diff<-1300) { |
Lightvalve | 11:82d8768d7351 | 512 | //MOT_E_STOP(0); |
Lightvalve | 11:82d8768d7351 | 513 | } |
Lightvalve | 11:82d8768d7351 | 514 | |
Lightvalve | 12:6f2531038ea4 | 515 | ENC_VEL_RAW = (int32_t) (ENC_pos_diff * TMR_FREQ_5k); |
Lightvalve | 11:82d8768d7351 | 516 | |
Lightvalve | 11:82d8768d7351 | 517 | KF_Y_11 = ENC_pos_cur; |
Lightvalve | 11:82d8768d7351 | 518 | KF_Y_21 = ENC_VEL_RAW; |
Lightvalve | 11:82d8768d7351 | 519 | KF_X_11 = KF_G1_11 * KF_X_11 + KF_G1_12 * KF_X_21 + KF_G2_11 * KF_Y_11 + KF_G2_12*KF_Y_21; |
Lightvalve | 11:82d8768d7351 | 520 | KF_X_21 = KF_G1_21 * KF_X_11 + KF_G1_22 * KF_X_21 + KF_G2_21 * KF_Y_11 + KF_G2_22*KF_Y_21; |
Lightvalve | 12:6f2531038ea4 | 521 | ENC_VEL_KF = (int32_t) KF_X_21; |
Lightvalve | 11:82d8768d7351 | 522 | |
Lightvalve | 11:82d8768d7351 | 523 | CUR_POSITION = (DIR_JOINT_ENC) * ENC_pos_cur + enc_offset; |
Lightvalve | 11:82d8768d7351 | 524 | // CUR_POSITION = (DIR_JOINT_ENC) * ENC_pos_cur; |
Lightvalve | 11:82d8768d7351 | 525 | CUR_VELOCITY = (DIR_JOINT_ENC) * ENC_VEL_KF; |
Lightvalve | 11:82d8768d7351 | 526 | |
Lightvalve | 11:82d8768d7351 | 527 | // CUR_POSITION = ENC_pos_cur; |
Lightvalve | 11:82d8768d7351 | 528 | // CUR_VELOCITY = ENC_VEL_KF; |
Lightvalve | 11:82d8768d7351 | 529 | |
Lightvalve | 11:82d8768d7351 | 530 | ENC_pos_old = ENC_pos_cur; |
Lightvalve | 11:82d8768d7351 | 531 | } |
Lightvalve | 11:82d8768d7351 | 532 | |
Lightvalve | 11:82d8768d7351 | 533 | void ENC_SET_ZERO(void) { |
Lightvalve | 11:82d8768d7351 | 534 | |
Lightvalve | 11:82d8768d7351 | 535 | spi_enc_set_clear(); |
Lightvalve | 11:82d8768d7351 | 536 | CUR_POSITION = 0; |
Lightvalve | 11:82d8768d7351 | 537 | ENC_pos_old = ENC_pos_cur = 0; |
Lightvalve | 11:82d8768d7351 | 538 | |
Lightvalve | 11:82d8768d7351 | 539 | } |
Lightvalve | 11:82d8768d7351 | 540 | |
Lightvalve | 13:747daba9cf59 | 541 | void ENC_SET(int32_t value_e) { |
Lightvalve | 11:82d8768d7351 | 542 | spi_enc_set_clear(); |
Lightvalve | 13:747daba9cf59 | 543 | enc_offset = value_e; |
Lightvalve | 13:747daba9cf59 | 544 | CUR_POSITION = value_e; |
Lightvalve | 13:747daba9cf59 | 545 | ENC_pos_old = ENC_pos_cur = value_e; |
Lightvalve | 11:82d8768d7351 | 546 | |
Lightvalve | 11:82d8768d7351 | 547 | } |