![]() |
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 |
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? |
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 |
Re: Strange gear tooth sensor port issue
Quote:
If this is the case, you can correct the problem either by printing the values using %ld, or by casting them as (int). |
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. |
| All times are GMT -5. The time now is 23:49. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi