Skip to content

Commit

Permalink
more test for waypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
yck011522 committed May 3, 2024
1 parent 576febb commit 754e4b2
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/compas_fab/robots/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,8 @@ def from_frame(cls, frame_WCF, tolerance_position, link_name, tool_coordinate_fr
if tool_coordinate_frame:
frame_WCF = from_tcf_to_t0cf(frame_WCF, tool_coordinate_frame)

sphere = Sphere(radius=tolerance_position, point=frame_WCF.point)
radius = float(tolerance_position)
sphere = Sphere(radius, point=frame_WCF.point)
return cls.from_sphere(link_name, sphere, weight)

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions src/compas_fab/robots/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ class PointAxisWaypoints(Waypoints):
The tool tip coordinate frame relative to the flange coordinate frame of the robot.
If not specified, the target point is relative to the robot's flange (T0CF) and the
Z axis of the flange can rotate around the target axis.
name : str, optional
The human-readable name of the target.
Defaults to 'Point-Axis Waypoints'.
"""

Expand Down
95 changes: 89 additions & 6 deletions tests/robots/test_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
from compas_fab.robots import PointAxisTarget
from compas_fab.robots import ConfigurationTarget
from compas_fab.robots import ConstraintSetTarget
from compas_fab.robots import Waypoints
from compas_fab.robots import JointConstraint
from compas_fab.robots import OrientationConstraint
from compas_fab.robots import PositionConstraint

from compas_fab.robots import FrameWaypoints
from compas_fab.robots import PointAxisWaypoints

Expand All @@ -27,7 +30,14 @@ def tool_coordinate_frame():
return Frame(Point(0.0, 10.0, 20.0), Vector(1.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0))


def test_serialization(target_frame, tool_coordinate_frame):
@pytest.fixture
def target_configuration():
return Configuration.from_prismatic_and_revolute_values(
[10.0, 20.0], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], ["J1", "J2", "J3", "J4", "J5", "J6", "J7", "J8"]
)


def test_serialization_targets(target_frame, tool_coordinate_frame, target_configuration):
tolerance_position = 0.001
tolerance_orientation = 0.001
name = "my testing name"
Expand All @@ -53,9 +63,7 @@ def test_serialization(target_frame, tool_coordinate_frame):
assert target.name == nt.name

# ConfigurationTarget
target_configuration = Configuration.from_prismatic_and_revolute_values(
[10.0, 20.0], [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
)

tolerance_above = [0.01] * 8
tolerance_below = [0.0009] * 8
target = ConfigurationTarget(target_configuration, tolerance_above, tolerance_below, name)
Expand All @@ -65,8 +73,83 @@ def test_serialization(target_frame, tool_coordinate_frame):
assert target.tolerance_below == nt.tolerance_below
assert target.name == nt.name

# ConstraintSetTarget

def test_serialization_constraint_sets(target_frame, tool_coordinate_frame, target_configuration):
tolerance_above = [0.01] * 8
tolerance_below = [0.0009] * 8
name = "my testing name"

# ConstraintSetTarget with JointConstraint
constraint_set = JointConstraint.joint_constraints_from_configuration(
target_configuration, tolerance_above, tolerance_below
)
target = ConstraintSetTarget(constraint_set, name)
nt = ConstraintSetTarget.__from_data__(target.__data__)
assert target.constraint_set == nt.constraint_set
assert target.name == nt.name
for c1, c2 in zip(target.constraint_set, nt.constraint_set):
assert c1.__data__ == c2.__data__

# ConstraintSetTarget with OrientationConstraint and Po
link_name = "tool0"
tolerances_orientation = [0.0123] * 3
orientation_constraint_weight = 0.789
orientation_constraint = OrientationConstraint.from_frame(
target_frame, tolerances_orientation, link_name, tool_coordinate_frame, orientation_constraint_weight
)
position_constraint_weight = 0.456
tolerances_position = 0.567
position_constraint = PositionConstraint.from_frame(
target_frame, tolerances_position, link_name, tool_coordinate_frame, position_constraint_weight
)
target = ConstraintSetTarget([orientation_constraint, position_constraint], name)
nt = ConstraintSetTarget.__from_data__(target.__data__)
assert target.constraint_set == nt.constraint_set
assert target.name == nt.name
for c1, c2 in zip(target.constraint_set, nt.constraint_set):
assert c1.__data__ == c2.__data__


@pytest.fixture
def frame_waypoints():
target_frames = []
target_frames.append(Frame(Point(1.0, -2.0, 3.0), Vector(1.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)))
target_frames.append(Frame(Point(4.0, -5.0, 6.0), Vector(1.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)))
target_frames.append(Frame(Point(7.0, -8.0, 9.0), Vector(-1.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0)))
tolerance_position = 0.001
tolerance_orientation = 0.001
tool_coordinate_frame = Frame(Point(0.0, 10.0, 20.0), Vector(1.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0))
name = "my testing waypoints"
return FrameWaypoints(target_frames, tolerance_position, tolerance_orientation, tool_coordinate_frame, name)


@pytest.fixture
def point_axis_waypoints():
target_points_and_axes = []
target_points_and_axes.append((Point(1.0, -2.0, 3.0), Vector(1.0, 0.0, 0.0)))
target_points_and_axes.append((Point(4.0, -5.0, 6.0), Vector(1.0, 0.0, 0.0)))
target_points_and_axes.append((Point(7.0, -8.0, 9.0), Vector(-1.0, 0.0, 0.0)))
tolerance_position = 0.001
tool_coordinate_frame = Frame(Point(0.0, 10.0, 20.0), Vector(1.0, 0.0, 0.0), Vector(0.0, 1.0, 0.0))
name = "my testing waypoints"
return PointAxisWaypoints(target_points_and_axes, tolerance_position, tool_coordinate_frame, name)


def test_serialization_waypoints(frame_waypoints, point_axis_waypoints):
# FrameWaypoints
nt = FrameWaypoints.__from_data__(frame_waypoints.__data__)
for f1, f2 in zip(frame_waypoints.target_frames, nt.target_frames):
assert f1 == f2
assert TOL.is_close(frame_waypoints.tolerance_position, nt.tolerance_position)
assert TOL.is_close(frame_waypoints.tolerance_orientation, nt.tolerance_orientation)
assert frame_waypoints.tool_coordinate_frame == nt.tool_coordinate_frame
assert frame_waypoints.name == nt.name

# PointAxisWaypoints
nt = PointAxisWaypoints.__from_data__(point_axis_waypoints.__data__)
for (p1, a1), (p2, a2) in zip(point_axis_waypoints.target_points_and_axes, nt.target_points_and_axes):
assert p1 == p2
assert a1 == a2
assert point_axis_waypoints.tolerance_position == nt.tolerance_position
assert point_axis_waypoints.tool_coordinate_frame == nt.tool_coordinate_frame
assert point_axis_waypoints.name == nt.name

0 comments on commit 754e4b2

Please sign in to comment.