gripper_action_example.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # Copyright 2018 RT Corporation
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 
18 # このサンプルは実機動作のみに対応しています
19 # fake_execution:=trueにすると、GripperCommandActionのサーバが立ち上がりません
20 
21 import sys
22 import rospy
23 import time
24 import actionlib
25 import math
26 from std_msgs.msg import Float64
27 from control_msgs.msg import (
28  GripperCommandAction,
29  GripperCommandGoal
30 )
31 
32 class GripperClient(object):
33  def __init__(self):
34  self._client = actionlib.SimpleActionClient("/crane_x7/gripper_controller/gripper_cmd",GripperCommandAction)
35  self._goal = GripperCommandGoal()
36 
37  # Wait 10 Seconds for the gripper action server to start or exit
38  self._client.wait_for_server(rospy.Duration(10.0))
39  if not self._client.wait_for_server(rospy.Duration(10.0)):
40  rospy.logerr("Exiting - Gripper Action Server Not Found.")
41  rospy.signal_shutdown("Action Server not found.")
42  sys.exit(1)
43  self.clear()
44 
45  def command(self, position, effort):
46  self._goal.command.position = position
47  self._goal.command.max_effort = effort
48  self._client.send_goal(self._goal,feedback_cb=self.feedback)
49 
50  def feedback(self,msg):
51  print("feedback callback")
52  print(msg)
53 
54  def stop(self):
55  self._client.cancel_goal()
56 
57  def wait(self, timeout=0.1 ):
58  self._client.wait_for_result(timeout=rospy.Duration(timeout))
59  return self._client.get_result()
60 
61  def clear(self):
62  self._goal = GripperCommandGoal()
63 
64 def main():
65  rospy.init_node("gipper_action_client")
66  gc = GripperClient()
67 
68  # Open grippers(45degrees)
69  print("Open Gripper.")
70  gripper = 45.0
71  gc.command(math.radians(gripper),1.0)
72  result = gc.wait(2.0)
73  print(result)
74  time.sleep(1)
75  print("")
76 
77  # Close grippers
78  print("Close Gripper.")
79  gripper = 0.0 # 0.0
80  gc.command(math.radians(gripper),1.0)
81  result = gc.wait(2.0)
82  print(result)
83  time.sleep(1)
84 
85 if __name__ == "__main__":
86  main()
gripper_action_example.GripperClient.feedback
def feedback(self, msg)
Definition: gripper_action_example.py:50
gripper_action_example.GripperClient._client
_client
Definition: gripper_action_example.py:34
gripper_action_example.GripperClient.__init__
def __init__(self)
Definition: gripper_action_example.py:33
gripper_action_example.GripperClient.stop
def stop(self)
Definition: gripper_action_example.py:54
gripper_action_example.GripperClient.wait
def wait(self, timeout=0.1)
Definition: gripper_action_example.py:57
gripper_action_example.GripperClient._goal
_goal
Definition: gripper_action_example.py:35
actionlib::SimpleActionClient
gripper_action_example.main
def main()
Definition: gripper_action_example.py:64
gripper_action_example.GripperClient.clear
def clear(self)
Definition: gripper_action_example.py:61
gripper_action_example.GripperClient.command
def command(self, position, effort)
Definition: gripper_action_example.py:45
gripper_action_example.GripperClient
Definition: gripper_action_example.py:32


crane_x7_examples
Author(s): Daisuke Sato , Hiroyuki Nomura
autogenerated on Mon Oct 2 2023 02:39:27