Skip to content

Commit 938bd42

Browse files
committed
[maxswerve/swerveutils] Fix sign bug
1 parent b2d0024 commit 938bd42

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

examples/maxswerve/swerveutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def stepTowardsCircular(current: float, target: float, stepsize: float) -> float
4141
current = wrapAngle(current)
4242
target = wrapAngle(target)
4343

44-
stepDirection = math.copysign(target - current, 1)
44+
stepDirection = math.copysign(1, target - current)
4545
difference = abs(current - target)
4646

4747
if difference <= stepsize:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import swerveutils
2+
3+
def test_stepTowardsCircular1():
4+
current = 0.6408134451373411
5+
stepsize = 0.3455804605358387
6+
target = 0.0 # stepping towards zero direction
7+
result = swerveutils.stepTowardsCircular(current=current, stepsize=stepsize, target=target)
8+
assert abs(result) < abs(current), f"swerveutils: why stepping from {current} to {target} results in {result}?"

0 commit comments

Comments
 (0)