Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EXECUTOR] Various refactoring #266

Open
benliao1 opened this issue Jun 22, 2023 · 1 comment
Open

[EXECUTOR] Various refactoring #266

benliao1 opened this issue Jun 22, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request high-priority Issues that should be fixed as soon as possible.

Comments

@benliao1
Copy link
Collaborator

In order to make the code easier for students to write and simplify the executor logic on our end, we've decided to try to change the way student code works to simply have one function that runs once in autonomous and another function that runs once in teleop. The student API functionality should be unchanged.

Essentially, sample student code will be like:

MOTOR_ID = "6_1234"

def autonomous():
    Robot.set_value(MOTOR_ID, "velocity_a", 1.0)
    Robot.set_value(MOTOR_ID, "velocity_b", 1.0)
    Robot.sleep(1)
    Robot.set_value(MOTOR_ID, "velocity_a", 0.0)
    Robot.set_value(MOTOR_ID, "velocity_b", 0.0)

def teleop():
    while True:
        left_stick = Gamepad.get_value("joystick_left_y")
        right_stick = Gamepad.get_value("joystick_right_y")
        if abs(left_stick) > 0.05:
            Robot.set_value(MOTOR_ID, "velocity_a", left_stick)
        else:
            Robot.set_value(MOTOR_ID, "velocity_a", 0.0)

        if abs(right_stick) > 0.05:
            Robot.set_value(MOTOR_ID, "velocity_b", right_stick)
        else:
            Robot.set_value(MOTOR_ID, "velocity_b", 0.0)        

Notice the lack of a setup function and the requirement of a while True loop around the entire teleop function. This will hopefully make more intuitive sense to the students and make it easier for us to write executor (we don't need to be calling Python functions from a C program continuously.

Additionally, it would be useful to look into whether we can remove Cython as a dependency completely from Runtime. Since Cython is such a massive library / tool, it will be really difficult for new Runtime members to pick it up and make meaningful changes to executor in the future if it is kept in Runtime (no one has learned in the three years since Ashwin wrote it in summer 2020). So, if it is at all possible, we should try to remove Cython as a dependency of Runtime.

@benliao1 benliao1 added enhancement New feature or request high-priority Issues that should be fixed as soon as possible. labels Jun 22, 2023
@AVSurfer123
Copy link
Member

Hey it's been a while and was perusing my Github notifications.

I still think Cython is relatively simple to learn when compared to the Python C interface (https://docs.python.org/3/extending/extending.html#). But I guess it does eliminate one library since executor.c is already using this interface regardless. It will just be pretty complex to rewrite studentapi.pyx, and you'll need to be wary about Python reference counting + figuring out threads for actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high-priority Issues that should be fixed as soon as possible.
Projects
None yet
Development

No branches or pull requests

3 participants