Skip to content

Commit 970ef62

Browse files
committed
[maxswerve/swerveutils] Fix sign bug
1 parent b2d0024 commit 970ef62

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

examples/maxswerve/swerveutils.py

+1-1
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:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (c) FIRST and other WPILib contributors.
3+
# Open Source Software; you can modify and/or share it under the terms of
4+
# the WPILib BSD license file in the root directory of this project.
5+
#
6+
7+
import swerveutils
8+
9+
10+
def test_stepTowardsCircular1():
11+
current = 0.6408134451373411
12+
stepsize = 0.3455804605358387
13+
target = 0.0 # stepping towards zero direction
14+
result = swerveutils.stepTowardsCircular(
15+
current=current, stepsize=stepsize, target=target
16+
)
17+
# stepping towards zero angle should result in smaller absolute value
18+
assert abs(result) < abs(current)

0 commit comments

Comments
 (0)