SModelTcpNode.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2012, Robotiq, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of Robotiq, Inc. nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 #
00035 # Copyright (c) 2012, Robotiq, Inc.
00036 # Revision $Id$
00037 
00038 """@package docstring
00039 ROS node for controling a Robotiq S-Model gripper using the Modbus TCP protocol.
00040 
00041 The script takes as an argument the IP address of the gripper. It initializes a baseSModel object and adds a comModbusTcp client to it. It then loops forever, reading the gripper status and updating its command. The gripper status is published on the 'SModelRobotInput' topic using the 'SModel_robot_input' msg type. The node subscribes to the 'SModelRobotOutput' topic for new commands using the 'SModel_robot_output' msg type. Examples are provided to control the gripper (SModelSimpleController.py) and interpreting its status (SModelStatusListener.py).
00042 """
00043 
00044 import roslib; roslib.load_manifest('robotiq_s_model_control')
00045 roslib.load_manifest('robotiq_modbus_tcp')
00046 import rospy
00047 import robotiq_s_model_control.baseSModel
00048 import robotiq_modbus_tcp.comModbusTcp
00049 import os, sys
00050 from robotiq_s_model_control.msg import _SModel_robot_input  as inputMsg
00051 from robotiq_s_model_control.msg import _SModel_robot_output as outputMsg
00052 
00053 def mainLoop(address):
00054     
00055     #Gripper is a S-Model with a TCP connection
00056     gripper = robotiq_s_model_control.baseSModel.robotiqBaseSModel()
00057     gripper.client = robotiq_modbus_tcp.comModbusTcp.communication()
00058 
00059     #We connect to the address received as an argument
00060     gripper.client.connectToDevice(address)
00061 
00062     rospy.init_node('robotiqSModel')
00063 
00064     #The Gripper status is published on the topic named 'SModelRobotInput'
00065     pub = rospy.Publisher('SModelRobotInput', inputMsg.SModel_robot_input)
00066 
00067     #The Gripper command is received from the topic named 'SModelRobotOutput'
00068     rospy.Subscriber('SModelRobotOutput', outputMsg.SModel_robot_output, gripper.refreshCommand)    
00069     
00070 
00071     #We loop
00072     while not rospy.is_shutdown():
00073 
00074       #Get and publish the Gripper status
00075       status = gripper.getStatus()
00076       pub.publish(status)     
00077 
00078       #Wait a little
00079       rospy.sleep(0.05)
00080 
00081       #Send the most recent command
00082       gripper.sendCommand()
00083 
00084       #Wait a little
00085       rospy.sleep(0.05)
00086             
00087 if __name__ == '__main__':
00088     try:
00089         #TODO: Add verification that the argument is an IP address
00090         mainLoop(sys.argv[1])
00091     except rospy.ROSInterruptException: pass


robotiq_s_model_control
Author(s): Nicolas Lauzier (Robotiq inc.)
autogenerated on Thu Aug 27 2015 14:44:26