NWChen
04-04-2014, 21:30
Our robot has two VEX ultrasonic rangefinders (http://www.vexrobotics.com/vex/products/accessories/sensors/276-2155.html), each connected to separate DIO ports on the digital sidecar. We're using the command-based template.
In a subsystem they're declared as:
private Ultrasonic wallSonar, ballSonar;
and in the constructor of the subsystem,
ballSonar = new Ultrasonic(Map.ARM_SONAR_INPUT, Map.ARM_SONAR_OUTPUT);
ballSonar.setEnabled(true);
ballSonar.setAutomaticMode(true);
wallSonar = new Ultrasonic(Map.LAUNCHER_SONAR_INPUT, Map.LAUNCHER_SONAR_OUTPUT);
wallSonar.setEnabled(true);
wallSonar.setAutomaticMode(true);
Ultrasonic.java in WPILib (https://github.com/eshsrobotics/wpilib-java/blob/master/src/edu/wpi/first/wpilibj/Ultrasonic.java) appears to be designed to handle >1 Ultrasonic instance, but when we try to run this code it throws an IllegalThreadStateException (http://pastebin.com/12chzCxZ).
Things we tried so far:
- Changing the order of assignment (wallSonar before ballSonar, ballSonar before wallSonar); still throws IllegalThreadStateException
- Moving one of the Ultrasonic sensors to a different subsystem; still throws IllegalThreadStateException.
- Declaring only one of the Ultrasonic sensors; having only one Ultrasonic sensor throws no errors, and the sensor works as expected.
- Unit testing with SimpleRobot, like this (http://pastebin.com/iKG6XdTy). Both sensors worked as expected, with no errors thrown.
Any idea why we can't declare/use two Ultrasonic sensors?
Thanks to Jeanne Boyarsky from team 694 at NYC today for helping us try to fix this.
In a subsystem they're declared as:
private Ultrasonic wallSonar, ballSonar;
and in the constructor of the subsystem,
ballSonar = new Ultrasonic(Map.ARM_SONAR_INPUT, Map.ARM_SONAR_OUTPUT);
ballSonar.setEnabled(true);
ballSonar.setAutomaticMode(true);
wallSonar = new Ultrasonic(Map.LAUNCHER_SONAR_INPUT, Map.LAUNCHER_SONAR_OUTPUT);
wallSonar.setEnabled(true);
wallSonar.setAutomaticMode(true);
Ultrasonic.java in WPILib (https://github.com/eshsrobotics/wpilib-java/blob/master/src/edu/wpi/first/wpilibj/Ultrasonic.java) appears to be designed to handle >1 Ultrasonic instance, but when we try to run this code it throws an IllegalThreadStateException (http://pastebin.com/12chzCxZ).
Things we tried so far:
- Changing the order of assignment (wallSonar before ballSonar, ballSonar before wallSonar); still throws IllegalThreadStateException
- Moving one of the Ultrasonic sensors to a different subsystem; still throws IllegalThreadStateException.
- Declaring only one of the Ultrasonic sensors; having only one Ultrasonic sensor throws no errors, and the sensor works as expected.
- Unit testing with SimpleRobot, like this (http://pastebin.com/iKG6XdTy). Both sensors worked as expected, with no errors thrown.
Any idea why we can't declare/use two Ultrasonic sensors?
Thanks to Jeanne Boyarsky from team 694 at NYC today for helping us try to fix this.