iCub-main
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 
13 import yarp;
14 yarp.Network.init();
15 
16 # prepare a property object
17 props = yarp.Property()
18 props.put("device","remote_controlboard")
19 props.put("local","/client/right_arm")
20 props.put("remote","/icubSim/right_arm")
21 
22 # create remote driver
23 armDriver = yarp.PolyDriver(props)
24 
25 #query motor control interfaces
26 iPos = armDriver.viewIPositionControl()
27 iVel = armDriver.viewIVelocityControl()
28 iEnc = armDriver.viewIEncoders()
29 
30 #retrieve number of joints
31 jnts=iPos.getAxes()
32 
33 print 'Controlling', jnts, 'joints'
34 
35 # read encoders
36 encs=yarp.Vector(jnts)
37 iEnc.getEncoders(encs.data())
38 
39 
40 home=yarp.Vector(jnts, encs.data())
41 
42 #initialize a new tmp vector identical to encs
43 tmp=yarp.Vector(jnts)
44 
45 
46 tmp.set(0, tmp.get(0)+10)
47 tmp.set(1, tmp.get(1)+10)
48 tmp.set(2, tmp.get(2)+10)
49 tmp.set(3, tmp.get(3)+10)
50 
51 iPos.positionMove(tmp.data())
52 
53 
54 iPos.positionMove(encs.data())