21 from std_msgs.msg
import String, Header
22 from cob_sound.msg
import SayAction, SayGoal
23 from move_base_msgs.msg
import MoveBaseAction, MoveBaseGoal
24 from control_msgs.msg
import FollowJointTrajectoryAction, FollowJointTrajectoryGoal, FollowJointTrajectoryResult
25 from trajectory_msgs.msg
import JointTrajectory, JointTrajectoryPoint
26 from cob_srvs.srv
import SetString, SetStringRequest
27 from geometry_msgs.msg
import PoseStamped, Pose, Point, Quaternion
29 charger_pose = PoseStamped(header=Header(frame_id=
'map'),
30 pose=Pose(position=Point(10, 10, 0),
31 orientation=Quaternion(1, 0, 0, 0)))
33 charger_arm_traj = FollowJointTrajectoryGoal(trajectory=JointTrajectory(points=[JointTrajectoryPoint(positions=[0])]))
35 if __name__ ==
"__main__":
36 rospy.init_node(
"dummy_behavior")
41 FollowJointTrajectoryAction)
42 dock_srv = rospy.ServiceProxy(
'/dock', SetString)
45 if 'charge' in msg.data:
46 rospy.loginfo(
"I'm told to go charge, lets go")
47 move_base_ac.send_goal_and_wait(MoveBaseGoal(target_pose=charger_pose))
49 rospy.loginfo(
"I'm going to dock")
50 dock_result =
dock_srv(SetStringRequest(
'charger'))
52 if not dock_result.success:
53 rospy.logwarn(
"I borked docking, let's try again")
54 say_ac.send_goal_and_wait(SayGoal(
'Docking has failed, lets try again'))
56 dock_srv(SetStringRequest(
'charger'))
59 rospy.loginfo(
"Let's use my arm to plug myself in")
60 move_arm_ac.send_goal_and_wait(charger_arm_traj)
61 arm_successful = move_arm_ac.get_result().error_code == FollowJointTrajectoryResult.SUCCESSFUL
62 if not arm_successful:
63 rospy.logwarn(
"I borked using my arm, let's try again")
64 say_ac.send_goal_and_wait(SayGoal(
'My arm has failed, lets try again'))
65 move_arm_ac.send_goal_and_wait(charger_arm_traj)
68 rospy.loginfo(
"Ah, finally charging, lets that juice flow in")
69 sentence = random.choice([
"Jummy, fresh juice!",
"Ah, some juice!"])
70 say_ac.send_goal_and_wait(SayGoal(sentence))
72 rospy.loginfo(
"Test succeeded, I'm done")
74 command_subscriber = rospy.Subscriber(
'/command', String, command_callback)
76 rospy.loginfo(
"I'm waiting for your command, e.g. to go charge")
def command_callback(msg)