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");
}
}
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);
}
}
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);
}
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);
}
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());
}
}
Aggregations