for learning

Dependencies:   mbed FastPWM

Committer:
Lightvalve
Date:
Wed Nov 18 12:03:39 2020 +0000
Revision:
170:42c938a40313
Parent:
169:645207e160ca
Child:
173:68c7914679ec
201118-1

Who changed what in which revision?

UserRevisionLine numberNew 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 14:8e7590227d22 4 #include "function_CAN.h"
Lightvalve 16:903b5a4433b4 5 #include "stm32f4xx_flash.h"
Lightvalve 16:903b5a4433b4 6 #include "FlashWriter.h"
Lightvalve 16:903b5a4433b4 7
Lightvalve 16:903b5a4433b4 8 int Rom_Sector = 6;
Lightvalve 16:903b5a4433b4 9 //FlashWriter writer(6);//2부터 7까지 되는듯 아마 sector
Lightvalve 16:903b5a4433b4 10
Lightvalve 11:82d8768d7351 11 /*******************************************************************************
Lightvalve 11:82d8768d7351 12 * VARIABLE
Lightvalve 11:82d8768d7351 13 ******************************************************************************/
Lightvalve 11:82d8768d7351 14
Lightvalve 34:bb2ca2fc2a8e 15 // Board Information
Lightvalve 11:82d8768d7351 16 uint8_t BNO = 0;
Lightvalve 11:82d8768d7351 17 uint8_t CONTROL_MODE = 0;
Lightvalve 57:f4819de54e7a 18 uint8_t OPERATING_MODE = 0; // (00 : Moog & Rot, 01 : Moog & Lin, 10 : KNR & Rot, 11 : KNR & Lin, 101 : SW & Lin)
Lightvalve 52:8ea76864368a 19 uint8_t SENSING_MODE = 0; // (0 : torque, 1: pressure)
Lightvalve 57:f4819de54e7a 20 uint8_t CONTROL_UTILITY_MODE = 0;
Lightvalve 52:8ea76864368a 21 uint8_t CURRENT_CONTROL_MODE = 0; // (0 : pwm, 1 : current control)
Lightvalve 52:8ea76864368a 22 uint8_t FLAG_VALVE_DEADZONE = 0;
Lightvalve 11:82d8768d7351 23 uint8_t REFERENCE_MODE = 0;
Lightvalve 54:647072f5307a 24 int16_t CAN_FREQ = 500;
Lightvalve 17:1865016ca2e7 25 int16_t DIR_JOINT_ENC = 0;
Lightvalve 17:1865016ca2e7 26 int16_t DIR_VALVE = 0;
Lightvalve 17:1865016ca2e7 27 int16_t DIR_VALVE_ENC = 0;
Lightvalve 11:82d8768d7351 28
Lightvalve 49:e7bcfc244d40 29 float SUPPLY_VOLTAGE = 12.0f;
Lightvalve 49:e7bcfc244d40 30 float VALVE_VOLTAGE_LIMIT = 12.0f; //v
Lightvalve 11:82d8768d7351 31
Lightvalve 30:8d561f16383b 32 float P_GAIN_VALVE_POSITION = 0.0f;
Lightvalve 30:8d561f16383b 33 float I_GAIN_VALVE_POSITION= 0.0f;
Lightvalve 30:8d561f16383b 34 float D_GAIN_VALVE_POSITION= 0.0f;
Lightvalve 30:8d561f16383b 35 float P_GAIN_JOINT_POSITION = 0.0f;
Lightvalve 30:8d561f16383b 36 float I_GAIN_JOINT_POSITION = 0.0f;
Lightvalve 30:8d561f16383b 37 float D_GAIN_JOINT_POSITION = 0.0f;
Lightvalve 30:8d561f16383b 38 float P_GAIN_JOINT_TORQUE = 0.0f;
Lightvalve 72:3436ce769b1e 39 float I_GAIN_JOINT_TORQUE = 0.0f;
Lightvalve 72:3436ce769b1e 40 float D_GAIN_JOINT_TORQUE = 0.0f;
Lightvalve 72:3436ce769b1e 41 float P_GAIN_JOINT_TORQUE_FF = 0.0f;
Lightvalve 72:3436ce769b1e 42 float I_GAIN_JOINT_TORQUE_FF = 0.0f;
Lightvalve 72:3436ce769b1e 43 float D_GAIN_JOINT_TORQUE_FF = 0.0f;
Lightvalve 11:82d8768d7351 44
Lightvalve 46:2694daea349b 45 int16_t K_SPRING = 0.0;
Lightvalve 46:2694daea349b 46 int16_t D_DAMPER = 0.0;
Lightvalve 72:3436ce769b1e 47
Lightvalve 54:647072f5307a 48 int16_t flag_delay_test = 0;
Lightvalve 46:2694daea349b 49
Lightvalve 36:a46e63505ed8 50 //float P_GAIN_VALVE_POSITION_OPP = 0.0f;
Lightvalve 36:a46e63505ed8 51 //float I_GAIN_VALVE_POSITION_OPP= 0.0f;
Lightvalve 36:a46e63505ed8 52 //float D_GAIN_VALVE_POSITION_OPP= 0.0f;
Lightvalve 36:a46e63505ed8 53 //float P_GAIN_JOINT_POSITION_OPP = 0.0f;
Lightvalve 36:a46e63505ed8 54 //float I_GAIN_JOINT_POSITION_OPP = 0.0f;
Lightvalve 36:a46e63505ed8 55 //float D_GAIN_JOINT_POSITION_OPP = 0.0f;
Lightvalve 36:a46e63505ed8 56 //float P_GAIN_JOINT_TORQUE_OPP = 0.0f;
Lightvalve 36:a46e63505ed8 57 //float I_GAIN_JOINT_TORQUE_OPP = 0.0;
Lightvalve 36:a46e63505ed8 58 //float D_GAIN_JOINT_TORQUE_OPP = 0.0;
Lightvalve 36:a46e63505ed8 59
Lightvalve 33:91b17819ec30 60 float VALVE_DEADZONE_PLUS;
Lightvalve 33:91b17819ec30 61 float VALVE_DEADZONE_MINUS;
Lightvalve 11:82d8768d7351 62
Lightvalve 11:82d8768d7351 63 int16_t VELOCITY_COMP_GAIN;
Lightvalve 11:82d8768d7351 64 int16_t COMPLIANCE_GAIN;
Lightvalve 11:82d8768d7351 65
Lightvalve 11:82d8768d7351 66 int16_t VALVE_CENTER;
Lightvalve 11:82d8768d7351 67
Lightvalve 11:82d8768d7351 68 int16_t VALVE_FF;
Lightvalve 11:82d8768d7351 69
Lightvalve 11:82d8768d7351 70 int16_t BULK_MODULUS;
Lightvalve 11:82d8768d7351 71
Lightvalve 11:82d8768d7351 72 int16_t CHAMBER_VOLUME_A;
Lightvalve 11:82d8768d7351 73 int16_t CHAMBER_VOLUME_B;
Lightvalve 11:82d8768d7351 74
Lightvalve 11:82d8768d7351 75 int16_t PISTON_AREA_A;
Lightvalve 11:82d8768d7351 76 int16_t PISTON_AREA_B;
Lightvalve 30:8d561f16383b 77 float PISTON_AREA_alpha;
Lightvalve 57:f4819de54e7a 78 float alpha3 = 1.0f;
Lightvalve 11:82d8768d7351 79
Lightvalve 11:82d8768d7351 80
Lightvalve 11:82d8768d7351 81 int16_t PRES_SUPPLY;
Lightvalve 11:82d8768d7351 82 int16_t PRES_RETURN;
Lightvalve 11:82d8768d7351 83
Lightvalve 11:82d8768d7351 84 int16_t ENC_LIMIT_PLUS;
Lightvalve 11:82d8768d7351 85 int16_t ENC_LIMIT_MINUS;
Lightvalve 11:82d8768d7351 86
Lightvalve 11:82d8768d7351 87 int16_t STROKE;
Lightvalve 11:82d8768d7351 88
Lightvalve 133:22ab22818e01 89 float Amm = 236.4f;
Lightvalve 133:22ab22818e01 90 float beta = 1300000000.0f;
Lightvalve 133:22ab22818e01 91 float Ps = 10000000.0f; //100bar = 100*10^5 Pa
Lightvalve 133:22ab22818e01 92 float Pt = 0.0f; // 0bar = 0Pa
Lightvalve 133:22ab22818e01 93 //float Kv = 0.00000002635f; // Q = Kv*xv*sqrt(Ps-Pa) => 100bar full opening 5LPM (full opening : xv = 1) [unit] m^3.5/kg^0.5
Lightvalve 133:22ab22818e01 94 float gamma_hat = 1075.0f; // Kv*beta*A/(sqrt(2)*V) 0.00000002635f * 1300000000.0f * / (sqrt(2.0f)*(1256.6f + 236.4f * 39.75f) * 0.000000001f / 2) [unit] m^3.5/kg^0.5
Lightvalve 170:42c938a40313 95 float V_adapt = 0.0000053f; // (1256.6f + 236.4f * 39.75f) * 0.000000001f / 2
Lightvalve 133:22ab22818e01 96 float x_4_des_old = 0.0f;
Lightvalve 11:82d8768d7351 97
Lightvalve 57:f4819de54e7a 98 //int16_t VALVE_LIMIT_PLUS;
Lightvalve 57:f4819de54e7a 99 //int16_t VALVE_LIMIT_MINUS;
Lightvalve 11:82d8768d7351 100
Lightvalve 48:889798ff9329 101 float ENC_PULSE_PER_POSITION;
Lightvalve 48:889798ff9329 102 float TORQUE_SENSOR_PULSE_PER_TORQUE;
Lightvalve 30:8d561f16383b 103 float PRES_SENSOR_A_PULSE_PER_BAR = 4096.0f / 200.0f;
Lightvalve 30:8d561f16383b 104 float PRES_SENSOR_B_PULSE_PER_BAR = 4096.0f / 200.0f;
Lightvalve 11:82d8768d7351 105
Lightvalve 11:82d8768d7351 106 int HOMEPOS_OFFSET;
Lightvalve 11:82d8768d7351 107 int HOMEPOS_VALVE_OPENING;
Lightvalve 11:82d8768d7351 108
Lightvalve 30:8d561f16383b 109 float FRICTION;
Lightvalve 30:8d561f16383b 110 float REF_PERIOD;
Lightvalve 30:8d561f16383b 111 float REF_MAG;
Lightvalve 11:82d8768d7351 112 int REF_NUM;
Lightvalve 11:82d8768d7351 113
Lightvalve 11:82d8768d7351 114
Lightvalve 30:8d561f16383b 115 float DAC_REF;
Lightvalve 30:8d561f16383b 116 float DAC_RESOL;
Lightvalve 11:82d8768d7351 117
Lightvalve 11:82d8768d7351 118 int REF_POSITION;
Lightvalve 11:82d8768d7351 119 int REF_VELOCITY;
Lightvalve 11:82d8768d7351 120 int16_t REF_TORQUE;
Lightvalve 11:82d8768d7351 121 int16_t REF_PRES_DIFF;
Lightvalve 11:82d8768d7351 122 int16_t REF_PWM;
Lightvalve 11:82d8768d7351 123 int16_t REF_VALVE_POSITION;
Lightvalve 14:8e7590227d22 124 int16_t REF_CURRENT;
Lightvalve 11:82d8768d7351 125
Lightvalve 11:82d8768d7351 126 int REF_MOVE_TIME_5k;
Lightvalve 11:82d8768d7351 127 int INIT_REF_PWM;
Lightvalve 11:82d8768d7351 128 int INIT_REF_VALVE_POS;
Lightvalve 11:82d8768d7351 129 int INIT_REF_POS;
Lightvalve 11:82d8768d7351 130 int INIT_REF_VEL;
Lightvalve 11:82d8768d7351 131 int INIT_REF_TORQUE;
Lightvalve 11:82d8768d7351 132 int INIT_REF_PRES_DIFF;
Lightvalve 14:8e7590227d22 133 int INIT_REF_CURRENT;
Lightvalve 11:82d8768d7351 134
Lightvalve 11:82d8768d7351 135 int CUR_POSITION;
Lightvalve 11:82d8768d7351 136 int CUR_VELOCITY;
Lightvalve 30:8d561f16383b 137 float CUR_TORQUE;
Lightvalve 30:8d561f16383b 138 float CUR_PRES_A;
Lightvalve 30:8d561f16383b 139 float CUR_PRES_B;
Lightvalve 11:82d8768d7351 140 int CUR_VALVE_POSITION;
Lightvalve 11:82d8768d7351 141
Lightvalve 11:82d8768d7351 142 unsigned int TMR2_COUNT_LED1;
Lightvalve 11:82d8768d7351 143 unsigned int TMR2_COUNT_LED2;
Lightvalve 54:647072f5307a 144 unsigned int TMR2_COUNT_CAN_TX = 0;
Lightvalve 54:647072f5307a 145 unsigned int TMR3_COUNT_TEST = 0;
Lightvalve 11:82d8768d7351 146
Lightvalve 11:82d8768d7351 147 int num_err;
Lightvalve 11:82d8768d7351 148 int flag_err[8];
Lightvalve 11:82d8768d7351 149 int flag_err_old[8];
Lightvalve 11:82d8768d7351 150 int flag_err_rt;
Lightvalve 11:82d8768d7351 151
Lightvalve 11:82d8768d7351 152 int flag_ref_enable;
Lightvalve 11:82d8768d7351 153
Lightvalve 11:82d8768d7351 154 int flag_data_request[5];
Lightvalve 11:82d8768d7351 155
Lightvalve 45:35fa6884d0c6 156 int MODE_POS_FT_TRANS = 0;
Lightvalve 66:a8e6799dbce3 157 int NN_Control_Flag = 0;
Lightvalve 45:35fa6884d0c6 158
Lightvalve 169:645207e160ca 159 int cnt_buffer = 0;
Lightvalve 169:645207e160ca 160
Lightvalve 57:f4819de54e7a 161 float CUR_CURRENT_mA = 0.0f;
Lightvalve 57:f4819de54e7a 162 float CUR_PRES_A_BAR = 0.0f;
Lightvalve 57:f4819de54e7a 163 float CUR_PRES_B_BAR = 0.0f;
Lightvalve 57:f4819de54e7a 164 float CUR_TORQUE_NM = 0.0f;
Lightvalve 57:f4819de54e7a 165 float CUR_TORQUE_NM_PRESS = 0.0f;
Lightvalve 11:82d8768d7351 166
Lightvalve 57:f4819de54e7a 167 float PRES_A_VREF = 0.0f;
Lightvalve 57:f4819de54e7a 168 float PRES_B_VREF = 0.0f;
Lightvalve 57:f4819de54e7a 169 float TORQUE_VREF = 0.0f;
Lightvalve 11:82d8768d7351 170
Lightvalve 57:f4819de54e7a 171 float VALVE_PWM_RAW_FB = 0.0f;
Lightvalve 57:f4819de54e7a 172 float VALVE_PWM_RAW_FF = 0.0f;
Lightvalve 57:f4819de54e7a 173 float VALVE_PWM_RAW = 0.0f;
Lightvalve 57:f4819de54e7a 174 int VALVE_PWM_VALVE_DZ = 0;
Lightvalve 11:82d8768d7351 175
Lightvalve 30:8d561f16383b 176 float VALVE_GAIN_LPM_PER_V[10];
Lightvalve 30:8d561f16383b 177 float VALVE_POS_VS_PWM[25];
Lightvalve 11:82d8768d7351 178 long JOINT_VEL[100];
Lightvalve 11:82d8768d7351 179
Lightvalve 11:82d8768d7351 180 int VALVE_MAX_POS;
Lightvalve 11:82d8768d7351 181 int VALVE_MIN_POS;
Lightvalve 11:82d8768d7351 182 int VALVE_POS_NUM;
Lightvalve 32:4b8c0fedaf2c 183 float VALVE_CENTER_OFFSET;
Lightvalve 33:91b17819ec30 184 float VALVE_DZ_MINUS_OFFSET;
Lightvalve 33:91b17819ec30 185 float VALVE_DZ_PLUS_OFFSET;
Lightvalve 11:82d8768d7351 186
Lightvalve 57:f4819de54e7a 187 int TMR3_COUNT_FINDHOME = 0;
Lightvalve 57:f4819de54e7a 188 int TMR3_COUNT_FLOWRATE = 0;
Lightvalve 57:f4819de54e7a 189 int TMR3_COUNT_DEADZONE = 0;
Lightvalve 57:f4819de54e7a 190 int TMR3_COUNT_PRES_NULL = 0;
Lightvalve 57:f4819de54e7a 191 int TMR3_COUNT_TORQUE_NULL = 0;
Lightvalve 57:f4819de54e7a 192 int TMR3_COUNT_PRES_CALIB = 0;
Lightvalve 57:f4819de54e7a 193 int TMR3_COUNT_REFERENCE = 0;
Lightvalve 57:f4819de54e7a 194 int TMR3_COUNT_JOINT = 0;
Lightvalve 57:f4819de54e7a 195 int TMR3_COUNT_ROTARY_FRIC_TUNE = 0;
Lightvalve 11:82d8768d7351 196
Lightvalve 57:f4819de54e7a 197 float TUNING_TIME = 600.0f; // sec
Lightvalve 56:6f50d9d3bfee 198
Lightvalve 57:f4819de54e7a 199 float REFERENCE_FREQ = 1.0f;
Lightvalve 57:f4819de54e7a 200 float REFERENCE_MAG = 0.0f;
Lightvalve 11:82d8768d7351 201
Lightvalve 11:82d8768d7351 202 bool FLAG_FIND_HOME;
Lightvalve 11:82d8768d7351 203
Lightvalve 11:82d8768d7351 204 int MODE_JUMP_STATUS;
Lightvalve 11:82d8768d7351 205 enum _JUMP_STATUS {
Lightvalve 11:82d8768d7351 206 JUMP_NO_ACT = 0, //0
Lightvalve 11:82d8768d7351 207 JUMP_START, //1
Lightvalve 11:82d8768d7351 208 JUMP_TAKEOFF, //2
Lightvalve 11:82d8768d7351 209 JUMP_FLYING, //3
Lightvalve 11:82d8768d7351 210 JUMP_LANDING, //4
Lightvalve 11:82d8768d7351 211 };
Lightvalve 11:82d8768d7351 212
Lightvalve 30:8d561f16383b 213 float CUR_PRES_DIFF_BAR = 0.0f;
Lightvalve 30:8d561f16383b 214 float CUR_PRES_A_sum = 0.0f;
Lightvalve 30:8d561f16383b 215 float CUR_PRES_B_sum = 0.0f;
Lightvalve 30:8d561f16383b 216 float CUR_PRES_A_mean = 0.0f;
Lightvalve 30:8d561f16383b 217 float CUR_PRES_B_mean = 0.0f;
Lightvalve 30:8d561f16383b 218 float CUR_TORQUE_sum = 0.0f;
Lightvalve 30:8d561f16383b 219 float CUR_TORQUE_mean = 0.0f;
Lightvalve 58:2eade98630e2 220 float PRES_A_NULL = 300.0f;
Lightvalve 58:2eade98630e2 221 float PRES_B_NULL = 300.0f;
Lightvalve 30:8d561f16383b 222 float TORQUE_NULL = 3900.0f;
Lightvalve 11:82d8768d7351 223
Lightvalve 30:8d561f16383b 224 float Ref_Valve_Pos_Old = 0.0f;
Lightvalve 11:82d8768d7351 225
Lightvalve 13:747daba9cf59 226 int VALVE_ID_timer = 0;
Lightvalve 13:747daba9cf59 227 int VALVE_DZ_timer = 0;
Lightvalve 13:747daba9cf59 228 int VALVE_FR_timer = 0;
Lightvalve 35:34ce7b0347b8 229 //int VALVE_HPL_timer = 0;
Lightvalve 13:747daba9cf59 230 int VALVE_POS_TMP = 0;
Lightvalve 13:747daba9cf59 231 int JOINT_VEL_TMP = 0;
Lightvalve 13:747daba9cf59 232 int DDV_POS_AVG = 0;
Lightvalve 19:23b7c1ad8683 233 int VALVE_POS_AVG[50] = {0};
Lightvalve 13:747daba9cf59 234 int VALVE_POS_AVG_OLD = 0;
Lightvalve 13:747daba9cf59 235 int data_num = 0;
Lightvalve 13:747daba9cf59 236 int ID_index = 0;
Lightvalve 13:747daba9cf59 237 int DZ_index = 1;
Lightvalve 19:23b7c1ad8683 238 int ID_index_array[50] = {0};
Lightvalve 13:747daba9cf59 239 int first_check = 0;
Lightvalve 30:8d561f16383b 240 float init_time = 0.0f;
Lightvalve 13:747daba9cf59 241 int DZ_case = 0;
Lightvalve 13:747daba9cf59 242 int START_POS = 0;
Lightvalve 13:747daba9cf59 243 int FINAL_POS = 0;
Lightvalve 13:747daba9cf59 244 int DZ_DIRECTION = 0;
Lightvalve 13:747daba9cf59 245 int FIRST_DZ = 0;
Lightvalve 13:747daba9cf59 246 int SECOND_DZ = 0;
Lightvalve 13:747daba9cf59 247 int DZ_NUM = 0;
Lightvalve 13:747daba9cf59 248 int one_period_end = 0;
Lightvalve 30:8d561f16383b 249 float Ref_Vel_Test = 0.0f;
Lightvalve 13:747daba9cf59 250 long TMR2_FOR_SLOW_LOGGING = 0;
Lightvalve 19:23b7c1ad8683 251 //int velcount = 0;
Lightvalve 13:747daba9cf59 252 char max_check = 0;
Lightvalve 34:bb2ca2fc2a8e 253 char min_check = 0;
Lightvalve 13:747daba9cf59 254
Lightvalve 30:8d561f16383b 255 float valve_pos_err = 0.0f, valve_pos_err_old = 0.0f, valve_pos_err_diff = 0.0f, valve_pos_err_sum = 0.0f;
Lightvalve 30:8d561f16383b 256 float joint_pos_err = 0.0f, joint_pos_err_old = 0.0f, joint_pos_err_diff = 0.0f, joint_pos_err_diff_fil = 0.0f, joint_pos_err_sum = 0.0f;
Lightvalve 30:8d561f16383b 257 float joint_torq_err = 0.0f, joint_torq_err_old = 0.0f, joint_torq_err_diff = 0.0f, joint_torq_err_sum = 0.0f;
Lightvalve 30:8d561f16383b 258 float VALVE_PWM_RAW_POS = 0.0f, VALVE_PWM_RAW_TORQ = 0.0f;
Lightvalve 13:747daba9cf59 259
Lightvalve 30:8d561f16383b 260 float CUR_FLOWRATE = 0.0f;
Lightvalve 30:8d561f16383b 261 float VALVE_FF_VOLTAGE = 0.0f;
Lightvalve 13:747daba9cf59 262
Lightvalve 13:747daba9cf59 263 int pos_plus_end = 0;
Lightvalve 13:747daba9cf59 264 int pos_minus_end = 0;
Lightvalve 13:747daba9cf59 265
Lightvalve 13:747daba9cf59 266 bool need_enc_init = false;
Lightvalve 13:747daba9cf59 267
Lightvalve 13:747daba9cf59 268 int temp_time = 0;
Lightvalve 13:747daba9cf59 269
Lightvalve 30:8d561f16383b 270 float CUR_VELOCITY_sum = 0.0f;
Lightvalve 30:8d561f16383b 271 float temp_vel_sum = 0.0f;
Lightvalve 13:747daba9cf59 272
Lightvalve 13:747daba9cf59 273 int DZ_dir = 0;
Lightvalve 13:747daba9cf59 274 int DZ_temp_cnt = 0;
Lightvalve 13:747daba9cf59 275 int DZ_temp_cnt2 = 0;
Lightvalve 13:747daba9cf59 276 int DZ_end = 2;
Lightvalve 13:747daba9cf59 277 int flag_flowrate = 0;
Lightvalve 13:747daba9cf59 278 int fl_temp_cnt = 0;
Lightvalve 13:747daba9cf59 279 int fl_temp_cnt2 = 0;
Lightvalve 13:747daba9cf59 280 int cur_vel_sum = 0;
Lightvalve 13:747daba9cf59 281
Lightvalve 57:f4819de54e7a 282 float Cur_Valve_Open_pulse = 0.0f;
Lightvalve 57:f4819de54e7a 283
Lightvalve 13:747daba9cf59 284 // find home
Lightvalve 13:747daba9cf59 285 int CUR_VELOCITY_OLD = 0;
Lightvalve 13:747daba9cf59 286 int cnt_findhome = 0;
Lightvalve 13:747daba9cf59 287 int cnt_vel_findhome = 0;
Lightvalve 13:747daba9cf59 288 int FINDHOME_VELOCITY = 0;
Lightvalve 13:747daba9cf59 289 int FINDHOME_VELOCITY_OLD = 0;
Lightvalve 13:747daba9cf59 290 int FINDHOME_POSITION = 0;
Lightvalve 13:747daba9cf59 291 int FINDHOME_POSITION_OLD = 0;
Lightvalve 13:747daba9cf59 292
Lightvalve 13:747daba9cf59 293 // valve gain
Lightvalve 13:747daba9cf59 294 int check_vel_pos_init = 0;
Lightvalve 13:747daba9cf59 295 int check_vel_pos_fin = 0;
Lightvalve 13:747daba9cf59 296 int check_vel_pos_interv = 0;
Lightvalve 13:747daba9cf59 297 int valve_gain_repeat_cnt = 0;
Lightvalve 30:8d561f16383b 298 float VALVE_VOLTAGE = 0.0f;
Lightvalve 13:747daba9cf59 299
Lightvalve 30:8d561f16383b 300 float freq_fric_tune = 1.0f;
Lightvalve 13:747daba9cf59 301
Lightvalve 14:8e7590227d22 302 uint32_t TMR3_COUNT_CAN_TX = 0;
Lightvalve 14:8e7590227d22 303
Lightvalve 57:f4819de54e7a 304 // Current Control Variables
Lightvalve 57:f4819de54e7a 305 double I_REF = 0.0f;
Lightvalve 57:f4819de54e7a 306 double I_REF_fil = 0.0f;
Lightvalve 57:f4819de54e7a 307 double I_ERR = 0.0f;
Lightvalve 57:f4819de54e7a 308 double I_ERR_INT = 0.0f;
Lightvalve 57:f4819de54e7a 309 double I_REF_fil_old = 0.0f;
Lightvalve 57:f4819de54e7a 310 double I_REF_fil_diff = 0.0f;
Lightvalve 57:f4819de54e7a 311
Lightvalve 57:f4819de54e7a 312 // system id
Lightvalve 57:f4819de54e7a 313 int cnt_sysid = 0;
Lightvalve 57:f4819de54e7a 314 double freq_sysid_Iref = 0.0f;
Lightvalve 57:f4819de54e7a 315
Lightvalve 169:645207e160ca 316 int cnt_freq_test = 0;
Lightvalve 169:645207e160ca 317 int cnt_step_test = 0;
Lightvalve 169:645207e160ca 318 int buffer_data_size = 0;
Lightvalve 169:645207e160ca 319 int cnt_send_buffer = 0;
Lightvalve 169:645207e160ca 320 float freq_test_valve_ref = 1.0f;
Lightvalve 169:645207e160ca 321 float ref_array[10000];
Lightvalve 169:645207e160ca 322 int pos_array[10000];
Lightvalve 169:645207e160ca 323
Lightvalve 14:8e7590227d22 324 int TMR3_COUNT_IREF = 0;
Lightvalve 30:8d561f16383b 325 float CUR_CURRENT = 0.0f;
Lightvalve 30:8d561f16383b 326 float u_CUR[3] = {0.0f,0.0f,0.0f};
Lightvalve 29:69f3f5445d6d 327 int FINDHOME_STAGE = 0;
Lightvalve 29:69f3f5445d6d 328 int FINDHOME_INIT = 0;
Lightvalve 30:8d561f16383b 329 int FINDHOME_GOTOLIMIT = 1;
Lightvalve 30:8d561f16383b 330 int FINDHOME_ZEROPOSE = 2;
Lightvalve 14:8e7590227d22 331
Lightvalve 45:35fa6884d0c6 332 float alpha_trans = 0.0f;
Lightvalve 45:35fa6884d0c6 333
Lightvalve 57:f4819de54e7a 334 float V_out=0.0f;
Lightvalve 57:f4819de54e7a 335 float V_rem=0.0f; // for anti-windup
Lightvalve 57:f4819de54e7a 336 float V_MAX = 12000.0f; // Maximum Voltage : 12V = 12000mV
Lightvalve 57:f4819de54e7a 337
Lightvalve 57:f4819de54e7a 338 float PWM_out=0.0f;
Lightvalve 57:f4819de54e7a 339
Lightvalve 57:f4819de54e7a 340 double K_v = 0.0f; // valve flowrate gain
Lightvalve 57:f4819de54e7a 341 double mV_PER_mA = 600.0f; // current >> voltage
Lightvalve 57:f4819de54e7a 342 double mV_PER_pulse = 0.6f; // pulse >> voltage
Lightvalve 57:f4819de54e7a 343 double mA_PER_pulse = 0.001f; // pulse >> current
Lightvalve 57:f4819de54e7a 344
Lightvalve 57:f4819de54e7a 345 int timer_while = 0;
Lightvalve 57:f4819de54e7a 346 int while_index = 0;
Lightvalve 170:42c938a40313 347 int RL_timer = 0;
Lightvalve 57:f4819de54e7a 348
Lightvalve 67:c2812cf26c38 349 float K_LPF = 0.0f;
Lightvalve 67:c2812cf26c38 350 float D_LPF = 0.0f;
Lightvalve 67:c2812cf26c38 351
Lightvalve 72:3436ce769b1e 352 float torq_ref_past = 0.0f;
Lightvalve 99:7bbcb3c0fb06 353 float output_normalized = 0.0f;
Lightvalve 99:7bbcb3c0fb06 354
Lightvalve 170:42c938a40313 355 int batch = 0;
Lightvalve 170:42c938a40313 356 float train_set_x[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 357 float train_set_error[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 358 float train_set_count[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 359 float state_array[batch_size][num_input_RL] = {0.0f};
Lightvalve 170:42c938a40313 360 float V[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 361 float r[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 362 float td_target[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 363 float delta[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 364 float advantage[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 365 float mean = 0.0f;
Lightvalve 170:42c938a40313 366 float deviation = 0.0f;
Lightvalve 170:42c938a40313 367 float mean_old = 0.0f;
Lightvalve 170:42c938a40313 368 float deviation_old = 0.0f;
Lightvalve 170:42c938a40313 369 float mean_before_SP = 0.0f;
Lightvalve 170:42c938a40313 370 float deviation_before_SP = 0.0f;
Lightvalve 170:42c938a40313 371 float mean_before_SP_array[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 372 float deviation_before_SP_array[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 373 float mean_array[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 374 float mean_array_old[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 375 float deviation_array[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 376 float deviation_array_old[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 377 float action = 0.0f;
Lightvalve 170:42c938a40313 378 float action_array[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 379 float ratio[batch_size] = {1.0f};
Lightvalve 170:42c938a40313 380 float pi[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 381 float pi_old[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 382 float epsilon = 0.2f;
Lightvalve 170:42c938a40313 383 float surr1[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 384 float surr2[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 385 float loss[batch_size] = {0.0f};
Lightvalve 170:42c938a40313 386 float loss_batch = 0.0f;
Lightvalve 170:42c938a40313 387 float gamma = 0.98f;
Lightvalve 170:42c938a40313 388 float lmbda = 0.95f;
Lightvalve 170:42c938a40313 389 char Update_Done_Flag = 1;
Lightvalve 170:42c938a40313 390 char Update_Case = 0;
Lightvalve 170:42c938a40313 391 float reward_sum = 0.0f;
Lightvalve 72:3436ce769b1e 392
Lightvalve 170:42c938a40313 393 float virt_pos = 0.0f;
Lightvalve 170:42c938a40313 394 float logging1 = 0.0f;
Lightvalve 170:42c938a40313 395 float logging2 = 0.0f;
Lightvalve 170:42c938a40313 396 float logging3 = 0.0f;
Lightvalve 170:42c938a40313 397 float logging4 = 0.0f;
Lightvalve 170:42c938a40313 398 float logging5 = 0.0f;
Lightvalve 170:42c938a40313 399
Lightvalve 23:59218d4a256d 400
Lightvalve 11:82d8768d7351 401 /*******************************************************************************
Lightvalve 11:82d8768d7351 402 * General math functions
Lightvalve 11:82d8768d7351 403 ******************************************************************************/
Lightvalve 11:82d8768d7351 404
Lightvalve 11:82d8768d7351 405
Lightvalve 34:bb2ca2fc2a8e 406 float dabs(float tx)
Lightvalve 34:bb2ca2fc2a8e 407 {
Lightvalve 30:8d561f16383b 408 if (tx >= 0.0f)
Lightvalve 11:82d8768d7351 409 return tx;
Lightvalve 11:82d8768d7351 410 else
Lightvalve 11:82d8768d7351 411 return -tx;
Lightvalve 11:82d8768d7351 412 }
Lightvalve 11:82d8768d7351 413
Lightvalve 34:bb2ca2fc2a8e 414 float change_int_to_efloat(int input)
Lightvalve 34:bb2ca2fc2a8e 415 {
Lightvalve 11:82d8768d7351 416 int i = 0;
Lightvalve 11:82d8768d7351 417
Lightvalve 30:8d561f16383b 418 float output = 0;
Lightvalve 48:889798ff9329 419 int vn = (int) ((float) input / 10.0f);
Lightvalve 11:82d8768d7351 420 int en = input % 10;
Lightvalve 11:82d8768d7351 421
Lightvalve 30:8d561f16383b 422 float temp = 1.;
Lightvalve 11:82d8768d7351 423 for (i = 0; i < en; i++)
Lightvalve 30:8d561f16383b 424 temp *= 0.1f;
Lightvalve 11:82d8768d7351 425
Lightvalve 30:8d561f16383b 426 output = (float) vn*temp;
Lightvalve 11:82d8768d7351 427 return output;
Lightvalve 11:82d8768d7351 428 }
Lightvalve 11:82d8768d7351 429
Lightvalve 34:bb2ca2fc2a8e 430 void make_delay(void)
Lightvalve 34:bb2ca2fc2a8e 431 {
Lightvalve 11:82d8768d7351 432 int i = 0;
Lightvalve 11:82d8768d7351 433
Lightvalve 65:a2d7c63419c2 434 for (i = 0; i < 1000000; i++) {
Lightvalve 11:82d8768d7351 435 ;
Lightvalve 11:82d8768d7351 436 }
Lightvalve 11:82d8768d7351 437
Lightvalve 11:82d8768d7351 438 }
Lightvalve 11:82d8768d7351 439
Lightvalve 11:82d8768d7351 440
Lightvalve 11:82d8768d7351 441 /*******************************************************************************
Lightvalve 11:82d8768d7351 442 * ROM functions
Lightvalve 11:82d8768d7351 443 ******************************************************************************/
Lightvalve 34:bb2ca2fc2a8e 444 void ROM_RESET_DATA(void)
Lightvalve 34:bb2ca2fc2a8e 445 {
Lightvalve 16:903b5a4433b4 446 FlashWriter writer(6);//2부터 7까지 되는듯 아마 sector
Lightvalve 16:903b5a4433b4 447 if (!writer.ready()) writer.open();
Lightvalve 16:903b5a4433b4 448 writer.write(RID_BNO,(int) BNO); // write at address, 쓸때도 4byte씩 씀
Lightvalve 16:903b5a4433b4 449 writer.write(RID_OPERATING_MODE,(int) OPERATING_MODE);
Lightvalve 52:8ea76864368a 450 writer.write(RID_SENSING_MODE, (int) SENSING_MODE);
Lightvalve 52:8ea76864368a 451 writer.write(RID_CURRENT_CONTROL_MODE, (int) CURRENT_CONTROL_MODE);
Lightvalve 52:8ea76864368a 452 writer.write(RID_FLAG_VALVE_DEADZONE, (int) FLAG_VALVE_DEADZONE);
Lightvalve 16:903b5a4433b4 453 writer.write(RID_CAN_FREQ,(int) CAN_FREQ);
Lightvalve 16:903b5a4433b4 454 writer.write(RID_JOINT_ENC_DIR,(int) DIR_JOINT_ENC);
Lightvalve 16:903b5a4433b4 455 writer.write(RID_VALVE_DIR,(int) DIR_VALVE);
Lightvalve 16:903b5a4433b4 456 writer.write(RID_VALVE_ENC_DIR,(int) DIR_VALVE_ENC);
Lightvalve 30:8d561f16383b 457 writer.write(RID_VOLATGE_SUPPLY,(int) (SUPPLY_VOLTAGE * 10.0f));
Lightvalve 30:8d561f16383b 458 writer.write(RID_VOLTAGE_VALVE,(int) (VALVE_VOLTAGE_LIMIT * 10.0f));
Lightvalve 16:903b5a4433b4 459 writer.write(RID_P_GAIN_VALVE_POSITION,(int) P_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 460 writer.write(RID_I_GAIN_VALVE_POSITION,(int) I_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 461 writer.write(RID_D_GAIN_VALVE_POSITION,(int) D_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 462 writer.write(RID_P_GAIN_JOINT_POSITION,(int) P_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 463 writer.write(RID_I_GAIN_JOINT_POSITION,(int) I_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 464 writer.write(RID_D_GAIN_JOINT_POSITION,(int) D_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 465 writer.write(RID_P_GAIN_JOINT_TORQUE,(int) P_GAIN_JOINT_TORQUE);
Lightvalve 16:903b5a4433b4 466 writer.write(RID_I_GAIN_JOINT_TORQUE,(int) I_GAIN_JOINT_TORQUE);
Lightvalve 16:903b5a4433b4 467 writer.write(RID_D_GAIN_JOINT_TORQUE,(int) D_GAIN_JOINT_TORQUE);
Lightvalve 33:91b17819ec30 468 writer.write(RID_VALVE_DEADZONE_PLUS,(int) (VALVE_DEADZONE_PLUS * 10.0f));
Lightvalve 33:91b17819ec30 469 writer.write(RID_VALVE_DEADZONE_MINUS,(int) (VALVE_DEADZONE_MINUS * 10.0f));
Lightvalve 16:903b5a4433b4 470 writer.write(RID_VELOCITY_COMP_GAIN,(int) VELOCITY_COMP_GAIN);
Lightvalve 16:903b5a4433b4 471 writer.write(RID_COMPLIANCE_GAIN,(int) COMPLIANCE_GAIN);
Lightvalve 16:903b5a4433b4 472 writer.write(RID_VALVE_CNETER,(int) VALVE_CENTER);
Lightvalve 16:903b5a4433b4 473 writer.write(RID_VALVE_FF,(int) VALVE_FF);
Lightvalve 16:903b5a4433b4 474 writer.write(RID_BULK_MODULUS,(int) BNO);
Lightvalve 16:903b5a4433b4 475 writer.write(RID_CHAMBER_VOLUME_A,(int) CHAMBER_VOLUME_A);
Lightvalve 16:903b5a4433b4 476 writer.write(RID_CHAMBER_VOLUME_B,(int) CHAMBER_VOLUME_B);
Lightvalve 16:903b5a4433b4 477 writer.write(RID_PISTON_AREA_A,(int) PISTON_AREA_A);
Lightvalve 16:903b5a4433b4 478 writer.write(RID_PISTON_AREA_B,(int) PISTON_AREA_B);
Lightvalve 16:903b5a4433b4 479 writer.write(RID_PRES_SUPPLY,(int) PRES_SUPPLY);
Lightvalve 16:903b5a4433b4 480 writer.write(RID_PRES_RETURN,(int) PRES_RETURN);
Lightvalve 16:903b5a4433b4 481 writer.write(RID_ENC_LIMIT_MINUS,(int) ENC_LIMIT_MINUS);
Lightvalve 16:903b5a4433b4 482 writer.write(RID_ENC_LIMIT_PLUS,(int) ENC_LIMIT_PLUS);
Lightvalve 16:903b5a4433b4 483 writer.write(RID_STROKE,(int) STROKE);
Lightvalve 57:f4819de54e7a 484 //writer.write(RID_VALVE_LIMIT_MINUS,(int) VALVE_LIMIT_MINUS);
Lightvalve 57:f4819de54e7a 485 //writer.write(RID_VALVE_LIMIT_PLUS,(int) VALVE_LIMIT_PLUS);
Lightvalve 48:889798ff9329 486 writer.write(RID_ENC_PULSE_PER_POSITION,(int) (ENC_PULSE_PER_POSITION*10.0f));
Lightvalve 58:2eade98630e2 487 writer.write(RID_TORQUE_SENSOR_PULSE_PER_TORQUE,(int) (TORQUE_SENSOR_PULSE_PER_TORQUE * 10000.0f));
Lightvalve 30:8d561f16383b 488 writer.write(RID_PRES_SENSOR_A_PULSE_PER_BAR,(int) (PRES_SENSOR_A_PULSE_PER_BAR * 100.0f));
Lightvalve 30:8d561f16383b 489 writer.write(RID_PRES_SENSOR_B_PULSE_PER_BAR,(int) (PRES_SENSOR_B_PULSE_PER_BAR * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 490 writer.write(RID_FRICTION,(int) (FRICTION * 10.0f));
Lightvalve 34:bb2ca2fc2a8e 491 writer.write(RID_HOMEPOS_OFFSET,(int) HOMEPOS_OFFSET);
Lightvalve 34:bb2ca2fc2a8e 492 writer.write(RID_HOMEPOS_VALVE_OPENING,(int) HOMEPOS_VALVE_OPENING);
Lightvalve 34:bb2ca2fc2a8e 493 writer.write(RID_TORQUE_SENSOR_VREF,(int) (TORQUE_VREF * 1000.0f));
Lightvalve 30:8d561f16383b 494 writer.write(RID_PRES_A_SENSOR_VREF, (int) (PRES_A_VREF * 1000.0f));
Lightvalve 30:8d561f16383b 495 writer.write(RID_PRES_B_SENSOR_VREF, (int) (PRES_B_VREF * 1000.0f));
Lightvalve 34:bb2ca2fc2a8e 496 writer.write(RID_VALVE_GAIN_PLUS_1,(int) (VALVE_GAIN_LPM_PER_V[0] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 497 writer.write(RID_VALVE_GAIN_PLUS_2,(int) (VALVE_GAIN_LPM_PER_V[2] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 498 writer.write(RID_VALVE_GAIN_PLUS_3,(int) (VALVE_GAIN_LPM_PER_V[4] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 499 writer.write(RID_VALVE_GAIN_PLUS_4,(int) (VALVE_GAIN_LPM_PER_V[6] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 500 writer.write(RID_VALVE_GAIN_PLUS_5,(int) (VALVE_GAIN_LPM_PER_V[8] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 501 writer.write(RID_VALVE_GAIN_MINUS_1,(int) (VALVE_GAIN_LPM_PER_V[1] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 502 writer.write(RID_VALVE_GAIN_MINUS_2,(int) (VALVE_GAIN_LPM_PER_V[3] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 503 writer.write(RID_VALVE_GAIN_MINUS_3,(int) (VALVE_GAIN_LPM_PER_V[5] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 504 writer.write(RID_VALVE_GAIN_MINUS_4,(int) (VALVE_GAIN_LPM_PER_V[7] * 100.0f));
Lightvalve 30:8d561f16383b 505 writer.write(RID_VALVE_GAIN_MINUS_5,(int) (VALVE_GAIN_LPM_PER_V[9] * 100.0f));
Lightvalve 34:bb2ca2fc2a8e 506 for(int i=0; i<25; i++) {
Lightvalve 18:b8adf1582ea3 507 writer.write(RID_VALVE_POS_VS_PWM_0 + i, (int) VALVE_POS_VS_PWM[i]);
Lightvalve 18:b8adf1582ea3 508 }
Lightvalve 34:bb2ca2fc2a8e 509 for(int i=0; i<100; i++) {
Lightvalve 19:23b7c1ad8683 510 writer.write(RID_VALVE_POS_VS_FLOWRATE_0 + i, (int) (JOINT_VEL[i] & 0xFFFF));
Lightvalve 19:23b7c1ad8683 511 writer.write(RID_VALVE_POS_VS_FLOWRATE_0_1 + i, (int) ((JOINT_VEL[i] >> 16) & 0xFFFF));
Lightvalve 18:b8adf1582ea3 512 }
Lightvalve 18:b8adf1582ea3 513 writer.write(RID_VALVE_MAX_POS, (int) VALVE_MAX_POS);
Lightvalve 18:b8adf1582ea3 514 writer.write(RID_VALVE_MIN_POS, (int) VALVE_MIN_POS);
Lightvalve 57:f4819de54e7a 515 //writer.write(RID_DDV_CENTER, (int) (DDV_CENTER * 10.0f));
Lightvalve 18:b8adf1582ea3 516 writer.write(RID_VALVE_POS_NUM, (int) VALVE_POS_NUM);
Lightvalve 46:2694daea349b 517
Lightvalve 46:2694daea349b 518 writer.write(RID_K_SPRING, (int) K_SPRING);
Lightvalve 46:2694daea349b 519 writer.write(RID_D_DAMPER, (int) D_DAMPER);
Lightvalve 11:82d8768d7351 520
Lightvalve 34:bb2ca2fc2a8e 521 writer.close();
Lightvalve 34:bb2ca2fc2a8e 522
Lightvalve 11:82d8768d7351 523 }
Lightvalve 11:82d8768d7351 524
Lightvalve 34:bb2ca2fc2a8e 525 void ROM_CALL_DATA(void)
Lightvalve 34:bb2ca2fc2a8e 526 {
Lightvalve 170:42c938a40313 527 BNO = spi_eeprom_read(RID_BNO);
Lightvalve 170:42c938a40313 528 // BNO = 11;
Lightvalve 170:42c938a40313 529 OPERATING_MODE = spi_eeprom_read(RID_OPERATING_MODE);
Lightvalve 170:42c938a40313 530 SENSING_MODE = spi_eeprom_read(RID_SENSING_MODE);
Lightvalve 170:42c938a40313 531 // SENSING_MODE = 1;
Lightvalve 170:42c938a40313 532 CURRENT_CONTROL_MODE = spi_eeprom_read(RID_CURRENT_CONTROL_MODE);
Lightvalve 170:42c938a40313 533 // CURRENT_CONTROL_MODE = 1;
Lightvalve 170:42c938a40313 534 FLAG_VALVE_DEADZONE = spi_eeprom_read(RID_FLAG_VALVE_DEADZONE);
Lightvalve 170:42c938a40313 535 CAN_FREQ = spi_eeprom_read(RID_CAN_FREQ);
Lightvalve 170:42c938a40313 536 // CAN_FREQ = 500;
Lightvalve 170:42c938a40313 537 DIR_JOINT_ENC = spi_eeprom_read(RID_JOINT_ENC_DIR);
Lightvalve 170:42c938a40313 538 DIR_VALVE = spi_eeprom_read(RID_VALVE_DIR);
Lightvalve 170:42c938a40313 539 DIR_VALVE_ENC = spi_eeprom_read(RID_VALVE_ENC_DIR);
Lightvalve 170:42c938a40313 540 SUPPLY_VOLTAGE = (float) (spi_eeprom_read(RID_VOLATGE_SUPPLY)) *0.1f;
Lightvalve 170:42c938a40313 541 VALVE_VOLTAGE_LIMIT = (float) (spi_eeprom_read(RID_VOLTAGE_VALVE)) * 0.1f;
Lightvalve 170:42c938a40313 542 P_GAIN_VALVE_POSITION = spi_eeprom_read(RID_P_GAIN_VALVE_POSITION);
Lightvalve 170:42c938a40313 543 I_GAIN_VALVE_POSITION = spi_eeprom_read(RID_I_GAIN_VALVE_POSITION);
Lightvalve 170:42c938a40313 544 D_GAIN_VALVE_POSITION = spi_eeprom_read(RID_D_GAIN_VALVE_POSITION);
Lightvalve 170:42c938a40313 545 P_GAIN_JOINT_POSITION = spi_eeprom_read(RID_P_GAIN_JOINT_POSITION);
Lightvalve 170:42c938a40313 546 I_GAIN_JOINT_POSITION = spi_eeprom_read(RID_I_GAIN_JOINT_POSITION);
Lightvalve 170:42c938a40313 547 D_GAIN_JOINT_POSITION = spi_eeprom_read(RID_D_GAIN_JOINT_POSITION);
Lightvalve 170:42c938a40313 548 P_GAIN_JOINT_TORQUE = spi_eeprom_read(RID_P_GAIN_JOINT_TORQUE);
Lightvalve 170:42c938a40313 549 I_GAIN_JOINT_TORQUE = spi_eeprom_read( RID_I_GAIN_JOINT_TORQUE);
Lightvalve 170:42c938a40313 550 D_GAIN_JOINT_TORQUE = spi_eeprom_read(RID_D_GAIN_JOINT_TORQUE);
Lightvalve 170:42c938a40313 551 VALVE_DEADZONE_PLUS = (float) (spi_eeprom_read( RID_VALVE_DEADZONE_PLUS)) * 0.1f;
Lightvalve 170:42c938a40313 552 VALVE_DEADZONE_MINUS = (float) (spi_eeprom_read(RID_VALVE_DEADZONE_MINUS)) * 0.1f;
Lightvalve 170:42c938a40313 553 VELOCITY_COMP_GAIN = spi_eeprom_read(RID_VELOCITY_COMP_GAIN);
Lightvalve 170:42c938a40313 554 COMPLIANCE_GAIN = spi_eeprom_read(RID_COMPLIANCE_GAIN);
Lightvalve 170:42c938a40313 555 VALVE_CENTER = spi_eeprom_read(RID_VALVE_CNETER);
Lightvalve 170:42c938a40313 556 VALVE_FF = spi_eeprom_read(RID_VALVE_FF);
Lightvalve 170:42c938a40313 557 BULK_MODULUS = spi_eeprom_read(RID_BULK_MODULUS);
Lightvalve 170:42c938a40313 558 CHAMBER_VOLUME_A = spi_eeprom_read(RID_CHAMBER_VOLUME_A);
Lightvalve 170:42c938a40313 559 CHAMBER_VOLUME_B = spi_eeprom_read(RID_CHAMBER_VOLUME_B);
Lightvalve 170:42c938a40313 560 PISTON_AREA_A = spi_eeprom_read(RID_PISTON_AREA_A);
Lightvalve 170:42c938a40313 561 PISTON_AREA_B = spi_eeprom_read(RID_PISTON_AREA_B);
Lightvalve 170:42c938a40313 562 PISTON_AREA_alpha = (float)PISTON_AREA_A/(float)PISTON_AREA_B;
Lightvalve 170:42c938a40313 563 alpha3 = PISTON_AREA_alpha * PISTON_AREA_alpha*PISTON_AREA_alpha;
Lightvalve 170:42c938a40313 564 PRES_SUPPLY = spi_eeprom_read(RID_PRES_SUPPLY);
Lightvalve 170:42c938a40313 565 PRES_RETURN = spi_eeprom_read(RID_PRES_RETURN);
Lightvalve 170:42c938a40313 566 ENC_LIMIT_MINUS = spi_eeprom_read(RID_ENC_LIMIT_MINUS);
Lightvalve 170:42c938a40313 567 ENC_LIMIT_PLUS = spi_eeprom_read(RID_ENC_LIMIT_PLUS);
Lightvalve 170:42c938a40313 568 STROKE = spi_eeprom_read(RID_STROKE);
Lightvalve 170:42c938a40313 569 //VALVE_LIMIT_MINUS = flashReadInt(Rom_Sector, RID_VALVE_LIMIT_MINUS);
Lightvalve 170:42c938a40313 570 //VALVE_LIMIT_PLUS = flashReadInt(Rom_Sector, RID_VALVE_LIMIT_PLUS);
Lightvalve 170:42c938a40313 571 ENC_PULSE_PER_POSITION = (float) (spi_eeprom_read(RID_ENC_PULSE_PER_POSITION)) * 0.1f;
Lightvalve 170:42c938a40313 572 // ENC_PULSE_PER_POSITION = (float) 1024.0f;
Lightvalve 170:42c938a40313 573 TORQUE_SENSOR_PULSE_PER_TORQUE = (float) (spi_eeprom_read(RID_TORQUE_SENSOR_PULSE_PER_TORQUE)) * 0.0001f;
Lightvalve 170:42c938a40313 574 //TORQUE_SENSOR_PULSE_PER_TORQUE = (float) 0.41928f; //for ankle
Lightvalve 170:42c938a40313 575 // TORQUE_SENSOR_PULSE_PER_TORQUE = (float) 10000.0f/2048.0f; //for knee
Lightvalve 170:42c938a40313 576 PRES_SENSOR_A_PULSE_PER_BAR = (float) (spi_eeprom_read(RID_PRES_SENSOR_A_PULSE_PER_BAR)) * 0.01f;
Lightvalve 170:42c938a40313 577 // PRES_SENSOR_A_PULSE_PER_BAR = 4096.0f * 946.0f / 3.3f / 300.0f / 210.0f;
Lightvalve 170:42c938a40313 578 PRES_SENSOR_B_PULSE_PER_BAR = (float) (spi_eeprom_read(RID_PRES_SENSOR_B_PULSE_PER_BAR)) * 0.01f;
Lightvalve 170:42c938a40313 579 // PRES_SENSOR_B_PULSE_PER_BAR = 4096.0f * 946.0f / 3.3f / 300.0f / 210.0f;
Lightvalve 170:42c938a40313 580 FRICTION = (float) (spi_eeprom_read(RID_FRICTION)) * 0.1f;
Lightvalve 170:42c938a40313 581 HOMEPOS_OFFSET = spi_eeprom_read(RID_HOMEPOS_OFFSET);
Lightvalve 170:42c938a40313 582 HOMEPOS_VALVE_OPENING = spi_eeprom_read(RID_HOMEPOS_VALVE_OPENING);
Lightvalve 170:42c938a40313 583 TORQUE_VREF = (float) (spi_eeprom_read(RID_TORQUE_SENSOR_VREF)) *0.001f;
Lightvalve 170:42c938a40313 584 PRES_A_VREF = (float) spi_eeprom_read(RID_PRES_A_SENSOR_VREF) * 0.001f;
Lightvalve 170:42c938a40313 585 PRES_B_VREF = (float) spi_eeprom_read(RID_PRES_B_SENSOR_VREF) * 0.001f;
Lightvalve 170:42c938a40313 586 VALVE_GAIN_LPM_PER_V[0] = (float) (spi_eeprom_read(RID_VALVE_GAIN_PLUS_1)) * 0.01f;
Lightvalve 170:42c938a40313 587 VALVE_GAIN_LPM_PER_V[2] = (float) (spi_eeprom_read(RID_VALVE_GAIN_PLUS_2)) * 0.01f;
Lightvalve 170:42c938a40313 588 VALVE_GAIN_LPM_PER_V[4] = (float) (spi_eeprom_read(RID_VALVE_GAIN_PLUS_3)) * 0.01f;
Lightvalve 170:42c938a40313 589 VALVE_GAIN_LPM_PER_V[6] = (float) (spi_eeprom_read(RID_VALVE_GAIN_PLUS_4)) * 0.01f;
Lightvalve 170:42c938a40313 590 VALVE_GAIN_LPM_PER_V[8] = (float) (spi_eeprom_read(RID_VALVE_GAIN_PLUS_5)) * 0.01f;
Lightvalve 170:42c938a40313 591 VALVE_GAIN_LPM_PER_V[1] = (float) (spi_eeprom_read(RID_VALVE_GAIN_MINUS_1)) * 0.01f;
Lightvalve 170:42c938a40313 592 VALVE_GAIN_LPM_PER_V[3] = (float) (spi_eeprom_read(RID_VALVE_GAIN_MINUS_2)) * 0.01f;
Lightvalve 170:42c938a40313 593 VALVE_GAIN_LPM_PER_V[5] = (float) (spi_eeprom_read(RID_VALVE_GAIN_MINUS_3)) * 0.01f;
Lightvalve 170:42c938a40313 594 VALVE_GAIN_LPM_PER_V[7] = (float) (spi_eeprom_read(RID_VALVE_GAIN_MINUS_4)) * 0.01f;
Lightvalve 170:42c938a40313 595 VALVE_GAIN_LPM_PER_V[9] = (float) (spi_eeprom_read(RID_VALVE_GAIN_MINUS_5)) * 0.01f;
Lightvalve 170:42c938a40313 596 for(int i=0; i<25; i++) {
Lightvalve 170:42c938a40313 597 VALVE_POS_VS_PWM[i] = (float) (spi_eeprom_read(RID_VALVE_POS_VS_PWM_0 + i));
Lightvalve 170:42c938a40313 598 }
Lightvalve 170:42c938a40313 599 for(int i=0; i<100; i++) {
Lightvalve 170:42c938a40313 600 JOINT_VEL[i] = ( ((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 170:42c938a40313 601 }
Lightvalve 170:42c938a40313 602 VALVE_MAX_POS = spi_eeprom_read(RID_VALVE_MAX_POS);
Lightvalve 170:42c938a40313 603 VALVE_MIN_POS = spi_eeprom_read(RID_VALVE_MIN_POS);
Lightvalve 170:42c938a40313 604 //DDV_CENTER = (float) (flashReadInt(Rom_Sector, RID_DDV_CENTER)) * 0.1f;
Lightvalve 170:42c938a40313 605 VALVE_POS_NUM = spi_eeprom_read(RID_VALVE_POS_NUM);
Lightvalve 170:42c938a40313 606
Lightvalve 170:42c938a40313 607 K_SPRING = spi_eeprom_read(RID_K_SPRING);
Lightvalve 170:42c938a40313 608 D_DAMPER = spi_eeprom_read(RID_D_DAMPER);
Lightvalve 170:42c938a40313 609
Lightvalve 170:42c938a40313 610
Lightvalve 170:42c938a40313 611
Lightvalve 170:42c938a40313 612
Lightvalve 170:42c938a40313 613
Lightvalve 170:42c938a40313 614 /*
Lightvalve 170:42c938a40313 615
Lightvalve 16:903b5a4433b4 616 BNO = flashReadInt(Rom_Sector, RID_BNO);
Lightvalve 169:645207e160ca 617 // BNO = 1;
Lightvalve 16:903b5a4433b4 618 OPERATING_MODE = flashReadInt(Rom_Sector, RID_OPERATING_MODE);
Lightvalve 89:a7b45368ea0f 619 // OPERATING_MODE = 5;
Lightvalve 52:8ea76864368a 620 SENSING_MODE = flashReadInt(Rom_Sector, RID_SENSING_MODE);
Lightvalve 89:a7b45368ea0f 621 // SENSING_MODE = 0;
Lightvalve 52:8ea76864368a 622 CURRENT_CONTROL_MODE = flashReadInt(Rom_Sector, RID_CURRENT_CONTROL_MODE);
Lightvalve 89:a7b45368ea0f 623 // CURRENT_CONTROL_MODE = 0;
Lightvalve 52:8ea76864368a 624 FLAG_VALVE_DEADZONE = flashReadInt(Rom_Sector, RID_FLAG_VALVE_DEADZONE);
Lightvalve 16:903b5a4433b4 625 CAN_FREQ = flashReadInt(Rom_Sector, RID_CAN_FREQ);
Lightvalve 16:903b5a4433b4 626 DIR_JOINT_ENC = flashReadInt(Rom_Sector, RID_JOINT_ENC_DIR);
Lightvalve 16:903b5a4433b4 627 DIR_VALVE = flashReadInt(Rom_Sector, RID_VALVE_DIR);
Lightvalve 16:903b5a4433b4 628 DIR_VALVE_ENC = flashReadInt(Rom_Sector, RID_VALVE_ENC_DIR);
Lightvalve 30:8d561f16383b 629 SUPPLY_VOLTAGE = (float) (flashReadInt(Rom_Sector, RID_VOLATGE_SUPPLY)) *0.1f;
Lightvalve 30:8d561f16383b 630 VALVE_VOLTAGE_LIMIT = (float) (flashReadInt(Rom_Sector, RID_VOLTAGE_VALVE)) * 0.1f;
Lightvalve 16:903b5a4433b4 631 P_GAIN_VALVE_POSITION = flashReadInt(Rom_Sector, RID_P_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 632 I_GAIN_VALVE_POSITION = flashReadInt(Rom_Sector, RID_I_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 633 D_GAIN_VALVE_POSITION = flashReadInt(Rom_Sector, RID_D_GAIN_VALVE_POSITION);
Lightvalve 16:903b5a4433b4 634 P_GAIN_JOINT_POSITION = flashReadInt(Rom_Sector, RID_P_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 635 I_GAIN_JOINT_POSITION = flashReadInt(Rom_Sector, RID_I_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 636 D_GAIN_JOINT_POSITION = flashReadInt(Rom_Sector, RID_D_GAIN_JOINT_POSITION);
Lightvalve 16:903b5a4433b4 637 P_GAIN_JOINT_TORQUE = flashReadInt(Rom_Sector, RID_P_GAIN_JOINT_TORQUE);
Lightvalve 16:903b5a4433b4 638 I_GAIN_JOINT_TORQUE = flashReadInt(Rom_Sector, RID_I_GAIN_JOINT_TORQUE);
Lightvalve 16:903b5a4433b4 639 D_GAIN_JOINT_TORQUE = flashReadInt(Rom_Sector, RID_D_GAIN_JOINT_TORQUE);
Lightvalve 33:91b17819ec30 640 VALVE_DEADZONE_PLUS = (float) (flashReadInt(Rom_Sector, RID_VALVE_DEADZONE_PLUS)) * 0.1f;
Lightvalve 33:91b17819ec30 641 VALVE_DEADZONE_MINUS = (float) (flashReadInt(Rom_Sector, RID_VALVE_DEADZONE_MINUS)) * 0.1f;
Lightvalve 16:903b5a4433b4 642 VELOCITY_COMP_GAIN = flashReadInt(Rom_Sector, RID_VELOCITY_COMP_GAIN);
Lightvalve 16:903b5a4433b4 643 COMPLIANCE_GAIN = flashReadInt(Rom_Sector, RID_COMPLIANCE_GAIN);
Lightvalve 16:903b5a4433b4 644 VALVE_CENTER = flashReadInt(Rom_Sector, RID_VALVE_CNETER);
Lightvalve 16:903b5a4433b4 645 VALVE_FF = flashReadInt(Rom_Sector, RID_VALVE_FF);
Lightvalve 16:903b5a4433b4 646 BULK_MODULUS = flashReadInt(Rom_Sector, RID_BULK_MODULUS);
Lightvalve 16:903b5a4433b4 647 CHAMBER_VOLUME_A = flashReadInt(Rom_Sector, RID_CHAMBER_VOLUME_A);
Lightvalve 16:903b5a4433b4 648 CHAMBER_VOLUME_B = flashReadInt(Rom_Sector, RID_CHAMBER_VOLUME_B);
Lightvalve 16:903b5a4433b4 649 PISTON_AREA_A = flashReadInt(Rom_Sector, RID_PISTON_AREA_A);
Lightvalve 16:903b5a4433b4 650 PISTON_AREA_B = flashReadInt(Rom_Sector, RID_PISTON_AREA_B);
Lightvalve 69:3995ffeaa786 651 PISTON_AREA_alpha = (float)PISTON_AREA_A/(float)PISTON_AREA_B;
Lightvalve 57:f4819de54e7a 652 alpha3 = PISTON_AREA_alpha * PISTON_AREA_alpha*PISTON_AREA_alpha;
Lightvalve 16:903b5a4433b4 653 PRES_SUPPLY = flashReadInt(Rom_Sector, RID_PRES_SUPPLY);
Lightvalve 16:903b5a4433b4 654 PRES_RETURN = flashReadInt(Rom_Sector, RID_PRES_RETURN);
Lightvalve 16:903b5a4433b4 655 ENC_LIMIT_MINUS = flashReadInt(Rom_Sector, RID_ENC_LIMIT_MINUS);
Lightvalve 16:903b5a4433b4 656 ENC_LIMIT_PLUS = flashReadInt(Rom_Sector, RID_ENC_LIMIT_PLUS);
Lightvalve 16:903b5a4433b4 657 STROKE = flashReadInt(Rom_Sector, RID_STROKE);
Lightvalve 57:f4819de54e7a 658 //VALVE_LIMIT_MINUS = flashReadInt(Rom_Sector, RID_VALVE_LIMIT_MINUS);
Lightvalve 57:f4819de54e7a 659 //VALVE_LIMIT_PLUS = flashReadInt(Rom_Sector, RID_VALVE_LIMIT_PLUS);
Lightvalve 48:889798ff9329 660 ENC_PULSE_PER_POSITION = (float) (flashReadInt(Rom_Sector, RID_ENC_PULSE_PER_POSITION)) * 0.1f;
Lightvalve 48:889798ff9329 661 // ENC_PULSE_PER_POSITION = (float) 1024.0f;
Lightvalve 58:2eade98630e2 662 TORQUE_SENSOR_PULSE_PER_TORQUE = (float) (flashReadInt(Rom_Sector, RID_TORQUE_SENSOR_PULSE_PER_TORQUE)) * 0.0001f;
Lightvalve 48:889798ff9329 663 //TORQUE_SENSOR_PULSE_PER_TORQUE = (float) 0.41928f; //for ankle
Lightvalve 48:889798ff9329 664 // TORQUE_SENSOR_PULSE_PER_TORQUE = (float) 10000.0f/2048.0f; //for knee
Lightvalve 30:8d561f16383b 665 PRES_SENSOR_A_PULSE_PER_BAR = (float) (flashReadInt(Rom_Sector, RID_PRES_SENSOR_A_PULSE_PER_BAR)) * 0.01f;
Lightvalve 48:889798ff9329 666 // PRES_SENSOR_A_PULSE_PER_BAR = 4096.0f / 200.0f;
Lightvalve 30:8d561f16383b 667 PRES_SENSOR_B_PULSE_PER_BAR = (float) (flashReadInt(Rom_Sector, RID_PRES_SENSOR_B_PULSE_PER_BAR)) * 0.01f;
Lightvalve 48:889798ff9329 668 // PRES_SENSOR_B_PULSE_PER_BAR = 4096.0f / 200.0f;
Lightvalve 30:8d561f16383b 669 FRICTION = (float) (flashReadInt(Rom_Sector, RID_FRICTION)) * 0.1f;
Lightvalve 16:903b5a4433b4 670 HOMEPOS_OFFSET = flashReadInt(Rom_Sector, RID_HOMEPOS_OFFSET);
Lightvalve 16:903b5a4433b4 671 HOMEPOS_VALVE_OPENING = flashReadInt(Rom_Sector, RID_HOMEPOS_VALVE_OPENING);
Lightvalve 30:8d561f16383b 672 TORQUE_VREF = (float) (flashReadInt(Rom_Sector, RID_TORQUE_SENSOR_VREF)) *0.001f;
Lightvalve 32:4b8c0fedaf2c 673 PRES_A_VREF = (float) flashReadInt(Rom_Sector, RID_PRES_A_SENSOR_VREF) * 0.001f;
Lightvalve 32:4b8c0fedaf2c 674 PRES_B_VREF = (float) flashReadInt(Rom_Sector, RID_PRES_B_SENSOR_VREF) * 0.001f;
Lightvalve 30:8d561f16383b 675 VALVE_GAIN_LPM_PER_V[0] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_PLUS_1)) * 0.01f;
Lightvalve 30:8d561f16383b 676 VALVE_GAIN_LPM_PER_V[2] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_PLUS_2)) * 0.01f;
Lightvalve 30:8d561f16383b 677 VALVE_GAIN_LPM_PER_V[4] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_PLUS_3)) * 0.01f;
Lightvalve 30:8d561f16383b 678 VALVE_GAIN_LPM_PER_V[6] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_PLUS_4)) * 0.01f;
Lightvalve 30:8d561f16383b 679 VALVE_GAIN_LPM_PER_V[8] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_PLUS_5)) * 0.01f;
Lightvalve 30:8d561f16383b 680 VALVE_GAIN_LPM_PER_V[1] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_MINUS_1)) * 0.01f;
Lightvalve 30:8d561f16383b 681 VALVE_GAIN_LPM_PER_V[3] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_MINUS_2)) * 0.01f;
Lightvalve 30:8d561f16383b 682 VALVE_GAIN_LPM_PER_V[5] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_MINUS_3)) * 0.01f;
Lightvalve 30:8d561f16383b 683 VALVE_GAIN_LPM_PER_V[7] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_MINUS_4)) * 0.01f;
Lightvalve 30:8d561f16383b 684 VALVE_GAIN_LPM_PER_V[9] = (float) (flashReadInt(Rom_Sector, RID_VALVE_GAIN_MINUS_5)) * 0.01f;
Lightvalve 34:bb2ca2fc2a8e 685 for(int i=0; i<25; i++) {
Lightvalve 30:8d561f16383b 686 VALVE_POS_VS_PWM[i] = (float) (flashReadInt(Rom_Sector, RID_VALVE_POS_VS_PWM_0 + i));
Lightvalve 16:903b5a4433b4 687 }
Lightvalve 34:bb2ca2fc2a8e 688 for(int i=0; i<100; i++) {
Lightvalve 16:903b5a4433b4 689 JOINT_VEL[i] = ( ((flashReadInt(Rom_Sector, RID_VALVE_POS_VS_FLOWRATE_0 + i)) & 0xFFFF) | ((flashReadInt(Rom_Sector, RID_VALVE_POS_VS_FLOWRATE_0_1 + i)) & 0xFFFF) << 16 ) ;
Lightvalve 16:903b5a4433b4 690 }
Lightvalve 16:903b5a4433b4 691 VALVE_MAX_POS = flashReadInt(Rom_Sector, RID_VALVE_MAX_POS);
Lightvalve 16:903b5a4433b4 692 VALVE_MIN_POS = flashReadInt(Rom_Sector, RID_VALVE_MIN_POS);
Lightvalve 57:f4819de54e7a 693 //DDV_CENTER = (float) (flashReadInt(Rom_Sector, RID_DDV_CENTER)) * 0.1f;
Lightvalve 16:903b5a4433b4 694 VALVE_POS_NUM = flashReadInt(Rom_Sector, RID_VALVE_POS_NUM);
Lightvalve 46:2694daea349b 695
Lightvalve 46:2694daea349b 696 K_SPRING = flashReadInt(Rom_Sector, RID_K_SPRING);
Lightvalve 46:2694daea349b 697 D_DAMPER = flashReadInt(Rom_Sector, RID_D_DAMPER);
Lightvalve 48:889798ff9329 698
Lightvalve 73:f80dc3970c99 699 // ROM_RESET_DATA();
Lightvalve 170:42c938a40313 700
Lightvalve 170:42c938a40313 701 */
Lightvalve 73:f80dc3970c99 702
Lightvalve 11:82d8768d7351 703 }
Lightvalve 11:82d8768d7351 704
Lightvalve 11:82d8768d7351 705 /*******************************************************************************
Lightvalve 11:82d8768d7351 706 * ENCODER functions
Lightvalve 11:82d8768d7351 707 ******************************************************************************/
Lightvalve 11:82d8768d7351 708 // A-KHA
Lightvalve 30:8d561f16383b 709 #define KF_G1_11 0.083920206005350f
Lightvalve 30:8d561f16383b 710 #define KF_G1_12 0.000013905329560f
Lightvalve 30:8d561f16383b 711 #define KF_G1_21 -0.000575742328210f
Lightvalve 30:8d561f16383b 712 #define KF_G1_22 0.799999939711725f
Lightvalve 11:82d8768d7351 713 // K
Lightvalve 30:8d561f16383b 714 #define KF_G2_11 0.916079793994650f
Lightvalve 30:8d561f16383b 715 #define KF_G2_12 0.000002878711641f
Lightvalve 30:8d561f16383b 716 #define KF_G2_21 0.000575742328210f
Lightvalve 30:8d561f16383b 717 #define KF_G2_22 0.199999945139809f
Lightvalve 11:82d8768d7351 718
Lightvalve 30:8d561f16383b 719 float KF_Y_11 = 0.0f;
Lightvalve 30:8d561f16383b 720 float KF_Y_21 = 0.0f;
Lightvalve 30:8d561f16383b 721 float KF_X_11 = 0.0f;
Lightvalve 30:8d561f16383b 722 float KF_X_21 = 0.0f;
Lightvalve 11:82d8768d7351 723
Lightvalve 11:82d8768d7351 724 long ENC_pos_old = 0, ENC_pos_cur = 0, ENC_pos_diff = 0;
Lightvalve 11:82d8768d7351 725 long ENC_RAW = 0, ENC_VEL_RAW = 0, ENC_VEL_KF = 0;
Lightvalve 11:82d8768d7351 726 long enc_offset = 0;
Lightvalve 11:82d8768d7351 727
Lightvalve 34:bb2ca2fc2a8e 728 void ENC_UPDATE(void)
Lightvalve 34:bb2ca2fc2a8e 729 {
Lightvalve 11:82d8768d7351 730
Lightvalve 11:82d8768d7351 731 ENC_pos_cur = spi_enc_read();
Lightvalve 11:82d8768d7351 732 ENC_pos_diff = ENC_pos_cur - ENC_pos_old;
Lightvalve 11:82d8768d7351 733
Lightvalve 57:f4819de54e7a 734 //Kalman Filter
Lightvalve 57:f4819de54e7a 735 // ENC_VEL_RAW = (int32_t) (ENC_pos_diff * TMR_FREQ_5k);
Lightvalve 54:647072f5307a 736 // KF_Y_11 = ENC_pos_cur;
Lightvalve 54:647072f5307a 737 // KF_Y_21 = ENC_VEL_RAW;
Lightvalve 54:647072f5307a 738 // 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 54:647072f5307a 739 // 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 54:647072f5307a 740 // ENC_VEL_KF = (int32_t) KF_X_21;
Lightvalve 54:647072f5307a 741 //
Lightvalve 54:647072f5307a 742 // pos.sen = (DIR_JOINT_ENC) * ENC_pos_cur + enc_offset;
Lightvalve 54:647072f5307a 743 // vel.sen = (DIR_JOINT_ENC) * ENC_VEL_KF;
Lightvalve 57:f4819de54e7a 744
Lightvalve 57:f4819de54e7a 745 //Low Pass Filter
Lightvalve 57:f4819de54e7a 746
Lightvalve 54:647072f5307a 747 double NEW_POSITION = (double) ((DIR_JOINT_ENC) * ENC_pos_cur + enc_offset);
Lightvalve 57:f4819de54e7a 748 double NEW_VELOCITY = (double) ((DIR_JOINT_ENC) * ENC_pos_diff * (int) FREQ_10k);
Lightvalve 54:647072f5307a 749
Lightvalve 57:f4819de54e7a 750 double alpha_update_pos = 1.0f/(1.0f + FREQ_10k/(2.0f*3.14f*100.0f));
Lightvalve 54:647072f5307a 751 pos.sen = NEW_POSITION;
Lightvalve 57:f4819de54e7a 752 vel.sen = (1.0f - alpha_update_pos) * vel.sen + alpha_update_pos * NEW_VELOCITY; // pulse/s
Lightvalve 57:f4819de54e7a 753
Lightvalve 11:82d8768d7351 754 ENC_pos_old = ENC_pos_cur;
Lightvalve 11:82d8768d7351 755 }
Lightvalve 11:82d8768d7351 756
Lightvalve 34:bb2ca2fc2a8e 757 void ENC_SET_ZERO(void)
Lightvalve 34:bb2ca2fc2a8e 758 {
Lightvalve 11:82d8768d7351 759
Lightvalve 11:82d8768d7351 760 spi_enc_set_clear();
Lightvalve 11:82d8768d7351 761 CUR_POSITION = 0;
Lightvalve 11:82d8768d7351 762 ENC_pos_old = ENC_pos_cur = 0;
Lightvalve 11:82d8768d7351 763
Lightvalve 11:82d8768d7351 764 }
Lightvalve 11:82d8768d7351 765
Lightvalve 34:bb2ca2fc2a8e 766 void ENC_SET(int32_t value_e)
Lightvalve 34:bb2ca2fc2a8e 767 {
Lightvalve 11:82d8768d7351 768 spi_enc_set_clear();
Lightvalve 13:747daba9cf59 769 enc_offset = value_e;
Lightvalve 13:747daba9cf59 770 CUR_POSITION = value_e;
Lightvalve 13:747daba9cf59 771 ENC_pos_old = ENC_pos_cur = value_e;
Lightvalve 11:82d8768d7351 772
Lightvalve 11:82d8768d7351 773 }
Lightvalve 18:b8adf1582ea3 774
Lightvalve 19:23b7c1ad8683 775
Lightvalve 30:8d561f16383b 776
Lightvalve 57:f4819de54e7a 777