Example #1
0
    def __init__(self, urdf_string):
        super(TestController, self).__init__()

        # Roboter aus URDF erzeugen
        self.robot = Robot(urdf_string)
        self.robot.parse_urdf()

        # Regler fuer den Roboter anlegen
        self.controller = SymEngineController(self.robot, '.controller_cache/')

        # Transformation vom Greifer zur Basis des Roboters erzeugen
        gripper_pose = self.robot.get_fk_expression('base_link',
                                                    'hand_palm_link')

        # Parameterisierbaren Punkt erzeugen
        self.point_input = Point3Input(to_expr, 'goal')

        # Mathematischen Punkt vom Punkt-Input erzeugen lassen
        goal_point = self.point_input.get_expression()

        # Distanz zwischen Zielpunkt und Greiferposition
        d = norm(goal_point - position_of(gripper_pose))

        a = dot(unitX, gripper_pose * unitZ)

        c_dist_angular = SoftConstraint(1 - a, 1 - a, 1, a)

        # Constraint, der die Distanz Richtung 0 zwingt
        c_dist = SoftConstraint(-d, -d, 1, d)

        free_symbols = configure_controller(self.controller, self.robot, {
            'dist': c_dist,
            'dist_angular': c_dist_angular
        })

        # Dictionary fuer die derzeitige Variablenbelegung. Initial sind alle Variablen 0
        self.cur_subs = {s: 0 for s in free_symbols}

        # Publisher fuer Kommandos
        self.pub_cmd = rospy.Publisher('/hsr/commands/joint_velocities',
                                       JointStateMsg,
                                       queue_size=1)

        # Abonent fuer Zielpunkt
        self.sub_point = rospy.Subscriber('/goal_point',
                                          PointMsg,
                                          self.cb_point,
                                          queue_size=1)

        # Abonent fuer Gelenkpositionen
        self.sub_js = rospy.Subscriber('/hsr/joint_states',
                                       JointStateMsg,
                                       self.cb_js,
                                       queue_size=1)
Example #2
0
def parsed_boxy(function_setup):
    """
    :rtype: Robot
    """
    return Robot(boxy_urdf())
Example #3
0
def parsed_donbot(function_setup):
    """
    :rtype: Robot
    """
    return Robot(donbot_urdf())
Example #4
0
def parsed_base_bot(function_setup):
    """
    :rtype: Robot
    """
    return Robot(base_bot_urdf())
Example #5
0
def parsed_pr2(function_setup):
    """
    :rtype: Robot
    """
    return Robot(pr2_urdf())
