Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil-Singhal-06 committed Sep 25, 2024
1 parent e3e1493 commit a4fbac4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@

from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.actions import DeclareLaunchArgument, ExecuteProcess
from launch.substitutions.launch_configuration import LaunchConfiguration
from launch_ros.actions import Node
from launch.conditions import LaunchConfigurationNotEquals
import os

ARGUMENTS = [
DeclareLaunchArgument('arm_group_controller', default_value='panda_arm_controller',
description='arm_group_controller name'),
DeclareLaunchArgument('gripper_group_controller', default_value='panda_hand_controller',
description='gripper_group_controller name'),
DeclareLaunchArgument('ros2_control_hardware_type', default_value='mock_components',
choices=['ignition', 'mock_components'],
description='ROS2 control hardware interface type to use for the launch file'),
]


Expand All @@ -51,34 +55,51 @@ def generate_launch_description():
("/controller_manager/robot_description", "/robot_description"),
],
output="screen",
condition=LaunchConfigurationNotEquals(
"ros2_control_hardware_type", "ignition"
),
)

joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=[
joint_state_broadcaster = ExecuteProcess(
cmd=[
"ros2",
"control",
"load_controller",
"--set-state",
"active",
"joint_state_broadcaster",
"--controller-manager",
"/controller_manager",
],
output="screen",
)

arm_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=[arm_group_controller, "-c", "/controller_manager"],
arm_controller_spawner = ExecuteProcess(
cmd=[
"ros2",
"control",
"load_controller",
"--set-state",
"active",
arm_group_controller,
],
output="screen",
)

gripper_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=[gripper_group_controller, "-c", "/controller_manager"],
gripper_controller_spawner = ExecuteProcess(
cmd=[
"ros2",
"control",
"load_controller",
"--set-state",
"active",
gripper_group_controller
],
output="screen",
)

# Define LaunchDescription variable
ld = LaunchDescription(ARGUMENTS)
ld.add_action(ros2_control_node)
ld.add_action(joint_state_broadcaster_spawner)
ld.add_action(joint_state_broadcaster)
ld.add_action(arm_controller_spawner)
ld.add_action(gripper_controller_spawner)
return ld
82 changes: 16 additions & 66 deletions simulation/gazebo/arm_sim_scenario/launch/ignition_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, ExecuteProcess, Shutdown, RegisterEventHandler
from launch.actions import DeclareLaunchArgument, ExecuteProcess, Shutdown
from launch.substitutions import LaunchConfiguration
from launch.event_handlers import OnProcessExit
from launch_ros.actions import Node

ARGUMENTS = [
Expand Down Expand Up @@ -56,78 +55,29 @@ def generate_launch_description():
)

spawn_robot_node = Node(
package='ros_ign_gazebo',
executable='create',
arguments=['-name', 'panda',
'-x', '0.0',
'-y', '0.0',
'-z', '0.0',
'-Y', '0.0',
'-topic', 'robot_description',
"allow-renaming", "true",
"--ros-args", '--log-level', 'warn'],
output={'both': 'log'},
)

clock_bridge = Node(package='ros_gz_bridge', executable='parameter_bridge',
name='clock_bridge',
output='screen',
arguments=[
'/clock' + '@rosgraph_msgs/msg/Clock' + '[ignition.msgs.Clock'
])

spawn_joint_state_broadcaster_node = Node(
name='joint_state_broadcaster_spawner',
package='controller_manager',
executable='spawner',
package="ros_gz_sim",
executable="create",
output="screen",
arguments=[
'-c',
'controller_manager',
'joint_state_broadcaster',
"-topic",
"robot_description",
"-name",
"panda",
"-allow-renaming",
"true",
],
parameters=[{
'use_sim_time': use_sim_time,
}],
)

arm_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["panda_arm_controller", "-c", "/controller_manager"],
)

gripper_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["panda_hand_controller", "-c", "/controller_manager"],
)

load_joint_state_broadcaster_event = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=spawn_robot_node,
on_exit=[spawn_joint_state_broadcaster_node]
)
)

load_arm_controller_event = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=spawn_joint_state_broadcaster_node,
on_exit=[arm_controller_spawner]
)
)

load_gripper_controller_event = RegisterEventHandler(
event_handler=OnProcessExit(
target_action=spawn_joint_state_broadcaster_node,
on_exit=[gripper_controller_spawner]
)
# Clock Bridge
clock_bridge = Node(
package="ros_gz_bridge",
executable="parameter_bridge",
arguments=["/clock@rosgraph_msgs/msg/Clock[ignition.msgs.Clock"],
output="screen",
)

ld = LaunchDescription(ARGUMENTS)
ld.add_action(ignition_gazebo)
ld.add_action(clock_bridge)
ld.add_action(spawn_robot_node)
ld.add_action(load_joint_state_broadcaster_event)
ld.add_action(load_arm_controller_event)
ld.add_action(load_gripper_controller_event)
return ld
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ def generate_launch_description():

controller_manager = IncludeLaunchDescription(
PythonLaunchDescriptionSource([PathJoinSubstitution([arm_sim_scenario_dir, 'launch', 'controller_manager_launch.py'])]),
condition=LaunchConfigurationEquals(
launch_configuration_name='arg_ros2_control_hardware_type',
expected_value='mock_components'
),
launch_arguments={
'arg_ros2_control_hardware_type': ros2_control_hardware_type,
}.items()
)

ignition = IncludeLaunchDescription(
Expand Down
4 changes: 3 additions & 1 deletion simulation/gazebo/arm_sim_scenario/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<depend>moveit_planners_chomp</depend>
<depend>gripper_controllers</depend>
<depend>joint_trajectory_controller</depend>

<depend>ros2_control</depend>
<depend>ros_gz_bridge</depend>
<depend>ros_gz_sim</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down

0 comments on commit a4fbac4

Please sign in to comment.