Go to Post Lesson learned, /always/ have a pick list! - Lil' Lavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-04-2014, 21:30
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
Dual Ultrasonic error

Our robot has two VEX ultrasonic rangefinders, each connected to separate DIO ports on the digital sidecar. We're using the command-based template.

In a subsystem they're declared as:
Code:
private Ultrasonic wallSonar, ballSonar;
and in the constructor of the subsystem,
Code:
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 appears to be designed to handle >1 Ultrasonic instance, but when we try to run this code it throws an IllegalThreadStateException.

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. 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.
__________________
2012 - 2015 • Team 2601


Last edited by NWChen : 04-04-2014 at 21:48.
Reply With Quote
  #2   Spotlight this post!  
Unread 05-04-2014, 08:09
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 102
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Dual Ultrasonic error

In looking through the Ultrasonic sensor source code (thanks for pasting in the link), it shows that the m_task variable associated with the background thread is static (a single instance for all Ultrasonic objects).

In looking at the comments for the setAutomaticMode() method, it looks like this method manages all of the configured sensors (to keep them time sequenced so they don't interfere with each other).

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);
Reply With Quote
  #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
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:10.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi