io_interface.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import rospy
00005 from ur_msgs.srv import *
00006 from ur_msgs.msg import *
00007 
00008 FUN_SET_DIGITAL_OUT = 1
00009 FUN_SET_FLAG = 2
00010 FUN_SET_ANALOG_OUT = 3
00011 FUN_SET_TOOL_VOLTAGE = 4
00012 
00013 #Flag_States = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
00014 Digital_Out_States = [0,0,0,0,0,0,0,0,0,0]  #8(controller)+2(tool)
00015 Digital_In_States = [0,0,0,0,0,0,0,0,0,0]   #8(controller)+2(tool)
00016 Analog_Out_States = [0,0]  #2(controller)
00017 Analog_In_States = [0,0]   #2(controller)+0(tool)
00018 
00019 ANALOG_TOLERANCE_VALUE = 0.01
00020 
00021 def set_io_val(fun, pin, val):
00022     try:
00023         set_io(fun, pin, val)
00024     except rospy.ServiceException, e:
00025         print "Service call failed: %s"%e
00026 
00027 def set_tool_voltage(volts):
00028     try:
00029         set_io(FUN_SET_TOOL_VOLTAGE, volts, 0)
00030     except rospy.ServiceException, e:
00031         print "Service call failed: %s"%e
00032 
00033 def set_digital_out(pin, val):
00034     try:
00035         set_io(FUN_SET_DIGITAL_OUT, pin, val)
00036     except rospy.ServiceException, e:
00037         print "Service call failed: %s"%e
00038 
00039 def set_analog_out(pin, val):
00040     try:
00041         set_io(FUN_SET_ANALOG_OUT, pin, val)
00042     except rospy.ServiceException, e:
00043         print "Service call failed: %s"%e
00044 
00045 def set_flag(pin, val):
00046     rospy.logerr("SETTING FLAGS IS NOT SUPPORTED!")
00047     #try:
00048         #set_io(FUN_SET_FLAG, pin, val)
00049     #except rospy.ServiceException, e:
00050         #print "Service call failed: %s"%e
00051 
00052 def callback(data):
00053     rospy.logerr("Flag_States are currently not supported")
00054     #for i in range(0,32):
00055         #del Flag_States[i]
00056         #Flag_States.insert(i, data.flag_states[i].state)
00057     for i in range(0,10):
00058         del Digital_Out_States[i]
00059         Digital_Out_States.insert(i, data.digital_out_states[i].state)
00060     for i in range(0,10):
00061         del Digital_In_States[i]
00062         Digital_In_States.insert(i, data.digital_in_states[i].state)
00063     for i in range(0,2):
00064         del Analog_Out_States[i]
00065         Analog_Out_States.insert(i, data.analog_out_states[i].state)
00066     rospy.logerr("ToolInput analog_in[2] and analog_in[3] currently not supported")
00067     for i in range(0,2):
00068         del Analog_In_States[i]
00069         Analog_In_States.insert(i, data.analog_in_states[i].state)
00070 
00071 def get_states():
00072     rospy.init_node('UR_State_Getter')
00073     rospy.Subscriber("io_states", IOStates, callback)
00074     
00075 def set_states():
00076     rospy.wait_for_service('set_io')
00077     global set_io
00078     set_io = rospy.ServiceProxy('set_io', SetIO)
00079 


ur_driver
Author(s): Stuart Glaser, Shaun Edwards , Felix Messmer
autogenerated on Fri Aug 28 2015 13:31:30