RobotPy still needs your help: frc-docs, examples, commands

Lots of progress has been made, but there’s still a lot of work to be done. If there aren’t examples and documentation, it’s going to be harder for new people to adopt python this year even though it is official.

Honestly, the example/commands translation might be very well suited for ChatGPT or copilot if you’ve been looking for an excuse to play with those. :slight_smile:

If you’ve been thinking about working on RobotPy now is a great time to do it. Thanks for your help!

12 Likes

I used ChatGPT to translate the arm simulation example using this prompt, and most of the code was pretty usable, just had to fix imports and change some conventions.

RobotPy code translator will translate code from WPILib Java to RobotPy python. The output python code is semantically the same as the original java code, and has identical comments. The output python code is complete and contains all of the code present in the original Java code. Here is the input code for the translator, output only the output code:

I’m currently working on porting over some of the examples. If there’s any you think I should focus on (or defer, e.g. pending the command rewrite), let me know!

Should some coordination be done to make sure multiple people aren’t working on the same ones?

2 Likes

If you have chatGPT plus or whatever it’s called you can upload files in addition to the prompt or in beta make a custom GPT with the API documents uploaded as it’s training data. Either method will yield better results than just a prompt on its own. It can use that “Knowledge base” data to not just guess, but base it’s replies on your real data instead of just the general stuff that it was trained on for the masses.

The custom GPTs you can also enable or disable analysis which is Python based anyways. This seems like a good use of that feature. Otherwise CoPilot with existing projects open in the same window will also help. It looks at your other classes and project files to try and make better suggestions.

Probably?

We have the gitter.im robotpy channel that people can chat in realtime. Or make a comment on Add necessary examples to be linked from frc-docs · Issue #49 · robotpy/examples · GitHub where the list of missing examples are?

I guess I could also just make an issue for each example and whoever is working on it could comment on it. It’s a bit more annoying though.

If you add new command examples you can test them with the 2023 libraries and it’ll likely work in 2024, but I’m not going to review/merge them until the 2024 command library gets finished.

I’d like to suggest prioritizing certain parts of the command rewrite over others. Having commands be pure Python is crucial for ease of use - the C++ bindings have sharp ownership semantics that don’t work well in Python.

The various ControllerCommands and Subsystems are a lot of boilerplate for little benefit; it’s way more important (imo) to get the core factories/utility commands implemented than the larger “all-in-one” abstractions.

1 Like

I’m going to try and fork and do this as well, but I just wanted to show how helpful this comment really is to someone that may be intimidated by the task:

I used the above prompt and also copied the PIDCommand java source file.

It gave me an immediate response, which was pretty close but it was confused by the DoubleSupplier in the Java file.

So I responded to ChatGPT and said:

Here is the resulting output:

from wpilib.controller import PIDController
from wpilib.command import Command, Subsystem
from wpilib.util import ErrorMessages
from typing import Set, Callable

class PIDCommand(Command):
    def __init__(
        self,
        controller: PIDController,
        measurement_source: Callable[[], float],
        setpoint_source: Callable[[], float],
        use_output: Callable[[float], None],
        *requirements: Subsystem
    ):
        ErrorMessages.requireNonNullParam(controller, "controller", "PIDCommand")
        ErrorMessages.requireNonNullParam(
            measurement_source, "measurementSource", "PIDCommand"
        )
        ErrorMessages.requireNonNullParam(
            setpoint_source, "setpointSource", "PIDCommand"
        )
        ErrorMessages.requireNonNullParam(use_output, "useOutput", "PIDCommand")

        self.m_controller = controller
        self.m_use_output = use_output
        self.m_measurement = measurement_source
        self.m_setpoint = setpoint_source
        self.m_requirements: Set[Subsystem] = set(requirements)

    def initialize(self):
        self.m_controller.reset()

    def execute(self):
        self.m_use_output(
            self.m_controller.calculate(
                self.m_measurement(), self.m_setpoint()
            )
        )

    def end(self, interrupted: bool):
        self.m_use_output(0)

    def get_controller(self) -> PIDController:
        return self.m_controller

    @overloads
    def __init__(
        self,
        controller: PIDController,
        measurement_source: Callable[[], float],
        setpoint: float,
        use_output: Callable[[float], None],
        *requirements: Subsystem
    ):
        self(controller, measurement_source, lambda: setpoint, use_output, *requirements)

At first glance that looks pretty well comprehensive and complete code. Will require some unit test development, and some docstrings but overall that experiment took me under a minute with ChatGPT.

Also @virtuald Is there a contributing guide or something for how to format code?

I’m going to take a swing at porting the commands, but realized I don’t really know what sort of standards I should be following for format/linting/etc.

I saw there’s a contributing.md file in the examples repo but couldn’t find one for robotpy proper.

Well, ironically, most RobotPy development these days is done in C++, so… there are no guidelines. Just don’t write bad code :wink:

The guidelines in the examples contributing.md are definitely all applicable. Use black for formatting. The only linter I really care about is mypy, which isn’t set up for commands yet but hopefully we can do that soon?

The other thing that’s really important wrt commands is that there are unit tests in WPILib, and we really must convert those all at the same time too.

There is an old guide from when we used to do more pure python things, but it’s very similar to the examples guidelines: Updating RobotPy source code to match WPILib — RobotPy 2019 documentation

Thanks for the contributions so far, keep them coming! Reviewing everything is also time consuming, and there are other things that I need to address right now, but will definitely get to them in the near future.

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.