So I want to make a function in which I can insert how many degrees I want it to turn and it will turn the robot that amount of degrees. The problem is I don’t know how I can go about accurately programming values which will make the robot turn the inputted degrees. It would be preferential if the robot would be doing a point turn, but a swing turn could also be helpful. Also, if it wasn’t obvious, please don’t try and write the code for me, I want to learn.
last year what my team did was the brute force method, using a stopwatch and timing the amount of time it takes to spin 360 degrees, and then dividing up that time to find the time taken to spin x degrees. Of course this will require a lot of testing to find the exact time, and would be less exact then going off of a count of motor revolutions to turn x degrees. You could also similarly guess-and-check with motor revolutions, until you find how many revolutions it takes to get to 360, then again dividing up the number of revolutions to get your desired turn. I’d always recommend measuring it to 360 degrees or greater, so small inconsistencies will fall away, rather than finding the motor spin required for, say, 40 degrees.
Someone please correct me if I’m wrong, but I can’t think of any math that could help you. If someone else knows the math required to calculate this stuff by all means let me know, but otherwise you may just be stuck to brute forcing it.
Here are some options:
- Use an inertial sensor and turn really slowly. Like, 10% velocity. Use a drivetrain: it will save you lots of code.
- Create a program that outputs motor rotation values. Slowly turn the robot on its center of rotation. Go until you hit 90% (for this use a floor tile or something). Keep track of the motor rotation values and use those (scale as necessary).
It’s possible to do the math theoretically, using the distance between each side of the chassis, the diameter of the wheel, and arc length formula to calculate the needed degrees per turn. However, generally, it’s best to generate a constant through experimentation, using this method:
Realize that without proper control loops and tuning it will be difficult to guarantee that your turn will hit the proper target each time - if you put in the time and the work, anything is possible.
Is there a reason to go so slow with the inertial sensor? As long as you hold the motor at the end you should be fine going at least 40%
I guess there are multiple reasons.
One is that you reduce chances of wheels slipping.
Another is to reduce vibrations that affect inertial sensor accuracy.
Finally, default V5 motor PID coefficients may not be able to handle high speed overshoot that well.
If you can’t use the inertial sensor for whatever reason, you are able to use encoders. You can set a function to stop the wheels when the encoder value is greater than a constant times the desired angle. This constant varies on all bots, you need to use trial and error to find it.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.