Skip to content

Commit 08ffed9

Browse files
committed
Update wpimath tests, add additional fromFeet to Translation2d
1 parent 62a3b82 commit 08ffed9

File tree

3 files changed

+20
-36
lines changed

3 files changed

+20
-36
lines changed

subprojects/robotpy-wpimath/gen/geometry/Translation2d.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ inline_code: |
5151
.def_static("fromFeet", [](units::foot_t x, units::foot_t y){
5252
return std::make_unique<Translation2d>(x, y);
5353
}, py::arg("x"), py::arg("y"))
54+
.def_static("fromFeet", [](units::foot_t distance, const Rotation2d &angle) {
55+
return std::make_unique<Translation2d>(distance, angle);
56+
}, py::arg("distance"), py::arg("angle"))
5457
.def_property_readonly("x", &Translation2d::X)
5558
.def_property_readonly("y", &Translation2d::Y)
5659
.def_property_readonly("x_feet", [](Translation2d * self) -> units::foot_t {

subprojects/robotpy-wpimath/tests/test_trajectory.py

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import wpimath.trajectory.constraint
55
from wpimath.spline import CubicHermiteSpline, SplineHelper
66

7-
from wpimath.geometry import Pose2d, Rotation2d, Translation2d
7+
from wpimath.geometry import Ellipse2d, Pose2d, Rectangle2d, Rotation2d, Translation2d
88

99
from wpimath.trajectory import Trajectory, TrajectoryConfig
1010

@@ -47,38 +47,30 @@ def getTestTrajectory(config: TrajectoryConfig) -> Trajectory:
4747

4848
def test_elliptical_region_constraint():
4949
maxVelocity = 2
50+
ellipse = Ellipse2d.fromFeet(Pose2d.fromFeet(5, 2.5, math.radians(180)), 5, 2.5)
51+
5052
config = TrajectoryConfig.fromFps(13, 13)
5153
maxVelConstraint = MaxVelocityConstraint.fromFps(maxVelocity)
52-
regionConstraint = EllipticalRegionConstraint.fromFeet(
53-
Translation2d.fromFeet(5, 2.5),
54-
10,
55-
5,
56-
Rotation2d.fromDegrees(180),
57-
maxVelConstraint,
58-
)
54+
regionConstraint = EllipticalRegionConstraint(ellipse, maxVelConstraint)
5955

6056
config.addConstraint(regionConstraint)
6157

6258
trajectory = getTestTrajectory(config)
6359

6460
exceededConstraintOutsideRegion = False
6561
for point in trajectory.states():
66-
translation = point.pose.translation()
67-
if translation.x_feet < 10 and translation.y_feet < 5:
62+
if ellipse.contains(point.pose.translation()):
6863
assert abs(point.velocity_fps) < maxVelocity + 0.05
6964
elif abs(point.velocity_fps) >= maxVelocity + 0.05:
7065
exceededConstraintOutsideRegion = True
7166

72-
assert exceededConstraintOutsideRegion
73-
74-
75-
def test_elliptical_region_is_pose_in_region():
76-
maxVelConstraint = MaxVelocityConstraint.fromFps(2)
77-
regionConstraintNoRotation = EllipticalRegionConstraint.fromFeet(
78-
Translation2d.fromFeet(1, 1), 2, 4, Rotation2d(0), maxVelConstraint
79-
)
67+
# translation = point.pose.translation()
68+
# if translation.x_feet < 10 and translation.y_feet < 5:
69+
# assert abs(point.velocity_fps) < maxVelocity + 0.05
70+
# elif abs(point.velocity_fps) >= maxVelocity + 0.05:
71+
# exceededConstraintOutsideRegion = True
8072

81-
assert not regionConstraintNoRotation.isPoseInRegion(Pose2d.fromFeet(2.1, 1, 0))
73+
assert exceededConstraintOutsideRegion
8274

8375

8476
#
@@ -88,37 +80,26 @@ def test_elliptical_region_is_pose_in_region():
8880

8981
def test_rectangular_region_constraint():
9082
maxVelocity = 2
83+
rectangle = Rectangle2d(Translation2d.fromFeet(1, 1), Translation2d.fromFeet(5, 27))
84+
9185
config = TrajectoryConfig.fromFps(13, 13)
9286
maxVelConstraint = MaxVelocityConstraint.fromFps(maxVelocity)
93-
regionConstraint = RectangularRegionConstraint(
94-
Translation2d.fromFeet(1, 1),
95-
Translation2d.fromFeet(5, 27),
96-
maxVelConstraint,
97-
)
87+
regionConstraint = RectangularRegionConstraint(rectangle, maxVelConstraint)
9888

9989
config.addConstraint(regionConstraint)
10090

10191
trajectory = getTestTrajectory(config)
10292

10393
exceededConstraintOutsideRegion = False
10494
for point in trajectory.states():
105-
if regionConstraint.isPoseInRegion(point.pose):
95+
if rectangle.contains(point.pose.translation()):
10696
assert abs(point.velocity_fps) < maxVelocity + 0.05
10797
elif abs(point.velocity_fps) >= maxVelocity + 0.05:
10898
exceededConstraintOutsideRegion = True
10999

110100
assert exceededConstraintOutsideRegion
111101

112102

113-
def test_rectangular_region_is_pose_in_region():
114-
maxVelConstraint = MaxVelocityConstraint.fromFps(2)
115-
regionConstraint = RectangularRegionConstraint(
116-
Translation2d.fromFeet(1, 1), Translation2d.fromFeet(5, 27), maxVelConstraint
117-
)
118-
assert not regionConstraint.isPoseInRegion(Pose2d())
119-
assert regionConstraint.isPoseInRegion(Pose2d.fromFeet(3, 14.5, Rotation2d()))
120-
121-
122103
#
123104
# TrajectoryParameterizer
124105
#

subprojects/robotpy-wpimath/tests/test_trajectory_exponential_profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from wpimath.trajectory import ExponentialProfileMeterVolts
99

1010
kDt = 0.01
11-
feedforward = SimpleMotorFeedforwardMeters(0, 2.5629, 0.43277)
11+
feedforward = SimpleMotorFeedforwardMeters(0, 2.5629, 0.43277, kDt)
1212
constraints = ExponentialProfileMeterVolts.Constraints.fromCharacteristics(
1313
12, 2.5629, 0.43277
1414
)
@@ -32,7 +32,7 @@ def check_dynamics(
3232
):
3333
next_state = profile.calculate(kDt, current, goal)
3434

35-
signal = feedforward.calculate(current.velocity, next_state.velocity, kDt)
35+
signal = feedforward.calculate(current.velocity, next_state.velocity)
3636

3737
assert abs(signal) < constraints.maxInput + 1e-9
3838

0 commit comments

Comments
 (0)