BowlerKernel
GenericPIDDevice.java
Go to the documentation of this file.
1 package com.neuronrobotics.sdk.pid;
2 
3 import java.util.ArrayList;
4 
5 import com.neuronrobotics.sdk.common.BowlerAbstractConnection;
6 import com.neuronrobotics.sdk.common.BowlerAbstractDevice;
7 import com.neuronrobotics.sdk.common.BowlerDatagram;
8 import com.neuronrobotics.sdk.common.IFlushable;
9 import com.neuronrobotics.sdk.common.Log;
10 import com.neuronrobotics.sdk.common.MACAddress;
11 import com.neuronrobotics.sdk.namespace.bcs.pid.AbstractPidNamespaceImp;
12 import com.neuronrobotics.sdk.namespace.bcs.pid.IExtendedPIDControl;
13 import com.neuronrobotics.sdk.namespace.bcs.pid.LegacyPidNamespaceImp;
14 import com.neuronrobotics.sdk.namespace.bcs.pid.PidNamespaceImp;
15 
16 // TODO: Auto-generated Javadoc
24 
26  private boolean isInit=false;
27 
30 
34  public GenericPIDDevice() {
36  }
37 
46  }
47 
48  /* (non-Javadoc)
49  * @see com.neuronrobotics.sdk.common.BowlerAbstractDevice#setConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection)
50  */
51  @Override
53  super.setConnection(connection);
55  init();
56  }
57 
58  /* (non-Javadoc)
59  * @see com.neuronrobotics.sdk.common.BowlerAbstractDevice#connect()
60  */
61  @Override
62  public boolean connect(){
63  if(super.connect()){
64  init();
65  return true;
66  }
67  return false;
68  }
69 
73  private void init(){
74  if(isInit){
75  return;
76  }
77  if(getImplementation() == null){
78 
79  }
80  isInit = true;
81  }
82 
83  /* (non-Javadoc)
84  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#ResetPIDChannel(int, int)
85  */
86  @Override
87  public boolean ResetPIDChannel(int group, float valueToSetCurrentTo) {
88  return getImplementation().ResetPIDChannel(group, valueToSetCurrentTo);
89  }
90 
91  /* (non-Javadoc)
92  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#ConfigurePIDController(com.neuronrobotics.sdk.pid.PIDConfiguration)
93  */
94  @Override
95  public boolean ConfigurePIDController(PIDConfiguration config) {
97  }
98 
99  /* (non-Javadoc)
100  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#getPIDConfiguration(int)
101  */
102  @Override
104  return getImplementation().getPIDConfiguration(group);
105  }
106 
107  /* (non-Javadoc)
108  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#ConfigurePDVelovityController(com.neuronrobotics.sdk.pid.PDVelocityConfiguration)
109  */
110  @Override
113  }
114 
115  /* (non-Javadoc)
116  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#getPDVelocityConfiguration(int)
117  */
118  @Override
121  }
122 
123  /* (non-Javadoc)
124  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#getPIDChannelCount()
125  */
126  @Override
127  public int getPIDChannelCount() {
129  }
130 
136  //This is added for backward compatibility
137  public int getNumberOfChannels(){
138  return getPIDChannelCount();
139  }
140 
141  /* (non-Javadoc)
142  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#SetPIDSetPoint(int, int, double)
143  */
144  @Override
145  public boolean SetPIDSetPoint(int group, float setpoint, double seconds) {
146  return getImplementation().SetPIDSetPoint(group, setpoint, seconds);
147  }
148 
149  /* (non-Javadoc)
150  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#SetAllPIDSetPoint(int[], double)
151  */
152  @Override
153  public boolean SetAllPIDSetPoint(float[] setpoints, double seconds) {
154  return getImplementation().SetAllPIDSetPoint(setpoints, seconds);
155  }
156 
157  /* (non-Javadoc)
158  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#GetPIDPosition(int)
159  */
160  @Override
161  public float GetPIDPosition(int group) {
162  return getImplementation().GetPIDPosition(group);
163  }
164 
165  /* (non-Javadoc)
166  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#GetAllPIDPosition()
167  */
168  @Override
169  public float[] GetAllPIDPosition() {
171  }
172 
173  /* (non-Javadoc)
174  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#addPIDEventListener(com.neuronrobotics.sdk.pid.IPIDEventListener)
175  */
176  @Override
179  }
180 
181  /* (non-Javadoc)
182  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#removePIDEventListener(com.neuronrobotics.sdk.pid.IPIDEventListener)
183  */
184  @Override
187  }
188 
189  /* (non-Javadoc)
190  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#flushPIDChannels(double)
191  */
192  @Override
193  public void flushPIDChannels(double time) {
195  }
196 
197  /* (non-Javadoc)
198  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#SetPIDInterpolatedVelocity(int, int, double)
199  */
200  @Override
201  public boolean SetPIDInterpolatedVelocity(int group, int unitsPerSecond,
202  double seconds) throws PIDCommandException {
203  return getImplementation().SetPIDInterpolatedVelocity(group, unitsPerSecond, seconds);
204  }
205 
206  /* (non-Javadoc)
207  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#SetPDVelocity(int, int, double)
208  */
209  @Override
210  public boolean SetPDVelocity(int group, int unitsPerSecond, double seconds)
211  throws PIDCommandException {
212  return getImplementation().SetPDVelocity(group, unitsPerSecond, seconds);
213  }
214 
215  /* (non-Javadoc)
216  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#getPIDChannel(int)
217  */
218  @Override
219  public PIDChannel getPIDChannel(int group) {
220  return getImplementation().getPIDChannel(group);
221  }
222 
223  /* (non-Javadoc)
224  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace#killAllPidGroups()
225  */
226  @Override
227  public boolean killAllPidGroups() {
229  }
230 
231  /* (non-Javadoc)
232  * @see com.neuronrobotics.sdk.common.IBowlerDatagramListener#onAsyncResponse(com.neuronrobotics.sdk.common.BowlerDatagram)
233  */
234  @Override
235  public void onAsyncResponse(BowlerDatagram data) {
237  }
238 
245  protected void firePIDResetEvent(int group, float val) {
246  getImplementation().firePIDResetEvent(group, val);
247  }
248 
254  protected void firePIDEvent(PIDEvent pidEvent) {
255  getImplementation().firePIDEvent(pidEvent);
256  }
257 
263  public ArrayList<PIDChannel> getChannels() {
264  return getImplementation().getChannels();
265  }
266 
272  public void setChannels(ArrayList<PIDChannel> channels) {
273  getImplementation().setChannels(channels);
274  }
275 
282 
283 
284  if(implementation==null){
285  if(this instanceof VirtualGenericPIDDevice){
287  return implementation;
288  }else{
289  if(hasNamespace("bcs.pid.*;0.3;;")){
290  //Log.info("Using legacy PID namespace");
292  }
293  else{
294  //Log.info("Using new PID namespace");
296  }
297  }
298  }
299  return implementation;
300  }
301 
308  this.implementation = implementation;
309  }
310 
311  /* (non-Javadoc)
312  * @see com.neuronrobotics.sdk.namespace.bcs.pid.IExtendedPIDControl#runOutputHysteresisCalibration(int)
313  */
314  @Override
315  public boolean runOutputHysteresisCalibration(int group) {
316  try{
318  }catch(RuntimeException e){
319  Log.error(e.getMessage());
320  return false;
321  }
322 
323  }
324 
325  @Override
326  public void flush(double seconds) {
327  flushPIDChannels(seconds);
328  }
329 
330 }
static void error(String message)
Definition: Log.java:92
boolean SetPIDInterpolatedVelocity(int group, int unitsPerSecond, double seconds)
boolean ConfigurePDVelovityController(PDVelocityConfiguration config)
boolean SetAllPIDSetPoint(float[] setpoints, double seconds)
boolean ResetPIDChannel(int group, float valueToSetCurrentTo)
boolean SetPDVelocity(int group, int unitsPerSecond, double seconds)
GenericPIDDevice(BowlerAbstractConnection connection)
void setImplementation(AbstractPidNamespaceImp implementation)
PDVelocityConfiguration getPDVelocityConfiguration(int group)
void setChannels(ArrayList< PIDChannel > channels)
PIDConfiguration getPIDConfiguration(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)
boolean ConfigurePDVelovityController(PDVelocityConfiguration config)
boolean SetAllPIDSetPoint(float[]setpoints, double seconds)
boolean SetPIDSetPoint(int group, float setpoint, double seconds)
PDVelocityConfiguration getPDVelocityConfiguration(int group)
boolean SetPDVelocity(int group, int unitsPerSecond, double seconds)
boolean ResetPIDChannel(int group, float valueToSetCurrentTo)