cps_loki_bringup/launch/robot_controller.launch.py

96 lines
3.1 KiB
Python
Raw Normal View History

2023-06-07 09:44:38 +00:00
# Copyright 2022 Factor Robotics
#
# 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 launch import LaunchDescription
from launch.substitutions import Command, FindExecutable, PathJoinSubstitution
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare
from ament_index_python.packages import get_package_share_directory
from launch_ros.actions import LifecycleNode
from launch_ros.descriptions import ParameterValue
2023-12-07 11:13:16 +00:00
from launch.substitutions import LaunchConfiguration, PythonExpression
from launch.actions import DeclareLaunchArgument, GroupAction, SetEnvironmentVariable
2023-06-07 09:44:38 +00:00
def generate_launch_description():
2023-12-07 11:13:16 +00:00
namespace = LaunchConfiguration('namespace')
use_sim_time = LaunchConfiguration('use_sim_time')
declare_namespace_cmd = DeclareLaunchArgument(
'namespace',
default_value='',
description='Top-level namespace')
declare_use_sim_time_cmd = DeclareLaunchArgument(
'use_sim_time',
default_value='false',
description='Use simulation (Gazebo) clock if true')
2023-06-07 09:44:38 +00:00
robot_description_content = Command(
[
PathJoinSubstitution([FindExecutable(name="xacro")]),
" ",
PathJoinSubstitution(
[
2023-11-20 09:49:14 +00:00
FindPackageShare("cps_loki_description"),
2023-06-07 09:44:38 +00:00
"urdf",
"odrive_diffbot.urdf.xacro"
]
),
]
)
robot_description = {"robot_description": ParameterValue(robot_description_content, value_type=str)}
robot_controllers = PathJoinSubstitution(
[
2023-11-20 09:49:14 +00:00
FindPackageShare("cps_loki_bringup"),
2023-06-07 09:44:38 +00:00
"config",
2023-12-07 11:13:16 +00:00
"controllers.yaml",
2023-06-07 09:44:38 +00:00
]
)
control_node = Node(
package="controller_manager",
executable="ros2_control_node",
parameters=[robot_description, robot_controllers],
output="both",
)
robot_state_pub_node = Node(
package="robot_state_publisher",
executable="robot_state_publisher",
output="both",
parameters=[robot_description],
)
joint_state_broadcaster_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["joint_state_broadcaster", "-c", "/controller_manager"],
)
robot_controller_spawner = Node(
package="controller_manager",
executable="spawner",
arguments=["diffbot_base_controller", "-c", "/controller_manager"],
)
return LaunchDescription([
control_node,
2023-06-13 07:59:33 +00:00
robot_state_pub_node,
2023-07-26 08:39:34 +00:00
joint_state_broadcaster_spawner,
robot_controller_spawner
2023-06-07 09:44:38 +00:00
])