Skip to content

Commit 3a04950

Browse files
format python code and remove unused imports
1 parent 123a791 commit 3a04950

File tree

4 files changed

+231
-226
lines changed

4 files changed

+231
-226
lines changed

robotiq_3f_gripper_control/nodes/Robotiq3FGripperSimpleController.py

+38-37
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@
4343
"""
4444

4545
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')
4750
import rospy
4851
from robotiq_3f_gripper_articulated_msgs.msg import Robotiq3FGripperRobotOutput
49-
from time import sleep
5052

5153

5254
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+
5557
if char == 'a':
5658
command = Robotiq3FGripperRobotOutput();
5759
command.rACT = 1
@@ -71,79 +73,78 @@ def genCommand(char, command):
7173

7274
if char == 'b':
7375
command.rMOD = 0
74-
76+
7577
if char == 'p':
7678
command.rMOD = 1
77-
79+
7880
if char == 'w':
7981
command.rMOD = 2
80-
82+
8183
if char == 's':
8284
command.rMOD = 3
8385

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:
8688
command.rPRA = int(char)
8789
if command.rPRA > 255:
8890
command.rPRA = 255
8991
if command.rPRA < 0:
9092
command.rPRA = 0
9193
except ValueError:
92-
pass
93-
94+
pass
95+
9496
if char == 'f':
9597
command.rSPA += 25
9698
if command.rSPA > 255:
9799
command.rSPA = 255
98-
100+
99101
if char == 'l':
100102
command.rSPA -= 25
101103
if command.rSPA < 0:
102104
command.rSPA = 0
103105

104-
105106
if char == 'i':
106107
command.rFRA += 25
107108
if command.rFRA > 255:
108109
command.rFRA = 255
109-
110+
110111
if char == 'd':
111112
command.rFRA -= 25
112113
if command.rFRA < 0:
113114
command.rFRA = 0
114115

115116
return command
116-
117+
117118

118119
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."""
120121

121-
currentCommand = 'Simple 3F gripper Controller\n-----\nCurrent command:'
122-
currentCommand += ' rACT = ' + str(command.rACT)
122+
currentCommand = 'Simple 3F gripper Controller\n-----\nCurrent command:'
123+
currentCommand += ' rACT = ' + str(command.rACT)
123124
currentCommand += ', rMOD = ' + str(command.rMOD)
124125
currentCommand += ', rGTO = ' + str(command.rGTO)
125126
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)
129130
currentCommand += ', rPRA = ' + str(command.rPRA)
130131
currentCommand += ', rSPA = ' + str(command.rSPA)
131132
currentCommand += ', rFRA = ' + str(command.rFRA)
132133

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)
143144

144145
print(currentCommand)
145146

146-
strAskForCommand = '-----\nAvailable commands\n\n'
147+
strAskForCommand = '-----\nAvailable commands\n\n'
147148
strAskForCommand += 'r: Reset\n'
148149
strAskForCommand += 'a: Activate\n'
149150
strAskForCommand += 'c: Close\n'
@@ -157,28 +158,28 @@ def askForCommand(command):
157158
strAskForCommand += 'l: Slower\n'
158159
strAskForCommand += 'i: Increase force\n'
159160
strAskForCommand += 'd: Decrease force\n'
160-
161+
161162
strAskForCommand += '-->'
162163

163164
return raw_input(strAskForCommand)
164165

166+
165167
def publisher():
166168
"""Main loop which requests new commands and publish them on the Robotiq3FGripperRobotOutput topic."""
167169

168170
rospy.init_node('Robotiq3FGripperSimpleController')
169-
171+
170172
pub = rospy.Publisher('Robotiq3FGripperRobotOutput', Robotiq3FGripperRobotOutput)
171173

172174
command = Robotiq3FGripperRobotOutput();
173175

174176
while not rospy.is_shutdown():
177+
command = genCommand(askForCommand(command), command)
175178

176-
command = genCommand(askForCommand(command), command)
177-
178179
pub.publish(command)
179180

180181
rospy.sleep(0.1)
181-
182+
182183

183184
if __name__ == '__main__':
184185
publisher()

0 commit comments

Comments
 (0)