本文整理汇总了Python中actionlib.SimpleActionClient.get_state方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleActionClient.get_state方法的具体用法?Python SimpleActionClient.get_state怎么用?Python SimpleActionClient.get_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类actionlib.SimpleActionClient
的用法示例。
在下文中一共展示了SimpleActionClient.get_state方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class ActionTasks:
def __init__(self, script_path):
rospy.init_node('action_testr')
rospy.on_shutdown(self.cleanup)
self.fridge = (Pose(Point(0.295, -2.304, 0.0), Quaternion(0.0, 0.0, -0.715, 0.699)))
self.client = SimpleActionClient("move_base", MoveBaseAction)
self.client.wait_for_server()
self.move_to(self.fridge)
def move_to(self, location):
goal = MoveBaseGoal()
goal.target_pose.pose = location
goal.target_pose.header.frame_id = 'map'
goal.target_pose.header.stamp = rospy.Time.now()
self.client.send_goal(goal)
#self.client.wait_for_result()
self.client.wait_for_result(rospy.Duration.from_sec(40.0))
if self.client.get_state() == GoalStatus.SUCCEEDED:
result = self.client.get_result()
print "Result: SUCCEEDED "
elif self.client.get_state() == GoalStatus.PREEMPTED:
print "Action pre-empted"
else:
print "Action failed"
def cleanup(self):
rospy.loginfo("Shutting down talk node...")
示例2: NavServer
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class NavServer(object):
def __init__(self, name):
rospy.loginfo("Starting '%s'." % name)
self._ps = PNPSimplePluginServer(
name=name,
ActionSpec=StringAction,
execute_cb=self.execute_cb,
auto_start=False
)
self._ps.register_preempt_callback(self.preempt_cb)
self.client = SimpleActionClient('topological_navigation', GotoNodeAction)
self.client.wait_for_server()
self._ps.start()
rospy.loginfo("Done")
def execute_cb(self, goal):
self.client.send_goal_and_wait(GotoNodeGoal(target=goal.value))
result = self.client.get_state()
if result == GoalStatus.PREEMPTED:
return
if result == GoalStatus.SUCCEEDED:
self._ps.set_succeeded()
else:
self._ps.set_aborted()
def preempt_cb(self):
self.client.cancel_all_goals()
self._ps.set_preempted()
示例3: __init__
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class TrajectoryExecution:
def __init__(self, side_prefix):
traj_controller_name = '/' + side_prefix + '_arm_controller/joint_trajectory_action'
self.traj_action_client = SimpleActionClient(traj_controller_name, JointTrajectoryAction)
rospy.loginfo('Waiting for a response from the trajectory action server arm: ' + side_prefix)
self.traj_action_client.wait_for_server()
rospy.loginfo('Trajectory executor is ready for arm: ' + side_prefix)
motion_request_name = '/' + side_prefix + '_arm_motion_request/joint_trajectory_action'
self.action_server = SimpleActionServer(motion_request_name, JointTrajectoryAction, execute_cb=self.move_to_joints)
self.action_server.start()
self.has_goal = False
def move_to_joints(self, traj_goal):
rospy.loginfo('Receieved a trajectory execution request.')
traj_goal.trajectory.header.stamp = (rospy.Time.now() + rospy.Duration(0.1))
self.traj_action_client.send_goal(traj_goal)
rospy.sleep(1)
is_terminated = False
while(not is_terminated):
action_state = self.traj_action_client.get_state()
if (action_state == GoalStatus.SUCCEEDED):
self.action_server.set_succeeded()
is_terminated = True
elif (action_state == GoalStatus.ABORTED):
self.action_server.set_aborted()
is_terminated = True
elif (action_state == GoalStatus.PREEMPTED):
self.action_server.set_preempted()
is_terminated = True
rospy.loginfo('Trajectory completed.')
示例4: move_arm_to_grasping_joint_pose
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
def move_arm_to_grasping_joint_pose(joint_names, joint_positions, allowed_contacts=[], link_padding=[], collision_operations=OrderedCollisionOperations()):
move_arm_client = SimpleActionClient('move_left_arm', MoveArmAction)
move_arm_client.wait_for_server()
rospy.loginfo('connected to move_left_arm action server')
goal = MoveArmGoal()
goal.planner_service_name = 'ompl_planning/plan_kinematic_path'
goal.motion_plan_request.planner_id = ''
goal.motion_plan_request.group_name = 'left_arm'
goal.motion_plan_request.num_planning_attempts = 1
goal.motion_plan_request.allowed_planning_time = rospy.Duration(5.0)
goal.motion_plan_request.goal_constraints.joint_constraints = [JointConstraint(j, p, 0.1, 0.1, 0.0) for (j,p) in zip(joint_names,joint_positions)]
goal.motion_plan_request.allowed_contacts = allowed_contacts
goal.motion_plan_request.link_padding = link_padding
goal.motion_plan_request.ordered_collision_operations = collision_operations
move_arm_client.send_goal(goal)
finished_within_time = move_arm_client.wait_for_result(rospy.Duration(200.0))
if not finished_within_time:
move_arm_client.cancel_goal()
rospy.loginfo('timed out trying to achieve a joint goal')
else:
state = move_arm_client.get_state()
if state == GoalStatus.SUCCEEDED:
rospy.loginfo('action finished: %s' % str(state))
return True
else:
rospy.loginfo('action failed: %s' % str(state))
return False
示例5: __init__
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class ExplorationController:
def __init__(self):
self._plan_service = rospy.ServiceProxy('get_exploration_path', GetRobotTrajectory)
self._move_base = SimpleActionClient('move_base', MoveBaseAction)
def run(self):
r = rospy.Rate(1 / 7.0)
while not rospy.is_shutdown():
self.run_once()
r.sleep()
def run_once(self):
path = self._plan_service().trajectory
poses = path.poses
if not path.poses:
rospy.loginfo('No frontiers left.')
return
rospy.loginfo('Moving to frontier...')
self.move_to_pose(poses[-1])
def move_to_pose(self, pose_stamped, timeout=20.0):
goal = MoveBaseGoal()
goal.target_pose = pose_stamped
self._move_base.send_goal(goal)
self._move_base.wait_for_result(rospy.Duration(timeout))
return self._move_base.get_state() == GoalStatus.SUCCEEDED
示例6: DoReset
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class DoReset(smach.State):
def __init__(self):
smach.State.__init__(self, outcomes=['succeeded', 'aborted', 'preempted'],
input_keys=['reset_plan'])
self.eef_pub = rospy.Publisher('/CModelRobotOutput', eef_cmd, queue_size=1, latch=True)
self.move_arm_client = SimpleActionClient('/wm_arm_driver_node/execute_plan', executePlanAction)
def execute(self, ud):
rospy.logdebug("Entered 'RO_RESET' state.")
hand_cmd = eef_cmd()
hand_cmd.rACT = 1 # activate gripper
hand_cmd.rGTO = 1 # request to go to position
hand_cmd.rSP = 200 # set activation speed (0[slowest]-255[fastest])
hand_cmd.rFR = 0 # set force limit (0[min] - 255[max])
hand_cmd.rPR = 0 # request to open
self.eef_pub.publish(hand_cmd)
self.move_arm_client.wait_for_server()
goal = executePlanGoal()
goal.trajectory = ud.reset_plan
self.move_arm_client.send_goal(goal)
self.move_arm_client.wait_for_result()
status = self.move_arm_client.get_state()
if status == GoalStatus.SUCCEEDED:
return 'succeeded'
elif status == GoalStatus.PREEMPTED:
return 'preempted'
else:
return 'aborted'
示例7: Move
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class Move(smach.State):
def __init__(self):
smach.State.__init__(self, outcomes=['wp_reached', 'wp_not_reached', 'test_finished'],
input_keys=['move_waypoints', 'move_target_wp', 'move_wp_str'],
output_keys=['move_target_wp'])
self.move_base_client = SimpleActionClient('move_base', MoveBaseAction)
self.tts_pub = rospy.Publisher('sara_tts', String, queue_size=1, latch=True)
def execute(self, ud):
self.move_base_client.wait_for_server()
goal = MoveBaseGoal()
goal.target_pose = ud.move_waypoints[ud.move_target_wp]
goal.target_pose.header.stamp = rospy.Time.now()
self.move_base_client.send_goal(goal)
self.move_base_client.wait_for_result()
status = self.move_base_client.get_state()
tts_msg = String()
if status == GoalStatus.SUCCEEDED:
tts_msg.data = "I have reached " + ud.move_wp_str[ud.move_target_wp] + "."
self.tts_pub.publish(tts_msg)
if ud.move_target_wp == 0:
return 'test_finished'
else:
ud.move_target_wp -= 1
return 'succeeded'
else:
return 'wp_not_reached'
示例8: testsimple
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
def testsimple(self):
client = SimpleActionClient('reference_action', TestAction)
self.assert_(client.wait_for_server(rospy.Duration(10.0)),
'Could not connect to the action server')
goal = TestGoal(1)
client.send_goal(goal)
self.assert_(client.wait_for_result(rospy.Duration(10.0)),
"Goal didn't finish")
self.assertEqual(GoalStatus.SUCCEEDED, client.get_state())
self.assertEqual("The ref server has succeeded", client.get_goal_status_text())
goal = TestGoal(2)
client.send_goal(goal)
self.assert_(client.wait_for_result(rospy.Duration(10.0)),
"Goal didn't finish")
self.assertEqual(GoalStatus.ABORTED, client.get_state())
self.assertEqual("The ref server has aborted", client.get_goal_status_text())
示例9: test_one
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
def test_one(self):
client = SimpleActionClient('reference_simple_action', TestAction)
self.assert_(client.wait_for_server(rospy.Duration(2.0)),
'Could not connect to the action server')
goal = TestGoal(1)
client.send_goal(goal)
self.assert_(client.wait_for_result(rospy.Duration(2.0)),
"Goal didn't finish")
self.assertEqual(GoalStatus.SUCCEEDED, client.get_state())
goal = TestGoal(2)
client.send_goal(goal)
self.assert_(client.wait_for_result(rospy.Duration(10.0)),
"Goal didn't finish")
self.assertEqual(GoalStatus.ABORTED, client.get_state())
goal = TestGoal(3)
client.send_goal(goal)
self.assert_(client.wait_for_result(rospy.Duration(10.0)),
"Goal didn't finish")
#The simple server can't reject goals
self.assertEqual(GoalStatus.ABORTED, client.get_state())
goal = TestGoal(9)
saved_feedback={};
def on_feedback(fb):
rospy.loginfo("Got feedback")
saved_feedback[0]=fb
client.send_goal(goal,feedback_cb=on_feedback)
self.assert_(client.wait_for_result(rospy.Duration(10.0)),
"Goal didn't finish")
self.assertEqual(GoalStatus.SUCCEEDED, client.get_state())
self.assertEqual(saved_feedback[0].feedback,9)
示例10: RecordPoseStampedFromPlayMotion
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class RecordPoseStampedFromPlayMotion():
"""Manage the learning from a play motion gesture"""
def __init__(self):
rospy.loginfo("Initializing RecordFromPlayMotion")
rospy.loginfo("Connecting to AS: '" + PLAY_MOTION_AS + "'")
self.play_motion_as = SimpleActionClient(PLAY_MOTION_AS, PlayMotionAction)
self.play_motion_as.wait_for_server()
rospy.loginfo("Connected.")
self.current_rosbag_name = "uninitialized_rosbag_name"
self.lfee = LearnFromEndEffector(['/tf_to_ps'], ['right_arm'])
def play_and_record(self, motion_name, groups=['right_arm'], bag_name="no_bag_name_set"):
"""Play the specified motion and start recording poses.
Try to get the joints to record from the metadata of the play_motion gesture
or, optionally, specify the joints to track"""
# Check if motion exists in param server
PLAYMOTIONPATH = '/play_motion/motions/'
if not rospy.has_param(PLAYMOTIONPATH + motion_name):
rospy.logerr("Motion named: " + motion_name + " does not exist in param server at " + PLAYMOTIONPATH + motion_name)
return
else:
rospy.loginfo("Found motion " + motion_name + " in param server at " + PLAYMOTIONPATH + motion_name)
# Get it's info
motion_info = rospy.get_param(PLAYMOTIONPATH + motion_name)
# check if joints was specified, if not, get the joints to actually save
if len(groups) > 0:
joints_to_record = groups
else:
joints_to_record = motion_info['groups']
rospy.loginfo("Got groups: " + str(joints_to_record))
# play motion
rospy.loginfo("Playing motion!")
pm_goal = PlayMotionGoal(motion_name, False, 0)
self.play_motion_as.send_goal(pm_goal)
self.lfee.start_learn(motion_name, bag_name)
done_with_motion = False
while not done_with_motion:
state = self.play_motion_as.get_state()
#rospy.loginfo("State is: " + str(state) + " which is: " + goal_status_dict[state])
if state == GoalStatus.ABORTED or state == GoalStatus.SUCCEEDED:
done_with_motion = True
elif state != GoalStatus.PENDING and state != GoalStatus.ACTIVE:
rospy.logerr("We got state " + str(state) + " unexpectedly, motion failed. Aborting.")
return None
rospy.sleep(0.1)
# data is written to rosbag in here
motion_data = self.lfee.stop_learn()
return motion_data
示例11: look_at_r_gripper
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
def look_at_r_gripper(self):
name_space = '/head_traj_controller/point_head_action'
head_client = SimpleActionClient(name_space, PointHeadAction)
head_client.wait_for_server()
head_goal = PointHeadGoal()
head_goal.target.header.frame_id = "r_gripper_tool_frame"
head_goal.min_duration = rospy.Duration(0.3)
head_goal.target.point = Point(0, 0, 0)
head_goal.max_velocity = 1.0
head_client.send_goal(head_goal)
head_client.wait_for_result(rospy.Duration(5.0))
if (head_client.get_state() != GoalStatus.SUCCEEDED):
rospy.logwarn('Head action unsuccessful.')
示例12: HeadNode
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
class HeadNode():
def __init__(self):
name_space = '/head_traj_controller/point_head_action'
self.head_client = SimpleActionClient(name_space, PointHeadAction)
self.head_client.wait_for_server()
def moveHead(self, theta, phi):
head_goal = PointHeadGoal()
head_goal.target.header.frame_id = 'base_link'
head_goal.min_duration = rospy.Duration(1.0)
head_goal.target.point = Point(math.cos(theta), math.sin(theta), phi)
self.head_client.send_goal(head_goal)
self.head_client.wait_for_result(rospy.Duration(10.0))
if (self.head_client.get_state() != GoalStatus.SUCCEEDED):
rospy.logwarn('Head action unsuccessful.')
示例13: move_head
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
def move_head():
name_space = '/head_traj_controller/point_head_action'
head_client = SimpleActionClient(name_space, PointHeadAction)
head_client.wait_for_server()
head_goal = PointHeadGoal()
head_goal.target.header.frame_id = self.get_frame()
head_goal.min_duration = rospy.Duration(0.3)
head_goal.target.point = self.get_target()
head_goal.max_velocity = 10.0
head_client.send_goal(head_goal)
head_client.wait_for_result(rospy.Duration(2.0))
if (head_client.get_state() != GoalStatus.SUCCEEDED):
rospy.logwarn('Head action unsuccessful.')
self.gui.show_text_in_rviz("Head!")
示例14: tilt_head
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
def tilt_head(self, down=True):
name_space = '/head_traj_controller/point_head_action'
head_client = SimpleActionClient(name_space, PointHeadAction)
head_client.wait_for_server()
head_goal = PointHeadGoal()
head_goal.target.header.frame_id = self.get_frame()
head_goal.min_duration = rospy.Duration(0.3)
if down:
head_goal.target.point = Point(1, 0, Head.speed * -0.1)
else:
head_goal.target.point = Point(1, 0, Head.speed * 0.1)
head_goal.max_velocity = 10.0
head_client.send_goal(head_goal)
head_client.wait_for_result(rospy.Duration(2.0))
if (head_client.get_state() != GoalStatus.SUCCEEDED):
rospy.logwarn('Head action unsuccessful.')
示例15: main
# 需要导入模块: from actionlib import SimpleActionClient [as 别名]
# 或者: from actionlib.SimpleActionClient import get_state [as 别名]
def main():
rospy.init_node("simple_navigation_goals")
move_base_client = SimpleActionClient('move_base', MoveBaseAction)
rospy.loginfo('Connecting to server')
move_base_client.wait_for_server()
goal = MoveBaseGoal()
goal.target_pose.header.frame_id = 'komodo_1/base_link'
goal.target_pose.header.stamp = rospy.Time.now()
goal.target_pose.pose.position.x = -1.0
goal.target_pose.pose.orientation.w = 1.0
rospy.loginfo('Sending goal')
move_base_client.send_goal(goal)
move_base_client.wait_for_result()
if move_base_client.get_state() == GoalStatus.SUCCEEDED:
rospy.loginfo('Hooray, the base moved 1 meter forward')
else:
rospy.loginfo('The base failed to move forward 1 meter for some reason')