BowlerKernel
PIDConfiguration.java
Go to the documentation of this file.
1 package com.neuronrobotics.sdk.pid;
2 
3 import com.neuronrobotics.sdk.common.BowlerDatagram;
4 import com.neuronrobotics.sdk.common.ByteList;
5 
6 // TODO: Auto-generated Javadoc
10 public class PIDConfiguration {
11 
13  private int group=0;
14 
16  private boolean enabled=false;
17 
19  private boolean inverted=false;
20 
22  private boolean async=false;
23 
25  private double KP=.1;
26 
28  private double KI=0;
29 
31  private double KD=0;
32 
34  private int latch=0;
35 
37  private boolean useLatch=false;
38 
40  private boolean stopOnIndex=false;
41 
43  private double up=0;
44 
46  private double low=0;
47 
49  private double hStop=0;
50 
54  public PIDConfiguration(){
55 
56  }
57 
63  public PIDConfiguration(int channel){
64  group=channel;
65  }
66 
84  public PIDConfiguration(int group,boolean enabled,boolean inverted,boolean async,double KP,double KI,double KD, double latch, boolean useLatch, boolean stopOnLatch, double up, double low,double hStop){
85  setGroup(group);
88  setAsync(async);
89  setKP(KP);
90  setKI(KI);
91  setKD(KD);
92  setIndexLatch((int)latch);
94  setStopOnIndex(stopOnLatch);
98 
99  }
100 
116  boolean enabled,
117  boolean inverted,
118  boolean async,
119  double KP,double KI,double KD,
120  double latch, boolean useLatch, boolean stopOnLatch) {
121 
122  this(group,enabled,inverted,async,KP,KI,KD,latch,useLatch,stopOnLatch,0,0,0);
123  }
124 
132  setGroup( conf.getData().get(0));
133  setEnabled( conf.getData().get(1)>0);
134  setInverted(conf.getData().get(2)>0);
135  setAsync( conf.getData().get(3)>0);
136  setKP(((double)ByteList.convertToInt(conf.getData().getBytes(4, 4),false))/100);
137  setKI(((double)ByteList.convertToInt(conf.getData().getBytes(8, 4),false))/100);
138  setKD(((double)ByteList.convertToInt(conf.getData().getBytes(12, 4),false))/100);
139  try{
140  setIndexLatch(((int)ByteList.convertToInt(conf.getData().getBytes(16, 4),true)));
141  setUseLatch(conf.getData().getBytes(20, 1)[0]>0);
142  setStopOnIndex(conf.getData().getBytes(21, 1)[0]>0);
143 
144  setHystersysStop(((double)ByteList.convertToInt(conf.getData().getBytes(22, 4),true))/1000);
145  setUpperHystersys(((double)ByteList.convertToInt(conf.getData().getBytes(26, 4),true))/1000);
146  setLowerHystersys(((double)ByteList.convertToInt(conf.getData().getBytes(30, 4),true))/1000);
147 
148  }catch(Exception e){
149  System.err.println("No latch value sent");
150  }
151  }
152 
153 
160  public PIDConfiguration(Object [] args) {
161  setGroup((Integer) args[0]);
162  setEnabled((Integer) args[1]==1?true:false);
163  setInverted((Integer) args[2]==1?true:false);
164  setAsync((Integer) args[3]==1?true:false);
165  setKP((Double) args[4]);
166  setKI((Double) args[5]);
167  setKD((Double) args[6]);
168  setIndexLatch((Integer) args[7]);
169  setUseLatch((Integer) args[8]==1?true:false);
170  setStopOnIndex((Integer) args[9]==1?true:false);
171  setHystersysStop((Double) args[10]);
172  setUpperHystersys((Double) args[11]);
173  setLowerHystersys((Double) args[12]);
174 
175  }
176 
177 
178  /* (non-Javadoc)
179  * @see java.lang.Object#toString()
180  */
181  @Override
182  public String toString(){
183  String s="PID configuration group #"+getGroup();
184  s+="\n\tConstants: P="+getKP()+" I="+getKI()+" D="+getKD();
185  s+="\n\tEnabled = "+isEnabled();
186  s+="\n\tAsync = "+isAsync();
187  s+="\n\tInverted = "+isInverted();
188  s+="\n\tUse Latch "+ isUseLatch();
189  s+="\n\tStop on Index "+ isStopOnIndex();
190  s+="\n\tLatch value "+getIndexLatch();
191  s+="\n\tCenter Stop "+getHystersysStop();
192  s+="\n\tUpper Hysterysys "+getUpperHystersys();
193  s+="\n\tLower Hysterysys "+getLowerHystersys();
194  return s;
195  }
196 
202  public void setGroup(int group) {
203  this.group = group;
204  }
205 
211  public int getGroup() {
212  return group;
213  }
214 
220  public void setEnabled(boolean enabled) {
221  this.enabled = enabled;
222  }
223 
229  public boolean isEnabled() {
230  return enabled;
231  }
232 
238  public void setInverted(boolean inverted) {
239  this.inverted = inverted;
240  }
241 
247  public boolean isInverted() {
248  return inverted;
249  }
250 
256  public void setAsync(boolean async) {
257  this.async = async;
258  }
259 
265  public boolean isAsync() {
266  return async;
267  }
268 
274  public void setKP(double kP) {
275  KP = kP;
276  }
277 
283  public double getKP() {
284  return KP;
285  }
286 
292  public void setKI(double kI) {
293  KI = kI;
294  }
295 
301  public double getKI() {
302  return KI;
303  }
304 
310  public void setKD(double kD) {
311  KD = kD;
312  }
313 
319  public double getKD() {
320  return KD;
321  }
322 
328  public double getIndexLatch() {
329  return latch;
330  }
331 
337  public void setIndexLatch(double latch) {
338  this.latch=(int) latch;
339  }
340 
346  public void setUseLatch(boolean useLatch) {
347  this.useLatch = useLatch;
348  }
349 
355  public boolean isUseLatch() {
356  return useLatch;
357  }
358 
364  public void setStopOnIndex(boolean stopOnIndex) {
365  this.stopOnIndex = stopOnIndex;
366  }
367 
373  public boolean isStopOnIndex() {
374  return stopOnIndex;
375  }
376 
382  public Object[] getArgs() {
383  Object[] args = new Object[]{
384  group,
385  enabled?1:0,
386  inverted?1:0,
387  async?1:0,
388  KP,
389  KI,
390  KD,
391  latch,
392  useLatch?1:0,
393  stopOnIndex?1:0,
394  hStop,
395  up,
396  low
397  };
398  return args;
399  }
400 
406  public double getUpperHystersys(){
407  return up;
408  }
409 
415  public void setUpperHystersys(double up) {
416  this.up = up;
417  }
418 
424  public double getLowerHystersys(){
425  return low;
426  }
427 
433  public void setLowerHystersys(double low) {
434  this.low = low;
435  }
436 
442  public double getHystersysStop(){
443  return hStop;
444  }
445 
451  public void setHystersysStop(double hStop) {
452  this.hStop = hStop;
453  }
454 }
static final int convertToInt(byte[] b)
Definition: ByteList.java:911
PIDConfiguration(int group, boolean enabled, boolean inverted, boolean async, double KP, double KI, double KD, double latch, boolean useLatch, boolean stopOnLatch, double up, double low, double hStop)
PIDConfiguration(int group, boolean enabled, boolean inverted, boolean async, double KP, double KI, double KD, double latch, boolean useLatch, boolean stopOnLatch)