1
36
37
38
39import yarp
40yarp.Network.init()
41if not yarp.Network.checkNetwork():
42 print('[error] Please try running yarp server')
43 quit()
44options = yarp.Property()
45options.put('device','remote_controlboard')
46options.put('remote','/robotName/partName')
47options.put('local','/exampleRemoteControlBoard')
48dd = yarp.PolyDriver(options)
49if not dd.isValid():
50 print('[error] Please launch robot side')
51 quit()
52
53pos = dd.viewIPositionControl()
54vel = dd.viewIVelocityControl()
55posd = dd.viewIPositionDirect()
56enc = dd.viewIEncoders()
57mode = dd.viewIControlMode()
58ll = dd.viewIControlLimits()
59
60axes = enc.getAxes()
61
62lmin = yarp.DVector(1)
63lmax = yarp.DVector(1)
64ll.getLimits(0,lmin,lmax)
65print('lmin',lmin[0],'lmax',lmax[0])
66
67
68mode.setControlModes(yarp.IVector(axes, yarp.encode('pos')))
69
70print('positionMove(1,-35) -> moves motor 1 (start count at motor 0) to -35 degrees')
71pos.positionMove(1,-35)
72
73done = False
74while not done:
75 print('wait to reach...')
76 yarp.delay(1.0)
77 done = pos.checkMotionDone()
78
79v = yarp.DVector(axes)
80enc.getEncoders(v)
81print('v[1] is: ' + str(v[1]))
82
83targets = list(range(0,10+5*axes,5))
84print('positionMove(...) -> [multiple axes] moves motor 0 to 10 degrees, motor 1 to 15 degrees and so on')
85pos.positionMove(yarp.DVector(targets))
86
87done = False
88while not done:
89 print('wait to reach...')
90 yarp.delay(1.0)
91 done = pos.checkMotionDone()
92
93
94mode.setControlModes(yarp.IVector(axes, yarp.encode('vel')))
95
96print('velocityMove(0,10) -> moves motor 0 (start count at motor 0) at 10 degrees per second')
97vel.velocityMove(0,10)
98
99print('delay(5)')
100yarp.delay(5)
101
102vel.velocityMove(0,0)
103
104mode.setControlModes(yarp.IVector(axes, yarp.encode('posd')))
105home = [0] * axes
106print('positionMove(home) -> [multiple axes] moves all to 0 immediately')
107posd.setPositions(yarp.DVector(home))
108
109dd.close()
110
111yarp.Network.fini()