This commit is contained in:
Your Name 2025-01-09 12:21:38 +01:00
parent 71bf12c8c5
commit 23e11bab56
2 changed files with 13 additions and 49 deletions

13
launch/rsp.launch Normal file
View File

@ -0,0 +1,13 @@
<launch>
<!-- Set the use_sim_time parameter -->
<param name="use_sim_time" value="false" />
<!-- Set the robot description -->
<param name="robot_description" command="$(find xacro)/xacro $(find cps_rmp220_support)/description/robot.urdf.xacro use_ros_control:=true sim_mode:=$(arg use_sim_time)" />
<!-- Start the robot state publisher node -->
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen"/>
<!-- Start the joint state publisher node -->
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" output="screen"/>
</launch>

View File

@ -1,49 +0,0 @@
import os
import rospy
import rospkg
import xacro
from xml.etree.ElementTree import Element, tostring
def generate_launch_description():
# Initialize ROS node
rospy.init_node('robot_description_launch', anonymous=True)
# Get the package path
rospack = rospkg.RosPack()
pkg_path = rospack.get_path('cps_rmp220_support')
xacro_file = os.path.join(pkg_path, 'description', 'robot.urdf.xacro')
# Read parameters
use_sim_time = rospy.get_param('~use_sim_time', False)
use_ros_control = rospy.get_param('~use_ros_control', True)
# Process the URDF file using xacro
try:
urdf_tree = xacro.process_file(
xacro_file,
mappings={
'use_ros_control': str(use_ros_control).lower(),
'sim_mode': str(use_sim_time).lower(),
}
)
robot_description = tostring(urdf_tree.getroot(), encoding='unicode')
except Exception as e:
rospy.logerr(f"Error processing xacro file: {e}")
robot_description = ""
# Set the parameter for the robot description
rospy.set_param('/robot_description', robot_description)
rospy.set_param('/use_sim_time', use_sim_time)
# Launch nodes
state_publisher_command = "rosrun robot_state_publisher robot_state_publisher"
joint_state_publisher_command = "rosrun joint_state_publisher joint_state_publisher"
os.system(state_publisher_command)
os.system(joint_state_publisher_command)
if __name__ == '__main__':
try:
generate_launch_description()
except rospy.ROSInterruptException:
pass