From 3c4dfac66ba498d1586ef2642e63e1dc2ed026a2 Mon Sep 17 00:00:00 2001 From: Binit Shah Date: Thu, 27 Jun 2024 14:28:50 -0400 Subject: [PATCH] Experiment with adding two robots to Gazebo sim --- stretch_gazebo/launch/base.launch | 21 ++++ stretch_gazebo/launch/multi_robot.launch | 103 ++++++++++++++++++ stretch_gazebo/launch/single_robot.launch | 54 +++++++++ .../scripts/publish_ground_truth_odom.py | 2 +- .../scripts/publish_ground_truth_odom2.py | 43 ++++++++ .../urdf/stretch_gazebo_dex_wrist.urdf.xacro | 3 +- ...stretch_gazebo_standard_gripper.urdf.xacro | 3 +- 7 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 stretch_gazebo/launch/base.launch create mode 100644 stretch_gazebo/launch/multi_robot.launch create mode 100644 stretch_gazebo/launch/single_robot.launch create mode 100755 stretch_gazebo/scripts/publish_ground_truth_odom2.py diff --git a/stretch_gazebo/launch/base.launch b/stretch_gazebo/launch/base.launch new file mode 100644 index 0000000..5019db2 --- /dev/null +++ b/stretch_gazebo/launch/base.launch @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/stretch_gazebo/launch/multi_robot.launch b/stretch_gazebo/launch/multi_robot.launch new file mode 100644 index 0000000..3fc2e2b --- /dev/null +++ b/stretch_gazebo/launch/multi_robot.launch @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stretch_gazebo/launch/single_robot.launch b/stretch_gazebo/launch/single_robot.launch new file mode 100644 index 0000000..310e3cd --- /dev/null +++ b/stretch_gazebo/launch/single_robot.launch @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stretch_gazebo/scripts/publish_ground_truth_odom.py b/stretch_gazebo/scripts/publish_ground_truth_odom.py index ac76c62..878d233 100755 --- a/stretch_gazebo/scripts/publish_ground_truth_odom.py +++ b/stretch_gazebo/scripts/publish_ground_truth_odom.py @@ -19,7 +19,7 @@ odom=Odometry() header = Header() header.frame_id='/ground_truth' model = GetModelStateRequest() -model.model_name='robot' +model.model_name='robot1' models = [] r = rospy.Rate(20) diff --git a/stretch_gazebo/scripts/publish_ground_truth_odom2.py b/stretch_gazebo/scripts/publish_ground_truth_odom2.py new file mode 100755 index 0000000..0030580 --- /dev/null +++ b/stretch_gazebo/scripts/publish_ground_truth_odom2.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python3 + +from gazebo_msgs.srv import GetModelState, GetModelStateRequest, GetWorldProperties +from nav_msgs.msg import Odometry +from std_msgs.msg import Header +from std_srvs.srv import Empty +import rospy +import time + +rospy.init_node('ground_truth_odometry_publisher') +odom_pub=rospy.Publisher('ground_truth', Odometry, queue_size=10) + +rospy.wait_for_service('/gazebo/get_model_state') +get_model_srv = rospy.ServiceProxy('/gazebo/get_model_state', GetModelState) +get_world_properties = rospy.ServiceProxy('/gazebo/get_world_properties', GetWorldProperties) +unpause_physics = rospy.ServiceProxy('/gazebo/unpause_physics', Empty) + +odom=Odometry() +header = Header() +header.frame_id='/ground_truth' +model = GetModelStateRequest() +model.model_name='robot2' +models = [] +r = rospy.Rate(20) + +pause_timeout = time.time() + 4.0 +while time.time() < pause_timeout: + rospy.logwarn("Waiting %.2f seconds to unpause physics", pause_timeout - time.time()) + time.sleep(1.0) +unpause_physics() + +while not rospy.is_shutdown(): + if model.model_name not in models: + models = get_world_properties().model_names + rospy.logwarn("Waiting for %s to spawn to publish ground truth odometry", model.model_name) + else: + result = get_model_srv(model) + odom.pose.pose = result.pose + odom.twist.twist = result.twist + header.stamp = rospy.Time.now() + odom.header = header + odom_pub.publish(odom) + r.sleep() diff --git a/stretch_gazebo/urdf/stretch_gazebo_dex_wrist.urdf.xacro b/stretch_gazebo/urdf/stretch_gazebo_dex_wrist.urdf.xacro index 83982c4..070069b 100644 --- a/stretch_gazebo/urdf/stretch_gazebo_dex_wrist.urdf.xacro +++ b/stretch_gazebo/urdf/stretch_gazebo_dex_wrist.urdf.xacro @@ -2,6 +2,7 @@ + @@ -12,7 +13,7 @@ - / + /robot_$(arg robot_num) diff --git a/stretch_gazebo/urdf/stretch_gazebo_standard_gripper.urdf.xacro b/stretch_gazebo/urdf/stretch_gazebo_standard_gripper.urdf.xacro index 17fb961..00bd1c0 100644 --- a/stretch_gazebo/urdf/stretch_gazebo_standard_gripper.urdf.xacro +++ b/stretch_gazebo/urdf/stretch_gazebo_standard_gripper.urdf.xacro @@ -2,6 +2,7 @@ + @@ -12,7 +13,7 @@ - / + /robot_$(arg robot_num)