-
Notifications
You must be signed in to change notification settings - Fork 82
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
Port cartesian_impedance_controller to franka_ros2 example controllers #51
Open
sp-sophia-labs
wants to merge
12
commits into
frankaemika:humble
Choose a base branch
from
sp-sophia-labs:humble
base: humble
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+457
−0
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c8ed063
import cartesian_impedance_controller to franka_ros2 example controllers
ZackqB 89c8aff
clean up headers
ZackqB edcf178
saturation
ZackqB a4fcfec
Cartesian Impedance Example Controller config
ZackqB 9306231
clenup leftover & fix equilibriumPoseCallback call & pseudo inversion…
ZackqB d6929be
Cartesian Impedance Example launch file
ZackqB dc89731
return inverse instead of receiving parameter
ZackqB bc5c07f
doc, variables and arm_id call fix
ZackqB 1370f93
overlap clean identity
ZackqB 07da33e
Merge branch 'frankaemika:humble' into humble
sp-sophia-labs 1b3b4ff
add executable and needed adjustement for local version
ZackqB 64966bf
add equilibrium pose publisher
ZackqB 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 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
69 changes: 69 additions & 0 deletions
69
franka_bringup/launch/cartesian_impedance_example_controller.launch.py
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,69 @@ | ||
from launch import LaunchDescription | ||
from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
from launch.substitutions import LaunchConfiguration, PathJoinSubstitution | ||
from launch_ros.actions import Node | ||
from launch_ros.substitutions import FindPackageShare | ||
|
||
|
||
def generate_launch_description(): | ||
robot_ip_parameter_name = 'robot_ip' | ||
arm_id_parameter_name = 'arm_id' | ||
load_gripper_parameter_name = 'load_gripper' | ||
use_fake_hardware_parameter_name = 'use_fake_hardware' | ||
fake_sensor_commands_parameter_name = 'fake_sensor_commands' | ||
use_rviz_parameter_name = 'use_rviz' | ||
|
||
robot_ip = LaunchConfiguration(robot_ip_parameter_name) | ||
arm_id = LaunchConfiguration(arm_id_parameter_name) | ||
load_gripper = LaunchConfiguration(load_gripper_parameter_name) | ||
use_fake_hardware = LaunchConfiguration(use_fake_hardware_parameter_name) | ||
fake_sensor_commands = LaunchConfiguration(fake_sensor_commands_parameter_name) | ||
use_rviz = LaunchConfiguration(use_rviz_parameter_name) | ||
|
||
return LaunchDescription([ | ||
DeclareLaunchArgument( | ||
robot_ip_parameter_name, | ||
description='Hostname or IP address of the robot.'), | ||
DeclareLaunchArgument( | ||
arm_id_parameter_name, | ||
default_value='fr3', | ||
description='ID of the type of arm used. Supported values: fer, fr3, fp3'), | ||
DeclareLaunchArgument( | ||
use_rviz_parameter_name, | ||
default_value='false', | ||
description='Visualize the robot in Rviz'), | ||
DeclareLaunchArgument( | ||
use_fake_hardware_parameter_name, | ||
default_value='false', | ||
description='Use fake hardware'), | ||
DeclareLaunchArgument( | ||
fake_sensor_commands_parameter_name, | ||
default_value='false', | ||
description="Fake sensor commands. Only valid when '{}' is true".format( | ||
use_fake_hardware_parameter_name)), | ||
DeclareLaunchArgument( | ||
load_gripper_parameter_name, | ||
default_value='true', | ||
description='Use Franka Gripper as an end-effector, otherwise, the robot is loaded ' | ||
'without an end-effector.'), | ||
|
||
IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource([PathJoinSubstitution( | ||
[FindPackageShare('franka_bringup'), 'launch', 'franka.launch.py'])]), | ||
launch_arguments={robot_ip_parameter_name: robot_ip, | ||
arm_id_parameter_name: arm_id, | ||
load_gripper_parameter_name: load_gripper, | ||
use_fake_hardware_parameter_name: use_fake_hardware, | ||
fake_sensor_commands_parameter_name: fake_sensor_commands, | ||
use_rviz_parameter_name: use_rviz | ||
}.items(), | ||
), | ||
|
||
Node( | ||
package='controller_manager', | ||
executable='spawner', | ||
arguments=['cartesian_impedance_example_controller'], | ||
output='screen', | ||
), | ||
]) |
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
91 changes: 91 additions & 0 deletions
91
...controllers/include/franka_example_controllers/cartesian_impedance_example_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,91 @@ | ||
#pragma once | ||
|
||
#include <Eigen/Dense> | ||
#include <cmath> | ||
#include <fstream> | ||
#include <functional> | ||
#include <memory> | ||
#include <mutex> | ||
#include <ostream> | ||
#include <string> | ||
#include <thread> | ||
#include <vector> | ||
|
||
#include <rclcpp/time.hpp> | ||
#include "geometry_msgs/msg/pose_stamped.hpp" | ||
#include "rclcpp/node.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
|
||
#include <franka/robot_state.h> | ||
#include <controller_interface/controller_interface.hpp> | ||
#include <franka_msgs/msg/franka_robot_state.hpp> | ||
#include "franka_semantic_components/franka_robot_model.hpp" | ||
#include "franka_semantic_components/franka_robot_state.hpp" | ||
|
||
#include "franka_example_controllers/visibility_control.h" | ||
|
||
namespace franka_example_controllers { | ||
class CartesianImpedanceExampleController : public controller_interface::ControllerInterface { | ||
public: | ||
using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn; | ||
|
||
// Config methods | ||
|
||
[[nodiscard]] controller_interface::InterfaceConfiguration command_interface_configuration() | ||
const override; | ||
[[nodiscard]] controller_interface::InterfaceConfiguration state_interface_configuration() | ||
const override; | ||
|
||
// ROS2 lifecycle related methods | ||
CallbackReturn on_init() override; | ||
CallbackReturn on_configure(const rclcpp_lifecycle::State& previous_state) override; | ||
CallbackReturn on_activate(const rclcpp_lifecycle::State& previous_state) override; | ||
CallbackReturn on_deactivate(const rclcpp_lifecycle::State& previous_state) override; | ||
|
||
// Main real-time method | ||
controller_interface::return_type update(const rclcpp::Time& time, | ||
const rclcpp::Duration& period) override; | ||
|
||
private: | ||
std::unique_ptr<franka_semantic_components::FrankaRobotModel> franka_robot_model_; | ||
std::unique_ptr<franka_semantic_components::FrankaRobotState> franka_robot_state_; | ||
|
||
bool k_elbow_activated{true}; | ||
|
||
franka_msgs::msg::FrankaRobotState robot_state_; | ||
franka_msgs::msg::FrankaRobotState init_robot_state_; | ||
|
||
const std::string k_robot_state_interface_name{"robot_state"}; | ||
const std::string k_robot_model_interface_name{"robot_model"}; | ||
|
||
std::string arm_id_; | ||
int num_joints{7}; | ||
|
||
// Saturation | ||
Eigen::Matrix<double, 7, 1> saturateTorqueRate( | ||
const Eigen::Matrix<double, 7, 1>& tau_d_calculated, | ||
const Eigen::Matrix<double, 7, 1>& tau_J_d); | ||
|
||
// Classic cartesian controller | ||
double filter_params_{0.005}; | ||
double nullspace_stiffness_{20.0}; | ||
double nullspace_stiffness_target_{20.0}; | ||
const double delta_tau_max_{1.0}; | ||
|
||
Eigen::Matrix<double, 6, 6> cartesian_stiffness_; | ||
Eigen::Matrix<double, 6, 6> cartesian_stiffness_target_; | ||
Eigen::Matrix<double, 6, 6> cartesian_damping_; | ||
Eigen::Matrix<double, 6, 6> cartesian_damping_target_; | ||
Eigen::Matrix<double, 7, 1> q_d_nullspace_; | ||
Eigen::Vector3d position_d_; | ||
Eigen::Quaterniond orientation_d_; | ||
std::mutex position_and_orientation_d_target_mutex_; | ||
Eigen::Vector3d position_d_target_; | ||
Eigen::Quaterniond orientation_d_target_; | ||
|
||
rclcpp::Subscription<geometry_msgs::msg::PoseStamped>::SharedPtr sub_equilibrium_pose_; | ||
|
||
void equilibriumPoseCallback(const geometry_msgs::msg::PoseStamped::SharedPtr msg); | ||
}; | ||
|
||
} // namespace franka_example_controllers |
21 changes: 21 additions & 0 deletions
21
franka_example_controllers/include/franka_example_controllers/pseudo_inversion.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,21 @@ | ||
#pragma once | ||
|
||
#include <Eigen/Dense> | ||
|
||
namespace franka_example_controllers { | ||
|
||
inline Eigen::MatrixXd pseudoInverse(const Eigen::MatrixXd& M_, bool damped = true) { | ||
double lambda_ = damped ? 0.2 : 0.0; | ||
|
||
Eigen::JacobiSVD<Eigen::MatrixXd> svd(M_, Eigen::ComputeFullU | Eigen::ComputeFullV); | ||
Eigen::JacobiSVD<Eigen::MatrixXd>::SingularValuesType sing_vals_ = svd.singularValues(); | ||
Eigen::MatrixXd S_ = M_; // copying the dimensions of M_, its content is not needed. | ||
S_.setZero(); | ||
|
||
for (int i = 0; i < sing_vals_.size(); i++) | ||
S_(i, i) = (sing_vals_(i)) / (sing_vals_(i) * sing_vals_(i) + lambda_ * lambda_); | ||
|
||
return svd.matrixV() * S_.transpose() * svd.matrixU().transpose(); | ||
} | ||
|
||
} // namespace franka_example_controllers |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.