
Re: Robot TC synchronize 4 dc motors with quad. encoders+ard
The tricky part may be setting up and reading the encoder values, depending on how they work exactly. Once they are set up, though, you can use something similar to an autostraighten program (short example below) to 'synchronize' the motors together:
You would have to repeat the process for the encoders/speeds of the other two motors as well. Also, you may want to put in an 'acceptable range', for instance, if the encoder counts are within 1 count of each other; this will prevent the motor speed from 'flip-flopping between a value that is 1 higher or 1 less than the desired encoder count. It's a bit tricky to do, but you definitely have the right idea.
I would focus on setting up the encoders in ROBOTC and normalizing their values first, then using them to control the motor speeds. We have done some testing with
programming a mechanical encoder you may want to look into as well. Keep us updated on the progress of this project!
Edit: Looking through this again, I did make an error with the previous code:
Needs to be outside of the infinite while loop; otherwise, it will reset speedB to 50 everything the loop executes (which is quite often, in the matter of milliseconds).
_________________Check out our
Blog! And our
Facebook page!
Need help? Take a look at our
Wiki and our
Forums.I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe? ~ Carly Rae Jepsen parody