Search in sources :

Example 16 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class DeviceManager method addConnection.

public static void addConnection(BowlerAbstractConnection connection) {
    if (connection == null) {
        return;
    }
    GenericDevice gen = new GenericDevice(connection);
    try {
        if (!gen.connect()) {
            throw new InvalidConnectionException("Connection is invalid");
        }
        if (!gen.ping(true)) {
            throw new InvalidConnectionException("Communication failed");
        }
    } catch (Exception e) {
        // connection.disconnect();
        ThreadUtil.wait(1000);
        BowlerDatagram.setUseBowlerV4(false);
        if (!gen.connect()) {
            throw new InvalidConnectionException("Connection is invalid");
        }
        if (!gen.ping()) {
            connection = null;
            throw new InvalidConnectionException("Communication failed");
        }
        throw new RuntimeException(e);
    }
    if (gen.hasNamespace("neuronrobotics.dyio.*")) {
        DyIO dyio = new DyIO(gen.getConnection());
        dyio.connect();
        String name = "dyio";
        addConnection(dyio, name);
    } else if (gen.hasNamespace("bcs.cartesian.*")) {
        BowlerBoardDevice delt = new BowlerBoardDevice();
        delt.setConnection(gen.getConnection());
        delt.connect();
        String name = "bowlerBoard";
        addConnection(delt, name);
        addConnection(new NRPrinter(delt), "cnc");
    } else if (gen.hasNamespace("bcs.pid.*")) {
        GenericPIDDevice delt = new GenericPIDDevice();
        delt.setConnection(gen.getConnection());
        delt.connect();
        String name = "pid";
        addConnection(delt, name);
    } else if (gen.hasNamespace("bcs.bootloader.*") || gen.hasNamespace("neuronrobotics.bootloader.*")) {
        NRBootLoader delt = new NRBootLoader(gen.getConnection());
        String name = "bootloader";
        addConnection(delt, name);
    } else if (gen.hasNamespace("neuronrobotics.bowlercam.*")) {
        BowlerCamDevice delt = new BowlerCamDevice();
        delt.setConnection(gen.getConnection());
        delt.connect();
        String name = "bowlercam";
        addConnection(delt, name);
    } else {
        addConnection(gen, "device");
    }
}
Also used : BowlerCamDevice(com.neuronrobotics.sdk.bowlercam.device.BowlerCamDevice) GenericDevice(com.neuronrobotics.sdk.genericdevice.GenericDevice) BowlerBoardDevice(com.neuronrobotics.replicator.driver.BowlerBoardDevice) NRBootLoader(com.neuronrobotics.sdk.bootloader.NRBootLoader) NRPrinter(com.neuronrobotics.replicator.driver.NRPrinter) GenericPIDDevice(com.neuronrobotics.sdk.pid.GenericPIDDevice) DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Example 17 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class SchedulerTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        DyIO dyio = new DyIO(ConnectionDialog.promptConnection());
        dyio.connect();
        CoreScheduler cs = new CoreScheduler(dyio, new File("SparkParty.xml"));
        cs.play();
        while (cs.isPlaying()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        System.exit(0);
    }
}
Also used : DyIO(com.neuronrobotics.sdk.dyio.DyIO) CoreScheduler(com.neuronrobotics.sdk.dyio.sequencer.CoreScheduler) File(java.io.File)

