yarp-devices
Loading...
Searching...
No Matches
exampleRemoteJr3.py
1
4
5
6
7import time
8import yarp
9
10yarp.Network.init()
11
12if not yarp.Network.checkNetwork():
13 print('[error] Please try running yarp server')
14 quit()
15
16options = yarp.Property()
17options.put('device', 'multipleanalogsensorsclient')
18options.put('remote', '/jr3')
19options.put('local', '/exampleRemoteJr3')
20
21device = yarp.PolyDriver(options)
22
23if not device.isValid():
24 print('Device not available')
25 quit()
26
27sensor = device.viewISixAxisForceTorqueSensors()
28
29channels = sensor.getNrOfSixAxisForceTorqueSensors()
30print('Channels:', channels)
31
32for ch in range(channels):
33 name = sensor.getSixAxisForceTorqueSensorName(ch)
34 print('Channel %d has name: %s' % (ch, name))
35
36status = -1
37retry = 0
38MAX_RETRIES = 10
39
40while status != yarp.MAS_OK:
41 status = yarp.MAS_OK # = 0
42
43 for ch in range(channels):
44 status += sensor.getSixAxisForceTorqueSensorStatus(ch)
45
46 retry += 1
47 print('Waiting for sensor to be ready... retry', retry)
48
49 if retry == MAX_RETRIES:
50 print('[error] Sensor initialization failure, max number of retries exceeded')
51 quit()
52
53 time.sleep(0.1)
54
55n = 0
56MAX_ITERS = 500
57
58print('Performing %d read iterations' % MAX_ITERS)
59
60out = yarp.Vector()
61
62while n < MAX_ITERS:
63 n += 1
64
65 for ch in range(channels):
66 timestamp = sensor.getSixAxisForceTorqueSensorMeasure(ch, out)
67 print("[%d] [%f] Channel %d: %s" % (n, timestamp, ch, out.toString()));
68
69 time.sleep(0.01)
70
71print('Done')