![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
rainbow
setting.h
- Committer:
- Lightvalve
- Date:
- 2019-09-10
- Revision:
- 23:59218d4a256d
- Parent:
- 22:966b35691d69
- Child:
- 26:8317d883d4f2
File content as of revision 23:59218d4a256d:
#include "mbed.h" #include "FastPWM.h" // pwm #define PIN_V PB_7 #define PIN_W PB_6 //#define PWM_ARR 0x465 // loop 80k, pwm 40k //#define PWM_ARR 0x8CA // loop 40k, pwm 20k //#define PWM_ARR 0x1194 // loop 20k, pwm 10k #define PWM_ARR 0x2328 // loop 10k, pwm 5k #define TMR3_COUNT 0x4650 // loop 5k #define TMR2_COUNT 0x2710 // loop 500hz with prescale 18 #define FREQ_500 500.0 #define FREQ_1k 1000.0 #define FREQ_5k 5000.0 #define FREQ_10k 10000.0 #define FREQ_20k 20000.0 #define FREQ_40k 40000.0 #define DT_500 0.002 #define DT_1k 0.0005 #define DT_5k 0.0002 #define DT_10k 0.0001 #define DT_20k 0.00005 #define DT_40k 0.000025 //extern int CID_RX_CMD; //extern int CID_RX_REF_POSITION; //extern int CID_RX_REF_TORQUE; //extern int CID_RX_REF_PRES_DIFF; //extern int CID_RX_REF_VOUT; //extern int CID_RX_REF_VALVE_POSITION; //extern int CID_RX_REF_CURRENT; // //extern int CID_TX_INFO; //extern int CID_TX_POSITION; //extern int CID_TX_TORQUE; //extern int CID_TX_PRES; //extern int CID_TX_VOUT; //extern int CID_TX_VALVE_POSITION; extern DigitalOut check; extern DigitalOut check_2; extern AnalogOut dac_1; extern AnalogOut dac_2; extern double dtc_v; extern double dtc_w; // I2C extern I2C i2c; // SDA, SCL (for K22F) extern const int i2c_slave_addr1; extern unsigned int value; // 10bit output of reading sensor AS5510 // SPI //extern SPI eeprom; //(SPI_MOSI, SPI_MISO, SPI_SCK); //extern DigitalOut eeprom_cs; extern SPI enc; extern DigitalOut enc_cs; // UART extern Serial pc; //Serial pc(PA_9,PA_10); _ UART // CAN extern CAN can; extern CANMessage msg; // Board Information // User Function void CurrentControl(); void ValveControl(unsigned int ControlMode); /******************************************************************************* * COMMON Settings ******************************************************************************/ #define LATEST_VERSION 19032 /******************************************************************************* * COMMON CONSTANTS ******************************************************************************/ #define RAD_30 0.523598775598299 #define RAD_60 1.047197551196598 #define RAD_120 2.094395102393195 #define RAD_180 3.141592653589793 #define RAD_240 4.188790204786391 #define RAD_300 5.235987755982989 #define RAD_360 6.283185307179586 #define SYSFREQ 200000000 #define PBCLK 100000000 //#define TMR_FREQ_10k 10000 #define TMR_FREQ_5k 5000 #define FALSE 0 #define TRUE 1 #define OUTPUT 0 #define INPUT 1 #define LOW 0 #define HIGH 1 #define DIGITAL 0 #define ANALOG 1 #define PI 3.141592653589793 #define D2R 0.017453292519943 #define R2D 57.295779513082323 /******************************************************************************* * HEADER INCLUDE ******************************************************************************/ /******************************************************************************* * VARIABLE ******************************************************************************/ // Board Information extern uint8_t BNO; extern uint8_t CONTROL_MODE; extern uint8_t OPERATING_MODE; extern uint8_t SETTING_SWITCH; extern uint8_t SETTING_SWITCH_OLD; extern uint8_t REFERENCE_MODE; extern uint16_t CAN_FREQ; extern int16_t DIR_JOINT_ENC; extern int16_t DIR_VALVE; extern int16_t DIR_VALVE_ENC; extern double SUPPLY_VOLTAGE; extern double VALVE_VOLTAGE_LIMIT; extern double P_GAIN_VALVE_POSITION; extern double I_GAIN_VALVE_POSITION; extern double D_GAIN_VALVE_POSITION; extern double P_GAIN_JOINT_POSITION; extern double I_GAIN_JOINT_POSITION; extern double D_GAIN_JOINT_POSITION; extern double P_GAIN_JOINT_TORQUE; extern double I_GAIN_JOINT_TORQUE; extern double D_GAIN_JOINT_TORQUE; extern int16_t VALVE_DEADZONE_PLUS; extern int16_t VALVE_DEADZONE_MINUS; extern int16_t VELOCITY_COMP_GAIN; extern int16_t COMPLIANCE_GAIN; extern int16_t VALVE_CENTER; extern int16_t VALVE_FF; extern int16_t BULK_MODULUS; extern int16_t CHAMBER_VOLUME_A; extern int16_t CHAMBER_VOLUME_B; extern int16_t PISTON_AREA_A; extern int16_t PISTON_AREA_B; extern double PISTON_AREA_alpha; extern int16_t PRES_SUPPLY; extern int16_t PRES_RETURN; extern int16_t ENC_LIMIT_PLUS; extern int16_t ENC_LIMIT_MINUS; extern int16_t STROKE; extern int16_t VALVE_LIMIT_PLUS; extern int16_t VALVE_LIMIT_MINUS; extern int16_t ENC_PULSE_PER_POSITION; extern int16_t TORQUE_SENSOR_PULSE_PER_TORQUE; extern double PRES_SENSOR_A_PULSE_PER_BAR; extern double PRES_SENSOR_B_PULSE_PER_BAR; extern int HOMEPOS_OFFSET; extern int HOMEPOS_VALVE_OPENING; extern double FRICTION; extern double REF_PERIOD; extern double REF_MAG; extern int REF_NUM; extern double DAC_REF; extern double DAC_RESOL; extern int REF_POSITION; extern int REF_VELOCITY; extern int16_t REF_TORQUE; extern int16_t REF_PRES_DIFF; extern int16_t REF_PWM; extern int16_t REF_VALVE_POSITION; extern int16_t REF_CURRENT; extern int REF_MOVE_TIME_5k; extern int INIT_REF_PWM; extern int INIT_REF_VALVE_POS; extern int INIT_REF_POS; extern int INIT_REF_VEL; extern int INIT_REF_TORQUE; extern int INIT_REF_PRES_DIFF; extern int INIT_REF_CURRENT; extern int CUR_POSITION; extern int CUR_VELOCITY; extern double CUR_TORQUE; extern double CUR_PRES_A; extern double CUR_PRES_B; extern int CUR_PWM; extern int CUR_VALVE_POSITION; extern unsigned int TMR2_COUNT_LED1; extern unsigned int TMR2_COUNT_LED2; extern unsigned int TMR2_COUNT_CAN_TX; extern int num_err; extern int flag_err[8]; extern int flag_err_old[8]; extern int flag_err_rt; extern int flag_ref_enable; extern int flag_data_request[5]; //////////////////////////////////////////////////////////////////////////////// ////////////////////////////// SEUNGHOON ADD /////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// extern double CUR_PRES_A_BAR; extern double CUR_PRES_B_BAR; extern double CUR_TORQUE_NM; extern double CUR_TORQUE_NM_PRESS; extern double PRES_A_VREF; extern double PRES_A_VREF_TEST; extern double PRES_B_VREF; extern double PRES_B_VREF_TEST; extern double TORQUE_VREF; extern double VALVE_PWM_RAW_FB; extern double VALVE_PWM_RAW_FF; extern int VALVE_PWM_VALVE_DZ; extern int VALVE_INPUT_PWM; extern double VALVE_GAIN_LPM_PER_V[10]; extern double VALVE_POS_VS_PWM[25]; extern long JOINT_VEL[100]; extern int VALVE_MAX_POS; extern int VALVE_MIN_POS; extern int DDV_CENTER; extern int VALVE_POS_NUM; extern int TMR3_COUNT_FINDHOME; extern int TMR3_COUNT_FLOWRATE; extern int TMR3_COUNT_DEADZONE; extern int TMR3_COUNT_PRES_NULL; extern int TMR3_COUNT_TORQUE_NULL; extern int TMR3_COUNT_PRES_CALIB; extern int TMR3_COUNT_REFERENCE; extern int TMR3_COUNT_JOINT; extern int TMR3_COUNT_ROTARY_FRIC_TUNE; extern bool FLAG_REFERENCE_VALVE_PWM; extern bool FLAG_REFERENCE_VALVE_POSITION; extern bool FLAG_REFERENCE_JOINT_POSITION; extern bool FLAG_REFERENCE_JOINT_TORQUE; extern bool FLAG_REFERENCE_PRES_DIFF; extern bool FLAG_REFERENCE_CURRENT; extern double TUNING_TIME; extern double REFERENCE_FREQ; extern double REFERENCE_MAG; extern bool FLAG_FIND_HOME; extern int MODE_JUMP_STATUS; extern double CUR_PRES_DIFF_BAR; extern double CUR_PRES_A_sum; extern double CUR_PRES_B_sum; extern double CUR_PRES_A_mean; extern double CUR_PRES_B_mean; extern double CUR_TORQUE_sum; extern double CUR_TORQUE_mean; extern double PRES_A_NULL; extern double PRES_B_NULL; extern double TORQUE_NULL; extern double Ref_Valve_Pos_Old; extern int VALVE_ID_timer; extern int VALVE_DZ_timer; extern int VALVE_FR_timer; extern int VALVE_POS_TMP; extern int JOINT_VEL_TMP; extern int DDV_POS_AVG ; extern int VALVE_POS_AVG[50]; extern int VALVE_POS_AVG_OLD; extern int data_num; extern int ID_index; extern int DZ_index; extern int ID_index_array[50]; extern int first_check; extern double init_time; extern int VEL_POINT; extern int DZ_case; extern int START_POS; extern int FINAL_POS; extern int DZ_DIRECTION; extern int FIRST_DZ; extern int SECOND_DZ; extern int DZ_NUM; extern int one_period_end; extern double Ref_Vel_Test; extern long TMR2_FOR_SLOW_LOGGING; //extern int velcount; extern int Ref_Valve_Pos_FF_CAN; extern char max_check; extern char min_check; extern double valve_pos_err, valve_pos_err_old, valve_pos_err_diff, valve_pos_err_sum; extern double joint_pos_err, joint_pos_err_old, joint_pos_err_diff, joint_pos_err_diff_fil, joint_pos_err_sum; extern double joint_torq_err, joint_torq_err_old, joint_torq_err_diff, joint_torq_err_sum; extern double VALVE_PWM_RAW_POS, VALVE_PWM_RAW_TORQ; extern double CUR_FLOWRATE; extern double VALVE_FF_VOLTAGE; extern int pos_plus_end; extern int pos_minus_end; extern bool need_enc_init; extern int temp_time; extern double CUR_VELOCITY_sum; extern double temp_vel_sum; extern int DZ_dir; extern int DZ_temp_cnt; extern int DZ_temp_cnt2; extern int DZ_end; extern int flag_flowrate; extern int fl_temp_cnt; extern int fl_temp_cnt2; extern int cur_vel_sum; // find home extern int CUR_VELOCITY_OLD; extern int cnt_findhome; extern int cnt_vel_findhome; extern int FINDHOME_VELOCITY; extern int FINDHOME_VELOCITY_OLD; extern int FINDHOME_POSITION; extern int FINDHOME_POSITION_OLD; // valve gain extern int check_vel_pos_init; extern int check_vel_pos_fin; extern int check_vel_pos_interv; extern int valve_gain_repeat_cnt; extern double VALVE_VOLTAGE; extern double freq_fric_tune; extern bool FLAG_VALVE_OUTPUT_CALIB; extern uint32_t TMR3_COUNT_CAN_TX; extern double I_REF; extern int TMR3_COUNT_IREF; extern double CUR_CURRENT; extern double u_CUR[3]; //extern int Ref_Valve_Pos_FF_CAN; //extern int h1, h2, h3, h4, h5, h6;