feat: add two-floor elevator simulation
This commit is contained in:
57
scripts/send_ride_goal.py
Executable file
57
scripts/send_ride_goal.py
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Send one simulated floor-to-floor ride action."""
|
||||
|
||||
import sys
|
||||
|
||||
import actionlib
|
||||
import rospy
|
||||
from two_floor_elevator_sim.msg import SimElevatorRideAction, SimElevatorRideGoal
|
||||
|
||||
|
||||
def feedback(message):
|
||||
rospy.loginfo("elevator=%s floor=%s door=%s boarded=%s",
|
||||
message.state_name, message.current_floor,
|
||||
message.door_state, message.robot_boarded)
|
||||
|
||||
|
||||
def main():
|
||||
rospy.init_node("send_sim_elevator_ride")
|
||||
args = rospy.myargv(argv=sys.argv)[1:]
|
||||
if len(args) not in (2, 3, 6):
|
||||
print("usage: send_ride_goal.py FROM_FLOOR TO_FLOOR [TIMEOUT_SEC [DEST_X DEST_Y DEST_YAW]]")
|
||||
return 2
|
||||
|
||||
goal = SimElevatorRideGoal()
|
||||
goal.elevator_id = rospy.get_param("~elevator_id", "sim_elevator")
|
||||
goal.from_floor = args[0]
|
||||
goal.to_floor = args[1]
|
||||
goal.timeout = float(args[2]) if len(args) >= 3 else 180.0
|
||||
if len(args) == 6:
|
||||
goal.navigate_to_destination = True
|
||||
goal.destination_x = float(args[3])
|
||||
goal.destination_y = float(args[4])
|
||||
goal.destination_yaw = float(args[5])
|
||||
|
||||
client = actionlib.SimpleActionClient("/sim_elevator/ride", SimElevatorRideAction)
|
||||
if not client.wait_for_server(rospy.Duration(15.0)):
|
||||
rospy.logerr("action server /sim_elevator/ride is unavailable")
|
||||
return 1
|
||||
client.send_goal(goal, feedback_cb=feedback)
|
||||
finished = client.wait_for_result(rospy.Duration(goal.timeout + 20.0))
|
||||
if not finished:
|
||||
client.cancel_goal()
|
||||
rospy.logerr("ride action timed out in the client")
|
||||
return 1
|
||||
result = client.get_result()
|
||||
if result is None:
|
||||
rospy.logerr("ride ended without a result")
|
||||
return 1
|
||||
if not result.success:
|
||||
rospy.logerr("ride failed (%s): %s", result.error_code, result.message)
|
||||
return 1
|
||||
rospy.loginfo("ride complete at %s: %s", result.reached_floor, result.message)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user