You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The ``toWheelSpeeds(ChassisSpeeds speeds)`` (Java) / ``ToWheelSpeeds(ChassisSpeeds speeds)`` (C++) method should be used to convert a ``ChassisSpeeds`` object to a ``MecanumDriveWheelSpeeds`` object. This is useful in situations where you have to convert a forward velocity, sideways velocity, and an angular velocity into individual wheel speeds.
55
+
The ``toWheelSpeeds(ChassisSpeeds speeds)`` (Java / Python) / ``ToWheelSpeeds(ChassisSpeeds speeds)`` (C++) method should be used to convert a ``ChassisSpeeds`` object to a ``MecanumDriveWheelSpeeds`` object. This is useful in situations where you have to convert a forward velocity, sideways velocity, and an angular velocity into individual wheel speeds.
41
56
42
57
.. tab-set-code::
43
58
@@ -69,6 +84,18 @@ The ``toWheelSpeeds(ChassisSpeeds speeds)`` (Java) / ``ToWheelSpeeds(ChassisSpee
69
84
// struct into it's individual components
70
85
auto [fl, fr, bl, br] = kinematics.ToWheelSpeeds(speeds);
71
86
87
+
.. code-block:: python
88
+
89
+
from wpimath.kinematics import ChassisSpeeds
90
+
91
+
# Example chassis speeds: 1 meter per second forward, 3 meters
92
+
# per second to the left, and rotation at 1.5 radians per second
:ref:`Recall <docs/software/kinematics-and-odometry/intro-and-chassis-speeds:Creating a ChassisSpeeds object from field-relative speeds>` that a ``ChassisSpeeds`` object can be created from a set of desired field-oriented speeds. This feature can be used to get wheel speeds from a set of desired field-oriented speeds.
@@ -101,6 +128,23 @@ Field-oriented drive
101
128
// Now use this in our kinematics
102
129
auto [fl, fr, bl, br] = kinematics.ToWheelSpeeds(speeds);
103
130
131
+
.. code-block:: python
132
+
133
+
from wpimath.kinematics import ChassisSpeeds
134
+
import math
135
+
from wpimath.geometry import Rotation2d
136
+
137
+
# The desired field relative speed here is 2 meters per second
138
+
# toward the opponent's alliance station wall, and 2 meters per
139
+
# second toward the left field boundary. The desired rotation
140
+
# is a quarter of a rotation per second counterclockwise. The current
Sometimes, rotating around one specific corner might be desirable for certain evasive maneuvers. This type of behavior is also supported by the WPILib classes. The same ``ToWheelSpeeds()`` method accepts a second parameter for the center of rotation (as a ``Translation2d``). Just like the wheel locations, the ``Translation2d`` representing the center of rotation should be relative to the robot center.
@@ -111,7 +155,7 @@ For example, one can set the center of rotation on a certain wheel and if the pr
111
155
112
156
Converting wheel speeds to chassis speeds
113
157
-----------------------------------------
114
-
One can also use the kinematics object to convert a ``MecanumDriveWheelSpeeds`` object to a singular ``ChassisSpeeds`` object. The ``toChassisSpeeds(MecanumDriveWheelSpeeds speeds)`` (Java) / ``ToChassisSpeeds(MecanumDriveWheelSpeeds speeds)`` (C++) method can be used to achieve this.
158
+
One can also use the kinematics object to convert a ``MecanumDriveWheelSpeeds`` object to a singular ``ChassisSpeeds`` object. The ``toChassisSpeeds(MecanumDriveWheelSpeeds speeds)`` (Java / Python) / ``ToChassisSpeeds(MecanumDriveWheelSpeeds speeds)`` (C++) method can be used to achieve this.
115
159
116
160
.. tab-set-code::
117
161
@@ -137,3 +181,18 @@ One can also use the kinematics object to convert a ``MecanumDriveWheelSpeeds``
137
181
// feature to automatically break up the ChassisSpeeds struct into its
138
182
// three components.
139
183
auto [forward, sideways, angular] = kinematics.ToChassisSpeeds(wheelSpeeds);
184
+
185
+
.. code-block:: python
186
+
187
+
from wpimath.kinematics import MecanumDriveWheelSpeeds
Copy file name to clipboardExpand all lines: source/docs/software/kinematics-and-odometry/mecanum-drive-odometry.rst
+51-3
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ The mandatory arguments are:
12
12
13
13
* The kinematics object that represents your mecanum drive (as a ``MecanumDriveKinematics`` instance)
14
14
* The angle reported by your gyroscope (as a ``Rotation2d``)
15
-
* The initial positions of the wheels (as ``MecanumDriveWheelPositions``). In Java, this must be constructed with each wheel position in meters. In C++, the :doc:`units library </docs/software/basic-programming/cpp-units>` must be used to represent your wheel positions.
15
+
* The initial positions of the wheels (as ``MecanumDriveWheelPositions``). In Java / Python, this must be constructed with each wheel position in meters. In C++, the :doc:`units library </docs/software/basic-programming/cpp-units>` must be used to represent your wheel positions.
16
16
17
17
The fourth optional argument is the starting pose of your robot on the field (as a ``Pose2d``). By default, the robot will start at ``x = 0, y = 0, theta = 0``.
18
18
@@ -74,6 +74,38 @@ The fourth optional argument is the starting pose of your robot on the field (as
74
74
},
75
75
frc::Pose2d{5_m, 13.5_m, 0_rad}};
76
76
77
+
.. code-block:: python
78
+
79
+
from wpimath.geometry import Translation2d
80
+
from wpimath.kinematics import MecanumDriveKinematics
81
+
from wpimath.kinematics import MecanumDriveOdometry
82
+
from wpimath.kinematics import MecanumDriveWheelPositions
83
+
from wpimath.geometry import Pose2d
84
+
from wpimath.geometry import Rotation2d
85
+
86
+
# Locations of the wheels relative to the robot center.
87
+
frontLeftLocation = Translation2d(0.381, 0.381)
88
+
frontRightLocation = Translation2d(0.381, -0.381)
89
+
backLeftLocation = Translation2d(-0.381, 0.381)
90
+
backRightLocation = Translation2d(-0.381, -0.381)
91
+
92
+
# Creating my kinematics object using the wheel locations.
The robot pose can be reset via the ``resetPosition`` method. This method accepts three arguments: the current gyro angle, the current wheel positions, and the new field-relative pose.
120
168
121
169
.. important:: If at any time, you decide to reset your gyroscope or encoders, the ``resetPosition`` method MUST be called with the new gyro angle and wheel positions.
122
170
123
-
.. note:: A full example of a mecanum drive robot with odometry is available here: `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/MecanumBot>`_ / `Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot>`_.
171
+
.. note:: A full example of a mecanum drive robot with odometry is available here: `C++ <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/MecanumBot>`_ / `Java <https://github.com/wpilibsuite/allwpilib/tree/main/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumbot>`_ / `Python <https://github.com/robotpy/examples/tree/main/MecanumBot>`_
124
172
125
-
In addition, the ``GetPose`` (C++) / ``getPoseMeters`` (Java) methods can be used to retrieve the current robot pose without an update.
173
+
In addition, the ``GetPose`` (C++) / ``getPoseMeters`` (Java / Python) methods can be used to retrieve the current robot pose without an update.
0 commit comments