-
Notifications
You must be signed in to change notification settings - Fork 654
Autotunng + a big reactor without API chnage #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
|
This seems like a good refactoring to me... One thing to maybe talk about is to make the PID and LPF classes exchangeable instead of hard-coded, and then instead of combining fixed and variable sample times into one class, to make separate classes and therefore also open the possibility to have alternative implementations. |
|
I like the idea. Do you have an idea on how to do it though? |
Good question what the best way to do it is. At the moment the LPF and PIDs are fields of FOCMotor. They can't be changed because they are direct members of the class, and also because their methods are not virtual and can't be overloaded. One way would be to use the same paradigm as for Driver and CurrentSense. Change them to be pointer types, and make their functions virtual for overloading. Another way, probably with better runtime performance would be to use templates. In general I was wondering if introducing templates in some places would not be a better approach altogether, but this would be a bigger refactoring... template<typename LPF, typename PID> FOCMotorT {
...
PID PID_current_q{DEF_PID_CURR_P,DEF_PID_CURR_I,DEF_PID_CURR_D,DEF_PID_CURR_RAMP, DEF_POWER_SUPPLY};//!< parameter determining the q current PID config
PID PID_current_d{DEF_PID_CURR_P,DEF_PID_CURR_I,DEF_PID_CURR_D,DEF_PID_CURR_RAMP, DEF_POWER_SUPPLY};//!< parameter determining the d current PID config
LPF LPF_current_q{DEF_CURR_FILTER_Tf};//!< parameter determining the current Low pass filter configuration
LPF LPF_current_d{DEF_CURR_FILTER_Tf};//!< parameter determining the current Low pass filter configuration
PID PID_velocity{DEF_PID_VEL_P,DEF_PID_VEL_I,DEF_PID_VEL_D,DEF_PID_VEL_RAMP,DEF_PID_VEL_LIMIT};//!< parameter determining the velocity PID configuration
PID P_angle{DEF_P_ANGLE_P,0,0,0,DEF_VEL_LIM}; //!< parameter determining the position PID configuration
LPF LPF_velocity{DEF_VEL_FILTER_Tf};//!< parameter determining the velocity Low pass filter configuration
LPF LPF_angle{0.0};//!< parameter determining the angle low pass filter configuration
...
};
typedef FOCMotorT<LowPassFiler,PIDController> FOCMotor; // standard version instantiated
then users could make their own, by writing a MyPIDController class fitting the PID template:
|
So this is a PR that does two things:
Refactor
Autotuning
MFC100for the bandwith of100Hzsetup. - exmotor.tuneCurrentController(100)motor.characteriseMotor