-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'foxy' into dev-foxy-optas
- Loading branch information
Showing
42 changed files
with
778 additions
and
732 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
43 changes: 43 additions & 0 deletions
43
lbr_demos/lbr_fri_ros2_advanced_python_demos/launch/admittance_control_node.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,43 @@ | ||
import os | ||
|
||
import xacro | ||
from ament_index_python import get_package_share_directory | ||
from launch import LaunchContext, LaunchDescription | ||
from launch.actions import DeclareLaunchArgument, OpaqueFunction | ||
from launch.substitutions import LaunchConfiguration | ||
from launch_ros.actions import Node | ||
|
||
|
||
def launch_setup(context: LaunchContext) -> LaunchDescription: | ||
model = LaunchConfiguration("model").perform(context) | ||
|
||
robot_description = { | ||
"robot_description": xacro.process( | ||
os.path.join( | ||
get_package_share_directory("lbr_description"), | ||
"urdf", | ||
model, | ||
f"{model}.urdf.xacro", | ||
), | ||
mappings={"sim": "false"}, | ||
) | ||
} | ||
|
||
admittance_control_node = Node( | ||
package="lbr_fri_ros2_advanced_python_demos", | ||
executable="admittance_control_node", | ||
output="screen", | ||
parameters=[robot_description], | ||
) | ||
|
||
return [admittance_control_node] | ||
|
||
|
||
def generate_launch_description() -> LaunchDescription: | ||
model_arg = DeclareLaunchArgument( | ||
name="model", | ||
default_value="iiwa7", | ||
description="The LBR model in use.", | ||
choices=["iiwa7", "iiwa14", "med7", "med14"], | ||
) | ||
return LaunchDescription([model_arg, OpaqueFunction(function=launch_setup)]) |
156 changes: 43 additions & 113 deletions
156
..._ros2_advanced_python_demos/lbr_fri_ros2_advanced_python_demos/admittance_control_node.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
60 changes: 60 additions & 0 deletions
60
...ri_ros2_advanced_python_demos/lbr_fri_ros2_advanced_python_demos/admittance_controller.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,60 @@ | ||
import numpy as np | ||
import optas | ||
|
||
from lbr_fri_msgs.msg import LBRCommand, LBRState | ||
|
||
|
||
class AdmittanceController(object): | ||
def __init__( | ||
self, | ||
robot_description: str, | ||
base_link: str = "lbr_link_0", | ||
end_effector_link: str = "lbr_link_ee", | ||
f_ext_th: np.ndarray = np.array([2.0, 2.0, 2.0, 0.5, 0.5, 0.5]), | ||
dq_gain: np.ndarray = np.array([1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5]), | ||
dx_gain: np.ndarray = np.array([1.0, 1.0, 1.0, 20.0, 40.0, 60.0]), | ||
) -> None: | ||
self.lbr_command_ = LBRCommand() | ||
|
||
robot = optas.RobotModel(urdf_string=robot_description) | ||
J = robot.get_geometric_jacobian_function(end_effector_link, base_link) | ||
self.jacobian_ = lambda q: J(q, numpy_output=True) | ||
|
||
self.dof_ = robot.ndof | ||
self.jacobian_inv_ = np.zeros((self.dof_, 6)) | ||
self.q = np.zeros(self.dof_) | ||
self.dq_ = np.zeros(self.dof_) | ||
self.tau_ext_ = np.zeros(6) | ||
self.dq_gain_ = np.diag(dq_gain) | ||
self.dx_gain_ = np.diag(dx_gain) | ||
self.f_ext_ = np.zeros(6) | ||
self.f_ext_th_ = f_ext_th | ||
self.alpha_ = 0.99 | ||
|
||
def __call__(self, lbr_state: LBRState) -> LBRCommand: | ||
self.q_ = np.array(lbr_state.measured_joint_position.tolist()) | ||
self.tau_ext_ = np.array(lbr_state.external_torque.tolist()) | ||
|
||
self.jacobian_ = self.jacobian_(self.q_) | ||
|
||
self.jacobian_inv_ = np.linalg.pinv(self.jacobian_, rcond=0.05) | ||
self.f_ext_ = self.jacobian_inv_.T @ self.tau_ext_ | ||
|
||
self.f_ext_ = np.where( | ||
abs(self.f_ext_) > self.f_ext_th_, | ||
self.dx_gain_ @ np.sign(self.f_ext_) * (abs(self.f_ext_) - self.f_ext_th_), | ||
0.0, | ||
) | ||
|
||
# additional smoothing required in python | ||
self.dq_ = ( | ||
self.alpha_ * self.dq_ | ||
+ (1 - self.alpha_) * self.dq_gain_ @ self.jacobian_inv_ @ self.f_ext_ | ||
) | ||
|
||
self.lbr_command_.joint_position = ( | ||
np.array(lbr_state.measured_joint_position.tolist()) | ||
+ lbr_state.sample_time * self.dq_ | ||
).data | ||
|
||
return self.lbr_command_ |
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 |
---|---|---|
|
@@ -2,12 +2,13 @@ | |
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>lbr_fri_ros2_advanced_python_demos</name> | ||
<version>1.0.0</version> | ||
<version>1.1.0</version> | ||
<description>Advanced Python demos for the lbr_fri_ros2.</description> | ||
<maintainer email="[email protected]">mhubii</maintainer> | ||
<license>MIT</license> | ||
|
||
<exec_depend>lbr_fri_msgs</exec_depend> | ||
<exec_depend>lbr_fri_ros2</exec_depend> | ||
<exec_depend>rclpy</exec_depend> | ||
|
||
<test_depend>ament_copyright</test_depend> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>lbr_fri_ros2_cpp_demos</name> | ||
<version>1.0.0</version> | ||
<version>1.1.0</version> | ||
<description>C++ demos for the lbr_fri_ros2.</description> | ||
<maintainer email="[email protected]">mhubii</maintainer> | ||
<license>MIT</license> | ||
|
Oops, something went wrong.