Search in sources :

Example 1 with SetAllChannelValuesCommand

use of com.neuronrobotics.sdk.commands.bcs.io.SetAllChannelValuesCommand in project java-bowler by NeuronRobotics.

the class DyIO method flushCache.

/**
 * This method will flush the DyIO cache for all channels. All channel values as stored by setting the value from code, or the value
 * stored at the time that the cache/flush mode was enabled. THis method will flush all 24 channel values in one packet allowing for
 * co-ordinated motion.
 * @param time in seconds
 */
public void flushCache(double seconds) {
    // System.out.println("Updating all channels");
    Integer[] values = new Integer[getInternalChannels().size()];
    int i = 0;
    for (DyIOChannel d : getInternalChannels()) {
        values[i++] = d.getCachedValue();
    // System.out.println("Flushing chan "+d+" to "+d.getCachedValue());
    }
    if (isLegacyParser()) {
        for (int j = 0; j < 5; j++) {
            try {
                send(new SetAllChannelValuesCommand(seconds, values));
                return;
            } catch (InvalidResponseException e1) {
                System.err.println("Failed to update all, retrying");
            }
        }
    } else {
        // for(DyIOChannel d:getInternalChannels()) {
        // d.setCachedTime((float) seconds);
        // if(d.getMode()==DyIOChannelMode.SERVO_OUT)
        // d.flush();
        // }
        send("bcs.io.*;0.3;;", BowlerMethod.POST, "sacv", new Object[] { new Integer((int) (seconds * 1000)), values });
    }
}
Also used : SetAllChannelValuesCommand(com.neuronrobotics.sdk.commands.bcs.io.SetAllChannelValuesCommand) InvalidResponseException(com.neuronrobotics.sdk.common.InvalidResponseException)

Aggregations

SetAllChannelValuesCommand (com.neuronrobotics.sdk.commands.bcs.io.SetAllChannelValuesCommand)1 InvalidResponseException (com.neuronrobotics.sdk.common.InvalidResponseException)1