Search in sources :

Example 16 with BowlerDatagram

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;
    }
}
Also used : BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) LinearInterpolationCommand(com.neuronrobotics.sdk.commands.cartesian.LinearInterpolationCommand)

Example 17 with BowlerDatagram

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;
}
Also used : GetChannelModeCommand(com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand) ByteList(com.neuronrobotics.sdk.common.ByteList) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) ArrayList(java.util.ArrayList) PIDCommandException(com.neuronrobotics.sdk.pid.PIDCommandException) InvalidConnectionException(com.neuronrobotics.sdk.common.InvalidConnectionException) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

Example 18 with BowlerDatagram

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;
}
Also used : ConfigureDynamicPIDCommand(com.neuronrobotics.sdk.commands.bcs.pid.DyPID.ConfigureDynamicPIDCommand) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) DyPIDConfiguration(com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration)

Example 19 with BowlerDatagram

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;
}
Also used : SetChannelModeCommand(com.neuronrobotics.sdk.commands.bcs.io.setmode.SetChannelModeCommand) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) PIDCommandException(com.neuronrobotics.sdk.pid.PIDCommandException) InvalidConnectionException(com.neuronrobotics.sdk.common.InvalidConnectionException) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

Example 20 with BowlerDatagram

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;
}
Also used : ByteList(com.neuronrobotics.sdk.common.ByteList) ProgramSectionCommand(com.neuronrobotics.sdk.commands.neuronrobotics.bootloader.ProgramSectionCommand) BowlerDatagram(com.neuronrobotics.sdk.common.BowlerDatagram) IOException(java.io.IOException)

Aggregations

BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)31 ByteList (com.neuronrobotics.sdk.common.ByteList)9 MACAddress (com.neuronrobotics.sdk.common.MACAddress)5 IOException (java.io.IOException)5 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)4 ArrayList (java.util.ArrayList)4 PingCommand (com.neuronrobotics.sdk.commands.bcs.core.PingCommand)3 GetChannelModeCommand (com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand)2 GetValueCommand (com.neuronrobotics.sdk.commands.bcs.io.GetValueCommand)2 InvalidConnectionException (com.neuronrobotics.sdk.common.InvalidConnectionException)2 RpcEncapsulation (com.neuronrobotics.sdk.common.RpcEncapsulation)2 PIDCommandException (com.neuronrobotics.sdk.pid.PIDCommandException)2 SocketException (java.net.SocketException)2 Test (org.junit.Test)2 GetChannelModeListCommand (com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeListCommand)1 GetDyIOChannelCountCommand (com.neuronrobotics.sdk.commands.bcs.io.GetDyIOChannelCountCommand)1 SetChannelModeCommand (com.neuronrobotics.sdk.commands.bcs.io.setmode.SetChannelModeCommand)1 ConfigurePIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.ConfigurePIDCommand)1 ControlAllPIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.ControlAllPIDCommand)1 ConfigureDynamicPIDCommand (com.neuronrobotics.sdk.commands.bcs.pid.DyPID.ConfigureDynamicPIDCommand)1