Search in sources :

Example 1 with BowlerAbstractConnection

use of com.neuronrobotics.sdk.common.BowlerAbstractConnection in project java-bowler by NeuronRobotics.

the class PingSpeedTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    // BowlerAbstractConnection c =  new SerialConnection("/dev/DyIO0");
    // BowlerAbstractConnection c =  new SerialConnection("COM65");
    BowlerAbstractConnection c = ConnectionDialog.promptConnection();
    // }
    if (c == null)
        System.exit(1);
    System.out.println("Starting test");
    // Log.enableInfoPrint();
    GenericDevice dev = new GenericDevice(c);
    dev.connect();
    long start;
    double avg = 0;
    int i;
    avg = 0;
    dev.ping();
    for (i = 1; i < 5000000 && dev.isAvailable(); i++) {
        start = System.currentTimeMillis();
        dev.ping();
        double ms = System.currentTimeMillis() - start;
        avg += ms;
        System.out.println("Average cycle time: " + (int) (avg / i) + "ms\t\t\t this loop was: " + ms);
        dev.getNamespaces();
    }
    System.out.println("Average cycle time for ping: " + (avg / i) + " ms");
    dev.disconnect();
    System.exit(0);
}
Also used : GenericDevice(com.neuronrobotics.sdk.genericdevice.GenericDevice) BowlerAbstractConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection)

Example 2 with BowlerAbstractConnection

use of com.neuronrobotics.sdk.common.BowlerAbstractConnection in project java-bowler by NeuronRobotics.

the class BowlerAbstractServer method pushAsyncPacket.

public synchronized void pushAsyncPacket(BowlerDatagram data) {
    localServers.clear();
    for (int i = 0; i < servers.size(); i++) {
        localServers.add(getServers().get(i));
    }
    for (int i = 0; i < servers.size(); i++) {
        try {
            boolean run = false;
            if (localServers.get(i).getClass() == BowlerTCPServer.class) {
                BowlerTCPServer b = (BowlerTCPServer) localServers.get(i);
                if (b.isClientConnected()) {
                    run = true;
                    Log.info("TCP Bowler client ...OK!");
                }
            } else {
                run = true;
            }
            if (localServers.get(i).getClass() != BowlerUDPServer.class) {
                // System.out.println("Sending packet to "+getServers().get(i).getClass());
                if (run && localServers.get(i).isConnected()) {
                    // Log.warning("ASYNC<<\r\n"+data );
                    String classString = localServers.get(i).getClass().toString();
                    localServers.get(i).sendAsync(data);
                    Log.info("Sent packet to " + classString);
                }
            } else {
                try {
                    localServers.get(i).sendAsync(data);
                } catch (NullPointerException ex) {
                }
            }
        } catch (IndexOutOfBoundsException ie) {
            ie.printStackTrace();
        } catch (Exception e) {
            try {
                e.printStackTrace();
                BowlerAbstractConnection abs = localServers.get(i);
                Log.error("No client connected to this connection " + abs.getClass());
                abs.disconnect();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    localServers.clear();
}
Also used : BowlerTCPServer(com.neuronrobotics.sdk.network.BowlerTCPServer) BowlerAbstractConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection) DeviceConnectionException(com.neuronrobotics.sdk.common.DeviceConnectionException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RuntimeErrorException(javax.management.RuntimeErrorException)

Example 3 with BowlerAbstractConnection

use of com.neuronrobotics.sdk.common.BowlerAbstractConnection in project java-bowler by NeuronRobotics.

the class BowlerAbstractServer method addServer.

public void addServer(BowlerAbstractConnection srv) {
    if (!servers.contains(srv)) {
        srv.addConnectionEventListener(new IConnectionEventListener() {

            @Override
            public void onDisconnect(BowlerAbstractConnection source) {
                Log.warning("Removing server from listener");
                removeServer(source);
            }

            @Override
            public void onConnect(BowlerAbstractConnection source) {
            }
        });
        servers.add(srv);
        srv.connect();
        srv.setSynchronousDatagramListener(this);
    }
}
Also used : BowlerAbstractConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection) IConnectionEventListener(com.neuronrobotics.sdk.common.IConnectionEventListener)

Example 4 with BowlerAbstractConnection

use of com.neuronrobotics.sdk.common.BowlerAbstractConnection 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 5 with BowlerAbstractConnection

use of com.neuronrobotics.sdk.common.BowlerAbstractConnection in project java-bowler by NeuronRobotics.

the class ConnectionDialog method getBowlerDevice.

/**
 * @param dev
 * @return Returns if the device has been found
 */
public static boolean getBowlerDevice(BowlerAbstractDevice dev, AbstractConnectionPanel panel) {
    if (dev == null) {
        return false;
    }
    BowlerAbstractConnection connection = null;
    while (connection == null) {
        Log.info("Select connection:");
        connection = ConnectionDialog.promptConnection(panel);
        if (connection == null) {
            Log.info("No connection selected...");
            return false;
        }
        Log.info("setting connection");
        try {
            dev.setConnection(connection);
            dev.connect();
            Log.info("Connected");
        } catch (DyIOCommunicationException e1) {
            String m = "The DyIO has not reported back to the library. \nCheck your connection and ensure you are attempting to talk to a DyIO, not another Bowler Device\nThis program will now exit.";
            JOptionPane.showMessageDialog(null, m, "DyIO Not Responding" + e1.getMessage(), JOptionPane.ERROR_MESSAGE);
            continue;
        } catch (Exception e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, e.getMessage(), "DyIO Connection problem ", JOptionPane.ERROR_MESSAGE);
            return false;
        }
        Log.info("Attempting to ping");
        if (dev.ping()) {
            Log.info("Ping OK!");
            break;
        } else {
            connection = null;
            JOptionPane.showMessageDialog(null, "No device on that port", "", JOptionPane.ERROR_MESSAGE);
        }
    }
    return true;
}
Also used : BowlerAbstractConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection) DyIOCommunicationException(com.neuronrobotics.sdk.dyio.DyIOCommunicationException) DyIOCommunicationException(com.neuronrobotics.sdk.dyio.DyIOCommunicationException)

Aggregations

BowlerAbstractConnection (com.neuronrobotics.sdk.common.BowlerAbstractConnection)5 DeviceConnectionException (com.neuronrobotics.sdk.common.DeviceConnectionException)1 IConnectionEventListener (com.neuronrobotics.sdk.common.IConnectionEventListener)1 DyIO (com.neuronrobotics.sdk.dyio.DyIO)1 DyIOCommunicationException (com.neuronrobotics.sdk.dyio.DyIOCommunicationException)1 DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)1 ServoChannel (com.neuronrobotics.sdk.dyio.peripherals.ServoChannel)1 GenericDevice (com.neuronrobotics.sdk.genericdevice.GenericDevice)1 BowlerTCPServer (com.neuronrobotics.sdk.network.BowlerTCPServer)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 RuntimeErrorException (javax.management.RuntimeErrorException)1