-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: joint impedance controller with moveit ik service
- Loading branch information
1 parent
958eeb7
commit acd0b87
Showing
13 changed files
with
632 additions
and
6 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
97 changes: 97 additions & 0 deletions
97
franka_bringup/launch/joint_impedance_with_ik_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,97 @@ | ||
# Copyright (c) 2023 Franka Robotics GmbH | ||
# | ||
# 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. | ||
|
||
|
||
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' | ||
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) | ||
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( | ||
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, | ||
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(), | ||
), | ||
IncludeLaunchDescription( | ||
PythonLaunchDescriptionSource( | ||
[ | ||
PathJoinSubstitution( | ||
[ | ||
FindPackageShare('franka_moveit_config'), | ||
'launch', | ||
'move_group.launch.py', | ||
] | ||
) | ||
] | ||
), | ||
launch_arguments={ | ||
robot_ip: robot_ip, | ||
load_gripper_parameter_name: load_gripper, | ||
use_fake_hardware_parameter_name: 'true', | ||
fake_sensor_commands_parameter_name: fake_sensor_commands, | ||
use_rviz_parameter_name: use_rviz, | ||
}.items(), | ||
), | ||
Node( | ||
package='controller_manager', | ||
executable='spawner', | ||
arguments=['joint_impedance_with_ik_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
...rollers/include/franka_example_controllers/joint_impedance_with_ik_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 @@ | ||
// Copyright (c) 2023 Franka Robotics GmbH | ||
// | ||
// 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. | ||
|
||
#pragma once | ||
|
||
#include <Eigen/Dense> | ||
#include <string> | ||
|
||
#include <controller_interface/controller_interface.hpp> | ||
#include <moveit_msgs/srv/get_position_ik.hpp> | ||
#include <rclcpp/rclcpp.hpp> | ||
#include "franka_semantic_components/franka_cartesian_pose_interface.hpp" | ||
#include "franka_semantic_components/franka_robot_model.hpp" | ||
|
||
using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn; | ||
|
||
namespace franka_example_controllers { | ||
|
||
/** | ||
* joint impedance example controller get desired pose and use moveit inverse kinematics | ||
*/ | ||
class JointImpedanceWithIKExampleController : public controller_interface::ControllerInterface { | ||
public: | ||
using Vector7d = Eigen::Matrix<double, 7, 1>; | ||
[[nodiscard]] controller_interface::InterfaceConfiguration command_interface_configuration() | ||
const override; | ||
[[nodiscard]] controller_interface::InterfaceConfiguration state_interface_configuration() | ||
const override; | ||
controller_interface::return_type update(const rclcpp::Time& time, | ||
const rclcpp::Duration& period) override; | ||
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; | ||
|
||
private: | ||
void update_joint_states(); | ||
Eigen::Vector3d compute_new_position(); | ||
std::shared_ptr<moveit_msgs::srv::GetPositionIK::Request> create_ik_service_request( | ||
Eigen::Vector3d new_position, | ||
Eigen::Quaterniond new_orientation, | ||
std::vector<double> joint_positions_desired, | ||
std::vector<double> joint_positions_current, | ||
std::vector<double> joint_efforts_current); | ||
|
||
Vector7d compute_torque_command(Vector7d joint_positions_desired, | ||
Vector7d joint_positions_current, | ||
Vector7d joint_velocities_current); | ||
|
||
bool assign_parameters(); | ||
|
||
std::unique_ptr<franka_semantic_components::FrankaCartesianPoseInterface> franka_cartesian_pose_; | ||
|
||
Eigen::Quaterniond orientation_; | ||
Eigen::Vector3d position_; | ||
rclcpp::Client<moveit_msgs::srv::GetPositionIK>::SharedPtr compute_ik_client_; | ||
|
||
double trajectory_period_{0.001}; | ||
const bool k_elbow_activated_{false}; | ||
bool initialization_flag_{true}; | ||
|
||
std::string arm_id_; | ||
|
||
double elapsed_time_{0.0}; | ||
std::unique_ptr<franka_semantic_components::FrankaRobotModel> franka_robot_model_; | ||
|
||
const std::string k_robot_state_interface_name{"robot_state"}; | ||
const std::string k_robot_model_interface_name{"robot_model"}; | ||
|
||
Vector7d dq_filtered_; | ||
Vector7d k_gains_; | ||
Vector7d d_gains_; | ||
int num_joints_{7}; | ||
|
||
std::vector<double> joint_positions_desired; | ||
std::vector<double> joint_positions_current{0, 0, 0, 0, 0, 0, 0}; | ||
std::vector<double> joint_velocities_current{0, 0, 0, 0, 0, 0, 0}; | ||
std::vector<double> joint_efforts_current{0, 0, 0, 0, 0, 0, 0}; | ||
}; | ||
} // namespace franka_example_controllers |
Oops, something went wrong.