use of com.neuronrobotics.sdk.dyio.peripherals.ServoChannel in project java-bowler by NeuronRobotics.
the class ServoRotoryLink method setServoChannel.
public void setServoChannel(ServoChannel srv) {
// System.out.println("Setting new servo channel: "+srv.getChannel().getNumber());
srv.getChannel().setCachedMode(true);
srv.addIServoPositionUpdateListener(new IServoPositionUpdateListener() {
@Override
public void onServoPositionUpdate(ServoChannel srv, int position, double time) {
fireLinkListener(position);
}
});
this.srv = srv;
}
use of com.neuronrobotics.sdk.dyio.peripherals.ServoChannel 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;
}
use of com.neuronrobotics.sdk.dyio.peripherals.ServoChannel in project java-bowler by NeuronRobotics.
the class BasicWalker method parse.
private void parse(InputStream is) {
/**
* sample code from
* http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
*/
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder;
Document doc = null;
try {
dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(is);
doc.getDocumentElement().normalize();
} catch (ParserConfigurationException e) {
throw new RuntimeException(e);
} catch (SAXException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
// System.out.println("Parsing File...");
NodeList nList = doc.getElementsByTagName("leg");
for (int temp = 0; temp < nList.getLength(); temp++) {
// System.out.println("Leg # "+temp);
Node nNode = nList.item(temp);
ArrayList<WalkerServoLink> legLinks = new ArrayList<WalkerServoLink>();
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
x = Double.parseDouble(getTagValue("x", eElement));
y = Double.parseDouble(getTagValue("y", eElement));
theta = Double.parseDouble(getTagValue("theta", eElement));
// Leg tmpLeg = new Leg(x,y,theta);
NodeList links = eElement.getElementsByTagName("link");
for (int i = 0; i < links.getLength(); i++) {
// System.out.println("\tLink # "+i);
Node lNode = links.item(i);
if (lNode.getNodeType() == Node.ELEMENT_NODE) {
Element lElement = (Element) lNode;
llimit = Integer.parseInt(getTagValue("llimit", lElement));
ulimit = Integer.parseInt(getTagValue("ulimit", lElement));
home = Integer.parseInt(getTagValue("home", lElement));
channel = Integer.parseInt(getTagValue("channel", lElement));
inverse = Double.parseDouble(getTagValue("inverse", lElement));
scale = Double.parseDouble(getTagValue("scale", lElement));
linkLen = Double.parseDouble(getTagValue("linkLen", lElement));
String type = getTagValue("type", lElement);
if (useHardware) {
ServoChannel srv = new ServoChannel(getDyio().getChannel(channel));
WalkerServoLink tmpLink = new WalkerServoLink(srv, new LinkConfiguration(home, llimit, ulimit, (scale * inverse)), linkLen, type);
legLinks.add(tmpLink);
}
}
}
addLeg(x, y, theta, legLinks);
} else {
// System.out.println("Not Element Node");
}
}
System.out.println("Populated Hexapod.");
}
use of com.neuronrobotics.sdk.dyio.peripherals.ServoChannel 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.peripherals.ServoChannel in project java-bowler by NeuronRobotics.
the class CoreScheduler method addServoChannel.
public ServoOutputScheduleChannel addServoChannel(int dyIOChannel) {
System.out.println("Adding DyIO channel: " + dyIOChannel);
ServoChannel srv = new ServoChannel(getDyIO().getChannel(dyIOChannel));
srv.SetPosition(srv.getValue());
srv.flush();
srv.getChannel().setCachedMode(true);
ServoOutputScheduleChannel soc = new ServoOutputScheduleChannel(srv);
soc.setIntervalTime(getLoopTime(), getTrackLength());
addISchedulerListener(soc);
// soc.setIntervalTime(loopTime);
getOutputs().add(soc);
return soc;
}
Aggregations