Motor control

From Wiki for iCub and Friends
Revision as of 19:10, 25 July 2006 by (talk) (Motor control in Yarp, a brief tutorial)
Jump to: navigation, search

Motor control in Yarp, a brief tutorial

Motor control in Yarp is done through a device driver. For more documentation please see: Yarp on SF and the related classes. The project on the iCub repository under src/simple_headcontrol 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 (initialization is different). Clearly, 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. using yarpdev).

In practice, we start by preparing a set of configuration parameters:

 Property options;
 options.put("robot", "icub"); // typically from the command line.
 options.put("device", "remote_controlboard");
 Value& robotname = options.find("robot");
 yarp::String s("/");
 s += robotname.asString();
 s += "/head/control";
 options.put("local", s.c_str());
 s += "/";
 s += robotname.asString();
 s += "/head";
 options.put("remote", s.c_str());

where the local and remote parameters are used to set the port names for the connection to the server side. To create the driver we use the PolyDriver:

 PolyDriver dd(options);
 if (!dd.isValid()) {
     ACE_OS::printf("Device not available.  Here are the known devices:\n");
     ACE_OS::printf("%s", Drivers::factory().toString().c_str());
     return 1;

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:

   IPositionControl *pos;
   IVelocityControl *vel;
   IEncoders *enc;
   IPidControl *pid;
   IAmplifierControl *amp;
   IControlLimits *lim;



if everything went ok the pointers are now different from NULL (check it!). We can thus start with checking how many axes we can control by doing:

   int jnts = 0;

and then starting up the controller and the amplifier:

   int i;
   for (i = 0; i < jnts; i++) {
       tmp[i] = 50.0;
   for (i = 0; i < jnts; i++) {