irex_demo.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from geometry_msgs.msg import Pose, PoseStamped, Point, Quaternion
3 from moveit_commander import MoveGroupCommander, conversions
4 from tf.transformations import quaternion_from_euler
5 import rospy
6 import os
7 from subprocess import check_call
8 import roslib
9 roslib.load_manifest("denso_pendant_publisher")
10 roslib.load_manifest("actionlib_msgs")
11 import denso_pendant_publisher.msg
12 import std_msgs.msg
13 import actionlib_msgs.msg
14 rospy.init_node("test_vs060_moveit")
15 
16 g_runnable = False
17 
18 g_prev_status = None
19 
20 def pendantCB(msg):
21  global g_runnable, g_prev_status
22  if g_prev_status:
23  if (not g_prev_status.button_cancel and msg.button_cancel) or (not g_prev_status.button_stop and msg.button_stop): # canceled or stopped
24  g_runnable = False
25  # here we should send cancel
26  cancel = actionlib_msgs.msg.GoalID()
27  cancel.id = ""
28  cancel_pub.publish(cancel)
29  rospy.loginfo("hello")
30  running_pub.publish(std_msgs.msg.Bool(g_runnable))
31  elif not g_prev_status.button_ok and msg.button_ok: # oked
32  g_runnable = True
33  running_pub.publish(std_msgs.msg.Bool(g_runnable))
34  g_prev_status = msg
35 
36 sub = rospy.Subscriber("/denso_pendant_publisher/status", denso_pendant_publisher.msg.PendantStatus, pendantCB)
37 arm = MoveGroupCommander("manipulator")
38 running_pub = rospy.Publisher("/irex_demo_running", std_msgs.msg.Bool);
39 #cancel_pub = rospy.Publisher("/arm_controller/follow_joint_trajectory/cancel", actionlib_msgs.msg.GoalID);
40 cancel_pub = rospy.Publisher("/move_group/cancel", actionlib_msgs.msg.GoalID);
41 
42 
43 SCENE_FILE = os.path.join(os.path.dirname(__file__), "..", "model", "irex_model.scene")
44 LOAD_SCENE_PROG = os.path.join(os.path.dirname(__file__), "..", "bin", "publish_scene_from_text")
45 
46 def demo() :
47  # load scene
48  global g_runnable
49  running_pub.publish(std_msgs.msg.Bool(g_runnable))
50  check_call([LOAD_SCENE_PROG, SCENE_FILE])
51  for p in [[ 0.35, -0.35, 0.4],
52  [ 0.6, 0.0, 0.4],
53  [ 0.35, 0.35, 0.4],
54  [ 0.6, 0.0, 0.2],
55  [ 0.4, 0.0, 0.8]]:
56  running_pub.publish(std_msgs.msg.Bool(g_runnable))
57  if g_runnable:
58  print "set_pose_target(", p, ")"
59  pose = PoseStamped(header = rospy.Header(stamp = rospy.Time.now(), frame_id = '/BASE'),
60  pose = Pose(position = Point(*p),
61  orientation = Quaternion(*quaternion_from_euler(1.57, 0, 1.57, 'sxyz'))))
62 
63  arm.set_pose_target(pose)
64  arm.go() or arm.go() or rospy.logerr("arm.go fails")
65  rospy.sleep(1)
66  if rospy.is_shutdown():
67  return
68 
69 if __name__ == "__main__":
70  while not rospy.is_shutdown():
71  demo()
72 
def demo()
Definition: irex_demo.py:46
def pendantCB(msg)
Definition: irex_demo.py:20


vs060
Author(s): Ryohei Ueda
autogenerated on Mon Jun 10 2019 13:13:22