File: irobot_create_client.py

package info (click to toggle)
robotraconteur 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,380 kB
  • sloc: cpp: 1,149,268; cs: 87,653; java: 58,127; python: 26,897; ansic: 356; sh: 152; makefile: 90; xml: 51
file content (64 lines) | stat: -rw-r--r-- 1,400 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Example iRobot Create client in Python

from RobotRaconteur.Client import *
import time
import numpy
import sys

# Function to call when "Bump" event occurs


def bumped():
    print("Bump!!")


def main():

    url = 'rr+tcp://localhost:22354?service=create'
    if (len(sys.argv) >= 2):
        url = sys.argv[1]

    # Connect to the service
    c = RRN.ConnectService(url)

    # Add a function handler for the "Bump" event
    c.bump += bumped

    # Demonstrate peeking a wire value
    state_val, _ = c.create_state.PeekInValue()
    print(state_val)

    # Connect a WireConnection to the "packets" wire
    wire = c.create_state.Connect()

    # Add a callback function for when the wire value changes
    wire.WireValueChanged += wire_changed

    # Set the play_callback function for this client
    c.claim_play_callback()
    c.play_callback.Function = play_callback

    # Drive a bit
    c.drive(0.1, 1)
    time.sleep(5)
    c.drive(0, 1)
    time.sleep(10)


# Function to call when the wire value changes
def wire_changed(w, value, time):

    val = w.InValue
    # Print the new value to the console.  Comment out this line
    # to see the other output more clearly
    print(val)

# Callback for when the play button is pressed on the Create


def play_callback(dist, angle):
    return numpy.array([69, 16, 60, 16, 69, 16], dtype='u1')


if __name__ == '__main__':
    main()