Quote:
Originally Posted by pblankenbaker
So, my best guess is that you only need to call setAutomaticMode(true) one time (even though it is not a static method).
Can you try changing your code to:
Code:
ballSonar = new Ultrasonic(Map.ARM_SONAR_INPUT, Map.ARM_SONAR_OUTPUT);
ballSonar.setEnabled(true);
wallSonar = new Ultrasonic(Map.LAUNCHER_SONAR_INPUT, Map.LAUNCHER_SONAR_OUTPUT);
wallSonar.setEnabled(true);
// Enable automatic pinging on all sensors (not sure why this method
// wasn't declared static in Ultrasonic class)
wallSonar.setAutomaticMode(true);
|
That makes sense to me. We didn't try this yet, thanks for the suggestion.
Having said that (and having not checked CD this morning, oops), we tried something else. Calling each constructor consecutively rather than after each setEnabled() and setAutomaticMode() method appeared to resolve the issue:
Code:
ballSonar = new Ultrasonic(Map.ARM_SONAR_INPUT, Map.ARM_SONAR_OUTPUT);
wallSonar = new Ultrasonic(Map.LAUNCHER_SONAR_INPUT, Map.LAUNCHER_SONAR_OUTPUT);
ballSonar.setEnabled(true);
ballSonar.setAutomaticMode(true);
wallSonar.setEnabled(true);
wallSonar.setAutomaticMode(true);
Both sensors returned accurate values from getRangeInches() after reordering these assignments in the constructor of the subsystem they were declared in:
Code:
private Ultrasonic wallSonar, ballSonar;
public Arms(){
ballSonar = new Ultrasonic(Map.ARM_SONAR_INPUT, Map.ARM_SONAR_OUTPUT);
wallSonar = new Ultrasonic(Map.LAUNCHER_SONAR_INPUT, Map.LAUNCHER_SONAR_OUTPUT);
ballSonar.setEnabled(true);
ballSonar.setAutomaticMode(true);
wallSonar.setEnabled(true);
wallSonar.setAutomaticMode(true);
...
}