Skip to content

Commit 776735d

Browse files
committed
Updated examples for better encoder firmware
1 parent 87fa5c0 commit 776735d

11 files changed

Lines changed: 14 additions & 24 deletions

examples/motors/driving_sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def sleep_until(end_time):
111111

112112
# Capture the state of all the encoders
113113
for i in range(NUM_MOTORS):
114-
captures[i] = board.encoders[i].capture(UPDATE_RATE)
114+
captures[i] = board.encoders[i].capture()
115115

116116
for i in range(NUM_MOTORS):
117117
# Calculate the acceleration to apply to the motor to move it closer to the velocity setpoint

examples/motors/position_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def sleep_until(end_time):
7676
start_time = time.monotonic()
7777

7878
# Capture the state of the encoder
79-
capture = enc.capture(UPDATE_RATE)
79+
capture = enc.capture()
8080

8181
# Calculate how far along this movement to be
8282
percent_along = min(update / UPDATES_PER_MOVE, 1.0)

examples/motors/position_on_velocity_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def sleep_until(end_time):
8383
start_time = time.monotonic()
8484

8585
# Capture the state of the encoder
86-
capture = enc.capture(UPDATE_RATE)
86+
capture = enc.capture()
8787

8888
# Calculate how far along this movement to be
8989
percent_along = min(update / UPDATES_PER_MOVE, 1.0)

examples/motors/position_wave.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def sleep_until(end_time):
7777

7878
# Capture the state of all the encoders
7979
for i in range(NUM_MOTORS):
80-
captures[i] = board.encoders[i].capture(UPDATE_RATE)
80+
captures[i] = board.encoders[i].capture()
8181

8282
# Calculate how far along this movement to be
8383
percent_along = min(update / UPDATES_PER_MOVE, 1.0)

examples/motors/reactive_encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def sleep_until(end_time):
9191
start_time = time.monotonic()
9292

9393
# Capture the state of the encoder
94-
capture = enc.capture(UPDATE_RATE)
94+
capture = enc.capture()
9595

9696
# Get the current detent's centre angle
9797
detent_angle = (current_detent * DETENT_SIZE)

examples/motors/tuning/motor_profiler.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
DUTY_STEPS = 100 # How many duty cycle steps to sample the speed of
1818
SETTLE_TIME = 0.1 # How long to wait after changing motor duty cycle
1919
CAPTURE_TIME = 0.2 # How long to capture the motor's speed at each step
20-
SLEEP_STEP = 0.02 # The time between taking counts during counting_sleep()
2120

2221
# Create a new InventorHATMini and get a motor and encoder from it
2322
board = InventorHATMini(motor_gear_ratio=GEAR_RATIO, init_leds=False)
@@ -34,32 +33,23 @@
3433
enc.direction(DIRECTION)
3534

3635

37-
# The encoder needs to be read semi-regularly to avoid the chip's internal counter
38-
# from wrapping and giving us wrong speed measurements, so use this instead of time.sleep()
39-
def counting_sleep(duration):
40-
start = time.monotonic()
41-
while time.monotonic() - start < duration:
42-
enc.count() # We don't do anything with the returned count
43-
time.sleep(SLEEP_STEP)
44-
45-
4636
# Function that performs a single profiling step
4737
def profile_at_duty(duty):
4838
# Set the motor to a new duty cycle and wait for it to settle
4939
if DIRECTION == 1:
5040
m.duty(0.0 - duty)
5141
else:
5242
m.duty(duty)
53-
counting_sleep(SETTLE_TIME)
43+
time.sleep(SETTLE_TIME)
5444

5545
# Perform a dummy capture to clear the encoder
56-
enc.capture(SETTLE_TIME)
46+
enc.capture()
5747

5848
# Wait for the capture time to pass
59-
counting_sleep(CAPTURE_TIME)
49+
time.sleep(CAPTURE_TIME)
6050

6151
# Perform a capture and read the measured speed
62-
capture = enc.capture(CAPTURE_TIME)
52+
capture = enc.capture()
6353
measured_speed = capture.revolutions_per_second
6454

6555
# These are some alternate speed measurements from the encoder

examples/motors/tuning/position_on_velocity_tuning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def sleep_until(end_time):
8181
start_time = time.monotonic()
8282

8383
# Capture the state of the encoder
84-
capture = enc.capture(UPDATE_RATE)
84+
capture = enc.capture()
8585

8686
# Calculate the velocity to move the motor closer to the position setpoint
8787
vel = pos_pid.calculate(capture.degrees, capture.degrees_per_second)

examples/motors/tuning/position_tuning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def sleep_until(end_time):
7474
start_time = time.monotonic()
7575

7676
# Capture the state of the encoder
77-
capture = enc.capture(UPDATE_RATE)
77+
capture = enc.capture()
7878

7979
# Calculate the velocity to move the motor closer to the position setpoint
8080
vel = pos_pid.calculate(capture.degrees, capture.degrees_per_second)

examples/motors/tuning/velocity_tuning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def sleep_until(end_time):
7474
start_time = time.monotonic()
7575

7676
# Capture the state of the encoder
77-
capture = enc.capture(UPDATE_RATE)
77+
capture = enc.capture()
7878

7979
# Calculate the acceleration to apply to the motor to move it closer to the velocity setpoint
8080
accel = vel_pid.calculate(capture.revolutions_per_second)

examples/motors/velocity_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def sleep_until(end_time):
7676
start_time = time.monotonic()
7777

7878
# Capture the state of the encoder
79-
capture = enc.capture(UPDATE_RATE)
79+
capture = enc.capture()
8080

8181
# Calculate how far along this movement to be
8282
percent_along = min(update / UPDATES_PER_MOVE, 1.0)

0 commit comments

Comments
 (0)