Go to Post The answer doesn't lie with an all student run team, or an Engineer-fest team... But somewhere in the middle. Moderation is key. - Cody Carey [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 03-19-2017, 02:05 PM
De_etz's Avatar
De_etz De_etz is offline
Registered User
AKA: Aditya Singh
FRC #5667 (The Digital Eagles)
Team Role: Leadership
 
Join Date: Feb 2017
Rookie Year: 2014
Location: New Albany Ohio
Posts: 5
De_etz is an unknown quantity at this point
Declaring Two Ultrasonic Sensors

16 public UltrasonicSensor() {
17 sensor1 = new Ultrasonic(2, 1);
18 sensor1.setAutomaticMode(true);
19 reading1 = 0;
20 inRange1 = false;
21
22 sensor2 = new Ultrasonic(5, 4);
23 sensor2.setAutomaticMode(true);
24 reading2 = 0;
25 inRange2 = false;
26 }

I'm getting an error on line 22 that says "Illegal Thread State Exception". The second ultrasonic sensor is wired exactly the same as the first in the appropriate ports, and I checked the physical sensors as well. Should I be declaring the second sensor differently?
Reply With Quote
  #2   Spotlight this post!  
Unread 03-19-2017, 02:54 PM
forbes's Avatar
forbes forbes is offline
Software developer
AKA: Evan Forbes
FRC #3507 (Ubotics), 694 (StuyPulse)
Team Role: Mentor
 
Join Date: Apr 2013
Rookie Year: 2012
Location: New York City
Posts: 205
forbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to beholdforbes is a splendid one to behold
Re: Declaring Two Ultrasonic Sensors

It looks like that is supposed to work, but you could try instantiating both of the Ultrasonic objects before setting automatic mode to true for either of them.
Reply With Quote
  #3   Spotlight this post!  
Unread 03-19-2017, 03:45 PM
PAR_WIG1350's Avatar
PAR_WIG1350 PAR_WIG1350 is offline
Registered User
AKA: Alan Wells
FRC #1350 (Rambots)
Team Role: Alumni
 
Join Date: Dec 2009
Rookie Year: 2009
Location: Rhode Island
Posts: 1,201
PAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond reputePAR_WIG1350 has a reputation beyond repute
Re: Declaring Two Ultrasonic Sensors

A bit more information about where this is and how and where it is used might be useful. I'm Also not sure what language you are using.
If this is Java, which it seems to be, you should specify that sensor1 and sensor2 are of the type Ultrasonic at the beginning of the line, giving something like the following:

Code:
Ultrasonic sensor1 = new Ultrasonic(2, 1);
In C++, you technically should do the same, but C++ allows that to be done before the constructor is called.

