Skip to content

Instantly share code, notes, and snippets.

@vixtory09678
Last active June 27, 2019 15:30
Show Gist options
  • Save vixtory09678/e9eebc048b91bb1caeb643e0e4205a6f to your computer and use it in GitHub Desktop.
Save vixtory09678/e9eebc048b91bb1caeb643e0e4205a6f to your computer and use it in GitHub Desktop.
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