-
Notifications
You must be signed in to change notification settings - Fork 29
refactor(motor-control): clarity pass - public helpers + named constants (no breaking changes) #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
18b8184
fix(motor-control): five correctness bugs in basicmicro / canopen (no…
finger563 729fc92
refactor(motor-control): clarity pass - surface public helpers, use n…
finger563 a598188
refactor(motor-control): address clarity-PR review comments
finger563 687dc9d
feat(canopen): libfmt formatters for the CiA 402 / NMT enums
finger563 64c909a
Merge branch 'main' into refactor/motor-control-clarity
finger563 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #pragma once | ||
|
|
||
| #include <string_view> | ||
|
|
||
| #include "format.hpp" | ||
|
|
||
| #include "detail/canopen_core.hpp" | ||
|
|
||
| // libfmt formatters for the CANopen / CiA 402 enums so application code can print | ||
| // them directly -- e.g. `logger.info("Drive state: {}", state)` -- instead of | ||
| // calling a to-string helper inline at every call site. | ||
|
|
||
| /// \brief fmt formatter for a CiA 402 drive state (espp::Ds402Drive::State). | ||
| template <> struct fmt::formatter<espp::detail::ds402::State> : fmt::formatter<std::string_view> { | ||
| template <typename FormatContext> | ||
| auto format(espp::detail::ds402::State state, FormatContext &ctx) const { | ||
| return fmt::formatter<std::string_view>::format(espp::detail::ds402::state_to_string(state), | ||
| ctx); | ||
| } | ||
| }; | ||
|
|
||
| /// \brief fmt formatter for a CiA 402 mode of operation | ||
| /// (espp::Ds402Drive::OperatingMode). | ||
| template <> | ||
| struct fmt::formatter<espp::detail::ds402::OperatingMode> : fmt::formatter<std::string_view> { | ||
| template <typename FormatContext> | ||
| auto format(espp::detail::ds402::OperatingMode mode, FormatContext &ctx) const { | ||
| using espp::detail::ds402::OperatingMode; | ||
| std::string_view s = "Unknown"; | ||
| switch (mode) { | ||
| case OperatingMode::ProfilePosition: | ||
| s = "Profile position"; | ||
| break; | ||
| case OperatingMode::ProfileVelocity: | ||
| s = "Profile velocity"; | ||
| break; | ||
| case OperatingMode::ProfileTorque: | ||
| s = "Profile torque"; | ||
| break; | ||
| case OperatingMode::Homing: | ||
| s = "Homing"; | ||
| break; | ||
| } | ||
| return fmt::formatter<std::string_view>::format(s, ctx); | ||
| } | ||
| }; | ||
|
|
||
| /// \brief fmt formatter for an NMT node state (espp::CanopenClient::NmtState). | ||
| template <> | ||
| struct fmt::formatter<espp::detail::canopen::NmtState> : fmt::formatter<std::string_view> { | ||
| template <typename FormatContext> | ||
| auto format(espp::detail::canopen::NmtState state, FormatContext &ctx) const { | ||
| using espp::detail::canopen::NmtState; | ||
| std::string_view s = "Unknown"; | ||
| switch (state) { | ||
| case NmtState::BootUp: | ||
| s = "Boot-up"; | ||
| break; | ||
| case NmtState::Stopped: | ||
| s = "Stopped"; | ||
| break; | ||
| case NmtState::Operational: | ||
| s = "Operational"; | ||
| break; | ||
| case NmtState::PreOperational: | ||
| s = "Pre-operational"; | ||
| break; | ||
| case NmtState::Unknown: | ||
| break; | ||
| } | ||
| return fmt::formatter<std::string_view>::format(s, ctx); | ||
| } | ||
| }; | ||
|
|
||
| /// \brief fmt formatter for an NMT master command (espp::CanopenClient::NmtCommand). | ||
| template <> | ||
| struct fmt::formatter<espp::detail::canopen::NmtCommand> : fmt::formatter<std::string_view> { | ||
| template <typename FormatContext> | ||
| auto format(espp::detail::canopen::NmtCommand cmd, FormatContext &ctx) const { | ||
| using espp::detail::canopen::NmtCommand; | ||
| std::string_view s = "Unknown"; | ||
| switch (cmd) { | ||
| case NmtCommand::Start: | ||
| s = "Start"; | ||
| break; | ||
| case NmtCommand::Stop: | ||
| s = "Stop"; | ||
| break; | ||
| case NmtCommand::PreOperational: | ||
| s = "Pre-operational"; | ||
| break; | ||
| case NmtCommand::ResetNode: | ||
| s = "Reset node"; | ||
| break; | ||
| case NmtCommand::ResetCommunication: | ||
| s = "Reset communication"; | ||
| break; | ||
| } | ||
| return fmt::formatter<std::string_view>::format(s, ctx); | ||
| } | ||
| }; |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.