Skip to content
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

Add iiwa7 and ignition support #36

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 251 additions & 0 deletions iiwa_bringup/launch/iiwa7.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
# Copyright 2022 ICube Laboratory, University of Strasbourg
#
# 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, RegisterEventHandler
from launch.conditions import IfCondition
from launch.event_handlers import OnProcessExit
from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution

from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():
# Declare arguments
declared_arguments = []
declared_arguments.append(
DeclareLaunchArgument(
'runtime_config_package',
default_value='iiwa_description',
description='Package with the controller\'s configuration in "config" folder. \
Usually the argument is not set, it enables use of a custom setup.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'controllers_file',
default_value='iiwa_controllers.yaml',
description='YAML file with the controllers configuration.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'description_package',
default_value='iiwa_description',
description='Description package with robot URDF/xacro files. Usually the argument \
is not set, it enables use of a custom description.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'description_file',
default_value='iiwa7.config.xacro',
description='URDF/XACRO description file with the robot.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'prefix',
default_value='""',
description='Prefix of the joint names, useful for multi-robot setup. \
If changed than also joint names in the controllers \
configuration have to be updated.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'use_sim',
default_value='false',
description='Start robot in Gazebo simulation.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'use_fake_hardware',
default_value='true',
description='Start robot with fake hardware mirroring command to its states.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'robot_controller',
default_value='iiwa_arm_controller',
description='Robot controller to start.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'start_rviz',
default_value='true',
description='Start RViz2 automatically with this launch file.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'robot_ip',
default_value='192.170.10.2',
description='Robot IP of FRI interface',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'robot_port',
default_value='30200',
description='Robot port of FRI interface.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'initial_positions_file',
default_value='initial_positions.yaml',
description='Configuration file of robot initial positions for simulation.',
)
)
declared_arguments.append(
DeclareLaunchArgument(
'command_interface',
default_value='position',
description='Robot command interface [position|velocity|effort].',
)
)

# Initialize Arguments
runtime_config_package = LaunchConfiguration('runtime_config_package')
controllers_file = LaunchConfiguration('controllers_file')
description_package = LaunchConfiguration('description_package')
description_file = LaunchConfiguration('description_file')
prefix = LaunchConfiguration('prefix')
use_sim = LaunchConfiguration('use_sim')
use_fake_hardware = LaunchConfiguration('use_fake_hardware')
robot_controller = LaunchConfiguration('robot_controller')
start_rviz = LaunchConfiguration('start_rviz')
robot_ip = LaunchConfiguration('robot_ip')
robot_port = LaunchConfiguration('robot_port')
initial_positions_file = LaunchConfiguration('initial_positions_file')
command_interface = LaunchConfiguration('command_interface')

# Get URDF via xacro
robot_description_content = Command(
[
PathJoinSubstitution([FindExecutable(name='xacro')]),
' ',
PathJoinSubstitution(
[FindPackageShare(description_package), 'config', description_file]
),
' ',
'prefix:=',
prefix,
' ',
'use_sim:=',
use_sim,
' ',
'use_fake_hardware:=',
use_fake_hardware,
' ',
'robot_ip:=',
robot_ip,
' ',
'robot_port:=',
robot_port,
' ',
'initial_positions_file:=',
initial_positions_file,
' ',
'command_interface:=',
command_interface,
]
)
robot_description = {'robot_description': robot_description_content}

robot_controllers = PathJoinSubstitution(
[
FindPackageShare(runtime_config_package),
'config',
controllers_file,
]
)
rviz_config_file = PathJoinSubstitution(
[FindPackageShare(description_package), 'rviz', 'iiwa.rviz']
)

control_node = Node(
package='controller_manager',
executable='ros2_control_node',
parameters=[robot_description, robot_controllers],
output={
'stdout': 'screen',
'stderr': 'screen',
},
)
robot_state_pub_node = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='both',
parameters=[robot_description],
)

rviz_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
output='log',
arguments=['-d', rviz_config_file],
condition=IfCondition(start_rviz),
)

joint_state_broadcaster_spawner = Node(
package='controller_manager',
executable='spawner.py',
arguments=['joint_state_broadcaster', '--controller-manager', '/controller_manager'],
)

eternal_torque_broadcaster_spawner = Node(
package='controller_manager',
executable='spawner.py',
arguments=['ets_state_broadcaster', '--controller-manager', '/controller_manager'],
)

