gripper_action_example.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # このサンプルは実機動作のみに対応しています
5 # fake_execution:=trueにすると、GripperCommandActionのサーバが立ち上がりません
6 
7 import sys
8 import rospy
9 import time
10 import actionlib
11 import math
12 from std_msgs.msg import Float64
13 from control_msgs.msg import (
14  GripperCommandAction,
15  GripperCommandGoal
16 )
17 
18 class GripperClient(object):
19  def __init__(self):
20  self._client = actionlib.SimpleActionClient("/crane_x7/gripper_controller/gripper_cmd",GripperCommandAction)
21  self._goal = GripperCommandGoal()
22 
23  # Wait 10 Seconds for the gripper action server to start or exit
24  self._client.wait_for_server(rospy.Duration(10.0))
25  if not self._client.wait_for_server(rospy.Duration(10.0)):
26  rospy.logerr("Exiting - Gripper Action Server Not Found.")
27  rospy.signal_shutdown("Action Server not found.")
28  sys.exit(1)
29  self.clear()
30 
31  def command(self, position, effort):
32  self._goal.command.position = position
33  self._goal.command.max_effort = effort
34  self._client.send_goal(self._goal,feedback_cb=self.feedback)
35 
36  def feedback(self,msg):
37  print("feedback callback")
38  print(msg)
39 
40  def stop(self):
41  self._client.cancel_goal()
42 
43  def wait(self, timeout=0.1 ):
44  self._client.wait_for_result(timeout=rospy.Duration(timeout))
45  return self._client.get_result()
46 
47  def clear(self):
48  self._goal = GripperCommandGoal()
49 
50 def main():
51  rospy.init_node("gipper_action_client")
52  gc = GripperClient()
53 
54  # Open grippers(45degrees)
55  print("Open Gripper.")
56  gripper = 45.0
57  gc.command(math.radians(gripper),1.0)
58  result = gc.wait(2.0)
59  print(result)
60  time.sleep(1)
61  print("")
62 
63  # Close grippers
64  print("Close Gripper.")
65  gripper = 0.0 # 0.0
66  gc.command(math.radians(gripper),1.0)
67  result = gc.wait(2.0)
68  print(result)
69  time.sleep(1)
70 
71 if __name__ == "__main__":
72  main()


crane_x7_examples
Author(s): Daisuke Sato , Hiroyuki Nomura
autogenerated on Mon Mar 1 2021 03:18:34