Skip to content

Instantly share code, notes, and snippets.

@gideongrinberg
Last active September 29, 2019 16:06
Show Gist options
  • Save gideongrinberg/87a93990d9d5dd833b76ab3bca3d8e32 to your computer and use it in GitHub Desktop.
Save gideongrinberg/87a93990d9d5dd833b76ab3bca3d8e32 to your computer and use it in GitHub Desktop.
An EV3dev2 Python Script that uses a PID algorithm to correct drift.
from ev3dev2.sensor.lego import GyroSensor
gyro = GyroSensor()
gyro.mode = GYRO-ANG
def gyroPID(ki,kp,kd,target,wheel,speed,distance)
while True:
error = target - gyro.mode
integral = integral + error
error - last_error = derivative
integralResult = integral*ki
porportionResult = kp*error
derivResult = kd*derivative
result = integralResult+derivResult+porportionResult
tank_drive = MoveTank(OUTPUT_A, OUTPUT_B)
r = wheel/distance
tank.on(result)
error = lastError
""" TODO: Incorprate move block into correction to allow this to run while moving forward.
Add to Griffy Class."""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment