44import wpimath .trajectory .constraint
55from 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
99from wpimath .trajectory import Trajectory , TrajectoryConfig
1010
@@ -47,38 +47,30 @@ def getTestTrajectory(config: TrajectoryConfig) -> Trajectory:
4747
4848def 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
8981def 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#
0 commit comments