Skip to content

Commit

Permalink
Fix power distribution tests for platforms with idle thrust
Browse files Browse the repository at this point in the history
  • Loading branch information
gemenerik committed Aug 7, 2024
1 parent 7db59d1 commit 7a66c4c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions test_python/test_power_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,18 @@ def test_power_distribution_cap_when_in_range():
input.motors.m4 = 4000

actual = cffirmware.motors_thrust_pwm_t()
idle_thrust = cffirmware.powerDistributionGetIdleThrust()

# Test
isCapped = cffirmware.powerDistributionCap(input, actual)

# Assert
# control.thrust will be at a (tuned) hover-state
assert not isCapped
assert actual.motors.m1 == input.motors.m1
assert actual.motors.m2 == input.motors.m2
assert actual.motors.m3 == input.motors.m3
assert actual.motors.m4 == input.motors.m4
assert actual.motors.m1 == max(input.motors.m1, idle_thrust)
assert actual.motors.m2 == max(input.motors.m2, idle_thrust)
assert actual.motors.m3 == max(input.motors.m3, idle_thrust)
assert actual.motors.m4 == max(input.motors.m4, idle_thrust)


def test_power_distribution_cap_when_all_negative():
Expand All @@ -140,16 +141,17 @@ def test_power_distribution_cap_when_all_negative():
input.motors.m4 = -4000

actual = cffirmware.motors_thrust_pwm_t()
idle_thrust = cffirmware.powerDistributionGetIdleThrust()

# Test
isCapped = cffirmware.powerDistributionCap(input, actual)

# Assert
assert not isCapped
assert actual.motors.m1 == 0
assert actual.motors.m2 == 0
assert actual.motors.m3 == 0
assert actual.motors.m4 == 0
assert actual.motors.m1 == max(0, idle_thrust)
assert actual.motors.m2 == max(0, idle_thrust)
assert actual.motors.m3 == max(0, idle_thrust)
assert actual.motors.m4 == max(0, idle_thrust)


def test_power_distribution_cap_when_all_above_range():
Expand Down Expand Up @@ -203,13 +205,14 @@ def test_power_distribution_cap_reduces_thrust_equally_much_with_lower_cap():
input.motors.m4 = 0xffff + 10

actual = cffirmware.motors_thrust_pwm_t()
idle_thrust = cffirmware.powerDistributionGetIdleThrust()

# Test
isCapped = cffirmware.powerDistributionCap(input, actual)

# Assert
assert isCapped
assert actual.motors.m1 == 0
assert actual.motors.m2 == 0
assert actual.motors.m3 == 1000 - 10
assert actual.motors.m4 == 0xffff
assert actual.motors.m1 == max(0, idle_thrust)
assert actual.motors.m2 == max(0, idle_thrust)
assert actual.motors.m3 == max(1000 - 10, idle_thrust)
assert actual.motors.m4 == max(0xffff, idle_thrust)

0 comments on commit 7a66c4c

Please sign in to comment.