Skip to content

[EXECUTOR] Various refactoring #266

@benliao1

Description

@benliao1

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.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requesthigh-priorityIssues that should be fixed as soon as possible.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions