It was exciting to meet all the RobotPy teams at champs this year and we’d love to hear feedback on how your experience was.
For everyone else, Python is becoming an official language next year! Do you have any suggestions on how Python should be integrated into WPILib or any new features you want to see in RobotPy?
Not a suggestion more of a question, how heavy is the performance hit using python since Rios 1 are on their last legs already or is it mitigated by a cpp backend?
Starting off with my personal endeavors. I’ve successfully used my students on 4096 as guinea pigs to try out new features I’ve been developing.
These are things I’d personally like to spend time integrating into Robotpy (In order of how much I care):
Remote Repl (Demo)
You know how typing python in the terminal opens an interactive python repl that you can type python code in? This does the same thing but opens a repl inside of your running robot code. So, you can mess with your robot’s state or change PID values using the same code you would type into your codebase.
Coroutines!
This is a wrapper around command based that lets you pause execution of a command. This lets you use while loops in your code. Also coming with this is the use of decorators to bind anonymous functions to buttons. More examples (here and here). This might change from being generator based to a full blown async/await version of commands, depending on feedback.
@self.driver1.X.whenHeld(requirements=[robot.intake, robot. Arm], interruptible=False)
def _():
robot.arm.target_angle -= 10
timer = Timer()
timer. Start()
while not timer.hasElapsed(0.25):
yield
robot.arm.target_length -= 2
while True:
robot.intake.outtake(0.3)
yield
Code Visualization
Especially with coroutines, it’s fairly straightforward to do introspection on the command scheduler to find the exact lines of code running at any given time. So you could display that info in vscode directly in your codebase. Unlike in the demo below, in teleop, the teleop_mode coroutine, and the coroutines for any buttons that are being pressed will be highlighted. IMG 9688 - YouTube
More Coroutines?
This is way more aggressive of a change. It gets rid of all of the init/Periodic functions in the Robot class and replaces them with coroutines. You just add in a while loop if you want it to loop (example).
Jupyter Notebooks
I was talking to @gerthworm about how using Jupyter Notebooks could be a useful way to teach students about using vendor libraries without going through the entire structure of robot code first. I’m imagining something like cell 1 - import ctre, cell 2 - motor = ctre.WPI_TalonFX(1), cell 3 - motor. set(1). I haven’t done any work on this at all yet.
If you keep it at 50hz, it’s fine. Ours on the rio 2 runs close to 50hz most of the time and we do introspection on the command scheduler 4 times a second and pump that data over NT. We don’t do state space so idk what the performance hit there is.
Alright, we do heavy state space computation along with pose estimations and the poor Rio 1 was stretched to the limit so I was concerned how bad it would be, but for a Rio 2 makes sense that it’s not too bad.