Reset drivetrain encoders for consistent autonomous

We’re having some issues with consistency in our autonomous, especially with the turning angle. To help with this, we’re wanting to reset the values on the encoders on the drivetrain motors before each time it drives. I see that Motor objects have resetRotation() and resetPostion() methods, but the Drivetrain objects don’t have these methods available. I’ve tried to call them on the individual Motors that are on the Drivetrain, but for some reason the code says it doesn’t recognize those Motor objects that were declared for the Drivetrain.

I’ve googled this a bunch, but have come up with nothing.

Some extra info, we’re using the drivetrain code that is generated in robot-config.cpp by using the GUI motor/controller setup in VexCode Text, so that code is readonly. We can copy/paste it to main.cpp if that’s what’s required, but was hoping to not have to deal with maintaining that. TIA

Your adding a resetRotation() isn’t going to help the methods within the drivetrain class. Those methods account for rotations however they account for them (including possibly resetting rotations.)

If you are using the drivetrain class, you are likely going to have to accept it being less consistent that you could make it with your own code. Thats sort of the point of it… gets you going with not too much to figure out, but isn’t so good that you have no incentive to learn to make better stuff.

That said, are the turns consistently incorrect? If you want it to move 20 but it always moves you 24… then just give it whatever random number that turns into a motion of 20. If you play with the dimensions for your drive base in the class (wheel track, etc.) what happens? If you are not using the inertial sensor, its making a guess on how your bot will turn based on the dimensions you give it. Tweaking them should change turn behavior.

You could also enable advanced editing and fiddle with the gear ratio or wheel size to try and tune your results.


Thanks so much, @DougMoyers. I was wondering that same thing about the Drivetrain. That the class already takes into consideration resetting the encoders, and that’s why it doesn’t give me that option. Our club consists mostly of 6 and 7 graders, so the graphical config option was the quickest way to introduce to using C++.

Yes, the issue was with the consistency of the turn distance. Sometimes it would overturn, sometimes under turn, and sometimes would hit the mark. They’ve been tinkering with the turn angle, but since it was inconsistent, it wasn’t much help.

That’s an interesting thought about monkeying with the drive train. I’ll have them play with that.

However, we were able to find a lot of the issue, and of course it was not programmatic. The robot would sometime drag a cube while turning, which would of course impact how far it turned. They updated it to backup before turning, so it wasn’t touching any other blocks.

1 Like