ar_demo.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import tf
5 import geometry_msgs.msg
6 import sys
7 
8 from moveit_commander import MoveGroupCommander
9 from tf.transformations import *
10 import math
11 
12 def kbhit():
13  import select
14  return sys.stdin in select.select([sys.stdin], [], [], 0)[0]
15 
16 if __name__ == '__main__':
17  rospy.init_node('ar_pose_commander', anonymous=True)
18  group = MoveGroupCommander("right_arm")
19 
20  base_frame_id = '/WAIST'
21  ar_marker_id = '/ar_marker_4'
22 
23  pub = rospy.Publisher('target_pose', geometry_msgs.msg.PoseStamped)
24  listener = tf.TransformListener()
25 
26  rate = rospy.Rate(10.0)
27  pose_st_target = None
28  while not rospy.is_shutdown() and not kbhit():
29  try:
30  now = rospy.Time(0)
31  (trans,quat) = listener.lookupTransform(base_frame_id, ar_marker_id, now)
32  quat = quaternion_multiply(quat, quaternion_about_axis(math.pi/2, (1,0,0)))
33  quat = quaternion_multiply(quat, quaternion_about_axis(math.pi/2, (0,0,1)))
34  pose_st_target = geometry_msgs.msg.PoseStamped()
35  pose_st_target.pose.position.x = trans[0]
36  pose_st_target.pose.position.y = trans[1]
37  pose_st_target.pose.position.z = trans[2]
38  pose_st_target.pose.orientation.x = quat[0]
39  pose_st_target.pose.orientation.y = quat[1]
40  pose_st_target.pose.orientation.z = quat[2]
41  pose_st_target.pose.orientation.w = quat[3]
42  pose_st_target.header.frame_id = base_frame_id
43  pose_st_target.header.stamp = now
45  rospy.logwarn(e)
46 
47  if pose_st_target:
48  pub.publish(pose_st_target)
49  rospy.loginfo(trans)
50 
51  rate.sleep()
52 
53  if raw_input() == 'q':
54  sys.exit(1)
55 
56  # move to a point above ar marker
57  pose_st_target.pose.position.z += 0.3
58  rospy.loginfo("set target to {}".format(pose_st_target.pose))
59  group.set_pose_target(pose_st_target.pose)
60  plan = group.plan()
61  rospy.loginfo("plan is {}".format(plan))
62  ret = group.go()
63  rospy.loginfo("executed ... {}".format(ret))
64 
def kbhit()
Definition: ar_demo.py:12


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed Jun 17 2020 04:14:47