iCub-main
|
This tutorial shows how to get interfaces to control the arm.
Motor control in YARP is done through a motor control device.
The code in this tutorial is a good example to start playing with motor control. This example uses a remoted device driver which exports exactly the same interfaces of the actual device driver (only initialization is different). The main difference between the two is in terms of efficiency, if you're developing a low-level control loop you might want to be local, on the other hand a simple sporadic position control can be effected through the remote device driver. Let's assume we have started the server side already (e.g. the simulator).
Let us assume the simulator is up and running.
In practice, we start by preparing a set of configuration parameters:
where the ''local'' and ''remote'' parameters are used to set the port names for the connection to the server side. In our example this means that the process will create the following (local) ports:
And will automatically connect them to the server, on the following (remote) ports (we assume here that the server created those ports correctly):
To create the driver we use the PolyDriver:
which instantiates the driver. If the parameters are correct and the server side has been prepared the local driver also connects to the remote one. The next step is to get a set of interfaces (pointers to) to work with, for example:
and:
if everything went ok the pointers are valid pointers (check it!). For example:
We can thus start with checking how many axes we can control by doing:
Let's create some vectors for later use:
Let's now initialize the controllers and start up the amplifiers:
if needed we can check the position of our axes by doing:
which reads the values of the motor encoders into a vector of doubles of size ''jnts''.
Important: check the return value of this function to ensure that communication with the robot is sane and that the function can return updated values.
First do:
which sets the reference speed for all axes to 40 degrees per second. The reference speed is used to interpolate the trajectory between the current and the desired position.
Now you can do:
where ''command_position'' is the desired position. This starts a movement of all axes toward the desired position.
To send velocity commands do:
which accelerates all axes to the velocity described by the vector ''command_velocity'' (in degrees per second).
When you are done with controlling the robot don't forget to close the device:
To read more about the interfaces that are available in YARP read the online documentation: http://eris.liralab.it/yarpdoc/namespaceyarp_1_1dev.html
See code in: src/motorControlBasic/tutorial_arm.cpp