robot_controller_spawner = Node(
package='controller_manager',
executable='spawner.py',
arguments=[robot_controller, '-c', '/controller_manager'],
)

# Delay rviz start after `joint_state_broadcaster`
delay_rviz_after_joint_state_broadcaster_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=joint_state_broadcaster_spawner,
on_exit=[rviz_node],
)
)

# Delay start of robot_controller after `joint_state_broadcaster`
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=joint_state_broadcaster_spawner,
on_exit=[robot_controller_spawner],
)
)

nodes = [
control_node,
robot_state_pub_node,
joint_state_broadcaster_spawner,
delay_rviz_after_joint_state_broadcaster_spawner,
eternal_torque_broadcaster_spawner,
delay_robot_controller_spawner_after_joint_state_broadcaster_spawner,
]

return LaunchDescription(declared_arguments + nodes)
125 changes: 125 additions & 0 deletions iiwa_bringup/launch/iiwa_ignition.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Copyright 2022 ICube Laboratory, University of Strasbourg
#
# 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.

import os

from ament_index_python.packages import get_package_share_directory, get_package_prefix
from launch import LaunchDescription
from launch.actions import ExecuteProcess, DeclareLaunchArgument, IncludeLaunchDescription, RegisterEventHandler, SetEnvironmentVariable
from launch.event_handlers import OnProcessExit, OnProcessIO, OnProcessStart
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.substitutions import Command, FindExecutable, PathJoinSubstitution
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


def generate_launch_description():

set_ign_path = SetEnvironmentVariable(
name = 'IGN_GAZEBO_SYSTEM_PLUGIN_PATH',
value = os.path.join(
get_package_prefix('ign_ros2_control'),
'lib'
)
)

iiwa_simulation_world = os.path.join(
get_package_share_directory('iiwa_description'),
'ignition/worlds',
'empty.sdf')

ignition = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
[os.path.join(get_package_share_directory('ros_ign_gazebo'),
'launch',
'ign_gazebo.launch.py')]
),
launch_arguments=[('ign_args', [' -r -v 4 ' + iiwa_simulation_world])]
)

# Get URDF via xacro
robot_description_content = Command(
[
PathJoinSubstitution([FindExecutable(name='xacro')]),
' ',
PathJoinSubstitution(
[
FindPackageShare('iiwa_description'),
'config',
'iiwa7.config.xacro',
]
),
' ',
'use_sim:=true',
' ',
'initial_positions_file:=',
PathJoinSubstitution(
[
FindPackageShare('iiwa_description'),
'config',
'initial_positions.yaml',
]
),
]
)
robot_description = {'robot_description': robot_description_content}

node_robot_state_publisher = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[robot_description],
)

spawn_entity = Node(
package='ros_ign_gazebo',
executable='create',
arguments=['-world', 'empty',
'-name', 'iiwa7',
'-string', robot_description_content],
output='screen',
)

load_jst_controller = ExecuteProcess(
cmd=['ros2', 'control', 'load_controller', '--set-state', 'start',
'joint_state_broadcaster'],
output='screen'
)

load_arm_controller = ExecuteProcess(
cmd=['ros2', 'control', 'load_controller', '--set-state', 'start',
'iiwa_arm_controller'],
output='screen'
)

return LaunchDescription(
[
set_ign_path,
ignition,
node_robot_state_publisher,
spawn_entity,
RegisterEventHandler(
event_handler=OnProcessExit(
target_action=spawn_entity,
on_exit=[load_jst_controller],
)
),
RegisterEventHandler(
event_handler=OnProcessExit(
target_action=load_jst_controller,
on_exit=[load_arm_controller],
)
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def generate_launch_description():
[
Node(
package='ros2_control_test_nodes',
executable='publisher_joint_trajectory_controller',
name='publisher_joint_trajectory_controller',
executable='publisher_joint_trajectory_position_controller',
name='publisher_joint_trajectory_position_controller',
parameters=[position_goals],
output={
'stdout': 'screen',
Expand Down
2 changes: 1 addition & 1 deletion iiwa_description/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endif()
# Install
################################################################################
install(
DIRECTORY urdf meshes gazebo rviz ros2_control config moveit2
DIRECTORY urdf meshes gazebo ignition rviz ros2_control config moveit2
DESTINATION share/${PROJECT_NAME}
)

Expand Down
Loading