I’ve been having an issue with my VEX IQ RC controller drifting for a while, and I’m not sure how to fix it.
I was wondering if it would be possible to solve this using Python or a PID controller. My idea is to use the gyro sensor to automatically correct the drift so that, when I’m driving straight without turning the controller, the robot keeps moving in a straight line.
Basically, I’m looking for a way to create code that continuously compensates for the drift automatically.
You can code in your own custom dead zones so that subtle joystick drift gets ignored.
How you implement it would depend on how you have configured your controls.
For example, if you are using only the left joystick for control (up/down for forward/reverse and left/right for turning), you original code snippet might look like this:
and with a dead zone for the horizontal axis, it could look something like this:
while True:
ljoy_vertical = controller.axisA.position()
ljoy_horizontal = controller.axisB.position()
if ljoy_horizontal < 10: # adjust dead zone here
ljoy_horizontal = 0
l_motor_power = ljoy_vertical + ljoy_horizontal
r_motor_power = ljoy_vertical - ljoy_horizontal
l_motor.spin(FORWARD, l_motor_power, PERCENT)
r_motor.spin(FORWARD, r_motor_power, PERCENT)
wait(20, MSEC)
This will not guarantee that the robot drives straight though! It will only ensure that subtle joystick drift is ignored (which is one possible cause for the robot not driving straight). To ensure driving straight, you may need to combine this with the gyro implementation that you suggested.