Skip to content

Conversation

@lizlooney
Copy link
Collaborator

Generate JSON componentArgs for component constructors, instead of componentPortName and componentPortType. Fixed python code that recognizes enums.

Moved PortType and related functions from module_content.ts to python_json_types.ts

Increment the current version to 0.0.10. Upgrade old projects so that Components have args instead of ports.

Changed blocks and the python generator where it used to assume that all components have a port argument and no other arguments.

Fixed the code that generates the robot when it creates a mechanism, passing one tuple of args for each component in the mechanism.

Fixed the code that generates a mechanism's init and define_hardware methods. The init and define_hardware methods take one parameter (which is is a tuple) for each component in the mechanism. The define_hardware method uses the * operator to unpack the elements of the tuple and pass each element as a separate positional argument to the component constructor.

Fixes #366
Fixes #367

Fixed isEnum.
Removed getComponentPortNameAndType.

Changes to python_tools/json_util.py:
Generate JSON componentArgs for component constructors, instead of componentPortName and componentPortType.
Added _createArgData.
Added _processComponent.
…_json_types.ts

Added preupgrade_009_to_0010 to change Component.ports to Component.args.
…all components have a port argument and no other arguments.

Fixed the code that generates the robot when it creates a mechanism, passing one tuple of args for each component in the mechanism.

Fixed the code that generates a mechanism's __init__ and define_hardware methods. The __init__ and define_hardware methods take one parameter (which is is a tuple) for each component in the mechanism. The define_hardware method uses the * operator to unpack the elements of the tuple and pass each element as a separate positional argument to the component constructor.
Upgrade old projects so that Components have args instead of ports.
@lizlooney lizlooney requested a review from alan412 December 27, 2025 02:32
Copy link
Collaborator

@alan412 alan412 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you test all of these changes? The code looks reasonable to me, and if you feel like it is tested well I am good with your merging it.

@lizlooney lizlooney merged commit ef11e08 into wpilibsuite:main Dec 30, 2025
1 check passed
@lizlooney
Copy link
Collaborator Author

How did you test all of these changes? The code looks reasonable to me, and if you feel like it is tested well I am good with your merging it.

I tested the blocks editor side of things and made sure it generated appropriate python code for normal components (that take a port, including both simple and compound ports), onboard imu (which takes a mount enum, but no port), and analog potentiometer (which takes a port and two other numeric arguments).

I tried to run the python code, but the analog potentiometer class in wpilib doesn't seem to work with the REV potentiometer that I have. But I was able to run blocks-generated python code that uses DigitalSensor, ExpansionHubMotor, and ExpansionHubServo.

@lizlooney lizlooney deleted the pr_more_components branch December 30, 2025 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support components whose constructors take additional arguments Support components whose constructor does not take a port, but takes other arguments

2 participants