View Single Post
  #3   Spotlight this post!  
Unread 05-04-2014, 19:13
NWChen's Avatar
NWChen NWChen is offline
Alum
no team
 
Join Date: Oct 2012
Rookie Year: 2012
Location: New York City
Posts: 205
NWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to beholdNWChen is a splendid one to behold
Re: Dual Ultrasonic error

Quote:
Originally Posted by pblankenbaker View Post
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);
...
}
__________________
2012 - 2015 • Team 2601

Reply With Quote