Skip to content

Commit 9684116

Browse files
authored
Merge pull request #244 from robotpy/hatchling
Migrate to hatchling
2 parents 27fe979 + 56ed779 commit 9684116

File tree

11 files changed

+181
-178
lines changed

11 files changed

+181
-178
lines changed

MANIFEST.in

Lines changed: 0 additions & 7 deletions
This file was deleted.

pyfrc/physics/core.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
"""
2-
pyfrc supports simplistic custom physics model implementations for
3-
simulation and testing support. It can be as simple or complex as you want
4-
to make it. We will continue to add helper functions (such as the
5-
:mod:`pyfrc.physics.drivetrains` module) to make this a lot easier
6-
to do. General purpose physics implementations are welcome also!
7-
8-
The idea is you provide a :class:`PhysicsEngine` object that interacts with
9-
the simulated HAL, and modifies motors/sensors accordingly depending on the
10-
state of the simulation. An example of this would be measuring a motor
11-
moving for a set period of time, and then changing a limit switch to turn
12-
on after that period of time. This can help you do more complex simulations
13-
of your robot code without too much extra effort.
14-
15-
By default, pyfrc doesn't modify any of your inputs/outputs without being
16-
told to do so by your code or the simulation GUI.
17-
18-
See the `physics sample <https://github.com/robotpy/examples/tree/master/physics/src>`_
19-
for more details.
20-
21-
Enabling physics support
22-
------------------------
23-
24-
You must create a python module called ``physics.py`` next to your
25-
``robot.py``. A physics module must have a class called
26-
:class:`PhysicsEngine` which must have a function called ``update_sim``.
27-
When initialized, it will be passed an instance of this object.
2+
pyfrc supports simplistic custom physics model implementations for
3+
simulation and testing support. It can be as simple or complex as you want
4+
to make it. We will continue to add helper functions (such as the
5+
:mod:`pyfrc.physics.drivetrains` module) to make this a lot easier
6+
to do. General purpose physics implementations are welcome also!
7+
8+
The idea is you provide a :class:`PhysicsEngine` object that interacts with
9+
the simulated HAL, and modifies motors/sensors accordingly depending on the
10+
state of the simulation. An example of this would be measuring a motor
11+
moving for a set period of time, and then changing a limit switch to turn
12+
on after that period of time. This can help you do more complex simulations
13+
of your robot code without too much extra effort.
14+
15+
By default, pyfrc doesn't modify any of your inputs/outputs without being
16+
told to do so by your code or the simulation GUI.
17+
18+
See the `physics sample <https://github.com/robotpy/examples/tree/master/physics/src>`_
19+
for more details.
20+
21+
Enabling physics support
22+
------------------------
23+
24+
You must create a python module called ``physics.py`` next to your
25+
``robot.py``. A physics module must have a class called
26+
:class:`PhysicsEngine` which must have a function called ``update_sim``.
27+
When initialized, it will be passed an instance of this object.
2828
"""
2929

3030
from importlib.machinery import SourceFileLoader

