0
$\begingroup$

Rosanswers logo

Hello,

I've been working with the hector_quadrotor package on ROS Melodic with Ubuntu 18.04 and I wanted to write a node that would move multiple drones from point to point simultaneously. I saw that the package has an action server called PoseAction that I want to use to send these commands, but I am unfamiliar with using actions. I've read the Turtlebot move_base tutorial and this is what my code looks like right now:

import rospy
import time
import random
from hector_uav_msgs.srv import EnableMotors
from geometry_msgs.msg import PoseStamped
import actionlib
import hector_uav_msgs.msg

def hector_pose_client():
     # First enable motor service
     rospy.wait_for_service("/drone1/enable_motors")
     enabler1 = rospy.ServiceProxy("/drone1/enable_motors", EnableMotors)
     resp1 = enabler1(True)

     rospy.loginfo("Creating Action Client.")
     client = actionlib.SimpleActionClient('/drone1/pose_action', hector_uav_msgs.msg.PoseAction)
     rospy.loginfo("Client created.")

     # This is where the program seems to hang even though I assumed hector would automatically run the action server
     client.wait_for_server()

     # Create a random goal
     g = hector_uav_msgs.msg.PoseGoal()
     g.target_pose.header.frame_id = 'drone1/world'
     g.target_pose.pose.position.x = random.randint(-5, 5)
     g.target_pose.pose.position.y = random.randint(-5, 5)
     g.target_pose.pose.position.z = 3
    
     rospy.loginfo("Sending goal")
     client.send_goal(g)
     client.wait_for_result()
     return(client.get_result())

if __name__ == "__main__":
     try:
         rospy.init_node('drone_explorer')
         result = hector_pose_client()
         rospy.loginfo("Client navigated")
     except rospy.ROSInterruptException:
         print("program interrupted before completion", file=sys.stderr)

I've checked rqt_graph and my node does show up but it doesn't appear to have a link to /drone1/action. How would I fix the hang on waiting for the server? Am I using incorrect syntax?


Originally posted by Ganach9 on ROS Answers with karma: 26 on 2020-05-21

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I solved the issue on my own. I was using the wrong name for the action server. Instead when creating the client, it should be:

client = actionlib.SimpleActionClient('/drone1/action/pose', hector_uav_msgs.msg.PoseAction)

It started working immediately after


Originally posted by Ganach9 with karma: 26 on 2020-05-21

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.