15 package com.neuronrobotics.sdk.dyio;
17 import java.util.ArrayList;
19 import com.neuronrobotics.sdk.commands.bcs.io.AsyncMode;
20 import com.neuronrobotics.sdk.commands.bcs.io.AsyncThreshholdEdgeType;
21 import com.neuronrobotics.sdk.commands.bcs.io.ConfigAsyncCommand;
22 import com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeCommand;
23 import com.neuronrobotics.sdk.commands.bcs.io.GetChannelModeListCommand;
24 import com.neuronrobotics.sdk.commands.bcs.io.GetDyIOChannelCountCommand;
25 import com.neuronrobotics.sdk.commands.bcs.io.SetAllChannelValuesCommand;
26 import com.neuronrobotics.sdk.commands.bcs.io.setmode.SetChannelModeCommand;
27 import com.neuronrobotics.sdk.commands.bcs.pid.DyPID.ConfigureDynamicPIDCommand;
28 import com.neuronrobotics.sdk.commands.bcs.safe.SafeModeCommand;
29 import com.neuronrobotics.sdk.commands.neuronrobotics.dyio.GetAllChannelValuesCommand;
30 import com.neuronrobotics.sdk.commands.neuronrobotics.dyio.PowerCommand;
31 import com.neuronrobotics.sdk.common.BowlerAbstractConnection;
32 import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
33 import com.neuronrobotics.sdk.common.BowlerDatagram;
34 import com.neuronrobotics.sdk.common.BowlerMethod;
35 import com.neuronrobotics.sdk.common.ByteList;
36 import com.neuronrobotics.sdk.common.IConnectionEventListener;
37 import com.neuronrobotics.sdk.common.IFlushable;
38 import com.neuronrobotics.sdk.common.InvalidConnectionException;
39 import com.neuronrobotics.sdk.common.InvalidResponseException;
40 import com.neuronrobotics.sdk.common.Log;
41 import com.neuronrobotics.sdk.common.MACAddress;
42 import com.neuronrobotics.sdk.config.SDKBuildInfo;
43 import com.neuronrobotics.sdk.dyio.dypid.DyPIDConfiguration;
44 import com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace;
45 import com.neuronrobotics.sdk.pid.GenericPIDDevice;
46 import com.neuronrobotics.sdk.pid.IPIDEventListener;
47 import com.neuronrobotics.sdk.pid.PDVelocityConfiguration;
48 import com.neuronrobotics.sdk.pid.PIDChannel;
49 import com.neuronrobotics.sdk.pid.PIDCommandException;
50 import com.neuronrobotics.sdk.pid.PIDConfiguration;
51 import com.neuronrobotics.sdk.pid.VirtualGenericPIDDevice;
52 import com.neuronrobotics.sdk.util.ThreadUtil;
66 private ArrayList<IDyIOEventListener>
listeners =
new ArrayList<IDyIOEventListener>();
69 private ArrayList<DyIOChannel>
channels =
new ArrayList<DyIOChannel>();
75 private String
info =
"DyIO";
169 return send(NS,method,rpcString,arguments,2);
245 public boolean setValue(
int channel, java.math.BigDecimal value) {
246 return setValue(channel,value.intValue());
302 String revFmt =
"%02d.%02d.%03d";
312 ArrayList<DyIOChannel> c =
new ArrayList<DyIOChannel>();
357 for(
int i=0;i<3;i++){
361 "\nTry updating your firmware using the firmware update instructions from"+
362 "\nhttp://wiki.neuronrobotics.com/NR_Console_Update_Firmware");
368 Log.
info(
"Not checking firmware version for DyIO");
378 ArrayList<DyIOChannelMode> modes =
new ArrayList<DyIOChannelMode>();
384 }
catch (Exception e) {
386 Log.
error(
"Initilization failed once, retrying");
389 }
catch(Exception e2){
390 e2.printStackTrace();
392 throw new DyIOCommunicationException(
"DyIO failed to report during initialization. Could not determine DyIO configuration: "+e2.getMessage());
405 @SuppressWarnings(
"unused")
412 Log.
error(
"Using old parsing model");
416 Object [] args =
send(
"bcs.io.*;0.3;;",
424 for (
int i = 0; i < bl.
size(); i++){
479 }
catch (Exception e){
486 for (
int i = 0; i < modes.size(); i++){
488 boolean editable =
true;
493 Log.
error(
"Mode get failed, setting to default");
495 }
catch(Exception e) {
501 Log.
info(
"\n\nUpdating channel: "+i);
503 }
catch(IndexOutOfBoundsException e){
598 Log.
error(
"Valadate will fail, no channels, resyncing");
608 throw new IndexOutOfBoundsException(
"DyIO channels must be between 0 and " +
getInternalChannels().size()+
" requested:"+channel);
631 d.setCachedMode(mode);
634 d.setCachedValue(d.getValue());
636 d.setCachedValue(128);
653 values[i++]=d.getCachedValue();
657 for(
int j=0;j<5;j++) {
662 System.err.println(
"Failed to update all, retrying");
671 send(
"bcs.io.*;0.3;;",
674 new Object[]{new Integer((int) (seconds*1000)),values});
739 if(data.
getRPC().contains(
"_pwr")){
755 Log.
error(
"Wrong type for updating Power state "+data);
767 if(data.
getRPC().equals(
"_pwr")) {
771 if(data.
getRPC().equals(
"gchv")) {
781 }
if(data.
getRPC().equals(
"gacv")) {
788 Log.
error(
"DyIO event "+c+
" value: "+val);
789 if(!c.isStreamChannel())
795 int numChan = bl.
pop();
797 Log.
error(
"Bad packet, wrong number of values");
802 Log.
info(
"DyIO event "+c+
" value: "+val);
808 }
if(data.
getRPC().equals(
"strm")) {
1066 if(super.connect()) {
1093 super.startHeartBeat(msHeartBeatTime);
1098 }
catch(Exception e){
1099 System.err.println(
"DyIO is out of date");
1121 super.stopHeartBeat();
1126 }
catch(Exception e){
1127 System.err.println(
"DyIO is out of date");
1243 String chFmt =
"%02d - ( %04d ) - %-20s %02d - ( %04d ) - %-20s\n";
1248 s += String.format(chFmt,
1275 if(!c.isStreamChannel()){
1279 if(!c.isStreamChannel()){
1280 c.fireChannelEvent(ev);
1288 Object [] args =
send(
"bcs.io.*;0.3;;",
1292 Integer [] values = (Integer [])args[0];
1351 ex.printStackTrace();
1354 Object [] args =
send(
"bcs.io.*;0.3;;",
1371 ArrayList<DyIOChannelMode> modes =
new ArrayList<DyIOChannelMode>();
1377 Log.
error(
"Packet "+channel+
"\r\n"+dg);
1378 Log.
error(
"Data: "+channel+
"\r\n"+m);
1383 Object [] args =
send(
"bcs.io.*;0.3;;",
1386 new Object[]{channel});
1390 String modeString =
" Availible modes on "+channel;
1391 for(
int i=0;i<m.
size();i++){
1393 modeString +=
"\r\n\t"+tmpMode.
toString()+
"\r\n\t";
void setSynchronusPacketTimeoutTime(int sleepTime)
void addConnectionEventListener(IConnectionEventListener l)
boolean hasNamespace(String string)
void setConnection(BowlerAbstractConnection connection)
ArrayList< ByteList > getRevisions()
BowlerAbstractConnection getConnection()
BowlerAbstractConnection connection
void setAddress(MACAddress address)
byte[] popList(int index)
static final int convertToInt(byte[] b)
static void info(String message)
static void error(String message)
static void warning(String message)
static final String BROADCAST
static int[] getBuildInfo()
boolean setValue(int value)
boolean setMode(DyIOChannelMode mode)
void fireModeChangeEvent(DyIOChannelMode e)
void fireChannelEvent(DyIOChannelEvent e)
DyIOChannelMode getMode(boolean resync)
DyIOChannelMode getCurrentMode()
boolean isStreamChannel()
void validateChannel(int channel)
boolean configAdvancedAsyncDeadBand(int pin, int deadbandSize)
boolean setValue(int channel, int value)
void flush(double seconds)
DyIO(BowlerAbstractConnection connection)
ArrayList< DyIOChannel > channels
boolean muteResyncOnModeChange
boolean setServoPowerSafeMode(boolean enable)
float[] GetAllPIDPosition()
boolean ResetPIDChannel(int group)
void removePIDEventListener(IPIDEventListener l)
void setCachedMode(boolean mode)
DyIO(MACAddress address, BowlerAbstractConnection connection)
DyIOPowerState getBankBState()
ArrayList< DyIOChannelMode > getAvailibleChannelModes(int channel)
ArrayList< DyIOChannel > getInternalChannels()
void setInfo(String info)
void setMuteResyncOnModeChange(boolean muteResyncOnModeChange)
DyIOPowerState getBankAState()
float GetPIDPosition(int group)
DyPIDConfiguration getDyPIDConfiguration(int group)
boolean ConfigurePIDController(PIDConfiguration config)
ArrayList< IDyIOEventListener > listeners
boolean SetPIDSetPoint(int group, float setpoint, double seconds)
Object[] send(String NS, BowlerMethod method, String rpcString, Object[] arguments)
DyIOChannelMode getMode(int channel)
boolean ResetPIDChannel(int group, float valueToSetCurrentTo)
DyIOPowerState bankBState
ArrayList< DyIOChannel > getChannels()
String getFirmwareRevString()
void removeDyIOEventListener(IDyIOEventListener l)
static final String NEURONROBOTICS_DYIO_1_0
boolean isMuteResyncOnModeChange()
void onAsyncResponse(BowlerDatagram data)
void startHeartBeat(long msHeartBeatTime)
void flushPIDChannels(double time)
boolean configAdvancedAsyncAutoSample(int pin)
int getValue(int channel)
static void disableFWCheck()
boolean setValue(int channel, java.math.BigDecimal value)
int[] getAllChannelValues()
boolean configAdvancedAsyncTreshhold(int pin, int threshholdValue, AsyncThreshholdEdgeType edgeType)
boolean killAllPidGroups()
boolean ConfigurePDVelovityController(PDVelocityConfiguration config)
void onConnect(BowlerAbstractConnection source)
PDVelocityConfiguration getPDVelocityConfiguration(int group)
void addDyIOEventListener(IDyIOEventListener l)
ArrayList< DyIOChannelMode > getAllChannelModes()
static boolean checkFirmware
void setResyncing(boolean resyncing)
void onDisconnect(BowlerAbstractConnection source)
boolean ConfigureDynamicPIDChannels(DyPIDConfiguration config)
boolean SetPIDInterpolatedVelocity(int group, int unitsPerSecond, double seconds)
void powerEvent(BowlerDatagram data)
static void enableFWCheck()
void fireDyIOEvent(IDyIOEvent e)
void flushCache(double seconds)
boolean configAdvancedAsyncNotEqual(int pin, int time)
DyIOPowerState bankAState
void setLegacyParser(boolean legacyParser)
boolean configAdvancedAsyncTreshhold(int pin, int time, int threshholdValue, AsyncThreshholdEdgeType edgeType)
boolean setValue(int channel, ByteList value)
boolean setMode(int channel, DyIOChannelMode mode, boolean async)
PIDChannel getPIDChannel(int group)
boolean configAdvancedAsyncDeadBand(int pin, int time, int deadbandSize)
double getBatteryVoltage(boolean refresh)
PIDConfiguration getPIDConfiguration(int group)
void addPIDEventListener(IPIDEventListener l)
boolean setMode(int channel, DyIOChannelMode mode)
void removeAllDyIOEventListeners()
boolean configAdvancedAsyncNotEqual(int pin)
boolean SetAllPIDSetPoint(float[]setpoints, double seconds)
boolean configAdvancedAsyncAutoSample(int pin, int time)
boolean SetPDVelocity(int group, int unitsPerSecond, double seconds)
Boolean isServoPowerSafeMode()
DyIOChannel getChannel(int channel)
Integer getDyIOChannelCount()
GenericPIDDevice getPid()
boolean ConfigurePDVelovityController(PDVelocityConfiguration config)
boolean SetAllPIDSetPoint(float[] setpoints, double seconds)
boolean ResetPIDChannel(int group, float valueToSetCurrentTo)
void onAsyncResponse(BowlerDatagram data)
boolean SetPDVelocity(int group, int unitsPerSecond, double seconds)
float GetPIDPosition(int group)
boolean killAllPidGroups()
float[] GetAllPIDPosition()
void addPIDEventListener(IPIDEventListener l)
void removePIDEventListener(IPIDEventListener l)
void flushPIDChannels(double time)
PDVelocityConfiguration getPDVelocityConfiguration(int group)
PIDConfiguration getPIDConfiguration(int group)
PIDChannel getPIDChannel(int group)
boolean SetPIDSetPoint(int group, float setpoint, double seconds)
boolean ConfigurePIDController(PIDConfiguration config)
void setConnection(BowlerAbstractConnection connection)
boolean SetPIDInterpolatedVelocity(int group, int unitsPerSecond, double seconds)
static void wait(int time)
static DyIOChannelMode get(byte code)
static DyIOPowerState valueOf(int code, double batteryVoltage)