pyfrc/physics/drivetrains.py

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
"""
2-
.. warning:: These drivetrain models are not particularly realistic, and
3-
if you are using a tank drive style drivetrain you should use
4-
the :class:`.TankModel` instead.
5-
6-
Based on input from various drive motors, these helper functions
7-
simulate moving the robot in various ways. Many thanks to
8-
`Ether <http://www.chiefdelphi.com/forums/member.php?u=34863>`_
9-
for assistance with the motion equations.
10-
11-
When specifying the robot speed to the below functions, the following
12-
may help you determine the approximate speed of your robot:
13-
14-
* Slow: 4ft/s
15-
* Typical: 5 to 7ft/s
16-
* Fast: 8 to 12ft/s
17-
18-
Obviously, to get the best simulation results, you should try to
19-
estimate the speed of your robot accurately.
20-
21-
Here's an example usage of the drivetrains::
22-
23-
import hal.simulation
24-
from pyfrc.physics import drivetrains
25-
26-
class PhysicsEngine:
27-
28-
def __init__(self, physics_controller):
29-
self.physics_controller = physics_controller
30-
self.drivetrain = drivetrains.TwoMotorDrivetrain(deadzone=drivetrains.linear_deadzone(0.2))
31-
32-
self.l_motor = hal.simulation.PWMSim(1)
33-
self.r_motor = hal.simulation.PWMSim(2)
34-
35-
def update_sim(self, now, tm_diff):
36-
l_motor = self.l_motor.getSpeed()
37-
r_motor = self.r_motor.getSpeed()
38-
39-
speeds = self.drivetrain.calculate(l_motor, r_motor)
40-
self.physics_controller.drive(speeds, tm_diff)
41-
42-
# optional: compute encoder
43-
# l_encoder = self.drivetrain.wheelSpeeds.left * tm_diff
44-
45-
.. versionchanged:: 2020.1.0
2+
.. warning:: These drivetrain models are not particularly realistic, and
3+
if you are using a tank drive style drivetrain you should use
4+
the :class:`.TankModel` instead.
5+
6+
Based on input from various drive motors, these helper functions
7+
simulate moving the robot in various ways. Many thanks to
8+
`Ether <http://www.chiefdelphi.com/forums/member.php?u=34863>`_
9+
for assistance with the motion equations.
10+
11+
When specifying the robot speed to the below functions, the following
12+
may help you determine the approximate speed of your robot:
13+
14+
* Slow: 4ft/s
15+
* Typical: 5 to 7ft/s
16+
* Fast: 8 to 12ft/s
17+
18+
Obviously, to get the best simulation results, you should try to
19+
estimate the speed of your robot accurately.
20+
21+
Here's an example usage of the drivetrains::
22+
23+
import hal.simulation
24+
from pyfrc.physics import drivetrains
25+
26+
class PhysicsEngine:
27+
28+
def __init__(self, physics_controller):
29+
self.physics_controller = physics_controller
30+
self.drivetrain = drivetrains.TwoMotorDrivetrain(deadzone=drivetrains.linear_deadzone(0.2))
31+
32+
self.l_motor = hal.simulation.PWMSim(1)
33+
self.r_motor = hal.simulation.PWMSim(2)
34+
35+
def update_sim(self, now, tm_diff):
36+
l_motor = self.l_motor.getSpeed()
37+
r_motor = self.r_motor.getSpeed()
38+
39+
speeds = self.drivetrain.calculate(l_motor, r_motor)
40+
self.physics_controller.drive(speeds, tm_diff)
41+
42+
# optional: compute encoder
43+
# l_encoder = self.drivetrain.wheelSpeeds.left * tm_diff
44+
45+
.. versionchanged:: 2020.1.0
4646
47-
The input speeds and output rotation angles were changed to reflect
48-
the current WPILib drivetrain/field objects. Wheelbases and default
49-
speeds all require units.
47+
The input speeds and output rotation angles were changed to reflect
48+
the current WPILib drivetrain/field objects. Wheelbases and default
49+
speeds all require units.
5050
"""
5151

5252
import math

pyfrc/physics/tankmodel.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"""
2-
.. versionadded:: 2018.4.0
3-
4-
.. note:: The equations used in our :class:`TankModel` is derived from
5-
`Noah Gleason and Eli Barnett's motor characterization whitepaper
6-
<https://www.chiefdelphi.com/media/papers/3402>`_. It is
7-
recommended that users of this model read the paper so they can
8-
more fully understand how this works.
9-
10-
In the interest of making progress, this API may receive
11-
backwards-incompatible changes before the start of the 2019
12-
FRC season.
2+
.. versionadded:: 2018.4.0
3+
4+
.. note:: The equations used in our :class:`TankModel` is derived from
5+
`Noah Gleason and Eli Barnett's motor characterization whitepaper
6+
<https://www.chiefdelphi.com/media/papers/3402>`_. It is
7+
recommended that users of this model read the paper so they can
8+
more fully understand how this works.
9+
10+
In the interest of making progress, this API may receive
11+
backwards-incompatible changes before the start of the 2019
12+
FRC season.
1313
"""
1414

1515
import math

pyfrc/physics/units.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
"""
2-
pyfrc uses the pint library in some places for representing physical
3-
quantities to allow users to specify the physical parameters of their robot
4-
in a natural and non-ambiguous way. For example, to represent 5 feet::
5-
6-
from pyfrc.physics.units import units
7-
8-
five_feet = 5 * units.feet
9-
10-
Unfortunately, actually using the quantities is a huge performance hit, so
11-
we don't use them to perform actual physics computations. Instead, pyfrc uses
12-
them to convert to known units, then performs computations using
13-
the magnitude of the quantity.
14-
15-
pyfrc defines the following custom units:
16-
17-
* ``counts_per_minute`` or ``cpm``: Counts per minute, which should be used
18-
instead of pint's predefined ``rpm`` (because it is rad/s). Used to
19-
represent motor free speed
20-
* ``N_m``: Shorthand for N-m or newton-meter. Used for motor torque.
21-
22-
* ``tm_ka``: The kA value used in the tankmodel (uses imperial units)
23-
* ``tm_kv``: The kV value used in the tankmodel (uses imperial units)
24-
25-
Refer to the `pint documentation <https://pint.readthedocs.io>`_ for more
26-
information on how to use pint.
2+
pyfrc uses the pint library in some places for representing physical
3+
quantities to allow users to specify the physical parameters of their robot
4+
in a natural and non-ambiguous way. For example, to represent 5 feet::
5+
6+
from pyfrc.physics.units import units
7+
8+
five_feet = 5 * units.feet
9+
10+
Unfortunately, actually using the quantities is a huge performance hit, so
11+
we don't use them to perform actual physics computations. Instead, pyfrc uses
12+
them to convert to known units, then performs computations using
13+
the magnitude of the quantity.
14+
15+
pyfrc defines the following custom units:
16+
17+
* ``counts_per_minute`` or ``cpm``: Counts per minute, which should be used
18+
instead of pint's predefined ``rpm`` (because it is rad/s). Used to
19+
represent motor free speed
20+
* ``N_m``: Shorthand for N-m or newton-meter. Used for motor torque.
21+
22+
* ``tm_ka``: The kA value used in the tankmodel (uses imperial units)
23+
* ``tm_kv``: The kV value used in the tankmodel (uses imperial units)
24+
25+
Refer to the `pint documentation <https://pint.readthedocs.io>`_ for more
26+
information on how to use pint.
2727
"""
2828

