Last active
September 29, 2019 16:06
-
-
Save gideongrinberg/87a93990d9d5dd833b76ab3bca3d8e32 to your computer and use it in GitHub Desktop.
An EV3dev2 Python Script that uses a PID algorithm to correct drift.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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