A command interpreter engine for use with the RobotPy command-based library
Project description
Interpreter Command
An overcomplicated solution to the question "How could we easily make multiple autonomous routines?"
The interpreter command provides a way to create a Domain Specific Language (DSL) that can run any sequence of commands at runtime. Ostensibly, this to write a command sequence for autonomous execution; however, this can be used to create a command sequence for any purpose (whether the hit to efficiency is worth it is up to the user).
Installation
Python
Windows:
py -3 install interpreter-command
MacOS/Linux:
python3 install interpreter-command
Usage
All you need to do to create an InterpretCommand is to instantiate the class in your language of choice, register commands to it, and register your fully-realized InterpretCommand object the same way you would register any other command. At any time, you can load a new program and replace the current one.
Python
# WARNING: This example will not work as-is
import wpilib
import interpretercommand as ic
import commands2
class MyRobot(wpilib.TimedRobot):
# ...
def robotInit(self):
# Creating the interpreter
self.interpreter = ic.InterpretCommand()
# Registering the commands
self.interpreter.register("say", commands2.PrintCommand)
self.interpreter.register("drive", SomeDriveCommand, drive_subsystem) # parameters: x, y, z
# ...
def autonomousInit(self):
self.interpreter.schedule()
def teleopInit(self):
self.interpreter.cancel()
Now you could write a program like
say "hello"
say "world"
drive 0, 0.4, 0
which would print "hello\nworld", then drive the robot in the Y
direction at 40% speed until the command is canceled, assuming
SomeDriveCommand
does nothing but drive continuously using its
inputs.
Further Information
For more information,
License
This project is licensed under the MIT License. If this doesn't work for you, feel free to create an issue requesting it.
Caveat
This library is specifically designed to work with RobotPy and WPILib. The concept may work well with other robotics frameworks, but this library is not compatible.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for interpreter-command-2024.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9d14345e33b2ad74bb112cb549e7bf866284c398fdf86eae34a79a25433d235 |
|
MD5 | 97aefff0ad1edb7e029866dfdb060785 |
|
BLAKE2b-256 | 56d66cc01a4307267d9cf80217a38789e36aa66c3def2a4ab6d04e8c0ac9ecc9 |
Hashes for interpreter_command-2024.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1771ab269b6a72c931191b3bc55746884d998e07261b43c164d7d172889fd7ae |
|
MD5 | ad2e6942061983dca52fa2c763de229d |
|
BLAKE2b-256 | b0adeaa773e8c0f6ef5762d17439fa87f3ab906892fde8f8d0b14b3c619f1a2e |