2929
import pint

pyfrc/physics/visionsim.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
The 'vision simulator' provides objects that assist in modeling inputs
3-
from a camera processing system.
2+
The 'vision simulator' provides objects that assist in modeling inputs
3+
from a camera processing system.
44
"""
55

66
import collections

pyfrc/tests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
These generic test modules can be applied to :class:`wpilib.iterativerobot.IterativeRobot`
3-
and :class:`wpilib.samplerobot.SampleRobot` based robots.
2+
These generic test modules can be applied to :class:`wpilib.iterativerobot.IterativeRobot`
3+
and :class:`wpilib.samplerobot.SampleRobot` based robots.
44
"""
55

66
# import basic tests

pyfrc/tests/basic.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
2-
The primary purpose of these tests is to run through your code
3-
and make sure that it doesn't crash. If you actually want to test
4-
your code, you need to write your own custom tests to tease out
5-
the edge cases.
6-
7-
To use these, add the following to a python file in your tests directory::
8-
9-
from pyfrc.tests import *
10-
2+
The primary purpose of these tests is to run through your code
3+
and make sure that it doesn't crash. If you actually want to test
4+
your code, you need to write your own custom tests to tease out
5+
the edge cases.
6+
7+
To use these, add the following to a python file in your tests directory::
8+
9+
from pyfrc.tests import *
10+
1111
"""
1212

1313
import pytest

pyproject.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[build-system]
2+
requires = ["hatchling", "hatch-vcs"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "pyfrc"
7+
dynamic = ["version"]
8+
description = "Development tools library for python interpreter used for the FIRST Robotics Competition"
9+
readme = "README.md"
10+
requires-python = ">=3.9"
11+
license = {file = "LICENSE"}
12+
classifiers = [
13+
"Development Status :: 5 - Production/Stable",
14+
"Intended Audience :: Developers",
15+
"License :: OSI Approved :: BSD License",
16+
"Programming Language :: Python :: 3 :: Only",
17+
"Topic :: Software Development",
18+
"Topic :: Software Development :: Testing"
19+
]
20+
dependencies = [
21+
"pytest>=3.9",
22+
"pytest-reraise",
23+
"pint>=0.24.4",
24+
"wpilib>=2025.1.1,<2026",
25+
"robotpy-cli~=2024.0",
26+
"tomli"
27+
]
28+
29+
[[project.authors]]
30+
name = "Dustin Spicuzza"
31+
32+
33+
[project.urls]
34+
"Source code" = "https://github.com/robotpy/pyfrc"
35+
36+
[project.entry-points."robotpy"]
37+
add-tests = "pyfrc.mains.cli_add_tests:PyFrcAddTests"
38+
coverage = "pyfrc.mains.cli_coverage:PyFrcCoverage"
39+
create-physics = "pyfrc.mains.cli_create_physics:PyFrcCreatePhysics"
40+
profiler = "pyfrc.mains.cli_profiler:PyFrcProfiler"
41+
sim = "pyfrc.mains.cli_sim:PyFrcSim"
42+
test = "pyfrc.mains.cli_test:PyFrcTest"
43+
44+
45+
[tool.hatch.build.targets.sdist]
46+
exclude = [
47+
".github",
48+
".readthedocs.yml",
49+
"docs"
50+
]
51+
52+
[tool.hatch.build.targets.wheel]
53+
packages = ["pyfrc"]
54+
55+
[tool.hatch.version]
56+
source = "vcs"
57+
58+
[tool.hatch.build.hooks.vcs]
59+
version-file = "pyfrc/version.py"

setup.cfg

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)