Skip to content

Add Eigen kinematics example - #737

Merged
chiphogg merged 1 commit into
mainfrom
chiphogg/eigen-example#529
Aug 25, 2026
Merged

Add Eigen kinematics example#737
chiphogg merged 1 commit into
mainfrom
chiphogg/eigen-example#529

Conversation

@chiphogg

Copy link
Copy Markdown
Member

This shows off a nice simplification of some Eigen code. We get good
mileage out of automatic unit conversions, and even the gravity
constant.

Along the way, we tweak the naming and ordering in the index file, to be
more consistent with the titles that show up in the sidebar.

This shows off a nice simplification of some Eigen code.  We get good
mileage out of automatic unit conversions, and even the gravity
constant.

Along the way, we tweak the naming and ordering in the index file, to be
more consistent with the titles that show up in the sidebar.
@chiphogg
chiphogg marked this pull request as ready for review August 24, 2026 20:10
@chiphogg
chiphogg requested a review from a team August 24, 2026 20:10

Au's Eigen support makes it easier to get your units right _robustly_, and often makes your code
easier to read. Lifetime safety is the one thing it leaves exactly as it found it, for better and
for worse, so make sure you're familiar with the Eigen [safety guide] before you start using Au with

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just out of curiosity, I was curious what kind of documentation Eigen had for all this. Mostly because I was thinking this could be simplified to "before you start using Eigen" (because Au doesn't add anything).

Having checked it out, we should leave it as you wrote it. The Eigen stuff is a little more scary ("don't use auto unless you are 100% sure)...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good find. In some ways, I think our docs are better, because they're more clear about the specific ingredients for a problem. Not just "avoid auto" (which was my mindset when I set out to write the article), but "here are the two ingredients for a lifetime bug, and you need both".

In some ways, I think we were more incentivized than Eigen to find and articulate this clarity in our docs, because auto is such a core part of using Au.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I don't know what the state of auto is in the broader industry at large. If I found "our" (good job!) docs on the safety pretty clearly written. It also helps understand template expressions pretty well. Almost seems like Eigen itself could stand to update at least two different parts of their docs into a similar type of doc.

const Velocity &v,
const Acceleration &a,
QuantityD<Seconds> dt) {
return x + v * dt + 0.5 * a * dt * dt;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to use int_pow here?

Suggested change
return x + v * dt + 0.5 * a * dt * dt;
return x + v * dt + 0.5 * a * int_pow<2>(dt);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could, but it seems like kind of a wash at best.

If we had more terms, we could build up the individual powers one at a time and store them in variables (dt2, dt3, etc.) to minimize recomputation.

@chiphogg
chiphogg merged commit bfd6ac0 into main Aug 25, 2026
30 checks passed
@chiphogg
chiphogg deleted the chiphogg/eigen-example#529 branch August 25, 2026 14:16
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