Git Product home page Git Product logo

robotpy-wpimath's Introduction

robotpy-wpimath

Python wrappers for WPILib's wpimath library.

robotpy-wpimath's People

Contributors

agelsomini avatar auscompgeek avatar benjiboy50fonz avatar megarubber avatar thetriplev avatar virtuald avatar woz4tetra avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

robotpy-wpimath's Issues

HolonomicDriveController not included in robotpy 2022 update.

Problem description

The holonomic drive controller class was moved this year to wpimath.controller, and it appears to be present in the gen folder. It is absent from the readthedocs and does not appear to be included in the updated library.

I attempted to import the library and then run the sim (I'm aware it does not work right now but it still gives errors). After removing the instances of the HolonomicDriveController it no longer showed the error, so I am under the assumption that it was not included in the 2022 release.

Operating System

Linux

Installed Python Packages

No response

Reproducible example code

from wpimath.controller import HolonomicDriveController

[BUG]: Type hints in `.pyi` don't resolve all units

Problem description

When type hints are generated, units are not properly resolved:
From robotpy-pathplannerlib:

class PathPlannerTrajectory():
    class PathPlannerState():
        def __init__(self) -> None: ...
        def interpolate(self, endVal: PathPlannerTrajectory.PathPlannerState, t: float) -> PathPlannerTrajectory.PathPlannerState: ...
        @property
        def acceleration(self) -> meters_per_second_squared:
            """
            :type: meters_per_second_squared
            """
        @property
        def angularAccel(self) -> units::unit_t<units::unit<std::__1::ratio<1l, 1l>, units::base_unit<std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<-2l, 1l>, std::__1::ratio<1l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l> >, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l> >, double, units::linear_scale>:
            """
            :type: units::unit_t<units::unit<std::__1::ratio<1l, 1l>, units::base_unit<std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<-2l, 1l>, std::__1::ratio<1l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l> >, std::__1::ratio<0l, 1l>, std::__1::ratio<0l, 1l> >, double, units::linear_scale>
            """
        @property
        def angularVel(self) -> radians_per_second:
            """
            :type: radians_per_second
            """
        @property
        def curveRadius(self) -> meters:
            """
            :type: meters
            """

Some types are left in C++ syntax (units::unit_t<units::unit<std::__1::ratio<1l, 1l>...) and others are simplified but not imported so they are not valid (meters).

robotpy-photonvision has the same issue.

Operating System

MacOS

Installed Python Packages

No response

Reproducible example code

No response

LinearSystem implementation is incomplete

Problem description

There is a limited number of options for LinearSystem and subsequent required objects. My system has 3 states and 2 inputs. This is not an available option. Is it feasible to make the number of states and inputs configurable at run time like Java and C++ do at compile time?

For reference this is the code I'm trying to copy over:
https://github.com/frc-88/DiffyJrROS/blob/78019a034a5ad7bcd59af6932be216159df703dd/src/main/java/frc/robot/util/diffswerve/DiffSwerveModule.java#L133

Operating System

Windows, MacOS, Linux, RoboRIO, Raspbian

Installed Python Packages

No response

Reproducible example code

No response

Confusion in loading Tuple[float] parameters in wpimath.spline.Spline5.ControlVector()

It may simply be ignorance on my part (the wpi documentation was a bit confusing on required input), but I could not figure out how to use the ControlVector without help.
Specifically, wpimath.spline.Spline5.ControlVector() requires two lists or tuples of length-three to initialize:

import wpimath
wpimath.spline.Spline5.ControlVector((0,0,0),(0,0,0))

otherwise if you try with the wrong length of lists you get the message:

TypeError Traceback (most recent call last)
in
1 import wpimath
----> 2 wpimath.spline.Spline5.ControlVector((0,0),(0,0))

TypeError: init(): incompatible constructor arguments. The following argument types are supported:
1. wpimath.spline._spline.Spline5.ControlVector(x: Tuple[float], y: Tuple[float])

Invoked with: (0, 0), (0, 0)

You need this function to make trajectories from Pathweaver paths on-robot (pathweaver generates trajectories for one velocity at a time, it is nice to simulate many velocities at once without rebuilding them externally for each velocity). Specifically, it's this overload:
generateTrajectory(controlVectors: List[wpimath.spline._spline.Spline5.ControlVector], config: wpimath.trajectory._trajectory.TrajectoryConfig) -> wpimath.trajectory._trajectory.Trajectory
I can confirm this function works and generates trajectories identical to pathweaver output.

TrajectoryConstraint.MinMax missing Python type names

The generated type stubs for this class are invalid Python syntax:

    class MinMax():
        """
        Represents a minimum and maximum acceleration.
        """
        def __init__(self) -> None: ...
        @property
        def maxAcceleration(self) -> units::unit_t<units::unit<std::ratio<1l, 1l>, units::base_unit<std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<-2l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, double, units::linear_scale>:
            """
            :type: units::unit_t<units::unit<std::ratio<1l, 1l>, units::base_unit<std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<-2l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, double, units::linear_scale>
            """
        @maxAcceleration.setter
        def maxAcceleration(self, arg0: units::unit_t<units::unit<std::ratio<1l, 1l>, units::base_unit<std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<-2l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, double, units::linear_scale>) -> None:
            pass
        @property
        def minAcceleration(self) -> units::unit_t<units::unit<std::ratio<1l, 1l>, units::base_unit<std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<-2l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, double, units::linear_scale>:
            """
            :type: units::unit_t<units::unit<std::ratio<1l, 1l>, units::base_unit<std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<-2l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, double, units::linear_scale>
            """
        @minAcceleration.setter
        def minAcceleration(self, arg0: units::unit_t<units::unit<std::ratio<1l, 1l>, units::base_unit<std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<-2l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, double, units::linear_scale>) -> None:
            pass
        pass

These are obtained from:

>>> from wpimath.trajectory.constraint import TrajectoryConstraint
>>> TrajectoryConstraint.MinMax.maxAcceleration.fget.__doc__
'(self: wpimath.trajectory._trajectory.constraints.TrajectoryConstraint.MinMax) -> units::unit_t<units::unit<std::ratio<1l, 1l>, units::base_unit<std::ratio<1l, 1l>, std::ratio<0l, 1l>, std::ratio<-2l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, std::ratio<0l, 1l>, std::ratio<0l, 1l> >, double, units::linear_scale>\n'

For some reason, the generated bindings for TrajectoryConstraint don't include our units/acceleration.h type casters.

Looks like these don't show up in the Sphinx-generated docs at all either, which might be worth looking into.

[BUG]: TrajectoryParameterizer returns None

Problem description

TrajectoryParameterizer.parameterizeTrajectory() is meant to return a trajectory but returns None and appears to have been overwritten to do nothing.

Operating System

Windows

Installed Python Packages

fresh python 3.8.6 venv with just `robotpy[all] --pre` installed

Reproducible example code

from wpimath.trajectory import TrajectoryParameterizer
from wpimath.spline import CubicHermiteSpline, SplineHelper
from wpimath.geometry import Pose2d
from typing import Tuple
from math import pi

start = Pose2d(1, 1, 0)
end = Pose2d(2, 2, pi/2)

# generate the spline from start and end poses
vec1, vec2 = SplineHelper.cubicControlVectorsFromWaypoints(start, [], end)
spline = CubicHermiteSpline(vec1.x, vec2.x, vec1.y, vec2.y)

# sample the pose and curvature along the spline
points: Tuple[Pose2d, float] = []
for i in range(100):
    points.append(spline.getPoint(i/100))

trajectory = TrajectoryParameterizer.timeParameterizeTrajectory(points, [], 0, 0, 4, 3, False)
print(trajectory) # None

Units class not implemented

Problem description

Following #49
In statespaceflywheel Java example Robot.java file, it uses the Units class for measurement conversion when it calls the rotationsPerMinuteToRadiansPerSecond static method.

I don't know if it's very necessary to add...

Operating System

Windows, MacOS, Linux

Installed Python Packages

robotpy 2023.0.0b7
robotpy-wpimath 2023.0.0b7

Reproducible example code

private static final double kSpinupRadPerSec = Units.rotationsPerMinuteToRadiansPerSecond(500.0);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.