Example 18 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class SpeedTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DyIO.disableFWCheck();
    ByteList.setUseStaticBuffer(true);
    // BowlerAbstractConnection c =  new SerialConnection("/dev/DyIO0")
    // BowlerAbstractConnection c =  new SerialConnection("COM65")
    BowlerAbstractConnection c = ConnectionDialog.promptConnection();
    c.setThreadedUpstreamPackets(false);
    if (c == null)
        System.exit(1);
    System.out.println("Starting test");
    DyIO dyio = new DyIO(c);
    // dyio.setThreadedUpstreamPackets(false);
    long start = System.currentTimeMillis();
    dyio.connect();
    dyio.setServoPowerSafeMode(false);
    System.out.println("Startup time: " + (System.currentTimeMillis() - start) + " ms");
    // dyio.enableDebug();
    dyio.setServoPowerSafeMode(false);
    for (int i = 0; i < 24; i++) {
        dyio.getChannel(i).setAsync(false);
    }
    DigitalInputChannel dip = new DigitalInputChannel(dyio.getChannel(0));
    ServoChannel dop = new ServoChannel(dyio.getChannel(1));
    // new PPMReaderChannel(dyio.getChannel(23));
    // new ServoChannel(dyio.getChannel(11));
    double avg = 0;
    int i;
    avg = 0;
    start = System.currentTimeMillis();
    double best = 1000;
    double worst = 0;
    for (i = 0; i < 500; i++) {
        dyio.ping();
        double ms = System.currentTimeMillis() - start;
        avg += ms;
        start = System.currentTimeMillis();
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
    }
    System.out.println("Average cycle time for ping: " + (avg / i) + " ms" + " best=" + best / 2 + "ms worst=" + worst / 2);
    boolean high = false;
    // dyio.setCachedMode(true);
    avg = 0;
    best = 1000;
    worst = 0;
    double numLoops = 500.0;
    for (i = 0; i < numLoops; i++) {
        start = System.currentTimeMillis();
        try {
            dip.getValue();
            dop.SetPosition((int) ((((double) i) / numLoops) * 255.0));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        double ms = System.currentTimeMillis() - start;
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
        avg += ms;
        start = System.currentTimeMillis();
    // System.out.println("Average cycle time: "+(int)(avg/i)/2+"ms\t\t\t this loop was: "+ms/2+"\t\tindex="+i);
    }
    dop.SetPosition(128);
    System.out.println("Average cycle time for IO : " + (avg / (i + 1)) / 2 + " ms best=" + best / 2 + "ms worst=" + worst / 2);
    avg = 0;
    best = 1000;
    worst = 0;
    dyio.setCachedMode(true);
    // Log.enableDebugPrint(true);
    for (i = 0; i < 500; i++) {
        start = System.currentTimeMillis();
        dyio.flushCache(0);
        double ms = System.currentTimeMillis() - start;
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
        avg += ms;
        start = System.currentTimeMillis();
    // System.out.println("Average cycle time: "+(int)(avg/i)+"ms\t\t\t this loop was: "+ms);
    }
    System.out.println("Average cycle time for cache flush: " + (avg / (i + 1)) + " ms best=" + best + "ms worst=" + worst);
    avg = 0;
    best = 1000;
    worst = 0;
    dyio.setCachedMode(true);
    // Log.enableDebugPrint(true);
    for (i = 0; i < 500; i++) {
        start = System.currentTimeMillis();
        dyio.getAllChannelValues();
        double ms = System.currentTimeMillis() - start;
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
        avg += ms;
        start = System.currentTimeMillis();
    // System.out.println("Average cycle time: "+(int)(avg/i)+"ms\t\t\t this loop was: "+ms);
    }
    System.out.println("Average cycle time for values get: " + (avg / (i + 1)) + " ms best=" + best + "ms worst=" + worst);
    dyio.setServoPowerSafeMode(true);
    System.exit(0);
}
Also used : DigitalInputChannel(com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel) ServoChannel(com.neuronrobotics.sdk.dyio.peripherals.ServoChannel) BowlerAbstractConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection) DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Example 19 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class ConnectionDialogTest method main.

public static void main(String[] args) {
    System.out.println("Starting");
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.err.println("Dialog failed");
        System.exit(1);
    }
    Log.enableDebugPrint();
    dyio.ping();
    dyio.disconnect();
    System.out.println("Connection OK!");
    System.exit(0);
// while(true);
}
Also used : DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Example 20 with DyIO

use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.

the class CounterInputTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.exit(1);
    }
    // Instantiate a new counter input
    CounterInputChannel enc = new CounterInputChannel(dyio.getChannel(23));
    // To reset the value of the encoder, simply set the channel value
    enc.setValue(0);
    while (true) {
        System.out.println(enc.getValue());
    }
}
Also used : CounterInputChannel(com.neuronrobotics.sdk.dyio.peripherals.CounterInputChannel) DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Aggregations

DyIO (com.neuronrobotics.sdk.dyio.DyIO)25 ServoChannel (com.neuronrobotics.sdk.dyio.peripherals.ServoChannel)5 AnalogInputChannel (com.neuronrobotics.sdk.dyio.peripherals.AnalogInputChannel)3 CounterOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.CounterOutputChannel)3 DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)3 ByteList (com.neuronrobotics.sdk.common.ByteList)2 DyIOChannelMode (com.neuronrobotics.sdk.dyio.DyIOChannelMode)2 BowlerBoardDevice (com.neuronrobotics.replicator.driver.BowlerBoardDevice)1 NRPrinter (com.neuronrobotics.replicator.driver.NRPrinter)1 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)1 LinkConfiguration (com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration)1 ServoRotoryLink (com.neuronrobotics.sdk.addons.kinematics.ServoRotoryLink)1 NRBootLoader (com.neuronrobotics.sdk.bootloader.NRBootLoader)1 BowlerCamDevice (com.neuronrobotics.sdk.bowlercam.device.BowlerCamDevice)1 BowlerAbstractConnection (com.neuronrobotics.sdk.common.BowlerAbstractConnection)1 DyPIDConfiguration (com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration)1 CounterInputChannel (com.neuronrobotics.sdk.dyio.peripherals.CounterInputChannel)1 DCMotorOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.DCMotorOutputChannel)1 DigitalOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalOutputChannel)1 PWMOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.PWMOutputChannel)1