Menu

#75 Java->swig->yarp->iCubSimulator

v1.0 (example)
closed-out-of-date
None
5
2017-11-02
2010-12-02
Klaus
No

Greetings!
Iḿ not sure if this is the right tracker to place this question, but here it goes. :)

I have yarp working with java thanks to swig here. But I would like to control my iCub simulator robot with it.
I couldn't find any tutorial regarding that, is it possible?

Thanks in advance!

Klaus

Discussion

  • Paul Fitzpatrick

    Yes, it is possible. Looks like it hasn't gotten written down anywhere though (other than in people's code). I'll prepare a tutorial. In the meantime, I added an example that should get you started in $YARP_ROOT/example/swig/src/Example4.java, copied here:

    import yarp.Network;
    import yarp.Time;
    import yarp.Property;
    import yarp.PolyDriver;
    import yarp.IPositionControl;
    import yarp.IEncoders;
    import yarp.DVector;

    class Example4 {

    public static void main(String[] args) {
    System.loadLibrary("jyarp");
    Network yarp = new Network();

    // set up a description of the device we want
    // in this case, a remote motor control board
    Property prop = new Property();
    prop.put("device","remote_controlboard");
    prop.put("local", "/example/motor/client");
    prop.put("remote", "/icubSim/head"); // this is for the icubSim
    // or fake it with "yarpdev --device test_motor --name /icubSim/head"
    System.out.println("Property is " + prop);

    // create the device
    PolyDriver dev = new PolyDriver(prop);

    // get the "IPositionControl" interface
    IPositionControl pos = dev.viewIPositionControl();
    IEncoders enc = dev.viewIEncoders();

    float at = 0;
    DVector v = new DVector(enc.getAxes());
    for (int i=0; i<10; i++) {
    pos.positionMove(0,at);
    System.out.println("Set axis 0 to " + at + " degrees");
    Time.delay(1);
    enc.getEncoders(v);
    System.out.println("Encoder at " + v.get(0));
    at += 5;
    }

    // shut things down
    dev.close();
    }
    }

     
  • Paul Fitzpatrick

    • assigned_to: nobody --> eshuy
     
  • Klaus

    Klaus - 2010-12-15

    You saved my life. :) Its working perfectly.
    Thanks!

     
  • Klaus

    Klaus - 2011-02-01
    • status: open --> open-accepted
     
  • Daniele E. Domenichelli

    • status: open-accepted --> closed-out-of-date
    • Group: --> v1.0 (example)