use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.
the class SafeModeWatchDog method main.
/**
* @param args
*/
public static void main(String[] args) {
DyIO dyio = new DyIO();
if (!ConnectionDialog.getBowlerDevice(dyio)) {
System.exit(1);
}
int heartbeatTime = 3000;
dyio.startHeartBeat(heartbeatTime);
int getheartBeat = dyio.getHeartBeatTime();
System.out.println("Told it to go to " + heartbeatTime + " got " + getheartBeat);
System.exit(0);
}
use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.
the class USARTTest method main.
public static void main(String[] args) throws InterruptedException {
DyIO dyio = new DyIO();
if (!ConnectionDialog.getBowlerDevice(dyio)) {
System.exit(0);
}
// Instantiate the UARTPassThroughChannel
UARTChannel uart = new UARTChannel(dyio);
// Configure the DyIO's output UART to use 115200 baud
uart.setUARTBaudrate(115200);
// Create a test string and send it to the serial port
String s = new String("abcdefghijklmnopqrstuvwxyz");
ByteList stream = new ByteList(s.getBytes());
try {
System.out.println("Sending: " + stream.asString());
uart.sendBytes(stream);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
Thread.sleep(1000);
// Wait for data to arrive
while (!uart.inStreamDataReady()) {
Thread.sleep(10);
}
// Print out the data we got back
try {
System.out.println("Got input: " + new ByteList(uart.getBytes()).asString());
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
// Cleanup and exit
dyio.disconnect();
System.exit(0);
}
use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.
the class DyIOConversation method onMessage.
@Override
public String onMessage(String input, Chat chat, String from) {
String[] packet = input.split("\\ ");
if (packet[0].toLowerCase().contains("ping")) {
return "ping: \n" + ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).ping();
} else if (packet[0].toLowerCase().contains("state")) {
return "state: \n" + ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).toString();
} else if (packet[0].toLowerCase().contains("setmode")) {
DyIOChannelMode m = DyIOChannelMode.DIGITAL_IN;
boolean found = false;
String options = "";
for (DyIOChannelMode cm : EnumSet.allOf(DyIOChannelMode.class)) {
options += cm.toSlug() + "\n";
if (packet[2].toLowerCase().equals(cm.toSlug())) {
m = cm;
found = true;
}
}
try {
int port = Integer.parseInt(packet[1]);
if (found && ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).canBeMode(m)) {
((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).setMode(port, m);
return "setMode " + port + " " + m.toSlug();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return "error: Mode not settible on channel #" + packet[1] + " mode options are:\n" + options;
} else if (packet[0].toLowerCase().contains("setvalue")) {
int port = Integer.parseInt(packet[1]);
int value = Integer.parseInt(packet[2]);
((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).setValue(value);
return "setValue " + port + " " + value;
} else if (packet[0].toLowerCase().contains("getvalue")) {
int port = Integer.parseInt(packet[1]);
int value = ((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).getValue();
return "getValue " + port + " " + value;
} else if (packet[0].toLowerCase().contains("addasync")) {
int port = Integer.parseInt(packet[1]);
int rate = 500;
try {
rate = Integer.parseInt(packet[2]);
} catch (Exception ex) {
rate = 500;
}
if (rate < 500)
rate = 500;
((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).setAsync(true);
((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).configAdvancedAsyncNotEqual(rate);
((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).addChannelEventListener(getListener(chat, from));
return "async " + port + " " + rate;
} else if (packet[0].toLowerCase().contains("removeasync")) {
int port = Integer.parseInt(packet[1]);
((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(port).removeChannelEventListener(getListener(chat, from));
return "async removed " + port + " ";
} else if (packet[0].toLowerCase().contains("reset")) {
for (int i = 0; i < 24; i++) {
((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(i).removeAllChannelEventListeners();
}
return "system reset!";
} else {
return help();
}
}
use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.
the class DHKinematicsViewer method main.
public static void main(String[] args) {
System.setProperty("prism.dirtyopts", "false");
JFrame frame = new JFrame();
DyIO.disableFWCheck();
// Log.enableInfoPrint();
// Create the references for my known DyIOs
DyIO master = new DyIO(ConnectionDialog.promptConnection());
master.connect();
if (master.isAvailable()) {
DHParameterKinematics model = new DHParameterKinematics(master, "TrobotMaster.xml");
frame.setContentPane(new DHKinematicsViewer(model));
frame.setSize(1024, 1024);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Log.enableSystemPrint(false);
while (true) {
ThreadUtil.wait(1);
master.getAllChannelValues();
}
}
use of com.neuronrobotics.sdk.dyio.DyIO in project java-bowler by NeuronRobotics.
the class LinkFactory method getLinkLocal.
private AbstractLink getLinkLocal(LinkConfiguration c) {
if (dyio == null)
dyio = (DyIO) DeviceManager.getSpecificDevice(DyIO.class, c.getDeviceScriptingName());
if (pid == null)
pid = (IPidControlNamespace) DeviceManager.getSpecificDevice(IPidControlNamespace.class, c.getDeviceScriptingName());
AbstractLink tmp = null;
Log.info("Loading link: " + c.getName() + " type = " + c.getType() + " device= " + c.getDeviceScriptingName());
switch(c.getType()) {
case ANALOG_PRISMATIC:
if (dyio != null) {
tmp = new AnalogPrismaticLink(new AnalogInputChannel(dyio.getChannel(c.getHardwareIndex())), c);
tmp.setUseLimits(false);
}
break;
case ANALOG_ROTORY:
if (dyio != null) {
tmp = new AnalogRotoryLink(new AnalogInputChannel(dyio.getChannel(c.getHardwareIndex())), c);
tmp.setUseLimits(false);
}
break;
case PID_TOOL:
case PID:
if (pid != null) {
tmp = new PidRotoryLink(pid.getPIDChannel(c.getHardwareIndex()), c);
}
break;
case PID_PRISMATIC:
if (pid != null) {
tmp = new PidPrismaticLink(pid.getPIDChannel(c.getHardwareIndex()), c);
}
break;
case SERVO_PRISMATIC:
if (dyio != null) {
tmp = new ServoPrismaticLink(new ServoChannel(dyio.getChannel(c.getHardwareIndex())), c);
}
break;
case SERVO_ROTORY:
case SERVO_TOOL:
if (dyio != null) {
tmp = new ServoRotoryLink(new ServoChannel(dyio.getChannel(c.getHardwareIndex())), c);
}
break;
case STEPPER_PRISMATIC:
if (dyio != null) {
tmp = new StepperPrismaticLink(new CounterOutputChannel(dyio.getChannel(c.getHardwareIndex())), c);
}
break;
case STEPPER_TOOL:
case STEPPER_ROTORY:
if (dyio != null) {
tmp = new StepperRotoryLink(new CounterOutputChannel(dyio.getChannel(c.getHardwareIndex())), c);
}
break;
case DUMMY:
case VIRTUAL:
String myVirtualDevName = c.getDeviceScriptingName();
virtual = (VirtualGenericPIDDevice) DeviceManager.getSpecificDevice(VirtualGenericPIDDevice.class, myVirtualDevName);
if (virtual == null) {
virtual = new VirtualGenericPIDDevice();
DeviceManager.addConnection(virtual, myVirtualDevName);
}
tmp = new PidRotoryLink(virtual.getPIDChannel(c.getHardwareIndex()), c);
break;
}
if (tmp == null) {
String myVirtualDevName = "virtual_" + c.getDeviceScriptingName();
virtual = (VirtualGenericPIDDevice) DeviceManager.getSpecificDevice(VirtualGenericPIDDevice.class, myVirtualDevName);
if (virtual == null) {
virtual = new VirtualGenericPIDDevice();
DeviceManager.addConnection(virtual, myVirtualDevName);
}
if (!c.getType().isPrismatic()) {
tmp = new PidRotoryLink(virtual.getPIDChannel(c.getHardwareIndex()), c);
} else {
tmp = new PidPrismaticLink(virtual.getPIDChannel(c.getHardwareIndex()), c);
}
}
tmp.setLinkConfiguration(c);
links.add(tmp);
if (!getLinkConfigurations().contains(c))
getLinkConfigurations().add(c);
return tmp;
}
Aggregations