Hi, this coding is something I picked up and want to learn more for our team. The one thing I have tried to look for is how to utilize the inertial sensor to turn 90 degrees and if it over turns it automatically corrects it self to turn back to the initial degree. If anyone would help with what the code should look like since I am very lost and would like any type of support.
I would recommend starting with a simple p loop.
the way this works is that you find your error, which is the difference between your intended angle (in this case, 90 degrees) and your current angle (found with the sensor). This error should get closer to 0 as your robot gets closer to facing the intended value.
error = intended angle - current angle
Then you use a p constant, tuned by you, to turn your error into a value you can put in your motors.
motor power = p*error
then with that motor power value you can simply plug it into your drive motors (some motors will have to be in reverse depending on how your motors are oriented or configured)
and your robot should move towards your target angle. You will have to tune the p value yourself, so play around with it until you get a speed and accuracy you like.
The advantage of a p loop is that your robot will move slower the closer it gets to your target angle, that way you end up with higher precision and accuracy.
you can make it even more accurate and reliable with more complicated control loops, like pd or pid, but that’s a bit more complex.
https://www.vexforum.com/t/inertial-sensor-turn-help/73720 so is this what you are trying to say?
yes, that is a good example of a p loop (the corrected version in the topic, not the original malfunctioning one in the first post)
Ok thank you so much
To build onto what Xenon said earlier, you can also consider using a PID loop in the, which builds on a P loop and is more effective. Here are some good resources on turning PID
General PID introduction:
Turn PID tutorial by Connor from 1814D
here is another set of readings that mention proportional control
Like these other people said, P and PID are OP. I used a PD controller (basically a PID with kI set to zero) and my turning was super accurate around the whole field in my skills routine.
Having the integral term will decrease settling times and also increase the degree of precision the controller can achieve by eliminating steady-state error