Last active
June 27, 2019 15:30
-
-
Save vixtory09678/e9eebc048b91bb1caeb643e0e4205a6f to your computer and use it in GitHub Desktop.
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
oldPower = 0.0 | |
power = 0.0 | |
oldVolt = 0.0 | |
volt = 0.0 | |
slope = 1 | |
func calculateOAndP() : | |
volt = readVolt() | |
current = readCurrent() | |
power = volt * current | |
slope = (power - oldPower) / (volt - oldVolt) | |
if slope > 0 : slope = 1 | |
else if slope == 0 : slope = 0 | |
else : slope = -1 | |
volt = volt + (volt - oldVolt) * slope | |
oldPower = power | |
oldVolt = volt | |
return slope | |
main: | |
loop: | |
slope = calculateOAndP() | |
if slope == 1: | |
// drive + | |
else if slope == -1: | |
// drive - | |
else: // slope = 0 | |
// drive stop | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment