iCub-main
Loading...
Searching...
No Matches
python-motor-control.py
Go to the documentation of this file.
1/**
2 * @ingroup icub_tutorials
3 *
4 * \defgroup icub_python_motor_interfaces Using motor interfaces with Python
5 *
6 * Shows how to control the robot using motor interfaces within Python.
7 *
8 * \author Lorenzo Natale
9 *
10 * CopyPolicy: Released under the terms of GPL 2.0 or later
11 */
12
13import yarp;
14yarp.Network.init();
15
16# prepare a property object
17props = yarp.Property()
18props.put("device","remote_controlboard")
19props.put("local","/client/right_arm")
20props.put("remote","/icubSim/right_arm")
21
22# create remote driver
23armDriver = yarp.PolyDriver(props)
24
25#query motor control interfaces
26iPos = armDriver.viewIPositionControl()
27iVel = armDriver.viewIVelocityControl()
28iEnc = armDriver.viewIEncoders()
29
30#retrieve number of joints
31jnts=iPos.getAxes()
32
33print 'Controlling', jnts, 'joints'
34
35# read encoders
36encs=yarp.Vector(jnts)
37iEnc.getEncoders(encs.data())
38
39
40home=yarp.Vector(jnts, encs.data())
41
42#initialize a new tmp vector identical to encs
43tmp=yarp.Vector(jnts)
44
45
46tmp.set(0, tmp.get(0)+10)
47tmp.set(1, tmp.get(1)+10)
48tmp.set(2, tmp.get(2)+10)
49tmp.set(3, tmp.get(3)+10)
50
51iPos.positionMove(tmp.data())
52
53
54iPos.positionMove(encs.data())