Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
/build

# python stuff
__pycache__
__pycache__/
venv/
*.egg-info

# misc
Expand Down
1 change: 1 addition & 0 deletions external_samples/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# external samples
3 changes: 2 additions & 1 deletion external_samples/spark_mini.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def __init__(self, ports : list[tuple[PortType, int]]):
portType, port = ports[0]
if portType != PortType.SMART_MOTOR_PORT:
raise InvalidPortException
self.spark_mini = wpilib.SparkMini(port)
# TODO(lizlooney): When we upgrade to 2027 robotpy, change PWMSparkMax to SparkMini.
self.spark_mini = wpilib.PWMSparkMax(port) # wpilib.SparkMini(port)

def get_manufacturer(self) -> str:
return "REV Robotics"
Expand Down
19 changes: 19 additions & 0 deletions python_tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Python Tools

## To generate JSON for the robotpy modules and classes:

The following instructions work on macOS Sonoma 14.6.1.

### Setup
1. cd <your repo>/python_tools
1. python3.12 -m venv ./venv
1. source ./venv/bin/activate
1. python3.12 -m pip install -r requirements.txt
1. deactivate

### To Regenerate robotpy_data.json
1. cd <your repo>/python_tools
1. python3.12 -m venv ./venv
1. source ./venv/bin/activate
1. python3.12 generate_json.py --output_directory=../src/blocks/utils
1. deactivate
145 changes: 145 additions & 0 deletions python_tools/generate_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

__author__ = "[email protected] (Liz Looney)"

# Python Standard Library
import pathlib
import sys

# absl
from absl import app
from absl import flags
from absl import logging

# robotpy
import hal
import hal.simulation
import ntcore
import pyfrc
import wpilib
import wpilib.counter
import wpilib.drive
import wpilib.event
import wpilib.interfaces
import wpilib.shuffleboard
import wpilib.simulation
import wpimath
import wpimath.controller
import wpimath.estimator
import wpimath.filter
import wpimath.geometry
import wpimath.interpolation
import wpimath.kinematics
import wpimath.optimization
import wpimath.path
import wpimath.spline
import wpimath.system
import wpimath.system.plant
import wpimath.trajectory
import wpimath.trajectory.constraint
import wpimath.units
import wpinet
import wpiutil

# Server python scripts
sys.path.append("../server_python_scripts")
import blocks_base_classes

# External samples
sys.path.append("../external_samples")
import color_range_sensor
import component
import rev_touch_sensor
import servo
import smart_motor
import spark_mini
import sparkfun_led_stick

# Local modules
import json_util
import python_util


FLAGS = flags.FLAGS

flags.DEFINE_string('output_directory', None, 'The directory where output should be written.')


def main(argv):
del argv # Unused.

if not FLAGS.output_directory:
logging.error(f'You must specify the --output_directory argument')
return

pathlib.Path(f'{FLAGS.output_directory}/generated/').mkdir(parents=True, exist_ok=True)

robotpy_modules = [
hal,
hal.simulation,
ntcore,
wpilib,
wpilib.counter,
wpilib.drive,
wpilib.event,
wpilib.interfaces,
wpilib.shuffleboard,
wpilib.simulation,
python_util.getModule('wpilib.sysid'),
wpimath,
wpimath.controller,
wpimath.estimator,
wpimath.filter,
wpimath.geometry,
wpimath.interpolation,
wpimath.kinematics,
wpimath.optimization,
wpimath.path,
wpimath.spline,
wpimath.system,
wpimath.system.plant,
wpimath.trajectory,
wpimath.trajectory.constraint,
wpimath.units,
wpinet,
wpiutil,
]
json_generator = json_util.JsonGenerator(robotpy_modules)
file_path = f'{FLAGS.output_directory}/generated/robotpy_data.json'
json_generator.writeJsonFile(file_path)

server_python_scripts = [
blocks_base_classes,
]
json_generator = json_util.JsonGenerator(server_python_scripts)
file_path = f'{FLAGS.output_directory}/generated/server_python_scripts.json'
json_generator.writeJsonFile(file_path)

external_samples_modules = [
color_range_sensor,
component,
rev_touch_sensor,
servo,
smart_motor,
spark_mini,
sparkfun_led_stick,
]
json_generator = json_util.JsonGenerator(external_samples_modules)
file_path = f'{FLAGS.output_directory}/generated/external_samples_data.json'
json_generator.writeJsonFile(file_path)


if __name__ == '__main__':
app.run(main)
Loading