Also, in the example, the setAutomaticMode() call is made in the robotInit() method, but the constructor is called outside of it (possibly in the RobotTemplate constructor, I'm unsure of where that is supposed to be).
I don't think that attempting to do both in robotInit() would cause the error that you are getting, but I'm not sure that it wouldn't cause an issue with scope.

In the future, you might find it useful to create a new class for handling multiple ultrasonic sensors at once, or anything else similar to this. That would allow you to organize your status variables, constructors, and methods in a manner more in line with how they are organized in the Ultrasonic class. Your constructor would call the constructors for the two ultrasonic sensors, and the other actions you are trying to perform could be distributed between the constructor, and an initialization method. This change might be a bit radical at this point in the season, that is for you to decide.

*Full disclosure: I'm more familiar with hardware than software, and my familiarity with WPIlib is minimal. While everything I have stated is, to my knowledge, reasonably accurate, I do not claim it to be perfect.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 03-19-2017, 07:41 PM
tcjinaz tcjinaz is offline
Tim
FRC #3853
Team Role: Mentor
 
Join Date: May 2011
Rookie Year: 2011
Location: Arizona
Posts: 215
tcjinaz has a spectacular aura abouttcjinaz has a spectacular aura about
Re: Declaring Two Ultrasonic Sensors

I think cramming all the ultrasonics together would not be efficient. The Java Ultrasonic class from WPILib already manages all of the U's together in a separate thread.
I haven't looked any closer, but I suspect getting all the U's constructed before configuring with them might be good. There may yet be a bug in Ultrasonic.
__________________
3853 Pridetronics[

Reply With Quote
  #5   Spotlight this post!  
Unread 03-20-2017, 07:50 AM
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 453
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Declaring Two Ultrasonic Sensors

This appears to be a bug in the Ultrasonic class. The solution for now is to call setautomaticmode on sensor2 only. It will actually enable automatic mode for both sensors.
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #6   Spotlight this post!  
Unread 03-20-2017, 08:14 AM
Nirnaeth Nirnaeth is offline
Coach/Mentor
AKA: Michael Liang
FRC #6367 (The Brooke High ElectroLights)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2001
Location: Boston, MA
Posts: 56
Nirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud ofNirnaeth has much to be proud of
Re: Declaring Two Ultrasonic Sensors

Quote:
Originally Posted by forbes View Post
It looks like that is supposed to work, but you could try instantiating both of the Ultrasonic objects before setting automatic mode to true for either of them.
If it's Java, I'm assuming that sensor1 and sensor2 are class variables, and are already typed outside of the constructor?
__________________
Lead Mentor - Team 6367 - The Brooke High ElectroLights
Former Mentor - Team 5969 - The English Skunkworks
Former Mentor - Team 1754 - The Excel Nitro Knights
Reply With Quote
  #7   Spotlight this post!  
Unread 03-20-2017, 03:38 PM
De_etz's Avatar
De_etz De_etz is offline
Registered User
AKA: Aditya Singh
FRC #5667 (The Digital Eagles)
Team Role: Leadership
 
Join Date: Feb 2017
Rookie Year: 2014
Location: New Albany Ohio
Posts: 5
De_etz is an unknown quantity at this point
Re: Declaring Two Ultrasonic Sensors

Quote:
Originally Posted by PAR_WIG1350 View Post
If this is Java, which it seems to be, you should specify that sensor1 and sensor2 are of the type Ultrasonic at the beginning of the line.

In the future, you might find it useful to create a new class for handling multiple ultrasonic sensors at once, or anything else similar to this. That would allow you to organize your status variables, constructors, and methods in a manner more in line with how they are organized in the Ultrasonic class. Your constructor would call the constructors for the two ultrasonic sensors, and the other actions you are trying to perform could be distributed between the constructor, and an initialization method. This change might be a bit radical at this point in the season, that is for you to decide.
https://github.com/De-etz/2017RobotDeetz5667

The Ultrasonics are class variables declared within an UltrasonicSensor class I created and constructed within the UltrasonicSensor constructor, which is what that excerpt is. I'll try seeing tomorrow if removing the setAutomaticMode() from before the second sensor fixes the problem.
Reply With Quote
  #8   Spotlight this post!  
Unread 03-20-2017, 06:33 PM
Thad House Thad House is offline
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,135
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: Declaring Two Ultrasonic Sensors

Try not calling setAutomaticMode until you have created both of the sensors. The code will not handle adding a new sensor after automatic mode has been enabled.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.
Reply With Quote
  #9   Spotlight this post!  
Unread 03-20-2017, 11:07 PM
MrRoboSteve MrRoboSteve is offline
Mentor
AKA: Steve Peterson
FRC #3081 (Kennedy RoboEagles)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2011
Location: Bloomington, MN
Posts: 664
MrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond reputeMrRoboSteve has a reputation beyond repute
Re: Declaring Two Ultrasonic Sensors

Be sure you are using sensors that can be paired. For example, some MaxBotix sensors can be paired and others can't.

http://maxbotix.com/SelectionGuide/i...obot.htm#robot
__________________
2011 - present FRC 3081 Kennedy RoboEagles mentor
2013 - present event volunteer at 10000 Lakes Regional, Northern Lights Regional, North Star Regional, Lake Superior Regional, Minnesota State Tournament, PNW District 4 Glacier Peak, MN FTC, CMP
http://twitter.com/MrRoboSteve www.linkedin.com/in/speterson
Reply With Quote
  #10   Spotlight this post!  
Unread 03-27-2017, 04:27 PM
De_etz's Avatar
De_etz De_etz is offline
Registered User
AKA: Aditya Singh
FRC #5667 (The Digital Eagles)
Team Role: Leadership
 
Join Date: Feb 2017
Rookie Year: 2014
Location: New Albany Ohio
Posts: 5
De_etz is an unknown quantity at this point
Re: Declaring Two Ultrasonic Sensors

Quote:
Originally Posted by euhlmann View Post
This appears to be a bug in the Ultrasonic class. The solution for now is to call setautomaticmode on sensor2 only. It will actually enable automatic mode for both sensors.
This did work, problem solved. Thank you all.
Reply With Quote
  #11   Spotlight this post!  
Unread 03-27-2017, 06:31 PM
GreyingJay GreyingJay is offline
we'll fix it in the pit
FRC #2706 (Merge Robotics)
Team Role: Mentor
 
Join Date: Mar 2015
Rookie Year: 2015
Location: Ottawa, Canada
Posts: 1,061
GreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond reputeGreyingJay has a reputation beyond repute
Re: Declaring Two Ultrasonic Sensors

Wish I'd seen this sooner. We struggled with this too back in February and made the same discovery. Kudos to our grade 10 software student for tracing through and finding the root cause.

On that note is there an official way to submit bug reports or feature suggestions?
__________________
"If I'm going to mentor someone, I'm going to be involved in their life as a positive force." -Mechvet
Reply With Quote
  #12   Spotlight this post!  
Unread 03-28-2017, 12:30 AM
SamCarlberg's Avatar
SamCarlberg SamCarlberg is offline
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 196
SamCarlberg has much to be proud ofSamCarlberg has much to be proud ofSamCarlberg has much to be proud ofSamCarlberg has much to be proud ofSamCarlberg has much to be proud ofSamCarlberg has much to be proud ofSamCarlberg has much to be proud ofSamCarlberg has much to be proud of
Re: Declaring Two Ultrasonic Sensors

Quote:
Originally Posted by GreyingJay View Post
Wish I'd seen this sooner. We struggled with this too back in February and made the same discovery. Kudos to our grade 10 software student for tracing through and finding the root cause.

On that note is there an official way to submit bug reports or feature suggestions?
You can open an issue on the GitHub repository
__________________
WPILib developer
GRIP, RobotBuilder, SmartDashboard
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 08:36 PM.

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