Python wrappers for WPILib's wpimath library.
- Installation instructions can be found in the RobotPy documentation
- Documentation can be found at readthedocs
Moved to https://github.com/robotpy/mostrobotpy
Python wrappers for WPILib's wpimath library.
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.
Linux
No response
from wpimath.controller import HolonomicDriveController
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.
MacOS
No response
No response
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
Windows, MacOS, Linux, RoboRIO, Raspbian
No response
No response
l believe this will need Eigen type casters (depends on robotpy/robotpy-build#105)
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.
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.
In wpilib they had circular dependencies but that isn't the case anymore.
TrajectoryParameterizer.parameterizeTrajectory() is meant to return a trajectory but returns None and appears to have been overwritten to do nothing.
Windows
fresh python 3.8.6 venv with just `robotpy[all] --pre` installed
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
Presumably this is meant to be in the wpimath.estimator package instead?
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...
Windows, MacOS, Linux
robotpy 2023.0.0b7
robotpy-wpimath 2023.0.0b7
private static final double kSpinupRadPerSec = Units.rotationsPerMinuteToRadiansPerSecond(500.0);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.