bin
one_side_gripper_controller.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
3
"""
4
one_side_gripper_controller.py - controls a gripper built with one servo
5
Copyright (c) 2011 Vanadium Labs LLC. All right reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are met:
9
* Redistributions of source code must retain the above copyright
10
notice, this list of conditions and the following disclaimer.
11
* Redistributions in binary form must reproduce the above copyright
12
notice, this list of conditions and the following disclaimer in the
13
documentation and/or other materials provided with the distribution.
14
* Neither the name of Vanadium Labs LLC nor the names of its
15
contributors may be used to endorse or promote products derived
16
from this software without specific prior written permission.
17
18
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
DISCLAIMED. IN NO EVENT SHALL VANADIUM LABS BE LIABLE FOR ANY DIRECT, INDIRECT,
22
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
"""
29
30
import
rospy
31
import
thread
32
33
from
std_msgs.msg
import
Float64
34
from
math
import
asin
35
36
class
OneSideGripperController
:
37
""" A simple controller that operates a servos to
38
open/close to a particular size opening. """
39
def
__init__
(self):
40
rospy.init_node(
"one_side_gripper_controller"
)
41
rospy.logwarn(
"one_side_gripper_controller.py is deprecated and will be removed in ROS Indigo, please use gripper_controller"
)
42
43
self.
pad_width
= rospy.get_param(
"~pad_width"
, 0.01)
44
self.
finger_length
= rospy.get_param(
"~finger_length"
, 0.02)
45
self.
center
= rospy.get_param(
"~center"
, 0.0)
46
self.
invert
= rospy.get_param(
"~invert"
,
False
)
47
48
# publishers
49
self.
pub
= rospy.Publisher(
"gripper_joint/command"
, Float64, queue_size=5)
50
51
# subscribe to command and then spin
52
rospy.Subscriber(
"~command"
, Float64, self.
commandCb
)
53
rospy.spin()
54
55
def
commandCb
(self, msg):
56
""" Take an input command of width to open gripper. """
57
# check limits
58
#if msg.data > self.max_opening or msg.data < self.min_opening:
59
# rospy.logerr("Command exceeds limits.")
60
# return
61
# compute angle
62
angle = asin((msg.data - self.
pad_width
)/(2*self.
finger_length
))
63
# publish message
64
if
self.
invert
:
65
self.
pub
.publish(-angle + self.
center
)
66
else
:
67
self.
pub
.publish(angle + self.
center
)
68
69
if
__name__==
"__main__"
:
70
try
:
71
OneSideGripperController
()
72
except
rospy.ROSInterruptException:
73
rospy.loginfo(
"Hasta la Vista..."
)
74
one_side_gripper_controller.OneSideGripperController.commandCb
def commandCb(self, msg)
Definition:
one_side_gripper_controller.py:55
one_side_gripper_controller.OneSideGripperController.finger_length
finger_length
Definition:
one_side_gripper_controller.py:44
one_side_gripper_controller.OneSideGripperController.invert
invert
Definition:
one_side_gripper_controller.py:46
one_side_gripper_controller.OneSideGripperController.center
center
Definition:
one_side_gripper_controller.py:45
one_side_gripper_controller.OneSideGripperController.pad_width
pad_width
Definition:
one_side_gripper_controller.py:43
one_side_gripper_controller.OneSideGripperController.pub
pub
Definition:
one_side_gripper_controller.py:49
one_side_gripper_controller.OneSideGripperController.__init__
def __init__(self)
Definition:
one_side_gripper_controller.py:39
one_side_gripper_controller.OneSideGripperController
Definition:
one_side_gripper_controller.py:36
arbotix_controllers
Author(s): Michael Ferguson
autogenerated on Tue Mar 1 2022 23:48:27