Go to Post you know you are addicted to first when u crave sprockets for breakfast! - Jones571 [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

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 01-02-2008, 00:22
scottanderson's Avatar
scottanderson scottanderson is offline
Software Architect
AKA: Scott Anderson
FRC #2608 (MiGHT)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Shelby Township
Posts: 20
scottanderson is an unknown quantity at this point
Strange gear tooth sensor port issue

After a battle with a broken gear tooth sensor, we finally have two sensors working. Good.

We're using MPLab and WPILib, which is nice. However, the problem is that the GetGTSensor code doesn't seem to work as advertised.

The sensors are on ports 1 and 2 of the digital inputs. StartGTSensor(1,0) and StartGTSensor(2,0) work.

However (and this is the weird bit), the values for GT 1 must be retrieved with GetGTSensor(2) and the values for GT 2 must be retrieved with GetGTSensor(4).

Even odder, if StartGTSensor is used with an invert value of 1, GetGTSensor(1) will return -1 once the gear on port 1 starts moving, and GetGTSensor(3) will return -1 once the gear on port 2 starts moving.

What's going on here?

Regards,
-scott
  #2   Spotlight this post!  
Unread 01-02-2008, 15:15
xrabohrok's Avatar
xrabohrok xrabohrok is offline
hunter of errors
FRC #1208 (The Metool Brigade)
Team Role: Programmer
 
Join Date: Jan 2006
Location: O'Fallon
Posts: 62
xrabohrok is an unknown quantity at this point
Re: Strange gear tooth sensor port issue

When you say get GTsensor code, is that kevin's code, or your own?
What project are you using?
If it is your code, can you show us it?
__________________
"It's programming's fault" may be a viable excuse for just about everything, except the robot falling apart.

It will 'cause it can!

constants aren't. variables won't.
  #3   Spotlight this post!  
Unread 01-02-2008, 16:01
scottanderson's Avatar
scottanderson scottanderson is offline
Software Architect
AKA: Scott Anderson
FRC #2608 (MiGHT)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Shelby Township
Posts: 20
scottanderson is an unknown quantity at this point
Re: Strange gear tooth sensor port issue

WPILib's "GetGTSensor" routine, from the latest release of WPILib.

The code is simply this:

void main(void) {
StartGTSensor(1, 0);
StartGTSensor(2, 0);

while (1) {
printf("1: %d 2: %d 3: %d 4: %d\n", GetGTSensor(1), GetGTSensor(2), GetGTSensor(3), GetGTSensor(4));
}
}

The gear tooth sensors are plugged into ports 1 and 2.

Output:

1: 0 2: <port 1 output> 3: 0 4: <port 2 output>
...

If I invert instead:

StartGTSensor(1, -1);
StartGTSensor(2, -1);

then I see this:

1: -1 2: <port 1 output> 3: -1 4: <port 2 output>
...

Regards,
-scott
  #4   Spotlight this post!  
Unread 01-02-2008, 16:19
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Strange gear tooth sensor port issue

Quote:
Originally Posted by scottanderson View Post
Code:
printf("1: %d   2: %d   3: %d   4: %d\n", GetGTSensor(1), GetGTSensor(2), GetGTSensor(3), GetGTSensor(4));
The problem is probably with the printf() statement, not with the Gear Tooth Sensor code. You're asking for four ints to be printed. It looks like GetGTSensor() returns a long. The first %d will show the first 16 bits of GetGTSensor(1), the second %d will show the rest of GetGTSensor(1), the third will show the first 16 bits of GetGTSensor(2), etc.

If this is the case, you can correct the problem either by printing the values using %ld, or by casting them as (int).
  #5   Spotlight this post!  
Unread 01-02-2008, 17:22
scottanderson's Avatar
scottanderson scottanderson is offline
Software Architect
AKA: Scott Anderson
FRC #2608 (MiGHT)
Team Role: Mentor
 
Join Date: Feb 2008
Rookie Year: 2008
Location: Shelby Township
Posts: 20
scottanderson is an unknown quantity at this point
Re: Strange gear tooth sensor port issue

Oh, jeez. For some reason I thought that function returned int.

Yes, that probably explains it. Thanks.

Regards,
-scott, who apparently has been programming in Java for far too long.
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gear Tooth Sensor marco_alchemy Electrical 7 06-02-2008 09:54
Gear Tooth Sensor Nathan Programming 4 12-01-2008 15:09
Gear Tooth Sensor? Raikon Kit & Additional Hardware 3 09-02-2007 16:40
Gear Tooth Sensor nukem Programming 9 04-02-2006 20:21
Gear Tooth Sensor Talha Electrical 1 23-01-2006 21:29


All times are GMT -5. The time now is 19:11.

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