-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wpilib] Pregenerate PWM motor controllers #6742
Conversation
wpilibc/src/generate/main/native/include/frc/motorcontroller/pwm_motor_controller.h.jinja
Show resolved
Hide resolved
wpilibc/src/generate/main/native/cpp/motorcontroller/pwm_motor_controller.cpp.jinja
Show resolved
Hide resolved
wpilibc/src/generate/main/native/cpp/motorcontroller/pwm_motor_controller.cpp.jinja
Outdated
Show resolved
Hide resolved
wpilibc/src/generate/main/native/include/frc/motorcontroller/pwm_motor_controller.h.jinja
Outdated
Show resolved
Hide resolved
wpilibc/src/generate/main/native/include/frc/motorcontroller/pwm_motor_controller.h.jinja
Outdated
Show resolved
Hide resolved
wpilibc/src/generate/main/native/cpp/motorcontroller/pwm_motor_controller.cpp.jinja
Outdated
Show resolved
Hide resolved
…_controller.cpp.jinja Co-authored-by: Gold856 <[email protected]>
…wm_motor_controller.h.jinja Co-authored-by: Gold856 <[email protected]>
…wm_motor_controller.h.jinja Co-authored-by: Gold856 <[email protected]>
Co-authored-by: Gold856 <[email protected]>
wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/motorcontrol/SD540.java
Show resolved
Hide resolved
* VEX Robotics Victor 888 Motor Controller The Vex Robotics Victor 884 Motor Controller can also be | ||
* used with this class but may need to be calibrated per the Victor 884 user manual. | ||
* Vex Robotics Victor 888 Motor Controller. | ||
* | ||
* <p>Note that the Victor uses the following bounds for PWM values. These values were determined | ||
* empirically and optimized for the Victor 888. These values should work reasonably well for Victor | ||
* 884 controllers also but if users experience issues such as asymmetric behavior around the | ||
* deadband or inability to saturate the controller in either direction, calibration is recommended. | ||
* The calibration procedure can be found in the Victor 884 User Manual available from VEX Robotics: | ||
* <a | ||
* href="http://content.vexrobotics.com/docs/ifi-v884-users-manual-9-25-06.pdf">http://content.vexrobotics.com/docs/ifi-v884-users-manual-9-25-06.pdf</a> | ||
* <p>Note that the Victor 888 uses the following bounds for PWM values. These values should work | ||
* reasonably well for most controllers, but if users experience issues such as asymmetric behavior | ||
* around the deadband or inability to saturate the controller in either direction, calibration is | ||
* recommended. The calibration procedure can be found in the Victor 888 User Manual available from | ||
* Vex Robotics. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Consider using pathlib instead of wrangling names manually. The trailing backslash vs no trailing backslash can bite someone who tries to update it in the future. Do explicitly set utf-8 as the encoding on file operations in case someone tries to run this on Windows. Python on Windows will switch to utf-8 by default (ignoring locale) in 2026. gpt conversion doing both for example#!/usr/bin/env python3
# Copyright (c) FIRST and other WPILib contributors.
# Open Source Software; you can modify and/or share it under the terms of
# the WPILib BSD license file in the root directory of this project.
import argparse
import json
import sys
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
def render_template(template, output_dir, filename, controller):
output_dir_path = Path(output_dir)
output_dir_path.mkdir(parents=True, exist_ok=True)
(output_dir_path / filename).write_text(template.render(controller), encoding="utf-8")
def generate_pwm_motor_controllers(output_root, template_root):
template_root_path = Path(template_root)
with (template_root_path / "pwm_motor_controllers.json").open(encoding="utf-8") as f:
controllers = json.load(f)
env = Environment(
loader=FileSystemLoader(str(template_root_path)),
autoescape=False,
keep_trailing_newline=True,
)
root_path = Path(output_root) / "main/java/edu/wpi/first/wpilibj/motorcontrol"
template = env.get_template("pwm_motor_controller.java.jinja")
for controller in controllers:
controller_name = f"{controller['name']}.java"
render_template(template, root_path, controller_name, controller)
def main(argv):
script_path = Path(__file__).resolve()
dirname = script_path.parent
parser = argparse.ArgumentParser()
parser.add_argument(
"--output_directory",
help="Optional. If set, will output the generated files to this directory, otherwise it will use a path relative to the script",
default=dirname / "src/generated",
)
parser.add_argument(
"--template_root",
help="Optional. If set, will use this directory as the root for the jinja templates",
default=dirname / "src/generate",
)
args = parser.parse_args(argv)
generate_pwm_motor_controllers(args.output_directory, args.template_root)
if __name__ == "__main__":
main(sys.argv[1:]) |
Fixes #6739