-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
359 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
101 changes: 101 additions & 0 deletions
101
lbr_ros2_control/include/lbr_ros2_control/controllers/twist_controller.hpp
This file contains 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 @@ | ||
#ifndef LBR_ROS2_CONTROL__LBR_TWIST_CONTROLLER_HPP_ | ||
#define LBR_ROS2_CONTROL__LBR_TWIST_CONTROLLER_HPP_ | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <functional> | ||
#include <memory> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "controller_interface/controller_interface.hpp" | ||
#include "eigen3/Eigen/Core" | ||
#include "geometry_msgs/msg/twist.hpp" | ||
#include "hardware_interface/loaned_state_interface.hpp" | ||
#include "hardware_interface/types/hardware_interface_type_values.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "realtime_tools/realtime_buffer.h" | ||
|
||
#include "friLBRState.h" | ||
|
||
#include "lbr_fri_ros2/kinematics.hpp" | ||
#include "lbr_fri_ros2/pinv.hpp" | ||
#include "lbr_ros2_control/system_interface_type_values.hpp" | ||
|
||
namespace lbr_ros2_control { | ||
struct TwistParameters { | ||
std::string chain_root; | ||
std::string chain_tip; | ||
double damping; | ||
double max_linear_velocity; | ||
double max_angular_velocity; | ||
}; | ||
|
||
class TwistImpl { | ||
public: | ||
TwistImpl(const std::string &robot_description, const TwistParameters ¶meters); | ||
|
||
void compute(const geometry_msgs::msg::Twist::SharedPtr &twist_target, | ||
lbr_fri_ros2::Kinematics::const_jnt_pos_array_t_ref q, | ||
lbr_fri_ros2::Kinematics::jnt_pos_array_t &dq); | ||
|
||
protected: | ||
TwistParameters parameters_; | ||
|
||
lbr_fri_ros2::Kinematics::jnt_pos_array_t q_; | ||
std::unique_ptr<lbr_fri_ros2::Kinematics> kinematics_ptr_; | ||
Eigen::Matrix<double, KUKA::FRI::LBRState::NUMBER_OF_JOINTS, | ||
lbr_fri_ros2::Kinematics::CARTESIAN_DOF> | ||
jacobian_inv_; | ||
Eigen::Matrix<double, lbr_fri_ros2::Kinematics::CARTESIAN_DOF, 1> twist_target_; | ||
}; | ||
|
||
class TwistController : public controller_interface::ControllerInterface { | ||
public: | ||
TwistController(); | ||
|
||
controller_interface::InterfaceConfiguration command_interface_configuration() const override; | ||
|
||
controller_interface::InterfaceConfiguration state_interface_configuration() const override; | ||
|
||
controller_interface::CallbackReturn on_init() override; | ||
|
||
controller_interface::return_type update(const rclcpp::Time &time, | ||
const rclcpp::Duration &period) override; | ||
|
||
controller_interface::CallbackReturn | ||
on_configure(const rclcpp_lifecycle::State &previous_state) override; | ||
|
||
controller_interface::CallbackReturn | ||
on_activate(const rclcpp_lifecycle::State &previous_state) override; | ||
|
||
controller_interface::CallbackReturn | ||
on_deactivate(const rclcpp_lifecycle::State &previous_state) override; | ||
|
||
protected: | ||
bool reference_state_interfaces_(); | ||
void clear_state_interfaces_(); | ||
void reset_command_buffer_(); | ||
void configure_joint_names_(); | ||
void configure_twist_impl_(); | ||
|
||
// joint veloctiy computation | ||
std::unique_ptr<TwistImpl> twist_impl_ptr_; | ||
lbr_fri_ros2::Kinematics::jnt_pos_array_t q_, dq_; | ||
|
||
// interfaces | ||
std::array<std::string, KUKA::FRI::LBRState::NUMBER_OF_JOINTS> joint_names_; | ||
std::vector<std::reference_wrapper<hardware_interface::LoanedStateInterface>> | ||
joint_position_state_interfaces_; | ||
std::unique_ptr<std::reference_wrapper<hardware_interface::LoanedStateInterface>> | ||
sample_time_state_interface_; | ||
std::unique_ptr<std::reference_wrapper<hardware_interface::LoanedStateInterface>> | ||
session_state_interface_; | ||
|
||
// real-time twist command topic | ||
realtime_tools::RealtimeBuffer<geometry_msgs::msg::Twist::SharedPtr> rt_twist_ptr_; | ||
rclcpp::Subscription<geometry_msgs::msg::Twist>::SharedPtr twist_subscription_ptr_; | ||
}; | ||
} // namespace lbr_ros2_control | ||
#endif // LBR_ROS2_CONTROL__LBR_TWIST_CONTROLLER_HPP_ |
This file contains 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 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.