forked from xArm-Developer/xarm_ros2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Call SDK API directly in xarm_controller
1. [RobotHW] use xarm_ros_driver in xarm_controller 2. [parameter] `robot1_ip` => `robot_ip_1` 3. [parameter] `robot2_ip` => `robot_ip_2`
- Loading branch information
Showing
38 changed files
with
671 additions
and
446 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
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 |
---|---|---|
|
@@ -7,8 +7,6 @@ | |
# Author: Vinman <[email protected]> <[email protected]> | ||
|
||
import os | ||
import yaml | ||
from tempfile import NamedTemporaryFile | ||
from ament_index_python import get_package_share_directory | ||
from launch import LaunchDescription | ||
from launch.actions import OpaqueFunction, DeclareLaunchArgument, IncludeLaunchDescription | ||
|
@@ -17,52 +15,7 @@ | |
from launch_ros.substitutions import FindPackageShare | ||
from launch import LaunchDescription | ||
from launch.launch_description_sources import PythonLaunchDescriptionSource | ||
|
||
def merge_dict(dict1, dict2): | ||
for k, v in dict1.items(): | ||
try: | ||
if k not in dict2: | ||
continue | ||
if isinstance(v, dict): | ||
merge_dict(v, dict2[k]) | ||
else: | ||
dict1[k] = dict2[k] | ||
except Exception as e: | ||
pass | ||
|
||
|
||
def load_yaml(path): | ||
if os.path.exists(path): | ||
try: | ||
with open(path, 'r') as file: | ||
return yaml.safe_load(file) | ||
except Exception as e: | ||
print('load {} error, {}'.format(path, e)) | ||
return {} | ||
|
||
|
||
def generate_xarm_params(xarm_default_params_path, xarm_user_params_path=None, ros_namespace=''): | ||
if not os.path.exists(xarm_user_params_path): | ||
xarm_user_params_path = None | ||
if ros_namespace or (xarm_user_params_path is not None and xarm_default_params_path != xarm_user_params_path): | ||
ros2_control_params_yaml = load_yaml(xarm_default_params_path) | ||
ros2_control_user_params_yaml = load_yaml(xarm_user_params_path) | ||
# change xarm_driver to ufactory_driver | ||
if 'xarm_driver' in ros2_control_params_yaml and 'ufactory_driver' not in ros2_control_params_yaml: | ||
ros2_control_params_yaml['ufactory_driver'] = ros2_control_params_yaml.pop('xarm_driver') | ||
if 'xarm_driver' in ros2_control_user_params_yaml and 'ufactory_driver' not in ros2_control_user_params_yaml: | ||
ros2_control_user_params_yaml['ufactory_driver'] = ros2_control_user_params_yaml.pop('xarm_driver') | ||
merge_dict(ros2_control_params_yaml, ros2_control_user_params_yaml) | ||
if ros_namespace: | ||
xarm_params_yaml = { | ||
ros_namespace: ros2_control_params_yaml | ||
} | ||
else: | ||
xarm_params_yaml = ros2_control_params_yaml | ||
with NamedTemporaryFile(mode='w', prefix='launch_params_', delete=False) as h: | ||
yaml.dump(xarm_params_yaml, h, default_flow_style=False) | ||
return h.name | ||
return xarm_default_params_path | ||
from launch.launch_description_sources import load_python_launch_file_as_module | ||
|
||
|
||
def launch_setup(context, *args, **kwargs): | ||
|
@@ -110,10 +63,12 @@ def launch_setup(context, *args, **kwargs): | |
show_rviz = LaunchConfiguration('show_rviz', default=False) | ||
robot_type = LaunchConfiguration('robot_type', default='xarm') | ||
|
||
xarm_params = generate_xarm_params( | ||
mod = load_python_launch_file_as_module(os.path.join(get_package_share_directory('xarm_api'), 'launch', 'lib', 'robot_api_lib.py')) | ||
generate_robot_api_params = getattr(mod, 'generate_robot_api_params') | ||
robot_params = generate_robot_api_params( | ||
os.path.join(get_package_share_directory('xarm_api'), 'config', 'xarm_params.yaml'), | ||
os.path.join(get_package_share_directory('xarm_api'), 'config', 'xarm_user_params.yaml'), | ||
LaunchConfiguration('ros_namespace', default='').perform(context) | ||
LaunchConfiguration('ros_namespace', default='').perform(context), node_name='ufactory_driver' | ||
) | ||
|
||
# robot driver node | ||
|
@@ -125,13 +80,13 @@ def launch_setup(context, *args, **kwargs): | |
output='screen', | ||
emulate_tty=True, | ||
parameters=[ | ||
xarm_params, | ||
robot_params, | ||
{ | ||
'robot_ip': robot_ip, | ||
'report_type': report_type, | ||
'dof': dof, | ||
'add_gripper': add_gripper if robot_type.perform(context) == 'xarm' else False, | ||
'hw_ns': hw_ns.perform(context).strip('/'), | ||
'hw_ns': '{}{}'.format(prefix.perform(context).strip('/'), hw_ns.perform(context).strip('/')), | ||
'prefix': prefix.perform(context).strip('/'), | ||
'baud_checkset': baud_checkset, | ||
'default_gripper_baud': default_gripper_baud, | ||
|
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,59 @@ | ||
#!/usr/bin/env python3 | ||
# Software License Agreement (BSD License) | ||
# | ||
# Copyright (c) 2022, UFACTORY, Inc. | ||
# All rights reserved. | ||
# | ||
# Author: Vinman <[email protected]> <[email protected]> | ||
|
||
import os | ||
import yaml | ||
from tempfile import NamedTemporaryFile | ||
|
||
|
||
def merge_dict(dict1, dict2): | ||
for k, v in dict1.items(): | ||
try: | ||
if k not in dict2: | ||
continue | ||
if isinstance(v, dict): | ||
merge_dict(v, dict2[k]) | ||
else: | ||
dict1[k] = dict2[k] | ||
except Exception as e: | ||
pass | ||
|
||
|
||
def load_yaml(path): | ||
if os.path.exists(path): | ||
try: | ||
with open(path, 'r') as file: | ||
return yaml.safe_load(file) | ||
except Exception as e: | ||
print('load {} error, {}'.format(path, e)) | ||
return {} | ||
|
||
|
||
def generate_robot_api_params(robot_default_params_path, robot_user_params_path=None, ros_namespace='', node_name='ufactory_driver'): | ||
if not os.path.exists(robot_user_params_path): | ||
robot_user_params_path = None | ||
if ros_namespace or (robot_user_params_path is not None and robot_default_params_path != robot_user_params_path): | ||
ros2_control_params_yaml = load_yaml(robot_default_params_path) | ||
ros2_control_user_params_yaml = load_yaml(robot_user_params_path) | ||
# change xarm_driver to ufactory_driver | ||
if 'xarm_driver' in ros2_control_params_yaml and node_name not in ros2_control_params_yaml: | ||
ros2_control_params_yaml[node_name] = ros2_control_params_yaml.pop('xarm_driver') | ||
if 'xarm_driver' in ros2_control_user_params_yaml and node_name not in ros2_control_user_params_yaml: | ||
ros2_control_user_params_yaml[node_name] = ros2_control_user_params_yaml.pop('xarm_driver') | ||
merge_dict(ros2_control_params_yaml, ros2_control_user_params_yaml) | ||
if ros_namespace: | ||
xarm_params_yaml = { | ||
ros_namespace: ros2_control_params_yaml | ||
} | ||
else: | ||
xarm_params_yaml = ros2_control_params_yaml | ||
with NamedTemporaryFile(mode='w', prefix='launch_params_', delete=False) as h: | ||
yaml.dump(xarm_params_yaml, h, default_flow_style=False) | ||
return h.name | ||
return robot_default_params_path | ||
|
Oops, something went wrong.