"""Teleport the AWSIM ego to an ABSOLUTE map pose by publishing /initialpose (the ego's Ros2ToVPPInput subscribes and sets its position+rotation). Publish-only (no flaky pose subscription); waits until the ego's /initialpose subscription matches before sending. python3 set_pose.py --x 81426 --y 49952.7 --z 41.6 --yaw-deg 42 """ import argparse, math, time, rclpy from rclpy.node import Node from rclpy.qos import QoSProfile, ReliabilityPolicy, DurabilityPolicy, HistoryPolicy from geometry_msgs.msg import PoseWithCovarianceStamped def main(): ap = argparse.ArgumentParser() ap.add_argument("--x", type=float, required=True) ap.add_argument("--y", type=float, required=True) ap.add_argument("--z", type=float, default=41.6) ap.add_argument("--yaw-deg", type=float, default=35.0) a = ap.parse_args() rclpy.init() n = rclpy.create_node("set_pose") q = QoSProfile(reliability=ReliabilityPolicy.RELIABLE, durability=DurabilityPolicy.TRANSIENT_LOCAL, history=HistoryPolicy.KEEP_LAST, depth=1) pub = n.create_publisher(PoseWithCovarianceStamped, "/initialpose", q) for _ in range(150): # wait for the ego to match (<=15s) if pub.get_subscription_count() >= 1: break rclpy.spin_once(n, timeout_sec=0.1) print("matched subs:", pub.get_subscription_count()) yaw = math.radians(a.yaw_deg) m = PoseWithCovarianceStamped() m.header.frame_id = "map" m.header.stamp = n.get_clock().now().to_msg() m.pose.pose.position.x = a.x; m.pose.pose.position.y = a.y; m.pose.pose.position.z = a.z m.pose.pose.orientation.z = math.sin(yaw / 2); m.pose.pose.orientation.w = math.cos(yaw / 2) for _ in range(12): pub.publish(m) rclpy.spin_once(n, timeout_sec=0.0); time.sleep(0.15) print(f"published /initialpose -> x={a.x} y={a.y} yaw={a.yaw_deg}deg") n.destroy_node(); rclpy.shutdown() if __name__ == "__main__": main()