-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/feedback control #12
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
19 commits
Select commit
Hold shift + click to select a range
5363bf6
Add JointKinematics
manumerous d399b14
Refactor JointFeedbackAction
manumerous 53b03dc
Format
manumerous 81de318
Refactor Robotstate
manumerous 8dba7ef
Add desired state to controllers
manumerous bb24cd3
Refactor to ImplicitJointPDController
manumerous 669dca6
Refactor non snake case variable name
manumerous 394e806
Refactor variable naming
manumerous dbfd2c3
make index vectors const reference
manumerous 563885a
Add Prototype of explicit joint pd controller
manumerous d73f6e5
Template PD controller with both impülicit and explicit instances
manumerous 503ef28
Add fromVector method and extend tests
manumerous 19d8555
Fix typos
manumerous 1c35c96
Remove validateConfig from PDController
manumerous 34e15f9
Improve test and check logic
manumerous 092043f
Add extra debug check to give better error message
manumerous 5a89cef
Update motorium/motorium_model/test/testFixedIDArray.cpp
manumerous 223230d
Format the code
manumerous 4d3d045
Fix bazel tests
manumerous 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
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 was deleted.
Oops, something went wrong.
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,108 @@ | ||
| /****************************************************************************** | ||
| Copyright (c) 2025, Manuel Yves Galliker. All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright notice, this | ||
| list of conditions and the following disclaimer. | ||
|
|
||
| * Redistributions in binary form must reproduce the above copyright notice, | ||
| this list of conditions and the following disclaimer in the documentation | ||
| and/or other materials provided with the distribution. | ||
|
|
||
| * Neither the name of the copyright holder nor the names of its | ||
| contributors may be used to endorse or promote products derived from | ||
| this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| ******************************************************************************/ | ||
|
|
||
| #include <motorium_control/JointPDController.h> | ||
|
|
||
| #include <motorium_core/Check.h> | ||
|
|
||
| namespace motorium::control { | ||
|
|
||
| void JointPDControllerConfig::validate() const { | ||
| MT_CHECK(!joint_names.empty()) << "[JointPDController] Configuration error: Joint names list is empty."; | ||
| MT_CHECK(static_cast<long>(joint_names.size()) == kp.size()) | ||
| << "[JointPDController] Configuration error: Size mismatch between joint_names and kp."; | ||
| MT_CHECK(static_cast<long>(joint_names.size()) == kd.size()) | ||
| << "[JointPDController] Configuration error: Size mismatch between joint_names and kd."; | ||
| } | ||
|
|
||
| template <bool IsImplicit> | ||
| JointPDController<IsImplicit>::JointPDController(const model::RobotDescription& robot_description, const JointPDControllerConfig& config) | ||
| : ControllerBase(robot_description), config_(config), joint_indices_(robot_description.getJointIndices(config_.joint_names)) { | ||
| config_.validate(); | ||
| } | ||
|
|
||
| template <bool IsImplicit> | ||
| void JointPDController<IsImplicit>::computeJointControlAction([[maybe_unused]] scalar_t time, | ||
| const model::RobotState& current_state, | ||
| const model::RobotState& desired_state, | ||
| model::RobotJointFeedbackAction& joint_action) { | ||
| if constexpr (IsImplicit) { | ||
| computeImplicitPD(desired_state, joint_action); | ||
| } else { | ||
| computeExplicitPD(current_state, desired_state, joint_action); | ||
| } | ||
| } | ||
|
|
||
| template <bool IsImplicit> | ||
| void JointPDController<IsImplicit>::computeImplicitPD(const model::RobotState& desired_state, | ||
| model::RobotJointFeedbackAction& joint_action) { | ||
| for (size_t i = 0; i < joint_indices_.size(); ++i) { | ||
| const auto joint_index = joint_indices_[i]; | ||
| if (joint_action.contains(joint_index)) { | ||
| model::JointFeedbackAction& action = joint_action[joint_index]; | ||
| const model::JointState& desired = desired_state.getJointState(joint_index); | ||
|
|
||
| action.q_des = desired.q; | ||
| action.v_des = desired.v; | ||
| action.feed_forward_effort = desired.effort; | ||
| action.kp = config_.kp(i); | ||
| action.kd = config_.kd(i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| template <bool IsImplicit> | ||
| void JointPDController<IsImplicit>::computeExplicitPD(const model::RobotState& current_state, | ||
| const model::RobotState& desired_state, | ||
| model::RobotJointFeedbackAction& joint_action) { | ||
| for (size_t i = 0; i < joint_indices_.size(); ++i) { | ||
| const auto joint_index = joint_indices_[i]; | ||
| if (joint_action.contains(joint_index)) { | ||
| model::JointFeedbackAction& action = joint_action[joint_index]; | ||
| const model::JointState& desired = desired_state.getJointState(joint_index); | ||
| const model::JointState& current = current_state.getJointState(joint_index); | ||
|
|
||
| scalar_t q_error = desired.q - current.q; | ||
| scalar_t v_error = desired.v - current.v; | ||
| scalar_t feedback = config_.kp(i) * q_error + config_.kd(i) * v_error; | ||
|
|
||
| action.q_des = desired.q; | ||
| action.v_des = desired.v; | ||
| action.feed_forward_effort = desired.effort + feedback; | ||
| action.kp = 0.0; | ||
| action.kd = 0.0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Explicit template instantiations | ||
| template class JointPDController<true>; | ||
| template class JointPDController<false>; | ||
|
|
||
| } // namespace motorium::control |
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.