Go to Post Robotics. Seems to be the answer to a lot of things I don't do. - Keith Chester [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 19-02-2012, 18:09
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Potentiometer and analogue channels

Hey guys, our code returns a NullPointerException because it was already allocated to that channel, but we are 100% sure that it was not. We have code specifically designed to prevent this here:

Code:
if(potentiometerOn) {
            if(potentiometer instanceof AnalogChannel) {
                potentiometerEnabled = true;
            }else {
                potentiometerEnabled = false;
                potentiometer = new AnalogChannel(potentiometerChannel);
                if(potentiometer instanceof AnalogChannel) {
                    potentiometerEnabled = true;
                }
            }
        }
Is it that the variable potentiometer is not registered as an instance of AnalogueChannel (A weird class or something?) Maybe if we used potentiometerEnabled as our qualifier to create the new instance it would work? We are a bit confused at this.
Reply With Quote
  #2   Spotlight this post!  
Unread 20-02-2012, 10:58
sjspry sjspry is offline
Registered User
FRC #1984
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Kansas
Posts: 125
sjspry has a spectacular aura aboutsjspry has a spectacular aura aboutsjspry has a spectacular aura about
Re: Potentiometer and analogue channels

If the code says it was enabled somewhere, it was enabled somewhere (I think the channel used to read the battery voltage is exposed on the header pins - you might be trying to use it).

However, since that exception throwing is mostly to keep you from mixing up what you are using channels for (if, for example, you happen to double-allocate a channel), you can bypass it and get the reading for that channel number with:

Code:
AnalogModule.getInstance(slot).getVoltage(chan);
Optionally storing the instance of the AnalogModule in your own variable.
Reply With Quote
  #3   Spotlight this post!  
Unread 20-02-2012, 11:32
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: Potentiometer and analogue channels

Yeah I ended up removing all potentiometer code and starting from scratch on it. Havn't tested yet but it should work. Otherwise, I'll just set up a singleton like you said. Thanks
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:53.

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