I tried this code to get my quadrator shaft encoders to work, but they won’t work. The code works if the encoders are not spun otherwise one of them have a higher value than the other and then you would have to spin it back to zero to get them to be equal to each other.
'/code] tags. (without the ' obviously, and you can access this with the </> button)
Second, what do you mean by work? Is your robot not behaving as expected? Make sure you understand the logic of your code fully. The nature of encoders is that they count ticks/rotation, meaning that yes, when you spin them they won't necessarily be the same. That's part of the logic with using PID.
okay.
When I spin the encoders the same amount, say 4 turns, by connecting them with an axle, then turn one way farther than the 30 tick range, one of the motors is supposed to stay on while the other stays off. However, during the initial turns, one of the motors turns on and when I turn the encoder either way past the 30 tick range, nothing happens. the motor stays on while the other stays off. To turn on the other motor and off the first, I have to turn the encoders back to the 0 tick start.
preferably the latest. I suppose it doesn’t particularly matter though as long as the joystick/cortex are compatible firmware.
If I understand correctly (clarify if I’m wrong): you intend for this program to essentially make your robot drive in a straight line while adjusting for mechanical inaccuracy. Or maybe you want to just make it center itself. Either way… the logic to do this seems to be missing some steps. For instance, you are at no point stopping/slowing the other side motor when the inequality condition is met. You will need to add that. Also, if this is not just for forward, you’ll need to zero out encoders between operations.