mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
The wpimath library is a new library designed to separate the reusable math functionality from the common utility library (wpiutil) and the hardware-dependent library (wpilibc/j). Package names / include file names were NOT changed to minimize breakage. In a future year it would be good to revamp these for a more uniform user experience and to reduce the risk of accidental naming conflicts. While theoretically all of this functionality could be placed into wpiutil, several pieces of this library (e.g. DARE) are very time-consuming to compile, so it's nice to avoid this expense for users who only want cscore or ntcore. It also allows for easy future separation of build tasks vs number of workers on memory-constrained machines. This moves the following functionality from wpiutil into wpimath: - Eigen - ejml - Drake - DARE - wpiutil.math package (Matrix etc) - units And the following functionality from wpilibc/j into wpimath: - Geometry - Kinematics - Spline - Trajectory - LinearFilter - MedianFilter - Feed-forward controllers
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
import os
|
|
import shutil
|
|
import sys
|
|
|
|
MAX_NUM = 20
|
|
|
|
dirname, _ = os.path.split(os.path.abspath(__file__))
|
|
cmake_binary_dir = sys.argv[1]
|
|
|
|
with open(f"{dirname}/src/generate/GenericNumber.java.in", "r") as templateFile:
|
|
template = templateFile.read()
|
|
rootPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/wpiutil/math/numbers"
|
|
|
|
if os.path.exists(rootPath):
|
|
shutil.rmtree(rootPath)
|
|
os.makedirs(rootPath)
|
|
|
|
for i in range(MAX_NUM + 1):
|
|
with open(f"{rootPath}/N{i}.java", "w") as f:
|
|
f.write(template.replace("${num}", str(i)))
|
|
|
|
with open(f"{dirname}/src/generate/Nat.java.in", "r") as templateFile:
|
|
template = templateFile.read()
|
|
outputPath = f"{cmake_binary_dir}/generated/main/java/edu/wpi/first/wpiutil/math/Nat.java"
|
|
with open(f"{dirname}/src/generate/NatGetter.java.in", "r") as getterFile:
|
|
getter = getterFile.read()
|
|
|
|
if os.path.exists(outputPath):
|
|
os.remove(outputPath)
|
|
|
|
importsString = ""
|
|
|
|
for i in range(MAX_NUM + 1):
|
|
importsString += f"import edu.wpi.first.wpiutil.math.numbers.N{i};\n"
|
|
template += getter.replace("${num}", str(i))
|
|
|
|
template += "}\n"
|
|
|
|
template = template.replace('{{REPLACEWITHIMPORTS}}', importsString)
|
|
|
|
with open(outputPath, "w") as f:
|
|
f.write(template)
|