def test_set_setpoints(self):
     new_setpoints = [ModifiableSetpoint(0.5 * t, 0.5 * t, t) for t in self.times]
     self.joint_trajectory.set_setpoints(new_setpoints)
     # The last setpoint should be at self.duration due to self.enforce_limits().
     # x and v should also be self.duration due to definition above.
     last_setpoint = ModifiableSetpoint(self.duration, 0.5 * self.duration, self.duration)
     self.assertEqual(self.joint_trajectory.setpoints[-1], last_setpoint)
    def test_undo_max_history_memory_redo_list_length(self):
        new_setpoint = ModifiableSetpoint(1.5, 0, 0)
        self.joint_trajectory.add_setpoint(new_setpoint)
        for i in range(100):
            new_setpoint = ModifiableSetpoint((i + 1) / 101.0, 0, 0)
            self.joint_trajectory.add_setpoint(new_setpoint)

        for i in range(110):
            self.joint_trajectory.undo()
        self.assertEqual(len(self.joint_trajectory.setpoints_redo_list), 100)
    def test_undo_max_history_memory(self):
        new_setpoint = ModifiableSetpoint(1.5, 0, 0)
        self.joint_trajectory.add_setpoint(new_setpoint)
        setpoints_copy = copy.deepcopy(self.joint_trajectory.setpoints)
        for i in range(100):
            new_setpoint = ModifiableSetpoint((i + 1) / 101.0, 0, 0)
            self.joint_trajectory.add_setpoint(new_setpoint)

        for i in range(110):
            self.joint_trajectory.undo()
        self.assertEqual(self.joint_trajectory.setpoints, setpoints_copy)
 def test_undo_multiple_things(self):
     new_setpoint = ModifiableSetpoint(0.5, 0, 0)
     self.joint_trajectory.add_setpoint(new_setpoint)
     setpoints_copy = copy.deepcopy(self.joint_trajectory.setpoints)
     new_setpoint = ModifiableSetpoint(0.7, 0, 0)
     self.joint_trajectory.add_setpoint(new_setpoint)
     self.joint_trajectory.invert()
     self.joint_trajectory.remove_setpoint(2)
     self.joint_trajectory.remove_setpoint(2)
     self.joint_trajectory.undo()
     self.joint_trajectory.undo()
     self.joint_trajectory.undo()
     self.joint_trajectory.undo()
     self.assertEqual(self.joint_trajectory.setpoints, setpoints_copy)
 def test_undo_redo_add_setpoint(self):
     new_setpoint = ModifiableSetpoint(0.5, 0, 0)
     self.joint_trajectory.add_setpoint(new_setpoint)
     setpoints_copy = copy.deepcopy(self.joint_trajectory.setpoints)
     self.joint_trajectory.undo()
     self.joint_trajectory.redo()
     self.assertEqual(self.joint_trajectory.setpoints, setpoints_copy)
    def test_undo_history_length(self):
        for i in range(100):
            new_setpoint = ModifiableSetpoint((i + 1) / 101.0, 0, 0)
            self.joint_trajectory.add_setpoint(new_setpoint)

        for i in range(80):
            self.joint_trajectory.undo()
        self.assertEqual(len(self.joint_trajectory.setpoints_history), 20)
 def setUp(self):
     self.gait_generator = Mock()
     self.joint_name = 'test_joint'
     self.limits = Limits(-1, 1, 2)
     self.duration = 2.0
     self.times = [0, self.duration / 2.0, self.duration]
     self.setpoints = [ModifiableSetpoint(t, 0.5 * t, t) for t in self.times]
     self.joint_trajectory = ModifiableJointTrajectory(self.joint_name, self.limits, copy.deepcopy(self.setpoints),
                                                       self.duration, self.gait_generator)
Exemple #8
0
 def test_set_duration_no_rescale_shorter(self):
     extra_setpoint = ModifiableSetpoint(0.4, 0, 0)
     self.subgait.get_joint("right_ankle").add_setpoint(extra_setpoint)
     self.subgait.get_joint("left_ankle").add_setpoint(extra_setpoint)
     self.subgait.get_joint("right_hip_fe").add_setpoint(extra_setpoint)
     self.subgait.scale_timestamps_subgait(0.8, False)
     self.assertEqual(len(self.subgait.get_joint("left_knee").setpoints), 2)
     self.assertEqual(self.subgait.duration, 0.8)
     self.assertEqual([joint.duration for joint in self.subgait.joints],
                      [0.8] * 8)
class ModifiableSetpointTest(unittest.TestCase):
    def setUp(self):
        self.setpoint = ModifiableSetpoint(1.123412541, 0.034341255, 123.162084549)

    def test_invert_time(self):
        self.setpoint.invert(2)
        self.assertAlmostEqual(self.setpoint.time, 2 - 1.123412541, 4)

    def test_invert_position(self):
        self.setpoint.invert(2)
        self.assertAlmostEqual(self.setpoint.position, 0.034341255, 4)

    def test_invert_velocity(self):
        self.setpoint.invert(2)
        self.assertAlmostEqual(self.setpoint.velocity, -123.162084549, 4)
 def test_remove_setpoint_removal_correct_setpoint(self):
     self.joint_trajectory.remove_setpoint(0)
     new_first_setpoint = ModifiableSetpoint(0, 0.5, 1)
     self.assertEqual(self.joint_trajectory.setpoints[0], new_first_setpoint)
 def test_add_setpoint_save_changed_joints_call(self):
     new_setpoint = ModifiableSetpoint(0.5, 0, 0)
     self.joint_trajectory.add_setpoint(new_setpoint)
     self.gait_generator.save_changed_settings.assert_called_once_with({'joints': [self.joint_trajectory]})
 def test_add_setpoint_number_of_setpoints(self):
     new_setpoint = ModifiableSetpoint(0.5, 0, 0)
     self.joint_trajectory.add_setpoint(new_setpoint)
     self.assertEqual(len(self.joint_trajectory.setpoints), 4)
 def test_add_setpoint_existence_new_setpoint(self):
     new_setpoint = ModifiableSetpoint(0.5, self.limits.upper + 1, 0)
     self.joint_trajectory.add_setpoint(new_setpoint)
     new_setpoint_limited = ModifiableSetpoint(0.5, self.limits.upper, 0)
     self.assertEqual(self.joint_trajectory.setpoints[1], new_setpoint_limited)
 def setUp(self):
     self.setpoint = ModifiableSetpoint(1.123412541, 0.034341255, 123.162084549)