From fe53fc9b0f7b4530233592269b39f22319214159 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 7 Nov 2016 09:02:26 -0800 Subject: [PATCH 1/3] Update auto-drive.py fixed bugs in the code. is_pressed is a function, as well as proximity. Also when run_timed, you must set the speed not duty cycle. --- demo/EXPLOR3R/auto-drive.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/demo/EXPLOR3R/auto-drive.py b/demo/EXPLOR3R/auto-drive.py index 48a56aa..2a19828 100755 --- a/demo/EXPLOR3R/auto-drive.py +++ b/demo/EXPLOR3R/auto-drive.py @@ -48,6 +48,8 @@ ir = InfraredSensor(); assert ir.connected ts = TouchSensor(); assert ts.connected +print('Robot Starting') + # We will need to check EV3 buttons state. btn = Button() @@ -64,9 +66,9 @@ def backup(): Back away from an obstacle. """ - # Sound backup alarm. + # Sound backup alarm. Sound.tone([(1000, 500, 500)] * 3) - + # Turn backup lights on: for light in (Leds.LEFT, Leds.RIGHT): Leds.set_color(light, Leds.RED) @@ -76,7 +78,7 @@ def backup(): # until both motors are stopped before continuing. for m in motors: m.stop(stop_action='brake') - m.run_timed(duty_cycle_sp=-50, time_sp=1500) + m.run_timed(speed_sp=-500, time_sp=1500) # When motor is stopped, its `state` attribute returns empty list. # Wait until both motors are stopped: @@ -99,7 +101,7 @@ def turn(): t = randint(250, 750) for m, p in zip(motors, power): - m.run_timed(duty_cycle_sp=p*75, time_sp=t) + m.run_timed(speed_sp=p*750, time_sp=t) # Wait until both motors are stopped: while any(m.state for m in motors): @@ -109,7 +111,7 @@ def turn(): start() while not btn.any(): - if ts.is_pressed: + if ts.is_pressed(): # We bumped an obstacle. # Back away, turn and go in other direction. backup() @@ -118,14 +120,14 @@ def turn(): # Infrared sensor in proximity mode will measure distance to the closest # object in front of it. - distance = ir.proximity + distance = ir.proximity() if distance > 60: # Path is clear, run at full speed. - dc = 90 + dc = 95 else: # Obstacle ahead, slow down. - dc = 40 + dc = 30 for m in motors: m.duty_cycle_sp = dc From 3dea7cc9a0f5852b10da6850a88672babb2bc5d9 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 7 Nov 2016 12:37:28 -0800 Subject: [PATCH 2/3] Update auto-drive.py removed whitespace, reverted function calls to properties --- demo/EXPLOR3R/auto-drive.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demo/EXPLOR3R/auto-drive.py b/demo/EXPLOR3R/auto-drive.py index 2a19828..3ff7f70 100755 --- a/demo/EXPLOR3R/auto-drive.py +++ b/demo/EXPLOR3R/auto-drive.py @@ -101,7 +101,7 @@ def turn(): t = randint(250, 750) for m, p in zip(motors, power): - m.run_timed(speed_sp=p*750, time_sp=t) + m.run_timed(speed_sp = p * 750, time_sp = t) # Wait until both motors are stopped: while any(m.state for m in motors): @@ -111,7 +111,7 @@ def turn(): start() while not btn.any(): - if ts.is_pressed(): + if ts.is_pressed: # We bumped an obstacle. # Back away, turn and go in other direction. backup() @@ -120,7 +120,7 @@ def turn(): # Infrared sensor in proximity mode will measure distance to the closest # object in front of it. - distance = ir.proximity() + distance = ir.proximity if distance > 60: # Path is clear, run at full speed. From 7cfe3499163c18588413c88c40c2855f701955fc Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Mon, 7 Nov 2016 21:07:25 -0800 Subject: [PATCH 3/3] Update auto-drive.py --- demo/EXPLOR3R/auto-drive.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/EXPLOR3R/auto-drive.py b/demo/EXPLOR3R/auto-drive.py index 3ff7f70..bae8fe3 100755 --- a/demo/EXPLOR3R/auto-drive.py +++ b/demo/EXPLOR3R/auto-drive.py @@ -66,9 +66,9 @@ def backup(): Back away from an obstacle. """ - # Sound backup alarm. + # Sound backup alarm. Sound.tone([(1000, 500, 500)] * 3) - + # Turn backup lights on: for light in (Leds.LEFT, Leds.RIGHT): Leds.set_color(light, Leds.RED)