How to setup a proper node that uses Services form other nodes
Hi i have been working on a node that has to use a service form ur_msgs
called set_io
i understand what parameters have to set in order for it to work because i can do that with the rosservice commands in my linux kernel and that worked.
But now i cannot seem to understand what i need in python code to make that exact same call run in a node.
setIO documentation
after a little bit of searching i found out that a service proxy has to be setup. What i have on code at the moment looks like this.
import time, socket, struct, math , sys, os
import rospy
from ur_msgs.srv import SetIO
rospy.init_node('relay_test')
rospy.wait_for_service('set_io')
rospy.ServiceProxy(set_io,SetIO')
req = set_io()
req.fun = 4
req.pin = 0
try:
#pseudo code because i do not know how to continue, the parameters for set_io are fun, pin and state, the state has to change from 24 to 0 and back every 10 seconds so i can see if the relay works.
req.state = 24
rospy.sleep(10.)
req.state = 0
rospy.sleep(10.)
except: rospy.ServiceException as exc:
Just making sure: have you seen (and completed) the Writing a Simple Service and Client (Python)? The UR driver is the server in your case. You'd write the client.
I have seen it, but did not understand it at the time i asked the question. I looked at it again and realized that i was not using the right structure.