|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +__author__ = "[email protected] (Liz Looney)" |
| 16 | + |
| 17 | +# Python Standard Library |
| 18 | +import pathlib |
| 19 | +import sys |
| 20 | + |
| 21 | +# absl |
| 22 | +from absl import app |
| 23 | +from absl import flags |
| 24 | +from absl import logging |
| 25 | + |
| 26 | +# robotpy |
| 27 | +import hal |
| 28 | +import hal.simulation |
| 29 | +import ntcore |
| 30 | +import pyfrc |
| 31 | +import wpilib |
| 32 | +import wpilib.counter |
| 33 | +import wpilib.drive |
| 34 | +import wpilib.event |
| 35 | +import wpilib.interfaces |
| 36 | +import wpilib.shuffleboard |
| 37 | +import wpilib.simulation |
| 38 | +import wpimath |
| 39 | +import wpimath.controller |
| 40 | +import wpimath.estimator |
| 41 | +import wpimath.filter |
| 42 | +import wpimath.geometry |
| 43 | +import wpimath.interpolation |
| 44 | +import wpimath.kinematics |
| 45 | +import wpimath.optimization |
| 46 | +import wpimath.path |
| 47 | +import wpimath.spline |
| 48 | +import wpimath.system |
| 49 | +import wpimath.system.plant |
| 50 | +import wpimath.trajectory |
| 51 | +import wpimath.trajectory.constraint |
| 52 | +import wpimath.units |
| 53 | +import wpinet |
| 54 | +import wpiutil |
| 55 | + |
| 56 | +# Server python scripts |
| 57 | +sys.path.append("../server_python_scripts") |
| 58 | +import blocks_base_classes |
| 59 | + |
| 60 | +# External samples |
| 61 | +sys.path.append("../external_samples") |
| 62 | +import color_range_sensor |
| 63 | +import component |
| 64 | +import rev_touch_sensor |
| 65 | +import servo |
| 66 | +import smart_motor |
| 67 | +import spark_mini |
| 68 | +import sparkfun_led_stick |
| 69 | + |
| 70 | +# Local modules |
| 71 | +import json_util |
| 72 | +import python_util |
| 73 | + |
| 74 | + |
| 75 | +FLAGS = flags.FLAGS |
| 76 | + |
| 77 | +flags.DEFINE_string('output_directory', None, 'The directory where output should be written.') |
| 78 | + |
| 79 | + |
| 80 | +def main(argv): |
| 81 | + del argv # Unused. |
| 82 | + |
| 83 | + if not FLAGS.output_directory: |
| 84 | + logging.error(f'You must specify the --output_directory argument') |
| 85 | + return |
| 86 | + |
| 87 | + pathlib.Path(f'{FLAGS.output_directory}/generated/').mkdir(parents=True, exist_ok=True) |
| 88 | + |
| 89 | + robotpy_modules = [ |
| 90 | + hal, |
| 91 | + hal.simulation, |
| 92 | + ntcore, |
| 93 | + wpilib, |
| 94 | + wpilib.counter, |
| 95 | + wpilib.drive, |
| 96 | + wpilib.event, |
| 97 | + wpilib.interfaces, |
| 98 | + wpilib.shuffleboard, |
| 99 | + wpilib.simulation, |
| 100 | + python_util.getModule('wpilib.sysid'), |
| 101 | + wpimath, |
| 102 | + wpimath.controller, |
| 103 | + wpimath.estimator, |
| 104 | + wpimath.filter, |
| 105 | + wpimath.geometry, |
| 106 | + wpimath.interpolation, |
| 107 | + wpimath.kinematics, |
| 108 | + wpimath.optimization, |
| 109 | + wpimath.path, |
| 110 | + wpimath.spline, |
| 111 | + wpimath.system, |
| 112 | + wpimath.system.plant, |
| 113 | + wpimath.trajectory, |
| 114 | + wpimath.trajectory.constraint, |
| 115 | + wpimath.units, |
| 116 | + wpinet, |
| 117 | + wpiutil, |
| 118 | + ] |
| 119 | + json_generator = json_util.JsonGenerator(robotpy_modules) |
| 120 | + file_path = f'{FLAGS.output_directory}/generated/robotpy_data.json' |
| 121 | + json_generator.writeJsonFile(file_path) |
| 122 | + |
| 123 | + server_python_scripts = [ |
| 124 | + blocks_base_classes, |
| 125 | + ] |
| 126 | + json_generator = json_util.JsonGenerator(server_python_scripts) |
| 127 | + file_path = f'{FLAGS.output_directory}/generated/server_python_scripts.json' |
| 128 | + json_generator.writeJsonFile(file_path) |
| 129 | + |
| 130 | + external_samples_modules = [ |
| 131 | + color_range_sensor, |
| 132 | + component, |
| 133 | + rev_touch_sensor, |
| 134 | + servo, |
| 135 | + smart_motor, |
| 136 | + spark_mini, |
| 137 | + sparkfun_led_stick, |
| 138 | + ] |
| 139 | + json_generator = json_util.JsonGenerator(external_samples_modules) |
| 140 | + file_path = f'{FLAGS.output_directory}/generated/external_samples_data.json' |
| 141 | + json_generator.writeJsonFile(file_path) |
| 142 | + |
| 143 | + |
| 144 | +if __name__ == '__main__': |
| 145 | + app.run(main) |
0 commit comments