def getInitializationSection(rosNode): """ Generates statements which initialize ROS publishers and subscribers. """ global gSubscribeInit global gPublisherInit linesBuffer = [] subscribeTopics = a3t.filterInEntities(rosNode, "ROSSubscribe") publishTopics = a3t.filterOutEntities(rosNode, "ROSPublish") pushBuf() for topic in subscribeTopics: name = nameOf(topic) ttype = rosType(getType(topic)) tcallback = makeCallbackName(name) write(gSubscribeInit.format(topicName=name, topicType=ttype, topicCallback=tcallback)) for topic in publishTopics: name = nameOf(topic) ttype = rosType(getType(topic)) outputName = nameOf(getOutput(topic)) write( gPublisherInit.format( topicName=name, topicType=ttype, outputName=outputName, callback = makePublishActionName(name) ) ) return flush(2)
def getCallbackSection(rosNode): """ Returns textblob with generated callbacks and publish actions. """ global gTwistCallbackTemplate subscribed = a3t.filterInEntities(rosNode, "ROSSubscribe") publishers = a3t.filterOutEntities(rosNode, "ROSPublish") blob = "" blob += "## ============ GENERATED SUBSCRIPTION CALLBACKS ==================\n\n" for topic in subscribed: blob += getCallback(topic) blob += "## ================= GENERATED PUBLISH ACTIONS ==================\n\n" for topic in publishers: blob += getPublishAction(topic) return blob