43
43
"""
44
44
45
45
from __future__ import print_function
46
- import roslib ; roslib .load_manifest ('robotiq_3f_gripper_control' )
46
+
47
+ import roslib ;
48
+
49
+ roslib .load_manifest ('robotiq_3f_gripper_control' )
47
50
import rospy
48
51
from robotiq_3f_gripper_articulated_msgs .msg import Robotiq3FGripperRobotOutput
49
- from time import sleep
50
52
51
53
52
54
def genCommand (char , command ):
53
- """Update the command according to the character entered by the user."""
54
-
55
+ """Update the command according to the character entered by the user."""
56
+
55
57
if char == 'a' :
56
58
command = Robotiq3FGripperRobotOutput ();
57
59
command .rACT = 1
@@ -71,79 +73,78 @@ def genCommand(char, command):
71
73
72
74
if char == 'b' :
73
75
command .rMOD = 0
74
-
76
+
75
77
if char == 'p' :
76
78
command .rMOD = 1
77
-
79
+
78
80
if char == 'w' :
79
81
command .rMOD = 2
80
-
82
+
81
83
if char == 's' :
82
84
command .rMOD = 3
83
85
84
- #If the command entered is a int, assign this value to rPRA
85
- try :
86
+ # If the command entered is a int, assign this value to rPRA
87
+ try :
86
88
command .rPRA = int (char )
87
89
if command .rPRA > 255 :
88
90
command .rPRA = 255
89
91
if command .rPRA < 0 :
90
92
command .rPRA = 0
91
93
except ValueError :
92
- pass
93
-
94
+ pass
95
+
94
96
if char == 'f' :
95
97
command .rSPA += 25
96
98
if command .rSPA > 255 :
97
99
command .rSPA = 255
98
-
100
+
99
101
if char == 'l' :
100
102
command .rSPA -= 25
101
103
if command .rSPA < 0 :
102
104
command .rSPA = 0
103
105
104
-
105
106
if char == 'i' :
106
107
command .rFRA += 25
107
108
if command .rFRA > 255 :
108
109
command .rFRA = 255
109
-
110
+
110
111
if char == 'd' :
111
112
command .rFRA -= 25
112
113
if command .rFRA < 0 :
113
114
command .rFRA = 0
114
115
115
116
return command
116
-
117
+
117
118
118
119
def askForCommand (command ):
119
- """Ask the user for a command to send to the gripper."""
120
+ """Ask the user for a command to send to the gripper."""
120
121
121
- currentCommand = 'Simple 3F gripper Controller\n -----\n Current command:'
122
- currentCommand += ' rACT = ' + str (command .rACT )
122
+ currentCommand = 'Simple 3F gripper Controller\n -----\n Current command:'
123
+ currentCommand += ' rACT = ' + str (command .rACT )
123
124
currentCommand += ', rMOD = ' + str (command .rMOD )
124
125
currentCommand += ', rGTO = ' + str (command .rGTO )
125
126
currentCommand += ', rATR = ' + str (command .rATR )
126
- ## currentCommand += ', rGLV = ' + str(command.rGLV)
127
- ## currentCommand += ', rICF = ' + str(command.rICF)
128
- ## currentCommand += ', rICS = ' + str(command.rICS)
127
+ ## currentCommand += ', rGLV = ' + str(command.rGLV)
128
+ ## currentCommand += ', rICF = ' + str(command.rICF)
129
+ ## currentCommand += ', rICS = ' + str(command.rICS)
129
130
currentCommand += ', rPRA = ' + str (command .rPRA )
130
131
currentCommand += ', rSPA = ' + str (command .rSPA )
131
132
currentCommand += ', rFRA = ' + str (command .rFRA )
132
133
133
- #We only show the simple control mode
134
- ## currentCommand += ', rPRB = ' + str(command.rPRB)
135
- ## currentCommand += ', rSPB = ' + str(command.rSPB)
136
- ## currentCommand += ', rFRB = ' + str(command.rFRB)
137
- ## currentCommand += ', rPRC = ' + str(command.rPRC)
138
- ## currentCommand += ', rSPC = ' + str(command.rSPC)
139
- ## currentCommand += ', rFRC = ' + str(command.rFRC)
140
- ## currentCommand += ', rPRS = ' + str(command.rPRS)
141
- ## currentCommand += ', rSPS = ' + str(command.rSPS)
142
- ## currentCommand += ', rFRS = ' + str(command.rFRS)
134
+ # We only show the simple control mode
135
+ ## currentCommand += ', rPRB = ' + str(command.rPRB)
136
+ ## currentCommand += ', rSPB = ' + str(command.rSPB)
137
+ ## currentCommand += ', rFRB = ' + str(command.rFRB)
138
+ ## currentCommand += ', rPRC = ' + str(command.rPRC)
139
+ ## currentCommand += ', rSPC = ' + str(command.rSPC)
140
+ ## currentCommand += ', rFRC = ' + str(command.rFRC)
141
+ ## currentCommand += ', rPRS = ' + str(command.rPRS)
142
+ ## currentCommand += ', rSPS = ' + str(command.rSPS)
143
+ ## currentCommand += ', rFRS = ' + str(command.rFRS)
143
144
144
145
print (currentCommand )
145
146
146
- strAskForCommand = '-----\n Available commands\n \n '
147
+ strAskForCommand = '-----\n Available commands\n \n '
147
148
strAskForCommand += 'r: Reset\n '
148
149
strAskForCommand += 'a: Activate\n '
149
150
strAskForCommand += 'c: Close\n '
@@ -157,28 +158,28 @@ def askForCommand(command):
157
158
strAskForCommand += 'l: Slower\n '
158
159
strAskForCommand += 'i: Increase force\n '
159
160
strAskForCommand += 'd: Decrease force\n '
160
-
161
+
161
162
strAskForCommand += '-->'
162
163
163
164
return raw_input (strAskForCommand )
164
165
166
+
165
167
def publisher ():
166
168
"""Main loop which requests new commands and publish them on the Robotiq3FGripperRobotOutput topic."""
167
169
168
170
rospy .init_node ('Robotiq3FGripperSimpleController' )
169
-
171
+
170
172
pub = rospy .Publisher ('Robotiq3FGripperRobotOutput' , Robotiq3FGripperRobotOutput )
171
173
172
174
command = Robotiq3FGripperRobotOutput ();
173
175
174
176
while not rospy .is_shutdown ():
177
+ command = genCommand (askForCommand (command ), command )
175
178
176
- command = genCommand (askForCommand (command ), command )
177
-
178
179
pub .publish (command )
179
180
180
181
rospy .sleep (0.1 )
181
-
182
+
182
183
183
184
if __name__ == '__main__' :
184
185
publisher ()
0 commit comments