use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class BowlerBoardDevice method sendLinearSection.
/**
* This function will set up a multi-dimentional send for position and interpolation
* @param x new x position
* @param y new y position
* @param z new z position
* @param mmOfFiliment new target for mm of filiment
* @param ms time in MS
* @return number of spaces in the buffer
*/
public int sendLinearSection(TransformNR taskSpaceTransform, double mmOfFiliment, int ms, boolean forceNoBuffer) {
// Log.enableInfoPrint();
RuntimeException e = new RuntimeException("There is no more room left");
;
if (numSpacesRemaining == 0) {
throw e;
}
BowlerDatagram dg = send(new LinearInterpolationCommand(taskSpaceTransform, mmOfFiliment, ms, forceNoBuffer));
if (dg.getRPC().equalsIgnoreCase("_err")) {
throw e;
}
try {
numSpacesRemaining = ByteList.convertToInt(// Starting index
dg.getData().getBytes(// Starting index
0, // number of bytes
4), // True for signed data
false);
sizeOfBuffer = ByteList.convertToInt(// Starting index
dg.getData().getBytes(// Starting index
4, // number of bytes
4), // True for signed data
false);
// Log.enableSystemPrint(false);
return numSpacesRemaining;
} catch (RuntimeException ex) {
Log.error("Response failed: " + dg);
ex.printStackTrace();
throw ex;
}
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class DyIO method getAllChannelModes.
public ArrayList<DyIOChannelMode> getAllChannelModes() {
ArrayList<DyIOChannelMode> modes = new ArrayList<DyIOChannelMode>();
BowlerDatagram response;
ByteList bl;
if (isLegacyParser()) {
try {
response = send(new GetChannelModeCommand());
} catch (Exception e) {
if (getInternalChannels().size() == 0) {
Log.error("Initilization failed once, retrying");
try {
response = send(new GetChannelModeCommand());
} catch (Exception e2) {
e2.printStackTrace();
setMuteResyncOnModeChange(false);
throw new DyIOCommunicationException("DyIO failed to report during initialization. Could not determine DyIO configuration: " + e2.getMessage());
}
} else {
setMuteResyncOnModeChange(false);
return null;
}
}
if (response == null)
checkFirmwareRev();
// if(getAddress().equals(new MACAddress(MACAddress.BROADCAST))) {
setAddress(response.getAddress());
// }
@SuppressWarnings("unused") int count = 0;
if (getDyIOChannelCount() != null) {
count = getDyIOChannelCount();
}
bl = response.getData();
Log.error("Using old parsing model");
} else {
Object[] args = send("bcs.io.*;0.3;;", BowlerMethod.GET, "gacm", new Object[] {});
bl = (ByteList) args[0];
}
for (int i = 0; i < bl.size(); i++) {
DyIOChannelMode cm = DyIOChannelMode.get(bl.getByte(i));
modes.add(cm);
}
return modes;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class DyIO method getDyPIDConfiguration.
/**
* This method gets the current state of the DyIO channel configuration of a given PID group
* @param group the index of the PID group to get information about
* @return
*/
public DyPIDConfiguration getDyPIDConfiguration(int group) {
BowlerDatagram conf = send(new ConfigureDynamicPIDCommand(group));
DyPIDConfiguration back = new DyPIDConfiguration(conf);
return back;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class DyIO method resync.
/**
* This method re-synchronizes the entire state of the DyIO object with the DyIO module.
* The Firmware version is checked
* The info string is checked
* All channel modes are updated
*
* @return true if success
*/
public boolean resync() {
if (getConnection() == null) {
Log.info("Not connected");
return false;
}
if (!getConnection().isConnected()) {
Log.info("Not connected");
return false;
}
if (isResyncing()) {
Log.info("Already resyncing");
return true;
}
if (hasNamespace(NEURONROBOTICS_DYIO_1_0)) {
setLegacyParser(false);
}
if (hasNamespace("neuronrobotics.dyio.*;0.3;;")) {
setLegacyParser(true);
}
setResyncing(true);
setMuteResyncOnModeChange(true);
Log.info("Re-syncing...");
getBatteryVoltage(true);
BowlerDatagram response;
try {
if (!haveFirmware()) {
firmware = getRevisions().get(0).getBytes();
}
checkFirmwareRev();
// if(info.contains("Unknown")){
// response = send(new InfoCommand());
// if (response != null) {
// info = response.getData().asString();
// }
// }
} catch (Exception e) {
e.printStackTrace();
checkFirmwareRev();
}
ArrayList<DyIOChannelMode> modes = getAllChannelModes();
for (int i = 0; i < modes.size(); i++) {
DyIOChannelMode cm = modes.get(i);
boolean editable = true;
if (cm == null) {
cm = DyIOChannelMode.DIGITAL_OUT;
editable = false;
try {
Log.error("Mode get failed, setting to default");
send(new SetChannelModeCommand(i, cm));
} catch (Exception e) {
setMuteResyncOnModeChange(false);
throw new DyIOCommunicationException("Setting a pin to Digital In failed");
}
}
try {
Log.info("\n\nUpdating channel: " + i);
getInternalChannels().get(i).update(this, i, cm, editable);
} catch (IndexOutOfBoundsException e) {
// System.out.println("New channel "+i);
getInternalChannels().add(new DyIOChannel(this, i, cm, editable));
DyIOChannel dc = getInternalChannels().get(i);
dc.fireModeChangeEvent(dc.getCurrentMode());
}
}
setMuteResyncOnModeChange(false);
if (getInternalChannels().size() == 0)
throw new DyIOCommunicationException("DyIO failed to report during initialization");
haveBeenSynced = true;
setResyncing(false);
return true;
}
use of com.neuronrobotics.sdk.common.BowlerDatagram in project java-bowler by NeuronRobotics.
the class NRBootLoader method write.
public boolean write(int core, ByteData flashData) {
BowlerDatagram b = null;
for (int i = 0; i < 10; i++) {
try {
b = send(new ProgramSectionCommand(core, (int) flashData.getStartAddress(), new ByteList(flashData.getData())));
} catch (Exception e) {
e.printStackTrace();
b = null;
}
if (b != null) {
if (!b.getRPC().contains("_err"))
return true;
}
}
System.err.println("\nFailed to send 10 times!\n");
return false;
}
Aggregations