-
Notifications
You must be signed in to change notification settings - Fork 536
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
[FEATURE] An idear for shaftAngle & filter. #302
Comments
I am not sure I understand… what problem are you trying to improve with this? the shaft angle is already computed via LPF filtering, and the full rotations are accounted for in the sensor class… |
src\common\base_classes\Sensor.cpp Line 54:
// TODO sensor precision: the shaft_angle actually stores the complete position, including full rotations, as a float |
I think internally it already works this way - see sensor.getMechanicalAngle() the precision problem exists still in position mode - where you can command angles mich larger than 2PI we would have to change the API for position mode to solve this problem. on the sensor side it is already solved… |
I do think this is the proper way to handle large angles, but it has a fairly large performance penalty to solve a problem that only affects a few users. The PID code in motor.move will have more added cost, and motor.target is still trouble. I'm more inclined to abandon the idea of handling large angles entirely, and instead provide a way for users to manually wrap the angle back into the safe range when needed.
LowPassFilter::y_prev will need to be made public or FOCMotor added as a friend class, and several sensor classes will need to implement wrapAngle, which in the case of the base class will simply be I think most applications that need unlimited angle range are controlled by step/dir, in which case you don't even need to keep track of the full rotations. Just do Or if you do need to keep track of it, call motor.wrapAngle() each frame and add the result to a full rotation counter. When commanding a new target, subtract that full rotation counter from the real high-resolution target value before passing to motor.move. |
Or we kick this problem down the road until 64bit MCUs and double precision FPUs are the standard :-D |
step 1:
if(mechanic_angle > mechanic_angle_prev + 180){
mechanic_angle -= 360;
}else if(mechanic_angle < mechanic_angle_prev - 180){
mechanic_angle += 360;
}
step 2:
LPF_angle(mechanic_angle);
step 3:
if(mechanic_angle >= 360.0f){
mechanic_angle -= 360.0f;
}else if(mechanic_angle < 0.0f){
mechanic_angle += 360.0f;
}
step 4:
if(LPF_angle.y_prev >= 360){
LPF_angle.y_prev -=360;
rotation_cnt += 1;
}
if(LPF_angle.y_prev < 0){
LPF_angle.y_prev +=360;
rotation_cnt -= 1;
}
The text was updated successfully, but these errors were encountered: