Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 """@package docstring
00040 Command-line interface for sending simple commands to a ROS node controlling a S-Model gripper.
00041
00042 This serves as an example for publishing messages on the 'SModelRobotOutput' topic using the 'SModel_robot_output' msg type for sending commands to a S-Model 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).
00043 """
00044
00045 import roslib; roslib.load_manifest('robotiq_s_model_control')
00046 import rospy
00047 from robotiq_s_model_control.msg import _SModel_robot_output as outputMsg
00048 from time import sleep
00049
00050
00051 def genCommand(char, command):
00052 """Update the command according to the character entered by the user."""
00053
00054 if char == 'a':
00055 command = outputMsg.SModel_robot_output();
00056 command.rACT = 1
00057 command.rGTO = 1
00058 command.rSPA = 255
00059 command.rFRA = 150
00060
00061 if char == 'r':
00062 command = outputMsg.SModel_robot_output();
00063 command.rACT = 0
00064
00065 if char == 'c':
00066 command.rPRA = 255
00067
00068 if char == 'o':
00069 command.rPRA = 0
00070
00071 if char == 'b':
00072 command.rMOD = 0
00073
00074 if char == 'p':
00075 command.rMOD = 1
00076
00077 if char == 'w':
00078 command.rMOD = 2
00079
00080 if char == 's':
00081 command.rMOD = 3
00082
00083
00084 try:
00085 command.rPRA = int(char)
00086 if command.rPRA > 255:
00087 command.rPRA = 255
00088 if command.rPRA < 0:
00089 command.rPRA = 0
00090 except ValueError:
00091 pass
00092
00093 if char == 'f':
00094 command.rSPA += 25
00095 if command.rSPA > 255:
00096 command.rSPA = 255
00097
00098 if char == 'l':
00099 command.rSPA -= 25
00100 if command.rSPA < 0:
00101 command.rSPA = 0
00102
00103
00104 if char == 'i':
00105 command.rFRA += 25
00106 if command.rFRA > 255:
00107 command.rFRA = 255
00108
00109 if char == 'd':
00110 command.rFRA -= 25
00111 if command.rFRA < 0:
00112 command.rFRA = 0
00113
00114 return command
00115
00116
00117 def askForCommand(command):
00118 """Ask the user for a command to send to the gripper."""
00119
00120 currentCommand = 'Simple S-Model Controller\n-----\nCurrent command:'
00121 currentCommand += ' rACT = ' + str(command.rACT)
00122 currentCommand += ', rMOD = ' + str(command.rMOD)
00123 currentCommand += ', rGTO = ' + str(command.rGTO)
00124 currentCommand += ', rATR = ' + str(command.rATR)
00125
00126
00127
00128 currentCommand += ', rPRA = ' + str(command.rPRA)
00129 currentCommand += ', rSPA = ' + str(command.rSPA)
00130 currentCommand += ', rFRA = ' + str(command.rFRA)
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 print currentCommand
00144
00145 strAskForCommand = '-----\nAvailable commands\n\n'
00146 strAskForCommand += 'r: Reset\n'
00147 strAskForCommand += 'a: Activate\n'
00148 strAskForCommand += 'c: Close\n'
00149 strAskForCommand += 'o: Open\n'
00150 strAskForCommand += 'b: Basic mode\n'
00151 strAskForCommand += 'p: Pinch mode\n'
00152 strAskForCommand += 'w: Wide mode\n'
00153 strAskForCommand += 's: Scissor mode\n'
00154 strAskForCommand += '(0-255): Go to that position\n'
00155 strAskForCommand += 'f: Faster\n'
00156 strAskForCommand += 'l: Slower\n'
00157 strAskForCommand += 'i: Increase force\n'
00158 strAskForCommand += 'd: Decrease force\n'
00159
00160 strAskForCommand += '-->'
00161
00162 return raw_input(strAskForCommand)
00163
00164 def publisher():
00165 """Main loop which requests new commands and publish them on the SModelRobotOutput topic."""
00166
00167 rospy.init_node('SModelSimpleController')
00168
00169 pub = rospy.Publisher('SModelRobotOutput', outputMsg.SModel_robot_output)
00170
00171 command = outputMsg.SModel_robot_output();
00172
00173 while not rospy.is_shutdown():
00174
00175 command = genCommand(askForCommand(command), command)
00176
00177 pub.publish(command)
00178
00179 rospy.sleep(0.1)
00180
00181
00182 if __name__ == '__main__':
00183 publisher()