This repository was archived by the owner on Feb 3, 2023. It is now read-only.
Allow varying units in printing odomState#487
Merged
Conversation
b7dfc95 to
9a3ba4a
Compare
Codecov Report
@@ Coverage Diff @@
## master #487 +/- ##
==========================================
+ Coverage 89.11% 89.13% +0.02%
==========================================
Files 139 140 +1
Lines 6143 6155 +12
==========================================
+ Hits 5474 5486 +12
Misses 669 669 |
karmanyaahm
commented
Jun 10, 2022
Contributor
Author
|
@Octogonapus Can you please answer the questions in the review comments? |
karmanyaahm
commented
Jun 10, 2022
9a3ba4a to
68d8158
Compare
The function std::string getShortUnitName(QType q) in include/okapi/api/units/RQuantityName.hpp returns the a string of the matching unit. For example, a call such as `getShortUnitName(1_m)` will return "m", 1_rad will return "rad". A value that doesn't exactly (within 0.01%) map to a unit such as 1.01_m will throw an error. This is currently only implemented for QLength and QAngle because that's what's needed for Odometry. It should be trivial to add other types to the map if the need arises in the future.
There are two versions of the function now, - one that takes in units, and uses the getShortUnitName function to determine the suffix for thestring representation of that value. - The other takes in a unit to convert to, but uses user input strings as the suffix. This allows the caller to use fancy units, or ignore units entirely. - The no arguments, backwards compatible caller uses the latter with default arguments of meter, "_m", and degree, "_deg". This default function removes the need for map lookups on the default function, which the former would require. Example calls to this function would be: - `OdomState::str()`: returns values in meters and degrees, with _m and _deg suffixes - `OdomState::str(1_ft, 1_rad)`: returns values in feet and radians, with getShortUnitName determining the appropriate suffixes (_ft and _rad) - `OdomState::str(6_tile / 100, "%", 360_deg / 100, "%")`: is a fancy way of getting the values in % of the vex field, and % degrees of a full circle. - `OdomState::str(1_m, 1.01_deg)`: should fail because it uses unit lookup on an undefined unit (1.01_deg has no unit suffix).
68d8158 to
c19a50a
Compare
e94636e to
358eb9d
Compare
Contributor
Author
|
@Octogonapus can you look at this please? |
Octogonapus
approved these changes
Jun 26, 2022
Member
Octogonapus
left a comment
There was a problem hiding this comment.
pretty sure you need double backticks for inline code but we'll see
Member
|
update: no that actually works |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test this with:
TODO:
Closes #467