How to use the pyfrc.physics.units.Helpers.ensure_length function in pyfrc

To help you get started, we’ve selected a few pyfrc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github robotpy / pyfrc / pyfrc / physics / tankmodel.py View on Github external
velocity_{max} = \frac{\omega_{free} \cdot \pi \cdot d_{wheels} }{r_{gearing}}
                
                acceleration_{max} = \frac{2 \cdot n \cdot \tau_{stall} \cdot r_{gearing} }{d_{wheels} \cdot m_{robot}}
                
                k_{v} = \frac{V_{max}}{velocity_{max}}
                
                k_{a} = \frac{V_{max}}{acceleration_{max}}
        """

        # Check input units
        # -> pint doesn't seem to support default args in check()
        Helpers.ensure_mass(robot_mass)
        Helpers.ensure_length(x_wheelbase)
        Helpers.ensure_length(robot_width)
        Helpers.ensure_length(robot_length)
        Helpers.ensure_length(wheel_diameter)

        max_velocity = (motor_config.freeSpeed * math.pi * wheel_diameter) / gearing
        max_acceleration = (2.0 * nmotors * motor_config.stallTorque * gearing) / (
            wheel_diameter * robot_mass
        )

        Helpers.ensure_velocity(max_velocity)
        Helpers.ensure_acceleration(max_acceleration)

        kv = motor_config.nominalVoltage / max_velocity
        ka = motor_config.nominalVoltage / max_acceleration

        kv = units.tm_kv.from_(kv, name="kv")
        ka = units.tm_ka.from_(ka, name="ka")
github robotpy / pyfrc / pyfrc / physics / tankmodel.py View on Github external
.. math::
            
                velocity_{max} = \frac{\omega_{free} \cdot \pi \cdot d_{wheels} }{r_{gearing}}
                
                acceleration_{max} = \frac{2 \cdot n \cdot \tau_{stall} \cdot r_{gearing} }{d_{wheels} \cdot m_{robot}}
                
                k_{v} = \frac{V_{max}}{velocity_{max}}
                
                k_{a} = \frac{V_{max}}{acceleration_{max}}
        """

        # Check input units
        # -> pint doesn't seem to support default args in check()
        Helpers.ensure_mass(robot_mass)
        Helpers.ensure_length(x_wheelbase)
        Helpers.ensure_length(robot_width)
        Helpers.ensure_length(robot_length)
        Helpers.ensure_length(wheel_diameter)

        max_velocity = (motor_config.freeSpeed * math.pi * wheel_diameter) / gearing
        max_acceleration = (2.0 * nmotors * motor_config.stallTorque * gearing) / (
            wheel_diameter * robot_mass
        )

        Helpers.ensure_velocity(max_velocity)
        Helpers.ensure_acceleration(max_acceleration)

        kv = motor_config.nominalVoltage / max_velocity
        ka = motor_config.nominalVoltage / max_acceleration

        kv = units.tm_kv.from_(kv, name="kv")
        ka = units.tm_ka.from_(ka, name="ka")
github robotpy / pyfrc / pyfrc / physics / tankmodel.py View on Github external
:param x_wheelbase:  Wheelbase of the robot
            :param robot_width:  Width of the robot
            :param robot_length: Length of the robot
            :param l_kv:         Left side ``kv``
            :param l_ka:         Left side ``ka``
            :param l_vi:         Left side ``Vintercept``
            :param r_kv:         Right side ``kv``
            :param r_ka:         Right side ``ka``
            :param r_vi:         Right side ``Vintercept``
            :param timestep:     Model computation timestep
        """

        # check input parameters
        Helpers.ensure_mass(robot_mass)
        Helpers.ensure_length(x_wheelbase)
        Helpers.ensure_length(robot_width)
        Helpers.ensure_length(robot_length)
        Helpers.ensure_time(timestep)

        logger.info(
            "Robot base: %.1fx%.1f frame, %.1f wheelbase, %.1f mass",
            robot_width.m,
            robot_length.m,
            x_wheelbase.m,
            robot_mass.m,
        )

        self._lmotor = MotorModel(motor_config, l_kv, l_ka, l_vi)
        self._rmotor = MotorModel(motor_config, r_kv, r_ka, r_vi)

        self.inertia = (1 / 12.0) * robot_mass * (robot_length ** 2 + robot_width ** 2)
github robotpy / pyfrc / pyfrc / physics / tankmodel.py View on Github external
velocity_{max} = \frac{\omega_{free} \cdot \pi \cdot d_{wheels} }{r_{gearing}}
                
                acceleration_{max} = \frac{2 \cdot n \cdot \tau_{stall} \cdot r_{gearing} }{d_{wheels} \cdot m_{robot}}
                
                k_{v} = \frac{V_{max}}{velocity_{max}}
                
                k_{a} = \frac{V_{max}}{acceleration_{max}}
        """

        # Check input units
        # -> pint doesn't seem to support default args in check()
        Helpers.ensure_mass(robot_mass)
        Helpers.ensure_length(x_wheelbase)
        Helpers.ensure_length(robot_width)
        Helpers.ensure_length(robot_length)
        Helpers.ensure_length(wheel_diameter)

        max_velocity = (motor_config.freeSpeed * math.pi * wheel_diameter) / gearing
        max_acceleration = (2.0 * nmotors * motor_config.stallTorque * gearing) / (
            wheel_diameter * robot_mass
        )

        Helpers.ensure_velocity(max_velocity)
        Helpers.ensure_acceleration(max_acceleration)

        kv = motor_config.nominalVoltage / max_velocity
        ka = motor_config.nominalVoltage / max_acceleration

        kv = units.tm_kv.from_(kv, name="kv")
        ka = units.tm_ka.from_(ka, name="ka")

        logger.info(
github robotpy / pyfrc / pyfrc / physics / tankmodel.py View on Github external
:param robot_width:  Width of the robot
            :param robot_length: Length of the robot
            :param l_kv:         Left side ``kv``
            :param l_ka:         Left side ``ka``
            :param l_vi:         Left side ``Vintercept``
            :param r_kv:         Right side ``kv``
            :param r_ka:         Right side ``ka``
            :param r_vi:         Right side ``Vintercept``
            :param timestep:     Model computation timestep
        """

        # check input parameters
        Helpers.ensure_mass(robot_mass)
        Helpers.ensure_length(x_wheelbase)
        Helpers.ensure_length(robot_width)
        Helpers.ensure_length(robot_length)
        Helpers.ensure_time(timestep)

        logger.info(
            "Robot base: %.1fx%.1f frame, %.1f wheelbase, %.1f mass",
            robot_width.m,
            robot_length.m,
            x_wheelbase.m,
            robot_mass.m,
        )

        self._lmotor = MotorModel(motor_config, l_kv, l_ka, l_vi)
        self._rmotor = MotorModel(motor_config, r_kv, r_ka, r_vi)

        self.inertia = (1 / 12.0) * robot_mass * (robot_length ** 2 + robot_width ** 2)

        # This is used to compute the rotational velocity