Ejemplo n.º 1
0
    def test_robot_transparency(self):
        # Update scene
        self.scene.scene.title = "Test Robot Transparency"

        # Create two joints
        joint1 = robot.RotationalJoint(self.se3, self.structure, self.scene)
        joint2 = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Create robot
        robot1 = robot.GraphicalRobot(self.scene, "Robot 1")

        # Add joints
        robot1.append_made_link(joint1)
        robot1.append_made_link(joint2)

        # Change opacity value
        opc_val = 0.33
        robot1.set_transparency(opc_val)

        # Verify change in all joints
        self.assertEqual(joint1.get_graphic_object().opacity, opc_val)
        self.assertEqual(joint2.get_graphic_object().opacity, opc_val)

        # Test bad opc val
        self.assertRaises(ValueError, robot1.set_transparency, -0.2)
Ejemplo n.º 2
0
    def test_robot_append_made_link(self):
        # Update scene
        self.scene.scene.title = "Test Robot Append Made Link"

        # Create 2 joints
        joint1 = robot.RotationalJoint(self.se3, self.structure, self.scene)
        joint2 = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Create robot
        robot1 = robot.GraphicalRobot(self.scene, "Robot 1")

        # Add 1 joint
        robot1.append_made_link(joint1)

        # Print joint poses to prove its added
        robot1.print_joint_poses()

        # Create a new scene
        scene2 = canvas.GraphicsCanvas3D(title="Test Robot Append Made Link 2")

        # Create a new robot in new scene
        robot2 = robot.GraphicalRobot(scene2, "Robot 2")

        # Add other joint to new scene
        # Expecting an error (can't add joint to robot in different scene
        self.assertRaises(RuntimeError, robot2.append_made_link, joint2)
Ejemplo n.º 3
0
    def test_joint_texture(self):
        # Scene update
        self.scene.scene.title = "Test Joint Texture"

        # Create joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Apply texture and colour
        joint.set_texture(
            colour=[0.5, 0, 1],
            texture_link="https://s3.amazonaws.com/glowscript/textures/flower_texture.jpg"
        )

        # Ensure texture is not none, and colour is not white
        gph_obj = joint.get_graphic_object()
        self.assertEqual(gph_obj.color, vector(0.5, 0, 1))
        self.assertIsNotNone(gph_obj.texture)

        # Remove Texture and colour
        joint.set_texture()

        # Ensure colour is white, texture is none
        self.assertEqual(gph_obj.color, vector(1, 1, 1))
        self.assertIsNone(gph_obj.texture)

        # Apply bad colour
        # Should assert Value Error
        self.assertRaises(ValueError, joint.set_texture, colour=[127, 0, 255])
Ejemplo n.º 4
0
    def test_joint_visibility(self):
        # Scene update
        self.scene.scene.title = "Test Joint Visibility"
        self.scene.grid_visibility(False)

        # Create a joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Count num objects
        num_obj_initial = len(self.scene.scene.objects)

        # Turn off joint graphic
        joint.set_joint_visibility(False)

        # Count num objects
        num_obj_off = len(self.scene.scene.objects)
        self.assertEqual(num_obj_initial - num_obj_off, 1)

        # Turn on
        joint.set_joint_visibility(True)

        # Count num objects
        num_obj_on = len(self.scene.scene.objects)
        self.assertEqual(num_obj_on - num_obj_off, 1)
        self.assertEqual(num_obj_on, num_obj_initial)
Ejemplo n.º 5
0
    def test_draw_reference_frame(self):
        # Scene update
        self.scene.scene.title = "Test Draw Reference Frame"
        self.scene.grid_visibility(False)

        # Create a joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Count num objects
        num_obj_initial = len(self.scene.scene.objects)

        # Turn off reference frame
        joint.draw_reference_frame(False)

        # Count num objects
        num_obj_off = len(self.scene.scene.objects)
        self.assertEqual(num_obj_initial - num_obj_off, 1)

        # Turn on
        joint.draw_reference_frame(True)

        # Count num objects
        num_obj_on = len(self.scene.scene.objects)
        self.assertEqual(num_obj_on - num_obj_off, 1)
        self.assertEqual(num_obj_on, num_obj_initial)
Ejemplo n.º 6
0
    def test_rotational_joint_init(self):
        self.scene.scene.title = "Test Rotational Joint init"
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)
        self.check_obj_pose(joint, self.se3)
        self.check_joint_type(joint, "R")

        # has int not float
        self.assertRaises(TypeError, robot.RotationalJoint, self.se3, 1, self.scene)
        # has vars in wrong order
        self.assertRaises(TypeError, robot.RotationalJoint, 1.0, self.se3, self.scene)
