[Python-ideas] Inline Functions - idea
Oscar Benjamin
oscar.j.benjamin at gmail.com
Wed Feb 5 15:47:07 CET 2014
On 5 February 2014 14:32, Alex Rodrigues <lemiant at hotmail.com> wrote:
>
> # First without an inline function
> def main():
> file = open('file.txt')
> counter = 0
> while True:
> counter += 1
> frontL, frontR, backL, backR = getWheelSpeeds()
> if counter > 100: # Log at least every 10 seconds
> slipL = abs(frontL - backL)
> slipR = abs(frontR - backR)
> file.write('Speeds: ('+frontL+', '+frontR+', '+backL+',
> '+backR+'), \n Slip: '+slipL+', '+slipR)
> counter = 0
> elif abs(frontR-backR) > 1 or abs(frontL-backL) > 1: # Also log if
> the wheels are slipping
> slipL = abs(frontL - backL)
> slipR = abs(frontR - backR)
> file.write('Speeds: ('+frontL+', '+frontR+', '+backL+',
> '+backR+'), \n Slip: '+slipL+', '+slipR)
> counter = 0
> elif average([frontL, frontR, backL, backR]) > 60: # Also log if
> we're going really fast
> slipL = abs(frontL - backL)
> slipR = abs(frontR - backR)
> file.write('Speeds: ('+frontL+', '+frontR+', '+backL+',
> '+backR+'), \n Slip: '+slipL+', '+slipR)
> counter = 0
> time.sleep(.1)
>
def main():
file = open('file.txt')
counter = 0
while True:
counter += 1
frontL, frontR, backL, backR = getWheelSpeeds()
slipL = abs(frontL - backL)
slipR = abs(frontR - backR)
if (counter > 100
or abs(frontR-backR) > 1
or abs(frontL-backL) > 1
or average([frontL, frontR, backL, backR]) > 60):
counter = 0
file.write('Speeds: ('+frontL+', '+frontR+', '+backL+',
'+backR+'), \n Slip: '+slipL+', '+slipR)
time.sleep(.1)
Oscar
More information about the Python-ideas
mailing list