Skip to content

Instantly share code, notes, and snippets.

@liborw
Last active December 15, 2015 18:08
Show Gist options
  • Select an option

  • Save liborw/5301003 to your computer and use it in GitHub Desktop.

Select an option

Save liborw/5301003 to your computer and use it in GitHub Desktop.
[clopema] IO Pulse
#!/usr/bin/env python
"""
io_pulse.py
Libor Wagner on April 3, 2013
"""
# Constants
NODE_NAME = "io_pulse"
NODE_PACKAGE = "clopema_utilities"
# Defalue ROS imports
import roslib; roslib.load_manifest(NODE_PACKAGE)
import rospy
import sys
# Import message types
from clopema_motoros.srv import WriteIO, IOPulse, IOPulseResponse
# The IO Pulse class
class IOPulseNode(object):
def __init__(self):
# Get parameter
self._write_io_srv = rospy.get_param('~write_io_srv', 'write_io')
# Regirster service proxy
self._write_io = rospy.ServiceProxy(self._write_io_srv, WriteIO)
# Advertise service
self._io_pulse = rospy.Service('~io_pulse', IOPulse, self.__handle_io_pulse)
def __handle_io_pulse(self, req):
self._write_io(req.address, req.value)
rospy.sleep(req.length)
self._write_io(req.address, not req.value)
return IOPulseResponse()
def usage(argv):
import os
print "usage: ", os.path.basename(argv[0]), "[-h] [PARAMS]"
print
print "OPTIONS"
print " -h Show this message"
print
print "PARAMS"
print " _write_io_srv IO Interface service name"
if __name__ == '__main__':
rospy.init_node(NODE_NAME)
argv = rospy.myargv(argv=sys.argv)
if '-h' in argv: usage(argv)
io_pulse = IOPulse()
rospy.spin()
int32 address
bool value
float32 length
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment