BowlerKernel
PIDChannel.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.Log;
6 import com.neuronrobotics.sdk.namespace.bcs.pid.IPidControlNamespace;
7 
8 // TODO: Auto-generated Javadoc
12 public class PIDChannel {
13 
16 
18  private int index;
19 
21  private float targetValue;
22 
24  private float currentCachedPosition;
25 
27  private ArrayList<IPIDEventListener> PIDEventListeners = new ArrayList<IPIDEventListener>();
28 
35  public PIDChannel(IPidControlNamespace p, int i) {
36  setPid(p);
37  index=i;
38  }
39 
47  public boolean SetPIDSetPoint(float setpoint,double seconds){
48 
49  return getPid().SetPIDSetPoint(index, setpoint, seconds);
50  }
51 
60  public boolean SetPIDInterpolatedVelocity( int unitsPerSecond, double seconds) throws PIDCommandException {
61  return getPid().SetPIDInterpolatedVelocity(index, unitsPerSecond, seconds);
62  }
63 
72  public boolean SetPDVelocity( int unitsPerSecond, double seconds) throws PIDCommandException {
73  return getPid().SetPDVelocity(index, unitsPerSecond, seconds);
74  }
75 
81  public float GetPIDPosition() {
82  return getPid().GetPIDPosition(index);
83  }
84 
91  public boolean ConfigurePIDController(PIDConfiguration config) {
92  config.setGroup(index);
93  return getPid().ConfigurePIDController(config);
94  }
95 
96 
103  return getPid().getPIDConfiguration(index);
104  }
105 
111  public boolean ResetPIDChannel() {
112  return getPid().ResetPIDChannel(index,0);
113  }
114 
115 
122  public boolean ResetPIDChannel( int valueToSetCurrentTo) {
123  return getPid().ResetPIDChannel(index,valueToSetCurrentTo);
124  }
125 
131  public void setPid(IPidControlNamespace p) {
132  pid = p;
134  @Override
135  public void onPIDReset(int group, float currentValue) {
136  if(group==index){
137  firePIDResetEvent(index, currentValue);
138  }
139  }
140 
141  @Override
142  public void onPIDLimitEvent(PIDLimitEvent e) {
143  if(e.getGroup()==index){
145  }
146  }
147 
148  @Override
149  public void onPIDEvent(PIDEvent e) {
150  if(e.getGroup()==index){
151  firePIDEvent(e);
152  }
153  }
154  });
155  }
156 
157 
164  return pid;
165  }
166 
173  if(PIDEventListeners.contains(l))
174  PIDEventListeners.remove(l);
175 
176  }
177 
184  if(!PIDEventListeners.contains(l))
185  PIDEventListeners.add(l);
186 
187  }
188 
195  for (int i=0;i<PIDEventListeners.size();i++){
196  PIDEventListeners.get(i).onPIDLimitEvent(e);
197  }
198  }
199 
205  public void firePIDEvent(PIDEvent e){
206  for (int i=0;i<PIDEventListeners.size();i++){
207 
208  PIDEventListeners.get(i).onPIDEvent(e);
209  }
210  }
211 
218  public void firePIDResetEvent(int group,float value){
219  for (int i=0;i<PIDEventListeners.size();i++){
220  PIDEventListeners.get(i).onPIDReset(group,value);
221  }
222  }
223 
229  public void flush(double time){
231  }
232 
238  public void setCachedTargetValue(float targetValue) {
239  if(new Double(targetValue).isNaN()) {
240  new RuntimeException("Setpoint in can not be set to nan").printStackTrace();
241  }else {
242  Log.info("Cacheing PID position group="+getGroup()+", setpoint="+targetValue+" ticks");
243  this.targetValue = targetValue;
244  }
245  }
246 
252  public float getCachedTargetValue() {
253  return targetValue;
254  }
255 
256 
257 
264  this.currentCachedPosition = currentCachedPosition;
265  }
266 
267 
268 
274  public float getCurrentCachedPosition() {
275  return currentCachedPosition;
276  }
277 
283  public boolean isAvailable() {
284  // TODO Auto-generated method stub
285  return pid.isAvailable();
286  }
287 
293  public int getGroup() {
294  // TODO Auto-generated method stub
295  return index;
296  }
297 
298 }
static void info(String message)
Definition: Log.java:110
boolean SetPIDSetPoint(float setpoint, double seconds)
Definition: PIDChannel.java:47
boolean SetPDVelocity(int unitsPerSecond, double seconds)
Definition: PIDChannel.java:72
void firePIDLimitEvent(PIDLimitEvent e)
void setCachedTargetValue(float targetValue)
void removePIDEventListener(IPIDEventListener l)
void firePIDResetEvent(int group, float value)
boolean SetPIDInterpolatedVelocity(int unitsPerSecond, double seconds)
Definition: PIDChannel.java:60
ArrayList< IPIDEventListener > PIDEventListeners
Definition: PIDChannel.java:27
void addPIDEventListener(IPIDEventListener l)
PIDChannel(IPidControlNamespace p, int i)
Definition: PIDChannel.java:35
boolean ConfigurePIDController(PIDConfiguration config)
Definition: PIDChannel.java:91
void setCurrentCachedPosition(float currentCachedPosition)
boolean ResetPIDChannel(int valueToSetCurrentTo)
void setPid(IPidControlNamespace p)
boolean SetPIDSetPoint(int group, float setpoint, double seconds)
boolean SetPDVelocity(int group, int unitsPerSecond, double seconds)
boolean ResetPIDChannel(int group, float valueToSetCurrentTo)
boolean SetPIDInterpolatedVelocity(int group, int unitsPerSecond, double seconds)