4242This serves as an example for publishing messages on the 'Robotiq3FGripperRobotOutput' topic using the 'Robotiq3FGripper_robot_output' msg type for sending commands to a 3F gripper gripper. In this example, only the simple control mode is implemented. For using the advanced control mode, please refer to the Robotiq support website (support.robotiq.com). 
4343""" 
4444
45- import  roslib ; roslib .load_manifest ('robotiq_3f_gripper_control' )
45+ from  __future__ import  print_function 
46+ 
47+ import  roslib ;
48+ 
49+ roslib .load_manifest ('robotiq_3f_gripper_control' )
4650import  rospy 
47- from  robotiq_3f_gripper_control .msg  import  _Robotiq3FGripper_robot_output   as  outputMsg 
48- from  time  import  sleep 
51+ from  robotiq_3f_gripper_articulated_msgs .msg  import  Robotiq3FGripperRobotOutput 
4952
5053
5154def  genCommand (char , command ):
52-     """Update the command according to the character entered by the user."""      
53-          
55+     """Update the command according to the character entered by the user.""" 
56+ 
5457    if  char  ==  'a' :
55-         command  =  outputMsg . Robotiq3FGripper_robot_output ();
58+         command  =  Robotiq3FGripperRobotOutput ();
5659        command .rACT  =  1 
5760        command .rGTO  =  1 
5861        command .rSPA  =  255 
5962        command .rFRA  =  150 
6063
6164    if  char  ==  'r' :
62-         command  =  outputMsg . Robotiq3FGripper_robot_output ();
65+         command  =  Robotiq3FGripperRobotOutput ();
6366        command .rACT  =  0 
6467
6568    if  char  ==  'c' :
@@ -70,79 +73,78 @@ def genCommand(char, command):
7073
7174    if  char  ==  'b' :
7275        command .rMOD  =  0 
73-          
76+ 
7477    if  char  ==  'p' :
7578        command .rMOD  =  1 
76-          
79+ 
7780    if  char  ==  'w' :
7881        command .rMOD  =  2 
79-          
82+ 
8083    if  char  ==  's' :
8184        command .rMOD  =  3 
8285
83-     #If the command entered is a int, assign this value to rPRA 
84-     try :  
86+     #  If the command entered is a int, assign this value to rPRA 
87+     try :
8588        command .rPRA  =  int (char )
8689        if  command .rPRA  >  255 :
8790            command .rPRA  =  255 
8891        if  command .rPRA  <  0 :
8992            command .rPRA  =  0 
9093    except  ValueError :
91-         pass                      
92-          
94+         pass 
95+ 
9396    if  char  ==  'f' :
9497        command .rSPA  +=  25 
9598        if  command .rSPA  >  255 :
9699            command .rSPA  =  255 
97-              
100+ 
98101    if  char  ==  'l' :
99102        command .rSPA  -=  25 
100103        if  command .rSPA  <  0 :
101104            command .rSPA  =  0 
102105
103-             
104106    if  char  ==  'i' :
105107        command .rFRA  +=  25 
106108        if  command .rFRA  >  255 :
107109            command .rFRA  =  255 
108-              
110+ 
109111    if  char  ==  'd' :
110112        command .rFRA  -=  25 
111113        if  command .rFRA  <  0 :
112114            command .rFRA  =  0 
113115
114116    return  command 
115-          
117+ 
116118
117119def  askForCommand (command ):
118-     """Ask the user for a command to send to the gripper."""      
120+     """Ask the user for a command to send to the gripper.""" 
119121
120-     currentCommand    =  'Simple 3F gripper Controller\n -----\n Current command:' 
121-     currentCommand  +=  ' rACT = '    +  str (command .rACT )
122+     currentCommand  =  'Simple 3F gripper Controller\n -----\n Current command:' 
123+     currentCommand  +=  ' rACT = '  +  str (command .rACT )
122124    currentCommand  +=  ', rMOD = '  +  str (command .rMOD )
123125    currentCommand  +=  ', rGTO = '  +  str (command .rGTO )
124126    currentCommand  +=  ', rATR = '  +  str (command .rATR )
125- ##    currentCommand += ', rGLV = ' + str(command.rGLV) 
126- ##    currentCommand += ', rICF = ' + str(command.rICF) 
127- ##    currentCommand += ', rICS = ' + str(command.rICS) 
127+      ##    currentCommand += ', rGLV = ' + str(command.rGLV) 
128+      ##    currentCommand += ', rICF = ' + str(command.rICF) 
129+      ##    currentCommand += ', rICS = ' + str(command.rICS) 
128130    currentCommand  +=  ', rPRA = '  +  str (command .rPRA )
129131    currentCommand  +=  ', rSPA = '  +  str (command .rSPA )
130132    currentCommand  +=  ', rFRA = '  +  str (command .rFRA )
131133
132-     #We only show the simple control mode 
133- ##    currentCommand += ', rPRB = ' + str(command.rPRB) 
134- ##    currentCommand += ', rSPB = ' + str(command.rSPB) 
135- ##    currentCommand += ', rFRB = ' + str(command.rFRB) 
136- ##    currentCommand += ', rPRC = ' + str(command.rPRC) 
137- ##    currentCommand += ', rSPC = ' + str(command.rSPC) 
138- ##    currentCommand += ', rFRC = ' + str(command.rFRC) 
139- ##    currentCommand += ', rPRS = ' + str(command.rPRS) 
140- ##    currentCommand += ', rSPS = ' + str(command.rSPS) 
141- ##    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) 
142144
143-     print   currentCommand 
145+     print ( currentCommand ) 
144146
145-     strAskForCommand    =  '-----\n Available commands\n \n ' 
147+     strAskForCommand  =  '-----\n Available commands\n \n ' 
146148    strAskForCommand  +=  'r: Reset\n ' 
147149    strAskForCommand  +=  'a: Activate\n ' 
148150    strAskForCommand  +=  'c: Close\n ' 
@@ -156,28 +158,28 @@ def askForCommand(command):
156158    strAskForCommand  +=  'l: Slower\n ' 
157159    strAskForCommand  +=  'i: Increase force\n ' 
158160    strAskForCommand  +=  'd: Decrease force\n ' 
159-      
161+ 
160162    strAskForCommand  +=  '-->' 
161163
162164    return  raw_input (strAskForCommand )
163165
166+ 
164167def  publisher ():
165168    """Main loop which requests new commands and publish them on the Robotiq3FGripperRobotOutput topic.""" 
166169
167170    rospy .init_node ('Robotiq3FGripperSimpleController' )
168-     
169-     pub  =  rospy .Publisher ('Robotiq3FGripperRobotOutput' , outputMsg .Robotiq3FGripper_robot_output )
170171
171-     command  =  outputMsg .Robotiq3FGripper_robot_output ();
172+     pub  =  rospy .Publisher ('Robotiq3FGripperRobotOutput' , Robotiq3FGripperRobotOutput )
173+ 
174+     command  =  Robotiq3FGripperRobotOutput ();
172175
173176    while  not  rospy .is_shutdown ():
177+         command  =  genCommand (askForCommand (command ), command )
174178
175-         command  =  genCommand (askForCommand (command ), command )            
176-         
177179        pub .publish (command )
178180
179181        rospy .sleep (0.1 )
180-                          
182+ 
181183
182184if  __name__  ==  '__main__' :
183185    publisher ()
0 commit comments