View Full Version : problems with multiple encoders, please help!
robself705
12-02-2009, 21:32
we're using a total of 4 encoders on our robot, 2 for steering, and 1 for a turret. but when any more than 1 encoder is defined, only the one that is defined first works. here is a sample of some code that only read one of the encoders in teleoperated mode
Encoder front(1,2);
Encoder back(3,4);
while (1)
{
printf("%d %d\n", front.Get(), back.Get());
}
front.Get gives back a value when we turn the encoder but back.get does not, we've checked the wiring a hundred times, any help would be greatly appreciated
Wylie99998
12-02-2009, 21:52
um well can u send ur actual code maybe ur instantiating them incorrectly. btw if u made them pointers u must use the -> operator instead of the . operator and also u have to have a line somewhere starting the counting ( ex back->Start();
dboisvert
12-02-2009, 22:00
Encoder front(1,2);
Encoder back(3,4);
while (1)
{
printf("%d %d\n", front->Get(), back->Get());
}
That should do the trick
robself705
12-02-2009, 22:06
we tried it with the pointers and we had the same result, one encoder worked while the other did nothing. if we didnt initiate them properly than either it wouldnt compile or both of them wouldnt run, right?
Wylie99998
12-02-2009, 22:11
hmm the fact that one is running is odd.. have u checked on a volt meter if the sensor is sending back pulses?
reversed_rocker
12-02-2009, 23:46
yeah we took an oscilliscope to all of the encoders and all of them are sending back pulses. whats especially weird is that if you comment out the first encoder, the second encoder gives data back. but if you have both encoders running at the same time, only the one that's defined first will send back data
Alan Anderson
13-02-2009, 00:22
printf("%d %d\n", front.Get(), back.Get());Shouldn't you be using the %f format specification instead of %d? I thought encoders returned floating point values.
reversed_rocker
13-02-2009, 00:56
thats problably true, but i dont see how that would cause only one encoder to give back values
Alan Anderson
13-02-2009, 01:00
It would cause the printf() to report the values incorrectly. If that's the only thing making you think the encoders aren't working right, the encoders might actually not be misbehaving at all.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.