Add Eigen kinematics example - #737
Conversation
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.
|
|
||
| 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 |
There was a problem hiding this comment.
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)...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Do you want to use int_pow here?
| return x + v * dt + 0.5 * a * dt * dt; | |
| return x + v * dt + 0.5 * a * int_pow<2>(dt); |
There was a problem hiding this comment.
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.
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.