Skip to content

Calculate Chassis velocities using pseudo-inverse using normal equations and Cholesky decomposition - #71

Open
JulianBarossi wants to merge 5 commits into
SJSURoboticsTeam:mainfrom
JulianBarossi:fix/drivetrain-math
Open

Calculate Chassis velocities using pseudo-inverse using normal equations and Cholesky decomposition#71
JulianBarossi wants to merge 5 commits into
SJSURoboticsTeam:mainfrom
JulianBarossi:fix/drivetrain-math

Conversation

@JulianBarossi

@JulianBarossi JulianBarossi commented Nov 15, 2025

Copy link
Copy Markdown
Contributor

chassis_velocities [calc_estimated_chassis_velocities] function

@MichaelYKersey MichaelYKersey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread drive/src/drivetrain_math.cpp Outdated
Comment thread drive/src/drivetrain_math.cpp Outdated
Comment thread drive/src/drivetrain_math.cpp Outdated
Comment thread drive/src/drivetrain_math.cpp Outdated
Comment thread drive/src/drivetrain_math.cpp Outdated
Comment thread drive/src/drivetrain_math.cpp Outdated
Comment thread drive/src/drivetrain_math.cpp Outdated
Comment thread drive/src/drivetrain_math.cpp Outdated
Julian Barossi added 4 commits February 7, 2026 15:39
…y decomposition

changed commit to the correct branch
-Removed temp arrays and accumulate directly now

-Converted angles to rad and stored angular velocity as deg/s

-Cholesky check now returns false when it fails computational check

@MichaelYKersey MichaelYKersey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a simple print demo that runs a couple test cases while I get unit tests set up to make sure the code works. Also rebase from main.

Comment thread drive/include/drivetrain_math.hpp Outdated
*/
float modulus_range(float p_value, float p_lower, float p_upper);

bool isSafe(const std::array<swerve_module_state, module_count>& modules)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c++ lib has it's own pi const, use that

Comment on lines +142 to +147
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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to make a state to velocity vector function if it doesn't already exist

Comment on lines +377 to +385
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +321 to +329
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to noy use modulus_range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants