示例#1
0
# Creates an Enable Service
enable_service = node.createService("~enable", SetBool, serviceCallback)

# Remote Service
remote_name = "ping" if "pong" in node.getName() else "pong"
remote_enable_service = node.getServiceProxy(remote_name + "/enable", SetBool)

# start
start_time = 0.0
start_offset = 0.0 if "ping" in node.getName() else math.pi

# Main Loop
while node.isActive():

    # Generates new Float message
    value = Float32()
    value.data = math.sin(node.getElapsedTimeInSecs() * 2 * math.pi * 0.2 -
                          start_offset)

    # Publish if enabled
    if enabled:
        Logger.warning("{} -> {}".format(node.getName(), value.data))
        output_publisher.publish(value)
        if value.data < 0:
            remote_enable_service(True)
            enabled = False
    else:
        output_publisher.publish(Float32(0.0))

    node.tick()
示例#2
0

for t, msg_type in topic_map.iteritems():
    topic = str(t)
    container_map[topic] = {'value': None}
    data_map[topic] = []

    callback_map[topic] = CallbackManager.createACallback(topic)
    node.createSubscriber(topic, msg_type, callback_map[topic])

for tf in tf_list:
    datatf_map[tf] = []

print("Started")
while node.isActive():
    if node.getElapsedTimeInSecs() >= node.getParameter("time_window"):
        print("Time Window")
        break
    try:
        found = True
        tf_frames = {}
        for tf in tf_list:
            tf_frame = node.retrieveTransform(
                tf, tf_base, -1)
            if tf_frame != None:
                tf_frames[tf] = tf_frame
            else:
                found = False
                break

        if found:
示例#3
0
#⬢⬢⬢⬢⬢➤ NODE
node = RosNode("ui_slave_example")
node.setHz(2)

flag1 = True

# Receive Data From Ui


def eventCallback(evt):
    global flag1
    print("*** New Event Received ***")
    print(evt)

    if evt.name == "flag1":
        flag1 = evt.value > 0


ui_proxy = UiProxy()

ui_proxy.registerApplicationCallback(eventCallback)

while node.isActive():
    s = 100 * math.sin(node.getElapsedTimeInSecs() * 1)

    if flag1:
        # Send data to UI
        ui_proxy.sendDataToUi("label", s)

    node.tick()