def test_head_pan_tilt_limits(self):
        # This assures that the motor limits for the head throwing exceptions
        joints = Joints()
        pan = joints.get_joint_by_name("HeadPan")
        tilt = joints.get_joint_by_name("HeadTilt")
        self.had_pan_tilt_limit_expect_exception(pan.limit_min - 1, 0)
        self.had_pan_tilt_limit_expect_exception(pan.limit_max + 1, 0)
        self.had_pan_tilt_limit_expect_exception(0, tilt.limit_min - 1)
        self.had_pan_tilt_limit_expect_exception(0, tilt.limit_max + 1)

        # This assures the motor limits that are inside the bounds do not raise
        # an exception
        self.had_pan_tilt_limit_expect_no_exception(pan.limit_min, 0)
        self.had_pan_tilt_limit_expect_no_exception(pan.limit_max, 0)
        self.had_pan_tilt_limit_expect_no_exception(0, tilt.limit_min)
        self.had_pan_tilt_limit_expect_no_exception(0, tilt.limit_max)
Exemplo n.º 2
0
 def __init__(self):
     self.joints = Joints().all()
Exemplo n.º 3
0
class MotorInfoProvider():
    def __init__(self):
        self.joints = Joints().all()

    def report_id(self, arg):
        """ Print out all ID belonging to the given Tag
        """
        matches = []
        for joint in self.joints:
            if joint.name.lower() == arg or arg in joint.tags:
                matches.append(joint.cid)
        if not matches:
            ilog.info("No Motor found in this Group!")
            return False

        ilog.info("%s" % sorted(matches))
        return True

    def get_motor_info(self, arg=""):
        matches = []
        # No specific info request, we give info on all motors
        if not arg:
            ilog.debug("No MotorInfo specification given, returning all Infos i have...")
            matches = self.joints

        # If we got a Motor ID given, just search for it
        elif arg.isdigit():
            try:
                arg = int(arg)
            except ValueError:
                # Can this even happen when arg.isdigit()?
                ilog.error("Thought %s was a int, but i appear to be in error...")
                return False
            try:
                match = self.joints.get_joint_by_cid(arg)
            except KeyError:
                # User might have given a random number get_joint_by_cid does
                # not check on its own
                ilog.warning("The given motor %i does not appear to exist!" % arg)
                return False

            # return Text Field list for use in the UI
            return [Text(self.formatted_motor_info(match))]

        # Otherwise search for a name match, or any tag matches
        else:
            for joint in self.joints:
                if joint.name.lower() == arg:
                    ilog.debug("Found exact match for MotorInfoRequest on %s" % arg)
                    return([Text(self.formatted_motor_info(joint))])
                elif arg in joint.tags:
                    matches.append(joint)

        # No match, no Info
        if not matches:
            ilog.warning("I could find no motors you could have meant by '%s'" % arg)
            return False

        new_texts = []
        for joint in matches:
            new_texts.append(Text(self.formatted_motor_info(joint)))
            #new_text.extend(self.formatted_motor_info(joint))
        return new_texts

    def formatted_motor_info(self, joint):
        """ Returns a urwid-formatted Info of the given "joint"
        """
        text = []
        text.append(('default', "Name: "))
        text.append(('mi_motor_name', str(joint.name) + "\n"))
        text.append(('default', "ID: "))
        text.append(('mi_motor_id', str(joint.cid) + "\n"))
        text.append(('default', "Tags:\n"))
        tags = ""
        for tag in joint.tags:
            tags += "    " + str(tag) + "\n"
        text.append(('mi_motor_tag', tags))
        if not joint.opposing:
            text.append(('default', "opposing motor: None\n\n"))
        else:
            text.append(('default', "opposing motor: %i\n" % joint.opposing))
            if joint.inverted:
                text.append(('default', "Motor IS inverted against the opposing motor\n\n"))
            else:
                text.append(('default', "Motor is NOT inverted against the opposing motor\n\n"))
        return text