11package us .ihmc .footstepPlanning .graphSearch .stepExpansion ;
22
33import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .BeforeEach ;
5+ import org .junit .jupiter .api .Disabled ;
46import org .junit .jupiter .api .Test ;
57import us .ihmc .commons .InterpolationTools ;
68import us .ihmc .euclid .geometry .ConvexPolygon2D ;
1921import java .util .*;
2022import java .util .function .ToDoubleFunction ;
2123
22- import static us . ihmc . robotics . Assert . assertTrue ;
24+ import static org . junit . jupiter . api . Assertions .* ;
2325
2426public class ParameterBasedNodeExpansionTest
2527{
2628 private static final double epsilon = 1e-6 ;
29+ private DefaultFootstepPlannerParameters parameters ;
30+
31+ @ BeforeEach
32+ public void setupParameters ()
33+ {
34+ // We create default parameters for the tests
35+ parameters = new DefaultFootstepPlannerParameters ();
36+ }
2737
2838 @ Test
29- public void testExpansionAlongBoundsFromOriginDefaultParametersWithRight ()
39+ public void testExpansionAlongBoundsFromOriginWithRight ()
3040 {
31- DefaultFootstepPlannerParameters parameters = new DefaultFootstepPlannerParameters ();
3241 ParameterBasedStepExpansion expansion = new ParameterBasedStepExpansion (parameters , null , PlannerTools .createDefaultFootPolygons ());
3342 expansion .initialize ();
3443
35- double maxYaw = parameters .getMaxStepYaw ();
36- double minYaw = parameters .getMinStepYaw ();
37-
38- List <FootstepGraphNode > childNodes = new ArrayList <>();
39-
44+ // Set up the feet to test moving a right foot
4045 DiscreteFootstep stanceStep = new DiscreteFootstep (0.0 , 0.0 , 0.0 , RobotSide .LEFT );
4146 DiscreteFootstep startOfSwingStep = new DiscreteFootstep (0.0 , 0.3 , 0.0 , RobotSide .RIGHT );
4247
48+ // Do full expansion of the steps
49+ List <FootstepGraphNode > childNodes = new ArrayList <>();
4350 expansion .doFullExpansion (new FootstepGraphNode (startOfSwingStep , stanceStep ), childNodes );
51+
52+ // Check the edges of where steps can reach in the x and y directions
4453 DiscreteFootstep mostForward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> node .getX ()));
45- DiscreteFootstep furthestReach = getExtremumNode (childNodes , Comparator .comparingDouble (node -> getReachAtNode (node , parameters .getIdealFootstepWidth ())));
4654 DiscreteFootstep mostBackward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -node .getX ()));
4755 DiscreteFootstep mostInward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> node .getY ()));
4856 DiscreteFootstep mostOutward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -node .getY ()));
57+
58+ assertTrue (mostForward .getX () <= parameters .getMaxStepReach ());
59+ assertTrue (mostBackward .getX () >= parameters .getMinStepLength ());
60+ assertTrue (mostInward .getY () <= -parameters .getMinStepWidth ());
61+ assertTrue (mostOutward .getY () >= -parameters .getMaxStepWidth ());
62+
63+ // Check the min and max a step can yaw
4964 DiscreteFootstep mostOutwardYawed = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -snapToCircle (node .getYaw ())));
5065 DiscreteFootstep mostInwardYawed = getExtremumNode (childNodes , Comparator .comparingDouble (node -> snapToCircle (node .getYaw ())));
5166
52- assertTrue (mostForward .getX () < parameters .getMaxStepReach () + epsilon );
53- assertTrue (mostBackward .getX () > parameters .getMinStepLength () - epsilon );
54- assertTrue (mostInward .getY () < -parameters .getMinStepWidth () + epsilon );
55- assertTrue (mostOutward .getY () > -parameters .getMaxStepWidth () - epsilon );
67+ // The yaw is a little tricky because we don't have any notion of things being negative.
68+ // So if the yaw is clockwise (which should be negative) it will be ~5.7 or something just less then 2 PI radians
69+ // To account for this, we need to subtract the yaw we got from 2 PI.
70+ double outwardYawFromZero = Math .PI * 2 - mostOutwardYawed .getYaw ();
71+ assertTrue (outwardYawFromZero <= parameters .getMaxStepYaw ());
72+ assertTrue (mostInwardYawed .getYaw () >= parameters .getMinStepYaw ());
5673
57- assertTrue (getReachAtNode (furthestReach , parameters .getIdealFootstepWidth ()) < parameters .getMaxStepReach ());
74+ // Get the footstep closest to the ideal step and ensure that it's less than the max reach
75+ DiscreteFootstep idealReach = getExtremumNode (childNodes , Comparator .comparingDouble (node -> getReachAtNode (node , parameters .getIdealFootstepWidth ())));
76+ assertTrue (getReachAtNode (idealReach , parameters .getIdealFootstepWidth ()) < parameters .getMaxStepReach ());
5877 }
5978
6079 @ Test
61- public void testExpansionAlongBoundsFromOriginDefaultParametersWithLeft ()
80+ public void testExpansionAlongBoundsFromOriginWithLeft ()
6281 {
63- DefaultFootstepPlannerParameters parameters = new DefaultFootstepPlannerParameters ();
6482 ParameterBasedStepExpansion expansion = new ParameterBasedStepExpansion (parameters , null , PlannerTools .createDefaultFootPolygons ());
6583 expansion .initialize ();
6684
67- double maxYaw = parameters .getMaxStepYaw ();
68- double minYaw = parameters .getMinStepYaw ();
69-
85+ // Set up the feet to test moving a right foot
7086 DiscreteFootstep stanceStep = new DiscreteFootstep (0.0 , 0.0 , 0.0 , RobotSide .RIGHT );
7187 DiscreteFootstep startOfSwingStep = new DiscreteFootstep (0.0 , -0.3 , 0.0 , RobotSide .LEFT );
7288
89+ // Do full expansion of the steps
7390 List <FootstepGraphNode > childNodes = new ArrayList <>();
7491 expansion .doFullExpansion (new FootstepGraphNode (startOfSwingStep , stanceStep ), childNodes );
92+
93+ // Check the edges of where steps can reach in the x and y directions
7594 DiscreteFootstep mostForward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> node .getX ()));
76- DiscreteFootstep furthestReach = getExtremumNode (childNodes , Comparator .comparingDouble (node -> getReachAtNode (node , parameters .getIdealFootstepWidth ())));
7795 DiscreteFootstep mostBackward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -node .getX ()));
7896 DiscreteFootstep mostInward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -node .getY ()));
7997 DiscreteFootstep mostOutward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> node .getY ()));
80- DiscreteFootstep mostOutwardYawed = getExtremumNode (childNodes , Comparator .comparingDouble (node -> snapToCircle (node .getYaw ())));
81- DiscreteFootstep mostInwardYawed = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -snapToCircle (node .getYaw ())));
8298
83- assertTrue (mostForward .getX () < parameters .getMaxStepReach () + epsilon );
84- assertTrue (mostBackward .getX () > parameters .getMinStepLength () - epsilon );
85- assertTrue (mostInward .getY () > parameters .getMinStepWidth () - epsilon );
86- assertTrue (mostOutward .getY () < parameters .getMaxStepWidth () + epsilon );
99+ assertTrue (mostForward .getX () <= parameters .getMaxStepReach ());
100+ assertTrue (mostBackward .getX () >= parameters .getMinStepLength ());
101+ assertTrue (mostInward .getY () >= parameters .getMinStepWidth ());
102+ assertTrue (mostOutward .getY () <= parameters .getMaxStepWidth ());
87103
88- double mostOutwardYawedReach = getReachAtNode (mostOutwardYawed , parameters .getIdealFootstepWidth ());
89- double mostInwardYawedReach = getReachAtNode (mostInwardYawed , parameters .getIdealFootstepWidth ());
90- assertTrue (getReachAtNode (furthestReach , parameters .getIdealFootstepWidth ()) < parameters .getMaxStepReach ());
104+ // Check the min and max a step can yaw
105+ DiscreteFootstep mostOutwardYawed = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -snapToCircle (node .getYaw ())));
106+ DiscreteFootstep mostInwardYawed = getExtremumNode (childNodes , Comparator .comparingDouble (node -> snapToCircle (node .getYaw ())));
107+
108+ // The yaw is a little tricky because we don't have any notion of things being negative.
109+ // So if the yaw is clockwise (which should be negative) it will be ~5.7 or something just less then 2 PI radians
110+ // To account for this, we need to subtract the yaw we got from 2 PI.
111+ double outwardYawFromZero = Math .PI * 2 - mostOutwardYawed .getYaw ();
112+ assertTrue (outwardYawFromZero <= parameters .getMaxStepYaw ());
113+ assertTrue (mostInwardYawed .getYaw () >= parameters .getMinStepYaw ());
114+
115+ // Get the footstep closest to the ideal step and ensure that it's less than the max reach
116+ DiscreteFootstep idealReach = getExtremumNode (childNodes , Comparator .comparingDouble (node -> getReachAtNode (node , parameters .getIdealFootstepWidth ())));
117+ assertTrue (getReachAtNode (idealReach , parameters .getIdealFootstepWidth ()) < parameters .getMaxStepReach ());
91118 }
92119
93120 @ Test
94121 public void testExpansionAlongBoundsFromOrigin ()
95122 {
96- DefaultFootstepPlannerParameters parameters = new DefaultFootstepPlannerParameters ();
97123 ParameterBasedStepExpansion expansion = new ParameterBasedStepExpansion (parameters , null , PlannerTools .createDefaultFootPolygons ());
98124 expansion .initialize ();
99125
@@ -112,7 +138,8 @@ public void testExpansionAlongBoundsFromOrigin()
112138 List <FootstepGraphNode > childNodes = new ArrayList <>();
113139 expansion .doFullExpansion (new FootstepGraphNode (startOfSwingStep , stanceStep ), childNodes );
114140 DiscreteFootstep mostForward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> node .getX ()));
115- DiscreteFootstep furthestReach = getExtremumNode (childNodes , Comparator .comparingDouble (node -> getReachAtNode (node , parameters .getIdealFootstepWidth ())));
141+ DiscreteFootstep furthestReach = getExtremumNode (childNodes ,
142+ Comparator .comparingDouble (node -> getReachAtNode (node , parameters .getIdealFootstepWidth ())));
116143 DiscreteFootstep mostBackward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -node .getX ()));
117144 DiscreteFootstep mostInward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> node .getY ()));
118145 DiscreteFootstep mostOutward = getExtremumNode (childNodes , Comparator .comparingDouble (node -> -node .getY ()));
@@ -171,11 +198,11 @@ else if (comparator.compare(node.getSecondStep(), extremumNode) == 1)
171198 @ Test
172199 public void testPartialExpansionSize ()
173200 {
174- DefaultFootstepPlannerParameters parameters = new DefaultFootstepPlannerParameters ();
175201 int branchFactor = 100 ;
176202 parameters .setMaxBranchFactor (branchFactor );
177203
178- IdealStepCalculatorInterface idealStepCalculator = (stance , startOfSwing ) -> new DiscreteFootstep (stance .getLatticePoint (), stance .getRobotSide ().getOppositeSide ());
204+ IdealStepCalculatorInterface idealStepCalculator = (stance , startOfSwing ) -> new DiscreteFootstep (stance .getLatticePoint (),
205+ stance .getRobotSide ().getOppositeSide ());
179206 ParameterBasedStepExpansion expansion = new ParameterBasedStepExpansion (parameters , idealStepCalculator , PlannerTools .createDefaultFootPolygons ());
180207
181208 expansion .initialize ();
@@ -202,7 +229,13 @@ public void testPartialExpansionSize()
202229 Assertions .assertTrue (expansionList .isEmpty ());
203230 }
204231
232+ /**
233+ * This test is meant to check if the full expansion returns a sorted list or not.
234+ * We don't always sort the full expansion, so by default, this test is
235+ * disabled.
236+ */
205237 @ Test
238+ @ Disabled
206239 public void testFullExpansionReturnsSortedOrder ()
207240 {
208241 Random random = new Random (329032 );
@@ -230,7 +263,8 @@ public void testFullExpansionReturnsSortedOrder()
230263 expansion .doFullExpansion (node , fullExpansion );
231264 List <FootstepGraphNode > fullExpansionSorted = new ArrayList <>(fullExpansion );
232265
233- ToDoubleFunction <FootstepGraphNode > stepDistance = step -> ParameterBasedStepExpansion .IdealStepProximityComparator .calculateStepProximity (step .getSecondStep (), idealStep );
266+ ToDoubleFunction <FootstepGraphNode > stepDistance = step -> ParameterBasedStepExpansion .IdealStepProximityComparator .calculateStepProximity (step .getSecondStep (),
267+ idealStep );
234268 Comparator <FootstepGraphNode > sorter = Comparator .comparingDouble (stepDistance );
235269 fullExpansionSorted .sort (sorter );
236270
0 commit comments