Example #6
0
class TestSymengineController(object):
    pr2_joint_limits = Robot(pr2_urdf()).get_all_joint_limits()
    donbot_joint_limits = Robot(donbot_urdf()).get_all_joint_limits()
    boxy_joint_limits = Robot(boxy_urdf()).get_all_joint_limits()

    def test_constraints_pr2(self, parsed_pr2):
        assert len(parsed_pr2.hard_constraints) == 26
        assert len(parsed_pr2.joint_constraints) == 45

    def test_constraints_donbot(self, parsed_donbot):
        assert len(parsed_donbot.hard_constraints) == 9
        assert len(parsed_donbot.joint_constraints) == 10

    def test_constraints_boxy(self, parsed_boxy):
        assert len(parsed_boxy.hard_constraints) == 26
        assert len(parsed_boxy.joint_constraints) == 26

    @given(rnd_joint_state(pr2_joint_limits))
    def test_pr2_fk1(self, parsed_pr2, js):
        """
        :type parsed_pr2: Robot
        :type js:
        :return:
        """
        kdl = KDL(pr2_urdf())
        root = u'base_link'
        tips = [u'l_gripper_tool_frame', u'r_gripper_tool_frame']
        for tip in tips:
            kdl_r = kdl.get_robot(root, tip)
            kdl_fk = kdl_to_pose(kdl_r.fk(js))
            mjs = {}
            for joint_name, position in js.items():
                mjs[joint_name] = SingleJointState(joint_name, position)
            parsed_pr2.joint_state = mjs
            symengine_fk = parsed_pr2.get_fk_pose(root, tip).pose
            compare_poses(kdl_fk, symengine_fk)

    @given(rnd_joint_state(donbot_joint_limits))
    def test_donbot_fk1(self, parsed_donbot, js):
        kdl = KDL(donbot_urdf())
        root = u'base_footprint'
        tips = [u'gripper_tool_frame']
        for tip in tips:
            kdl_r = kdl.get_robot(root, tip)
            kdl_fk = kdl_to_pose(kdl_r.fk(js))
            mjs = {}
            for joint_name, position in js.items():
                mjs[joint_name] = SingleJointState(joint_name, position)
            parsed_donbot.joint_state = mjs
            symengine_fk = parsed_donbot.get_fk_pose(root, tip).pose
            compare_poses(kdl_fk, symengine_fk)

    @given(rnd_joint_state(boxy_joint_limits))
    def test_boxy_fk1(self, parsed_boxy, js):
        kdl = KDL(boxy_urdf())
        root = u'base_footprint'
        tips = [u'left_gripper_tool_frame', u'right_gripper_tool_frame']
        for tip in tips:
            kdl_r = kdl.get_robot(root, tip)
            kdl_fk = kdl_to_pose(kdl_r.fk(js))
            mjs = {}
            for joint_name, position in js.items():
                mjs[joint_name] = SingleJointState(joint_name, position)
            parsed_boxy.joint_state = mjs
            symengine_fk = parsed_boxy.get_fk_pose(root, tip).pose
            compare_poses(kdl_fk, symengine_fk)


    def test_get_controllable_joint_names_pr2(self, parsed_pr2):
        expected = {u'l_shoulder_pan_joint', u'br_caster_l_wheel_joint', u'r_gripper_l_finger_tip_joint',
                    u'r_elbow_flex_joint', u'torso_lift_joint', u'r_gripper_l_finger_joint', u'r_forearm_roll_joint',
                    u'l_gripper_r_finger_tip_joint', u'r_shoulder_lift_joint', u'fl_caster_rotation_joint',
                    u'l_gripper_motor_screw_joint', u'r_wrist_roll_joint', u'r_gripper_motor_slider_joint',
                    u'l_forearm_roll_joint', u'r_gripper_joint', u'bl_caster_rotation_joint',
                    u'fl_caster_r_wheel_joint', u'l_shoulder_lift_joint', u'head_pan_joint', u'head_tilt_joint',
                    u'fr_caster_l_wheel_joint', u'fl_caster_l_wheel_joint', u'l_gripper_motor_slider_joint',
                    u'br_caster_r_wheel_joint', u'r_gripper_motor_screw_joint', u'r_upper_arm_roll_joint',
                    u'fr_caster_rotation_joint', u'torso_lift_motor_screw_joint', u'bl_caster_l_wheel_joint',
                    u'r_wrist_flex_joint', u'r_gripper_r_finger_tip_joint', u'l_elbow_flex_joint',
                    u'laser_tilt_mount_joint', u'r_shoulder_pan_joint', u'fr_caster_r_wheel_joint',
                    u'l_wrist_roll_joint', u'r_gripper_r_finger_joint', u'bl_caster_r_wheel_joint', u'l_gripper_joint',
                    u'l_gripper_l_finger_tip_joint', u'br_caster_rotation_joint', u'l_gripper_l_finger_joint',
                    u'l_wrist_flex_joint', u'l_upper_arm_roll_joint', u'l_gripper_r_finger_joint'}

        assert set(parsed_pr2.get_joint_names_controllable()).difference(expected) == set()

    def test_get_joint_names_donbot(self, parsed_donbot):
        expected = {u'ur5_wrist_3_joint', u'ur5_elbow_joint', u'ur5_wrist_1_joint', u'odom_z_joint',
                    u'ur5_shoulder_lift_joint', u'odom_y_joint', u'ur5_wrist_2_joint', u'odom_x_joint',
                    u'ur5_shoulder_pan_joint', u'gripper_joint'}

        assert set(parsed_donbot.get_joint_names_controllable()).difference(expected) == set()

    def test_get_joint_names_boxy(self, parsed_boxy):
        expected = {u'left_arm_2_joint', u'neck_joint_end', u'neck_wrist_1_joint', u'right_arm_2_joint',
                    u'right_arm_4_joint', u'neck_wrist_3_joint', u'right_arm_3_joint',
                    u'right_gripper_base_gripper_right_joint', u'left_gripper_base_gripper_right_joint',
                    u'left_arm_0_joint', u'right_gripper_base_gripper_left_joint', u'left_arm_4_joint',
                    u'left_arm_6_joint', u'right_arm_1_joint', u'left_arm_1_joint', u'neck_wrist_2_joint',
                    u'triangle_base_joint', u'neck_elbow_joint', u'right_arm_5_joint', u'left_arm_3_joint',
                    u'neck_shoulder_pan_joint', u'right_arm_0_joint', u'neck_shoulder_lift_joint', u'left_arm_5_joint',
                    u'left_gripper_base_gripper_left_joint', u'right_arm_6_joint'}

        assert set(parsed_boxy.get_joint_names_controllable()).difference(expected) == set()