-
Notifications
You must be signed in to change notification settings - Fork 18
Convert interface to use Eigen #6
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
destogl
merged 22 commits into
ros-controls:master
from
pac48:convert-interface-to-eigen
Aug 17, 2022
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
dd61a1c
add underscore to end_effector
pac48 19e9813
add test to ensure inverse then forward calculation is approximately …
pac48 ba56cf4
use eigen interface and update tests
pac48 2a5353b
export Eigen dependency
pac48 34d714d
update docs
pac48 46e4b46
use VectorXd type and general cleanup
pac48 1a1919e
Update kinematics_interface_kdl/src/kinematics_interface_kdl.cpp
pac48 7288044
Update kinematics_interface_kdl/test/test_kinematics_interface_kdl.cpp
pac48 a326900
add pre-commit to repo (#7)
pac48 c792ca4
Update kinematics_interface_kdl/test/test_kinematics_interface_kdl.cpp
pac48 42af298
Merge branch 'master' into convert-interface-to-eigen
pac48 f2f3c50
use Isometry3d transform type
pac48 7e6991b
rename classes to match their namespaces
pac48 28ea0df
use parameter interface instead of life_cycle node
pac48 060c704
add interface for std::vector
pac48 38858c4
Merge branch 'master' into convert-interface-to-eigen
destogl a921a34
Merge branch 'master' of https://github.com/ros-controls/kinematics_i…
pac48 62167bc
rename class and file names
pac48 be7a26b
Merge branch 'convert-interface-to-eigen' of github.com:pac48/kinemat…
pac48 5c0eece
Apply suggestions from code review
destogl 326c7bb
remove duplicated documentation
destogl fe995d5
Fixup linters.
destogl 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
156 changes: 156 additions & 0 deletions
156
kinematics_interface/include/kinematics_interface/kinematics_interface.hpp
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,156 @@ | ||
// Copyright (c) 2022, PickNik, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
/// \author: Andy Zelenak, Paul Gesel | ||
/// \description: Base class for kinematics interface | ||
|
||
#ifndef KINEMATICS_INTERFACE__KINEMATICS_INTERFACE_HPP_ | ||
#define KINEMATICS_INTERFACE__KINEMATICS_INTERFACE_HPP_ | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "eigen3/Eigen/Core" | ||
#include "eigen3/Eigen/Geometry" | ||
#include "eigen3/Eigen/LU" | ||
#include "rclcpp/logging.hpp" | ||
#include "rclcpp/node_interfaces/node_parameters_interface.hpp" | ||
|
||
namespace kinematics_interface | ||
{ | ||
rclcpp::Logger LOGGER = rclcpp::get_logger("kinematics_interface"); | ||
|
||
class KinematicsInterface | ||
{ | ||
public: | ||
KinematicsInterface() = default; | ||
|
||
virtual ~KinematicsInterface() = default; | ||
|
||
/** | ||
* \brief Initialize plugin. This method must be called before any other. | ||
*/ | ||
virtual bool initialize( | ||
std::shared_ptr<rclcpp::node_interfaces::NodeParametersInterface> parameters_interface, | ||
const std::string & end_effector_name) = 0; | ||
|
||
/** | ||
* \brief Convert Cartesian delta-x to joint delta-theta, using the Jacobian. | ||
* \param[in] joint_pos joint positions of the robot in radians | ||
* \param[in] delta_x input Cartesian deltas (x, y, z, wx, wy, wz) | ||
* \param[in] link_name the link name at which delta_x is applied | ||
* \param[out] delta_theta outputs joint deltas | ||
* \return true if successful | ||
*/ | ||
virtual bool convert_cartesian_deltas_to_joint_deltas( | ||
const Eigen::VectorXd & joint_pos, const Eigen::Matrix<double, 6, 1> & delta_x, | ||
const std::string & link_name, Eigen::VectorXd & delta_theta) = 0; | ||
|
||
/** | ||
* \brief Convert joint delta-theta to Cartesian delta-x. | ||
* \param joint_pos joint positions of the robot in radians | ||
* \param[in] delta_theta joint deltas | ||
* \param[in] link_name the link name at which delta_x is calculated | ||
* \param[out] delta_x Cartesian deltas (x, y, z, wx, wy, wz) | ||
* \return true if successful | ||
*/ | ||
virtual bool convert_joint_deltas_to_cartesian_deltas( | ||
const Eigen::VectorXd & joint_pos, const Eigen::VectorXd & delta_theta, | ||
const std::string & link_name, Eigen::Matrix<double, 6, 1> & delta_x) = 0; | ||
|
||
/** | ||
* \brief Calculates the joint transform for a specified link using provided joint positions. | ||
* \param[in] joint_pos joint positions of the robot in radians | ||
* \param[in] link_name the name of the link to find the transform for | ||
* \param[out] transform transformation matrix of the specified link | ||
* \return true if successful | ||
*/ | ||
virtual bool calculate_link_transform( | ||
const Eigen::VectorXd & joint_pos, const std::string & link_name, | ||
Eigen::Isometry3d & transform) = 0; | ||
|
||
/** | ||
* \brief Calculates the jacobian for a specified link using provided joint positions. | ||
* \param[in] joint_pos joint positions of the robot in radians | ||
* \param[in] link_name the name of the link to find the transform for | ||
* \param[out] jacobian Jacobian matrix of the specified link in column major format. | ||
* \return true if successful | ||
*/ | ||
virtual bool calculate_jacobian( | ||
const Eigen::VectorXd & joint_pos, const std::string & link_name, | ||
Eigen::Matrix<double, 6, Eigen::Dynamic> & jacobian) = 0; | ||
|
||
bool convert_cartesian_deltas_to_joint_deltas( | ||
std::vector<double> & joint_pos_vec, const std::vector<double> & delta_x_vec, | ||
const std::string & link_name, std::vector<double> & delta_theta_vec) | ||
{ | ||
auto joint_pos = Eigen::Map<const Eigen::VectorXd>(joint_pos_vec.data(), joint_pos_vec.size()); | ||
auto delta_x = Eigen::Map<const Eigen::VectorXd>(delta_x_vec.data(), delta_x_vec.size()); | ||
// TODO(anyone): heap allocation should be removed for realtime use | ||
Eigen::VectorXd delta_theta = | ||
Eigen::Map<Eigen::VectorXd>(delta_theta_vec.data(), delta_theta_vec.size()); | ||
|
||
bool ret = convert_cartesian_deltas_to_joint_deltas(joint_pos, delta_x, link_name, delta_theta); | ||
for (auto i = 0ul; i < delta_theta_vec.size(); i++) | ||
{ | ||
delta_theta_vec[i] = delta_theta[i]; | ||
} | ||
return ret; | ||
} | ||
|
||
bool convert_joint_deltas_to_cartesian_deltas( | ||
const std::vector<double> & joint_pos_vec, const std::vector<double> & delta_theta_vec, | ||
const std::string & link_name, std::vector<double> & delta_x_vec) | ||
{ | ||
auto joint_pos = Eigen::Map<const Eigen::VectorXd>(joint_pos_vec.data(), joint_pos_vec.size()); | ||
Eigen::VectorXd delta_theta = | ||
Eigen::Map<const Eigen::VectorXd>(delta_theta_vec.data(), delta_theta_vec.size()); | ||
if (delta_x_vec.size() != 6) | ||
{ | ||
RCLCPP_ERROR( | ||
LOGGER, "The length of the cartesian delta vector (%zu) must be 6.", delta_x_vec.size()); | ||
return false; | ||
} | ||
Eigen::Matrix<double, 6, 1> delta_x(delta_x_vec.data()); | ||
bool ret = convert_joint_deltas_to_cartesian_deltas(joint_pos, delta_theta, link_name, delta_x); | ||
for (auto i = 0ul; i < delta_x_vec.size(); i++) | ||
{ | ||
delta_x_vec[i] = delta_x[i]; | ||
} | ||
return ret; | ||
} | ||
|
||
bool calculate_link_transform( | ||
const std::vector<double> & joint_pos_vec, const std::string & link_name, | ||
Eigen::Isometry3d & transform) | ||
{ | ||
auto joint_pos = Eigen::Map<const Eigen::VectorXd>(joint_pos_vec.data(), joint_pos_vec.size()); | ||
|
||
return calculate_link_transform(joint_pos, link_name, transform); | ||
} | ||
|
||
bool calculate_jacobian( | ||
const std::vector<double> & joint_pos_vec, const std::string & link_name, | ||
Eigen::Matrix<double, 6, Eigen::Dynamic> & jacobian) | ||
{ | ||
auto joint_pos = Eigen::Map<const Eigen::VectorXd>(joint_pos_vec.data(), joint_pos_vec.size()); | ||
|
||
return calculate_jacobian(joint_pos, link_name, jacobian); | ||
} | ||
}; | ||
|
||
} // namespace kinematics_interface | ||
|
||
#endif // KINEMATICS_INTERFACE__KINEMATICS_INTERFACE_HPP_ |
90 changes: 0 additions & 90 deletions
90
kinematics_interface/include/kinematics_interface/kinematics_interface_base.hpp
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
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.