Ejemplo n.º 7
0
    def test_joint_get_pose(self):
        # Update scene
        self.scene.scene.title = "Test Get Joint Pose"

        # Create a joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Get pose
        pose = joint.get_pose()

        # Check it's equal (proves get returned correctly)
        self.assertEqual(self.se3, pose)
Ejemplo n.º 8
0
    def test_set_joint_pose(self):
        # Create a scene
        self.scene.scene.title = "Test Set Joint Pose"

        # Create a joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Move joint x+30d, y, z-2
        joint.update_pose(self.se3 * SE3().Rx(30, 'deg') * SE3().Tz(-2))

        # Check position
        self.check_obj_pose(joint, self.se3 * SE3().Rx(30, 'deg') * SE3().Tz(-2))
Ejemplo n.º 9
0
    def test_set_joint_orientation(self):
        # Create a scene
        self.scene.scene.title = "Test Set Joint Orientation"

        # Create a joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Rotate joint x+30d, y, z+45d
        joint.update_orientation(self.se3 * SE3().Rx(30, 'deg') * SE3().Rz(45, 'deg'))

        # Check position
        self.check_obj_pose(joint, self.se3 * SE3().Rx(30, 'deg') * SE3().Rz(45, 'deg'))
Ejemplo n.º 10
0
    def test_joint_get_graphic(self):
        # Update scene
        self.scene.scene.title = "Test Joint Get Graphic"
        self.scene.grid_visibility(False)

        # Create a joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)
        joint.draw_reference_frame(False)

        # Get graphic obj
        gph_obj = joint.get_graphic_object()

        # If obj equal only obj in scene
        self.assertEqual(len(self.scene.scene.objects), 1)
        self.assertEqual(gph_obj, self.scene.scene.objects[0])
Ejemplo n.º 11
0
    def test_joint_get_type(self):
        # Update scene
        self.scene.scene.title = "Test Joint Get Type"

        # Create one of each joint
        r = robot.RotationalJoint(self.se3, self.structure, self.scene)
        p = robot.PrismaticJoint(self.se3, self.structure, self.scene)
        s = robot.StaticJoint(self.se3, self.structure, self.scene)
        g = robot.Gripper(self.se3, self.structure, self.scene)

        # Check each is correct
        self.check_joint_type(r, "R")
        self.check_joint_type(p, "P")
        self.check_joint_type(s, "S")
        self.check_joint_type(g, "G")
Ejemplo n.º 12
0
    def test_joint_transparency(self):
        # Scene update
        self.scene.scene.title = "Test Joint Transparency"

        # Create joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Apply texture and colour
        opc_val = 0.34
        joint.set_transparency(opc_val)

        # Ensure texture is not none, and colour is not white
        gph_obj = joint.get_graphic_object()
        self.assertEqual(gph_obj.opacity, opc_val)

        # Set transparency out of range
        # Should throw value error
        self.assertRaises(ValueError, joint.set_transparency, 1.5)
Ejemplo n.º 13
0
    def test_joint_get_axis_vector(self):
        # Update scene
        self.scene.scene.title = "Test Get Joint Pose"

        # Create a joint
        joint = robot.RotationalJoint(self.se3, self.structure, self.scene)

        # Get axis vector
        x_vec = joint.get_axis_vector(common.x_axis_vector)
        y_vec = joint.get_axis_vector(common.y_axis_vector)
        z_vec = joint.get_axis_vector(common.z_axis_vector)

        # Check it's equal (proves get returned correctly)
        self.assertEqual(common.get_pose_x_vec(self.se3), x_vec)
        self.assertEqual(common.get_pose_y_vec(self.se3), y_vec)
        self.assertEqual(common.get_pose_z_vec(self.se3), z_vec)

        # Check error is thrown
        self.assertRaises(ValueError, joint.get_axis_vector, vector(0.5, 2, 3))
Ejemplo n.º 14
0
    def test_set_origin(self):
        # Update scene
        self.scene.scene.title = "Test Set Origin"

        # Create a joint
        joint = robot.RotationalJoint(SE3(), self.structure, self.scene)

        # Save origin pos (copy of)
        first_pos = vector(joint.get_graphic_object().origin)

        # Move origin
        current_pos = vector(1, 0, -0.5)
        new_pos = vector(0, 0, 0.5)
        joint.set_stl_joint_origin(current_pos, new_pos)

        # Save new origin
        second_pos = joint.get_graphic_object().origin

        # Object should go from along +x-axis, to along -x-axis slightly above z=0 plane
        # Compare
        self.assertEqual(first_pos, vector(0, 0, 0))  # Check original origin is at 0, 0, 0 (Default)
        self.assertEqual(second_pos, new_pos - current_pos)  # Check new set origin is at the new position