Calculate Chassis velocities using pseudo-inverse using normal equations and Cholesky decomposition - #71
Conversation
…ns and cholesky decomposition
MichaelYKersey
left a comment
There was a problem hiding this comment.
I will trust that the actual math correct, but add some comments so someone has some ideas of what to search up/look at if they want to understand in the future.
…y decomposition changed commit to the correct branch
| */ | ||
| float modulus_range(float p_value, float p_lower, float p_upper); | ||
|
|
||
| bool isSafe(const std::array<swerve_module_state, module_count>& modules) |
There was a problem hiding this comment.
use type const& not const type&
| // https://www.youtube.com/watch?v=C7LEuhS4H94&t=8s | ||
| // https://math.mit.edu/icg/resources/teaching/18.085-spring2015/LeastSquares.pdf | ||
| // https://tobydriscoll.net/fnc-julia/leastsq/normaleqns.html | ||
| constexpr float M_PI = 3.14159265358979323846f; |
There was a problem hiding this comment.
c++ lib has it's own pi const, use that
| auto const state = module.get_actual_state_cache(); | ||
| float const speed = state.propulsion_velocity; | ||
| float const angle_degrees = state.steer_angle; | ||
| float const angle_rad = angle_degrees * deg_to_rad; | ||
| float const vix = speed * std::cos(angle_rad); | ||
| float const viy = speed * std::sin(angle_rad); |
There was a problem hiding this comment.
might be good to make a state to velocity vector function if it doesn't already exist
| auto const& module = *p_modules[i]; | ||
| auto const state = module.get_actual_state_cache(); | ||
| auto const& position = module.settings.position; | ||
|
|
||
| // convert deg/sec to rad/sec | ||
| float omega_radians = estimates.rotational_vel * deg_to_rad; | ||
|
|
||
| float est_vx = estimates.translation.x - omega_radians * position.y; | ||
| float est_vy = estimates.translation.y + omega_radians * position.x; |
There was a problem hiding this comment.
these math calculations (module velocity vector & chassis speeds to module sate or vector) should already exist in some other drive math function, if not then make one.
| float angleDiff(float a, float b) | ||
| { | ||
|
|
||
| float d = std::fmod(a - b + M_PI, 2.0 * M_PI); | ||
| if (d < 0) | ||
| d += 2.0 * M_PI; | ||
|
|
||
| return d - M_PI; | ||
| } |
There was a problem hiding this comment.
Is there a reason to noy use modulus_range
chassis_velocities [calc_estimated_chassis_velocities] function