Skip to content

Commit

Permalink
test serializing top/bottom angles
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed May 22, 2024
1 parent fc4bb2d commit be0a555
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,14 @@ public void addTorque(double value) {
* @return angle in degrees
*/
public double getAngleMax() {
if(hinge==null) return 0;
return Math.toDegrees(hinge.getParam(DJoint.PARAM_N.dParamHiStop1));
return top;
}

/**
* @return angle in degrees
*/
public double getAngleMin() {
if(hinge==null) return 0;
return Math.toDegrees(hinge.getParam(DJoint.PARAM_N.dParamLoStop1));
return bottom;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,27 @@ public void test() {
Assertions.assertNotNull(afterHinge2.getHinge().getBody(0));
Assertions.assertNotNull(afterHinge2.getHinge().getBody(1));
}

// test that serializing with infinite limits works, and with non-infinite limits works.
@Test
public void testLimits() {
Registry.start();

ODEHinge before = new ODEHinge();
before.setAngleMax(Double.POSITIVE_INFINITY);
before.setAngleMin(Double.NEGATIVE_INFINITY);
JSONObject json = before.toJSON();
ODEHinge after = new ODEHinge();
after.fromJSON(json);
Assertions.assertEquals(Double.POSITIVE_INFINITY,after.getAngleMax());
Assertions.assertEquals(Double.NEGATIVE_INFINITY,after.getAngleMin());

before.setAngleMax(90);
before.setAngleMin(-90);
json = before.toJSON();
after = new ODEHinge();
after.fromJSON(json);
Assertions.assertEquals(90,after.getAngleMax());
Assertions.assertEquals(-90,after.getAngleMin());
}
}

0 comments on commit be0a555

Please sign in to comment.