From 4b121a2ce58c8c34715d139a7306a85b73ff468e Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Tue, 28 May 2024 21:32:26 -0700 Subject: [PATCH 01/18] [EXECUTOR] Modified to remove internal loop for student code --- executor/executor.c | 93 ++++++++++++++++------------------------- executor/studentcode.py | 9 +--- 2 files changed, 39 insertions(+), 63 deletions(-) diff --git a/executor/executor.c b/executor/executor.c index 6415c59e..b1714a0e 100644 --- a/executor/executor.c +++ b/executor/executor.c @@ -208,64 +208,51 @@ static uint8_t run_py_function(const char* func_name, struct timespec* timeout, max_time = timeout->tv_sec * 1e9 + timeout->tv_nsec; } - do { - clock_gettime(CLOCK_MONOTONIC, &start); - pValue = PyObject_CallObject(pFunc, args); // make call to Python function - clock_gettime(CLOCK_MONOTONIC, &end); - - // if the time the Python function took was greater than max_time, warn that it's taking too long - time = (end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec); - if (timeout != NULL && time > max_time) { - log_printf(WARN, "Function %s is taking longer than %lu milliseconds, indicating a loop or sleep in the code. You probably forgot to put a Robot.sleep call into a robot action instead of a regular function.", func_name, (long) (max_time / 1e6)); - } - // if the time the Python function took was less than min_time, sleep to slow down execution - if (time < min_time) { - usleep((min_time - time) / 1000); // Need to convert nanoseconds to microseconds - } + pValue = PyObject_CallObject(pFunc, args); // make call to Python function + + // Set return value + if (py_ret != NULL) { + Py_XDECREF(*py_ret); // Decrement previous reference, if it exists + *py_ret = pValue; + } else { + Py_XDECREF(pValue); + } - // Set return value - if (py_ret != NULL) { - Py_XDECREF(*py_ret); // Decrement previous reference, if it exists - *py_ret = pValue; + // catch execution error + if (pValue == NULL) { + if (!PyErr_ExceptionMatches(PyExc_TimeoutError)) { + PyErr_Print(); + log_printf(ERROR, "Python function %s call failed", func_name); + ret = 2; } else { - Py_XDECREF(pValue); + ret = 3; // Timed out by parent process } - - // catch execution error - if (pValue == NULL) { + break; + } else if (mode == AUTO || mode == TELEOP) { + // Need to check if error occurred in action thread + PyObject* event = PyObject_GetAttrString(pRobot, "error_event"); + if (event == NULL) { + PyErr_Print(); + log_printf(ERROR, "Could not get error_event from Robot instance"); + exit(2); + } + PyObject* event_set = PyObject_CallMethod(event, "is_set", NULL); + if (event_set == NULL) { if (!PyErr_ExceptionMatches(PyExc_TimeoutError)) { PyErr_Print(); - log_printf(ERROR, "Python function %s call failed", func_name); - ret = 2; + log_printf(DEBUG, "Could not get if error is set from error_event"); + exit(2); } else { ret = 3; // Timed out by parent process } break; - } else if (mode == AUTO || mode == TELEOP) { - // Need to check if error occurred in action thread - PyObject* event = PyObject_GetAttrString(pRobot, "error_event"); - if (event == NULL) { - PyErr_Print(); - log_printf(ERROR, "Could not get error_event from Robot instance"); - exit(2); - } - PyObject* event_set = PyObject_CallMethod(event, "is_set", NULL); - if (event_set == NULL) { - if (!PyErr_ExceptionMatches(PyExc_TimeoutError)) { - PyErr_Print(); - log_printf(DEBUG, "Could not get if error is set from error_event"); - exit(2); - } else { - ret = 3; // Timed out by parent process - } - break; - } else if (PyObject_IsTrue(event_set) == 1) { - log_printf(ERROR, "Stopping %s due to error in action", func_name); - ret = 1; - break; - } + } else if (PyObject_IsTrue(event_set) == 1) { + log_printf(ERROR, "Stopping %s due to error in action", func_name); + ret = 1; + break; } - } while (loop); + } + Py_DECREF(pFunc); } else { if (PyErr_Occurred()) { @@ -290,16 +277,10 @@ static uint8_t run_py_function(const char* func_name, struct timespec* timeout, static void run_mode(robot_desc_val_t mode) { // Set up the arguments to the threads that will run the setup and main threads char* mode_str = get_mode_str(mode); - char setup_str[20], main_str[20]; - sprintf(setup_str, "%s_setup", mode_str); + char main_str[20]; sprintf(main_str, "%s_main", mode_str); - int err = run_py_function(setup_str, &setup_time, 0, NULL, NULL); // Run setup function once - if (err == 0) { - err = run_py_function(main_str, &main_interval, 1, NULL, NULL); // Run main function on loop - } else { - log_printf(WARN, "Won't run %s due to error %d in %s", main_str, err, setup_str); - } + err = run_py_function(main_str, &main_interval, 1, NULL, NULL); // Run main function on loop return; } diff --git a/executor/studentcode.py b/executor/studentcode.py index 005fa383..0fc8305a 100755 --- a/executor/studentcode.py +++ b/executor/studentcode.py @@ -1,12 +1,7 @@ - -def autonomous_setup(): - print('Autonomous setup has begun!') - def autonomous_main(): + print("Autonomous has begun!") pass -def teleop_setup(): - print('Teleop setup has begun!') - def teleop_main(): + print("Teleop has begun!") pass From 545ae14e7debd2dbc8aa347c0fae3d3d7cb7f9e7 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Mon, 10 Jun 2024 13:29:23 -0700 Subject: [PATCH 02/18] [EXECUTOR] removed timing and loop argument from run_py_function, removed run_mode function --- executor/executor.c | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/executor/executor.c b/executor/executor.c index b1714a0e..5bd96e2e 100644 --- a/executor/executor.c +++ b/executor/executor.c @@ -195,19 +195,13 @@ static void executor_init(char* student_code) { * 3: Timed out by executor * 4: Unable to find the given function in the student code */ -static uint8_t run_py_function(const char* func_name, struct timespec* timeout, int loop, PyObject* args, PyObject** py_ret) { +static uint8_t run_py_function(const char* func_name, struct timespec* timeout, PyObject* args, PyObject** py_ret) { uint8_t ret = 0; // retrieve the Python function from the student code PyObject* pFunc = PyObject_GetAttrString(pModule, func_name); PyObject* pValue = NULL; if (pFunc && PyCallable_Check(pFunc)) { - struct timespec start, end; - uint64_t time, max_time = 0; - if (timeout != NULL) { - max_time = timeout->tv_sec * 1e9 + timeout->tv_nsec; - } - pValue = PyObject_CallObject(pFunc, args); // make call to Python function // Set return value @@ -265,26 +259,6 @@ static uint8_t run_py_function(const char* func_name, struct timespec* timeout, } -/** - * Begins the given game mode and calls setup and main appropriately. Will run main forever. - * - * Behavior: This is a blocking function and will block the calling thread forever. - * This should only be run as a separate thread. - * - * Inputs: - * args: string of the mode to start running - */ -static void run_mode(robot_desc_val_t mode) { - // Set up the arguments to the threads that will run the setup and main threads - char* mode_str = get_mode_str(mode); - char main_str[20]; - sprintf(main_str, "%s_main", mode_str); - - err = run_py_function(main_str, &main_interval, 1, NULL, NULL); // Run main function on loop - return; -} - - /** * Handler for killing the child mode subprocess */ @@ -342,7 +316,10 @@ static pid_t start_mode_subprocess(char* student_code) { signal(SIGINT, SIG_IGN); // Disable Ctrl+C for child process executor_init(student_code); signal(SIGTERM, python_exit_handler); // Set handler for killing subprocess - run_mode(mode); + + char* mode_str = get_mode_str(mode); + err = run_py_function(mode_str, &main_interval, 1, NULL, NULL); // Run main function + exit(0); return pid; // Never reach this statement due to exit, needed to fix compiler warning } else { From 5b5a4c332e3634343df564958fad6a45448f6c7f Mon Sep 17 00:00:00 2001 From: Luke Wang Date: Tue, 11 Jun 2024 20:29:28 -0700 Subject: [PATCH 03/18] updated last 4 student code files to work with new executor --- tests/student_code/sound_device.py | 44 ++++++++++++++---------------- tests/student_code/tc_212_a.py | 10 ++----- tests/student_code/tc_212_b.py | 14 ++++------ tests/student_code/tc_212_c.py | 19 +++++-------- 4 files changed, 34 insertions(+), 53 deletions(-) diff --git a/tests/student_code/sound_device.py b/tests/student_code/sound_device.py index cc9cb825..49465235 100644 --- a/tests/student_code/sound_device.py +++ b/tests/student_code/sound_device.py @@ -1,4 +1,5 @@ # Student code that plays pitches from keyboard inputs +# Commented out print_buttons and play_notes functions as they are not run import time SOUND = '59_1' @@ -23,8 +24,8 @@ ################################## AUTONOMOUS ################################## -def autonomous_setup(): - print("Now executing AUTONOMOUS SETUP") +def autonomous(): + print("Now executing AUTONOMOUS") # Write pitches for note in NOTES: if (note == ' '): @@ -35,35 +36,30 @@ def autonomous_setup(): Robot.set_value(SOUND, "PITCH", MAP[note]) time.sleep(NOTE_DURATION) -def autonomous_main(): - pass - #################################### TELEOP #################################### -def teleop_setup(): - print("Now executing TELEOP SETUP") +def teleop(): + print("Now executing TELEOP") # Robot.run(print_button) # Robot.run(play_notes) - pass - -def teleop_main(): - if Gamepad.get_value('button_a'): - Robot.set_value(SOUND, "PITCH", MAP['C']) - print("Wrote Button A: Pitch C") - time.sleep(NOTE_DURATION); - if Gamepad.get_value('button_b'): - Robot.set_value(SOUND, "PITCH", MAP['B']) - print("Wrote Button B: Pitch B") - time.sleep(NOTE_DURATION); + while True: + if Gamepad.get_value('button_a'): + Robot.set_value(SOUND, "PITCH", MAP['C']) + print("Wrote Button A: Pitch C") + time.sleep(NOTE_DURATION); + if Gamepad.get_value('button_b'): + Robot.set_value(SOUND, "PITCH", MAP['B']) + print("Wrote Button B: Pitch B") + time.sleep(NOTE_DURATION); ################################### THREADS #################################### -def print_button(): - while (1): - if Gamepad.get_value('button_a'): - print("BUTTON A IS PRESSED") - if Gamepad.get_value('button_b'): - print("BUTTON B IS PRESSED") +# def print_button(): +# while (1): +# if Gamepad.get_value('button_a'): +# print("BUTTON A IS PRESSED") +# if Gamepad.get_value('button_b'): +# print("BUTTON B IS PRESSED") # def play_notes(): # while (1): diff --git a/tests/student_code/tc_212_a.py b/tests/student_code/tc_212_a.py index df235457..722ce7ce 100644 --- a/tests/student_code/tc_212_a.py +++ b/tests/student_code/tc_212_a.py @@ -6,15 +6,9 @@ DEVICE = "62_1" PARAM = "MY_INT" -def autonomous_setup(): +def autonomous(): pass -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): +def teleop(): Robot.set_value(DEVICE, PARAM, 999) diff --git a/tests/student_code/tc_212_b.py b/tests/student_code/tc_212_b.py index 1951da90..43990b1f 100644 --- a/tests/student_code/tc_212_b.py +++ b/tests/student_code/tc_212_b.py @@ -7,16 +7,12 @@ DEVICE = "62_1" PARAM = "MY_INT" -def autonomous_setup(): +def autonomous(): pass -def autonomous_main(): - pass - -def teleop_setup(): +def teleop(): Robot.set_value(DEVICE, PARAM, 999) - -def teleop_main(): - if Keyboard.get_value('w'): - Robot.set_value(DEVICE, PARAM, 1000) + while True: + if Keyboard.get_value('w'): + Robot.set_value(DEVICE, PARAM, 1000) \ No newline at end of file diff --git a/tests/student_code/tc_212_c.py b/tests/student_code/tc_212_c.py index a58a563e..c29a0aec 100644 --- a/tests/student_code/tc_212_c.py +++ b/tests/student_code/tc_212_c.py @@ -6,17 +6,12 @@ DEVICE = "62_1" PARAM = "MY_INT" -def autonomous_setup(): +def autonomous(): pass -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): - if Keyboard.get_value('w'): - Robot.set_value(DEVICE, PARAM, 999) - else: - Robot.set_value(DEVICE, PARAM, 111) \ No newline at end of file +def teleop(): + while True: + if Keyboard.get_value('w'): + Robot.set_value(DEVICE, PARAM, 999) + else: + Robot.set_value(DEVICE, PARAM, 111) \ No newline at end of file From 0c01724839cf915861f907ce48659b8bbd53f06b Mon Sep 17 00:00:00 2001 From: Luke Wang Date: Tue, 11 Jun 2024 20:35:53 -0700 Subject: [PATCH 04/18] added while True to tc_212_a.py --- tests/student_code/tc_212_a.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/student_code/tc_212_a.py b/tests/student_code/tc_212_a.py index 722ce7ce..6f003897 100644 --- a/tests/student_code/tc_212_a.py +++ b/tests/student_code/tc_212_a.py @@ -10,5 +10,6 @@ def autonomous(): pass def teleop(): - Robot.set_value(DEVICE, PARAM, 999) + while True: + Robot.set_value(DEVICE, PARAM, 999) From 58d70f0ee681d3250831b8edc3d31c36821d4b5d Mon Sep 17 00:00:00 2001 From: ishan-monie Date: Tue, 18 Jun 2024 22:36:41 -0500 Subject: [PATCH 05/18] modified first 5 student_code tests --- tests/student_code/executor_sanity.py | 24 ++++++++++++++++++++++++ tests/student_code/keyboard_input.py | 17 ++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/tests/student_code/executor_sanity.py b/tests/student_code/executor_sanity.py index 2d17be72..7cb644e1 100644 --- a/tests/student_code/executor_sanity.py +++ b/tests/student_code/executor_sanity.py @@ -1,3 +1,4 @@ +''' import time import math @@ -23,3 +24,26 @@ def teleop_setup(): def teleop_main(): oops = 1 / 0 +''' + +import time +import math + +# This autonomous code prints some output every two seconds + +def constant_print(msg): + while True: + print(f"{msg} printing again") + time.sleep(2) + +def autonomous(): + print('Autonomous has begun!') + print(f"Starting position: {Robot.start_pos}") + while True: + Robot.run(constant_print, "autonomous") + +# This teleop code generates a DivisionByZero Python error + +def teleop(): + while True: + oops = 1 / 0 diff --git a/tests/student_code/keyboard_input.py b/tests/student_code/keyboard_input.py index fe72d09f..0c92ed32 100644 --- a/tests/student_code/keyboard_input.py +++ b/tests/student_code/keyboard_input.py @@ -1,4 +1,4 @@ - +''' simple_device = "62_20" def autonomous_setup(): @@ -16,3 +16,18 @@ def teleop_main(): elif Keyboard.get_value('y'): print(Robot.get_value(simple_device, "MY_INT")) Robot.sleep(.45) +''' + +simple_device = "62_20" + +def autonomous(): + while True: + pass + +def teleop(): + while True: + if Keyboard.get_value('a'): + Robot.set_value(simple_device, "MY_INT", 123454321) + elif Keyboard.get_value('y'): + print(Robot.get_value(simple_device, "MY_INT")) + Robot.sleep(0.45) From f37b42f807acb06a570f4e2dc64d2eb15d9c6507 Mon Sep 17 00:00:00 2001 From: ishan-monie Date: Tue, 18 Jun 2024 23:09:50 -0500 Subject: [PATCH 06/18] modified first 5 student_code tests 2 --- tests/student_code/executor_sanity.py | 28 ------------------- tests/student_code/keyboard_input.py | 20 ------------- tests/student_code/net_handler_integration.py | 18 +++++++----- tests/student_code/runtime_latency.py | 21 ++++++-------- tests/student_code/sanity_write.py | 17 +++++------ 5 files changed, 27 insertions(+), 77 deletions(-) diff --git a/tests/student_code/executor_sanity.py b/tests/student_code/executor_sanity.py index 7cb644e1..cccb431a 100644 --- a/tests/student_code/executor_sanity.py +++ b/tests/student_code/executor_sanity.py @@ -1,31 +1,3 @@ -''' -import time -import math - -# This autonomous code prints some output every two seconds - -def constant_print(msg): - while True: - print(f"{msg} printing again") - time.sleep(2) - -def autonomous_setup(): - print('Autonomous setup has begun!') - print(f"Starting position: {Robot.start_pos}") - Robot.run(constant_print, "autonomous") - -def autonomous_main(): - pass - -# This teleop code generates a DivisionByZero Python error - -def teleop_setup(): - pass - -def teleop_main(): - oops = 1 / 0 -''' - import time import math diff --git a/tests/student_code/keyboard_input.py b/tests/student_code/keyboard_input.py index 0c92ed32..7b0595bc 100644 --- a/tests/student_code/keyboard_input.py +++ b/tests/student_code/keyboard_input.py @@ -1,23 +1,3 @@ -''' -simple_device = "62_20" - -def autonomous_setup(): - pass - -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): - if Keyboard.get_value('a'): - Robot.set_value(simple_device, "MY_INT", 123454321) - elif Keyboard.get_value('y'): - print(Robot.get_value(simple_device, "MY_INT")) - Robot.sleep(.45) -''' - simple_device = "62_20" def autonomous(): diff --git a/tests/student_code/net_handler_integration.py b/tests/student_code/net_handler_integration.py index cddaaab7..1bf91c44 100644 --- a/tests/student_code/net_handler_integration.py +++ b/tests/student_code/net_handler_integration.py @@ -20,13 +20,17 @@ def modify_my_int(): Robot.set_value(SIMPLE_DEV, "MY_INT", Robot.get_value(SIMPLE_DEV, "MY_INT") - 1) Robot.sleep(1) -def teleop_setup(): - print("Teleop setup has begun!") +def teleop(): + print("Teleop has begun!") Robot.run(print_if_button_a) Robot.run(modify_my_int) - -def teleop_main(): global i - if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: - print("Left joystick moved in x direction!") - i += 1 + while True: + if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: + print("Left joystick moved in x direction!") + i += 1 + Robot.sleep(0.1) + +def autonomous(): + while True: + pass diff --git a/tests/student_code/runtime_latency.py b/tests/student_code/runtime_latency.py index 471c343c..20b10acc 100644 --- a/tests/student_code/runtime_latency.py +++ b/tests/student_code/runtime_latency.py @@ -2,15 +2,12 @@ time_dev = '60_123' -def autonomous_setup(): - pass - -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): - if Gamepad.get_value('button_a'): - Robot.set_value(time_dev, "GET_TIME", True) +def autonomous(): + while True: + pass + +def teleop(): + while True: + if Gamepad.get_value('button_a'): + Robot.set_value(time_dev, "GET_TIME", True) + Robot.sleep(0.1) diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index f3801448..df01a16c 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -15,18 +15,15 @@ def constant_write(): Robot.set_value(GeneralTestDevice, "RED_INT", int_val) Robot.set_value(GeneralTestDevice, "ORANGE_FLOAT", float_val) Robot.set_value(GeneralTestDevice, "YELLOW_BOOL", bool_val) - int_val += 2; + int_val += 2 float_val += 3.14 bool_val = not bool_val -def autonomous_setup(): +def autonomous(): Robot.run(constant_write) + while True: + pass -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): - pass +def teleop(): + while True: + pass From 39a145fe2d15b79459fbb0a46cd576ae82651939 Mon Sep 17 00:00:00 2001 From: ishan-monie Date: Tue, 18 Jun 2024 23:17:52 -0500 Subject: [PATCH 07/18] modified first 5 student_code tests 3 --- tests/student_code/executor_sanity.py | 5 +---- tests/student_code/keyboard_input.py | 3 +-- tests/student_code/net_handler_integration.py | 5 ++--- tests/student_code/runtime_latency.py | 3 +-- tests/student_code/sanity_write.py | 3 +-- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/tests/student_code/executor_sanity.py b/tests/student_code/executor_sanity.py index cccb431a..b866f371 100644 --- a/tests/student_code/executor_sanity.py +++ b/tests/student_code/executor_sanity.py @@ -9,10 +9,7 @@ def constant_print(msg): time.sleep(2) def autonomous(): - print('Autonomous has begun!') - print(f"Starting position: {Robot.start_pos}") - while True: - Robot.run(constant_print, "autonomous") + pass # This teleop code generates a DivisionByZero Python error diff --git a/tests/student_code/keyboard_input.py b/tests/student_code/keyboard_input.py index 7b0595bc..97194c17 100644 --- a/tests/student_code/keyboard_input.py +++ b/tests/student_code/keyboard_input.py @@ -1,8 +1,7 @@ simple_device = "62_20" def autonomous(): - while True: - pass + pass def teleop(): while True: diff --git a/tests/student_code/net_handler_integration.py b/tests/student_code/net_handler_integration.py index 1bf91c44..235003ef 100644 --- a/tests/student_code/net_handler_integration.py +++ b/tests/student_code/net_handler_integration.py @@ -24,13 +24,12 @@ def teleop(): print("Teleop has begun!") Robot.run(print_if_button_a) Robot.run(modify_my_int) - global i while True: + global i if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: print("Left joystick moved in x direction!") i += 1 Robot.sleep(0.1) def autonomous(): - while True: - pass + pass diff --git a/tests/student_code/runtime_latency.py b/tests/student_code/runtime_latency.py index 20b10acc..6c20bc10 100644 --- a/tests/student_code/runtime_latency.py +++ b/tests/student_code/runtime_latency.py @@ -3,8 +3,7 @@ time_dev = '60_123' def autonomous(): - while True: - pass + pass def teleop(): while True: diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index df01a16c..54a9f670 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -25,5 +25,4 @@ def autonomous(): pass def teleop(): - while True: - pass + pass From c05d7f2aa24d77227f0750577f36d3c5d081ac8c Mon Sep 17 00:00:00 2001 From: ishan-monie Date: Tue, 18 Jun 2024 23:20:54 -0500 Subject: [PATCH 08/18] modified first 5 student_code tests 4 --- tests/student_code/net_handler_integration.py | 1 - tests/student_code/runtime_latency.py | 1 - tests/student_code/sanity_write.py | 2 -- 3 files changed, 4 deletions(-) diff --git a/tests/student_code/net_handler_integration.py b/tests/student_code/net_handler_integration.py index 235003ef..81a505d8 100644 --- a/tests/student_code/net_handler_integration.py +++ b/tests/student_code/net_handler_integration.py @@ -29,7 +29,6 @@ def teleop(): if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: print("Left joystick moved in x direction!") i += 1 - Robot.sleep(0.1) def autonomous(): pass diff --git a/tests/student_code/runtime_latency.py b/tests/student_code/runtime_latency.py index 6c20bc10..0ac2d67c 100644 --- a/tests/student_code/runtime_latency.py +++ b/tests/student_code/runtime_latency.py @@ -9,4 +9,3 @@ def teleop(): while True: if Gamepad.get_value('button_a'): Robot.set_value(time_dev, "GET_TIME", True) - Robot.sleep(0.1) diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index 54a9f670..35ef1244 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -21,8 +21,6 @@ def constant_write(): def autonomous(): Robot.run(constant_write) - while True: - pass def teleop(): pass From d7fb74a5b20181539f74c4a6c7f1ecd8c9f3c952 Mon Sep 17 00:00:00 2001 From: Luke Wang <56856692+3142008956@users.noreply.github.com> Date: Tue, 18 Jun 2024 21:24:53 -0700 Subject: [PATCH 09/18] Revert "modified first 5 student_code tests" --- tests/student_code/executor_sanity.py | 23 ++++++++++++------- tests/student_code/keyboard_input.py | 22 +++++++++++------- tests/student_code/net_handler_integration.py | 16 ++++++------- tests/student_code/runtime_latency.py | 15 ++++++++---- tests/student_code/sanity_write.py | 12 +++++++--- 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/tests/student_code/executor_sanity.py b/tests/student_code/executor_sanity.py index b866f371..2d17be72 100644 --- a/tests/student_code/executor_sanity.py +++ b/tests/student_code/executor_sanity.py @@ -4,15 +4,22 @@ # This autonomous code prints some output every two seconds def constant_print(msg): - while True: - print(f"{msg} printing again") - time.sleep(2) + while True: + print(f"{msg} printing again") + time.sleep(2) -def autonomous(): - pass +def autonomous_setup(): + print('Autonomous setup has begun!') + print(f"Starting position: {Robot.start_pos}") + Robot.run(constant_print, "autonomous") + +def autonomous_main(): + pass # This teleop code generates a DivisionByZero Python error -def teleop(): - while True: - oops = 1 / 0 +def teleop_setup(): + pass + +def teleop_main(): + oops = 1 / 0 diff --git a/tests/student_code/keyboard_input.py b/tests/student_code/keyboard_input.py index 97194c17..fe72d09f 100644 --- a/tests/student_code/keyboard_input.py +++ b/tests/student_code/keyboard_input.py @@ -1,12 +1,18 @@ + simple_device = "62_20" -def autonomous(): +def autonomous_setup(): + pass + +def autonomous_main(): + pass + +def teleop_setup(): pass -def teleop(): - while True: - if Keyboard.get_value('a'): - Robot.set_value(simple_device, "MY_INT", 123454321) - elif Keyboard.get_value('y'): - print(Robot.get_value(simple_device, "MY_INT")) - Robot.sleep(0.45) +def teleop_main(): + if Keyboard.get_value('a'): + Robot.set_value(simple_device, "MY_INT", 123454321) + elif Keyboard.get_value('y'): + print(Robot.get_value(simple_device, "MY_INT")) + Robot.sleep(.45) diff --git a/tests/student_code/net_handler_integration.py b/tests/student_code/net_handler_integration.py index 81a505d8..cddaaab7 100644 --- a/tests/student_code/net_handler_integration.py +++ b/tests/student_code/net_handler_integration.py @@ -20,15 +20,13 @@ def modify_my_int(): Robot.set_value(SIMPLE_DEV, "MY_INT", Robot.get_value(SIMPLE_DEV, "MY_INT") - 1) Robot.sleep(1) -def teleop(): - print("Teleop has begun!") +def teleop_setup(): + print("Teleop setup has begun!") Robot.run(print_if_button_a) Robot.run(modify_my_int) - while True: - global i - if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: - print("Left joystick moved in x direction!") - i += 1 -def autonomous(): - pass +def teleop_main(): + global i + if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: + print("Left joystick moved in x direction!") + i += 1 diff --git a/tests/student_code/runtime_latency.py b/tests/student_code/runtime_latency.py index 0ac2d67c..471c343c 100644 --- a/tests/student_code/runtime_latency.py +++ b/tests/student_code/runtime_latency.py @@ -2,10 +2,15 @@ time_dev = '60_123' -def autonomous(): +def autonomous_setup(): pass -def teleop(): - while True: - if Gamepad.get_value('button_a'): - Robot.set_value(time_dev, "GET_TIME", True) +def autonomous_main(): + pass + +def teleop_setup(): + pass + +def teleop_main(): + if Gamepad.get_value('button_a'): + Robot.set_value(time_dev, "GET_TIME", True) diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index 35ef1244..f3801448 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -15,12 +15,18 @@ def constant_write(): Robot.set_value(GeneralTestDevice, "RED_INT", int_val) Robot.set_value(GeneralTestDevice, "ORANGE_FLOAT", float_val) Robot.set_value(GeneralTestDevice, "YELLOW_BOOL", bool_val) - int_val += 2 + int_val += 2; float_val += 3.14 bool_val = not bool_val -def autonomous(): +def autonomous_setup(): Robot.run(constant_write) -def teleop(): +def autonomous_main(): + pass + +def teleop_setup(): + pass + +def teleop_main(): pass From bf94d1a1c14ca59102ea9d604c16f92e4d103904 Mon Sep 17 00:00:00 2001 From: Luke Wang Date: Wed, 4 Sep 2024 18:46:10 -0700 Subject: [PATCH 10/18] Modified studentcode files --- executor/studentcode.py | 6 ++---- tests/student_code/executor_sanity.py | 10 ++------- tests/student_code/keyboard_input.py | 21 +++++++------------ tests/student_code/net_handler_integration.py | 11 +++++----- tests/student_code/runtime_latency.py | 15 +++++-------- tests/student_code/sanity_write.py | 10 ++------- 6 files changed, 24 insertions(+), 49 deletions(-) diff --git a/executor/studentcode.py b/executor/studentcode.py index 0fc8305a..92bca9a5 100755 --- a/executor/studentcode.py +++ b/executor/studentcode.py @@ -1,7 +1,5 @@ -def autonomous_main(): +def autonomous(): print("Autonomous has begun!") - pass -def teleop_main(): +def teleop(): print("Teleop has begun!") - pass diff --git a/tests/student_code/executor_sanity.py b/tests/student_code/executor_sanity.py index 2d17be72..adf561e8 100644 --- a/tests/student_code/executor_sanity.py +++ b/tests/student_code/executor_sanity.py @@ -8,18 +8,12 @@ def constant_print(msg): print(f"{msg} printing again") time.sleep(2) -def autonomous_setup(): +def autonomous(): print('Autonomous setup has begun!') print(f"Starting position: {Robot.start_pos}") Robot.run(constant_print, "autonomous") -def autonomous_main(): - pass - # This teleop code generates a DivisionByZero Python error -def teleop_setup(): - pass - -def teleop_main(): +def teleop(): oops = 1 / 0 diff --git a/tests/student_code/keyboard_input.py b/tests/student_code/keyboard_input.py index fe72d09f..90ac611b 100644 --- a/tests/student_code/keyboard_input.py +++ b/tests/student_code/keyboard_input.py @@ -1,18 +1,13 @@ simple_device = "62_20" -def autonomous_setup(): +def autonomous(): pass -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): - if Keyboard.get_value('a'): - Robot.set_value(simple_device, "MY_INT", 123454321) - elif Keyboard.get_value('y'): - print(Robot.get_value(simple_device, "MY_INT")) - Robot.sleep(.45) +def teleop(): + while True: + if Keyboard.get_value('a'): + Robot.set_value(simple_device, "MY_INT", 123454321) + elif Keyboard.get_value('y'): + print(Robot.get_value(simple_device, "MY_INT")) + Robot.sleep(.45) diff --git a/tests/student_code/net_handler_integration.py b/tests/student_code/net_handler_integration.py index cddaaab7..5ee27eb8 100644 --- a/tests/student_code/net_handler_integration.py +++ b/tests/student_code/net_handler_integration.py @@ -20,13 +20,12 @@ def modify_my_int(): Robot.set_value(SIMPLE_DEV, "MY_INT", Robot.get_value(SIMPLE_DEV, "MY_INT") - 1) Robot.sleep(1) -def teleop_setup(): +def teleop(): print("Teleop setup has begun!") Robot.run(print_if_button_a) Robot.run(modify_my_int) - -def teleop_main(): global i - if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: - print("Left joystick moved in x direction!") - i += 1 + while True: + if i < 3 and Gamepad.get_value('joystick_left_x') != 0.0: + print("Left joystick moved in x direction!") + i += 1 diff --git a/tests/student_code/runtime_latency.py b/tests/student_code/runtime_latency.py index 471c343c..0ac2d67c 100644 --- a/tests/student_code/runtime_latency.py +++ b/tests/student_code/runtime_latency.py @@ -2,15 +2,10 @@ time_dev = '60_123' -def autonomous_setup(): +def autonomous(): pass -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): - if Gamepad.get_value('button_a'): - Robot.set_value(time_dev, "GET_TIME", True) +def teleop(): + while True: + if Gamepad.get_value('button_a'): + Robot.set_value(time_dev, "GET_TIME", True) diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index f3801448..b7665cac 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -19,14 +19,8 @@ def constant_write(): float_val += 3.14 bool_val = not bool_val -def autonomous_setup(): +def autonomous(): Robot.run(constant_write) -def autonomous_main(): - pass - -def teleop_setup(): - pass - -def teleop_main(): +def teleop(): pass From c328edfa265c9cef25a2b5c14eb0ea9bee48eaa1 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Wed, 12 Feb 2025 20:40:39 -0800 Subject: [PATCH 11/18] [EXECUTOR] confirmed executor rewrite works, made small bug fixes --- executor/Makefile | 2 +- executor/executor.c | 12 ++++++------ executor/studentcode.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/executor/Makefile b/executor/Makefile index ec1f2cfe..43411b8e 100755 --- a/executor/Makefile +++ b/executor/Makefile @@ -5,7 +5,7 @@ LIBS=-pthread -lrt -Wall -export-dynamic -fPIC SRCS = executor.c gamestate_filter.c ../logger/logger.c ../runtime_util/runtime_util.c ../shm_wrapper/shm_wrapper.c # Python compilation definitions -PY_VER = python3.10 +PY_VER = python3.11 PY_LIB = -l$(PY_VER) CFLAGS = $(shell $(PY_VER)-config --cflags) diff --git a/executor/executor.c b/executor/executor.c index 5bd96e2e..7d35e470 100644 --- a/executor/executor.c +++ b/executor/executor.c @@ -1,7 +1,7 @@ #define PY_SSIZE_T_CLEAN #include //for networking #include //for POSIX threads -#include // For Python's C API +#include // For Python's C API #include // Used to handle SIGTERM, SIGINT, SIGKILL #include //for standard int types #include //for i/o @@ -201,6 +201,7 @@ static uint8_t run_py_function(const char* func_name, struct timespec* timeout, // retrieve the Python function from the student code PyObject* pFunc = PyObject_GetAttrString(pModule, func_name); PyObject* pValue = NULL; + log_printf(ERROR, "%s",func_name); if (pFunc && PyCallable_Check(pFunc)) { pValue = PyObject_CallObject(pFunc, args); // make call to Python function @@ -221,7 +222,6 @@ static uint8_t run_py_function(const char* func_name, struct timespec* timeout, } else { ret = 3; // Timed out by parent process } - break; } else if (mode == AUTO || mode == TELEOP) { // Need to check if error occurred in action thread PyObject* event = PyObject_GetAttrString(pRobot, "error_event"); @@ -239,11 +239,9 @@ static uint8_t run_py_function(const char* func_name, struct timespec* timeout, } else { ret = 3; // Timed out by parent process } - break; } else if (PyObject_IsTrue(event_set) == 1) { log_printf(ERROR, "Stopping %s due to error in action", func_name); ret = 1; - break; } } @@ -318,8 +316,10 @@ static pid_t start_mode_subprocess(char* student_code) { signal(SIGTERM, python_exit_handler); // Set handler for killing subprocess char* mode_str = get_mode_str(mode); - err = run_py_function(mode_str, &main_interval, 1, NULL, NULL); // Run main function - + int err = run_py_function(mode_str, &main_interval, NULL, NULL); // Run main function + if (err) { + log_printf(WARN, "NEED TO EDIT STATEMENT"); // "Problem Child" + } exit(0); return pid; // Never reach this statement due to exit, needed to fix compiler warning } else { diff --git a/executor/studentcode.py b/executor/studentcode.py index 0fc8305a..7505f4aa 100755 --- a/executor/studentcode.py +++ b/executor/studentcode.py @@ -1,7 +1,7 @@ -def autonomous_main(): +def autonomous(): print("Autonomous has begun!") pass -def teleop_main(): +def teleop(): print("Teleop has begun!") pass From 4ccbb21ab1b9e22f0ccba5657ab0c24dbb38e40d Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Wed, 5 Mar 2025 21:53:06 -0800 Subject: [PATCH 12/18] merged master into executor_rewrite branch, correctly --- executor/Makefile | 4 ---- executor/executor.c | 12 ++++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/executor/Makefile b/executor/Makefile index 39d0fbca..2065917b 100755 --- a/executor/Makefile +++ b/executor/Makefile @@ -5,11 +5,7 @@ LIBS=-pthread -lrt -Wall -export-dynamic -fPIC SRCS = executor.c gamestate_filter.c ../logger/logger.c ../runtime_util/runtime_util.c ../shm_wrapper/shm_wrapper.c # Python compilation definitions -<<<<<<< HEAD -PY_VER = python3.11 -======= PY_VER = python3.12 ->>>>>>> c02bcc59add84236ca74b9652ff8e2528b2c1394 PY_LIB = -l$(PY_VER) CFLAGS = $(shell $(PY_VER)-config --cflags) diff --git a/executor/executor.c b/executor/executor.c index e814da67..e1b96df6 100644 --- a/executor/executor.c +++ b/executor/executor.c @@ -1,11 +1,7 @@ #define PY_SSIZE_T_CLEAN #include //for networking #include //for POSIX threads -<<<<<<< HEAD -#include // For Python's C API -======= #include // For Python's C API ->>>>>>> c02bcc59add84236ca74b9652ff8e2528b2c1394 #include // Used to handle SIGTERM, SIGINT, SIGKILL #include //for standard int types #include //for i/o @@ -205,7 +201,7 @@ static uint8_t run_py_function(const char* func_name, struct timespec* timeout, // retrieve the Python function from the student code PyObject* pFunc = PyObject_GetAttrString(pModule, func_name); PyObject* pValue = NULL; - log_printf(ERROR, "%s",func_name); + log_printf(ERROR, "%s", func_name); if (pFunc && PyCallable_Check(pFunc)) { pValue = PyObject_CallObject(pFunc, args); // make call to Python function @@ -321,9 +317,9 @@ static pid_t start_mode_subprocess(char* student_code) { char* mode_str = get_mode_str(mode); int err = run_py_function(mode_str, &main_interval, NULL, NULL); // Run main function - if (err) { - log_printf(WARN, "NEED TO EDIT STATEMENT"); // "Problem Child" - } + if (err) { + log_printf(WARN, "NEED TO EDIT STATEMENT"); // "Problem Child" + } exit(0); return pid; // Never reach this statement due to exit, needed to fix compiler warning } else { From e6e384f89d1ab6b06146fdd0fa6ec3404701b215 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Wed, 5 Mar 2025 22:02:48 -0800 Subject: [PATCH 13/18] [TESTS] fixed tc_71_2 and tc_71_15 to account for updates executor correctly --- tests/integration/tc_71_2.c | 2 +- tests/student_code/sanity_write.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/tc_71_2.c b/tests/integration/tc_71_2.c index 4579c479..824c3cfe 100644 --- a/tests/integration/tc_71_2.c +++ b/tests/integration/tc_71_2.c @@ -8,7 +8,7 @@ */ char check_output_6[] = - " File \"/home/runner/work/runtime/runtime/tests/student_code/executor_sanity.py\", line 25, in teleop_main\n" + " File \"/home/runner/work/runtime/runtime/tests/student_code/executor_sanity.py\", line 19, in teleop_main\n" " oops = 1 / 0\n" " ~~^~~\n" "ZeroDivisionError: division by zero\n"; diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index b7665cac..35ef1244 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -15,7 +15,7 @@ def constant_write(): Robot.set_value(GeneralTestDevice, "RED_INT", int_val) Robot.set_value(GeneralTestDevice, "ORANGE_FLOAT", float_val) Robot.set_value(GeneralTestDevice, "YELLOW_BOOL", bool_val) - int_val += 2; + int_val += 2 float_val += 3.14 bool_val = not bool_val From 35020204c2c5c9d29f32d399c7cb86ed70ddd779 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Wed, 5 Mar 2025 22:37:39 -0800 Subject: [PATCH 14/18] [TESTS] fixed tc_71_12, attempting fix for tc_71_15 --- tests/integration/tc_71_2.c | 2 +- tests/student_code/sanity_write.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/tc_71_2.c b/tests/integration/tc_71_2.c index 824c3cfe..4c6cbdff 100644 --- a/tests/integration/tc_71_2.c +++ b/tests/integration/tc_71_2.c @@ -8,7 +8,7 @@ */ char check_output_6[] = - " File \"/home/runner/work/runtime/runtime/tests/student_code/executor_sanity.py\", line 19, in teleop_main\n" + " File \"/home/runner/work/runtime/runtime/tests/student_code/executor_sanity.py\", line 19, in teleop\n" " oops = 1 / 0\n" " ~~^~~\n" "ZeroDivisionError: division by zero\n"; diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index 35ef1244..f24f425a 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -21,6 +21,8 @@ def constant_write(): def autonomous(): Robot.run(constant_write) + while True: + time.sleep(2) def teleop(): pass From b715646b9c5a9fd2f50a9a37d377418a5be784d6 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Wed, 5 Mar 2025 22:46:50 -0800 Subject: [PATCH 15/18] [TESTS] attempting fix for tc_71_15 --- tests/student_code/sanity_write.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/student_code/sanity_write.py b/tests/student_code/sanity_write.py index f24f425a..54a9f670 100644 --- a/tests/student_code/sanity_write.py +++ b/tests/student_code/sanity_write.py @@ -22,7 +22,7 @@ def constant_write(): def autonomous(): Robot.run(constant_write) while True: - time.sleep(2) + pass def teleop(): pass From e391b360879a79300e5dd3f1b779a54800994d43 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Wed, 5 Mar 2025 22:58:00 -0800 Subject: [PATCH 16/18] [TESTS] modified tc_71_2 so it expects teleop rather than teleop_main --- tests/integration/tc_71_2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/tc_71_2.c b/tests/integration/tc_71_2.c index 4c6cbdff..3eac4ff4 100644 --- a/tests/integration/tc_71_2.c +++ b/tests/integration/tc_71_2.c @@ -37,7 +37,7 @@ int main() { send_run_mode(SHEPHERD, TELEOP); add_ordered_string_output("Traceback (most recent call last):\n"); add_ordered_string_output(check_output_6); - add_ordered_string_output("Python function teleop_main call failed\n"); + add_ordered_string_output("Python function teleop call failed\n"); check_run_mode(TELEOP); send_run_mode(DAWN, IDLE); From f4f8db0d26c9a27627182e23e231d5b87b820e39 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Fri, 14 Mar 2025 16:34:15 -0700 Subject: [PATCH 17/18] [EXECUTOR][SYSTEMD] changed python version to rasbian default, updated pi to ubuntu is runtime_update service file --- executor/Makefile | 2 +- executor/executor.c | 2 +- systemd/runtime_update.service | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/executor/Makefile b/executor/Makefile index 2065917b..43411b8e 100755 --- a/executor/Makefile +++ b/executor/Makefile @@ -5,7 +5,7 @@ LIBS=-pthread -lrt -Wall -export-dynamic -fPIC SRCS = executor.c gamestate_filter.c ../logger/logger.c ../runtime_util/runtime_util.c ../shm_wrapper/shm_wrapper.c # Python compilation definitions -PY_VER = python3.12 +PY_VER = python3.11 PY_LIB = -l$(PY_VER) CFLAGS = $(shell $(PY_VER)-config --cflags) diff --git a/executor/executor.c b/executor/executor.c index e1b96df6..473f3e98 100644 --- a/executor/executor.c +++ b/executor/executor.c @@ -1,7 +1,7 @@ #define PY_SSIZE_T_CLEAN #include //for networking #include //for POSIX threads -#include // For Python's C API +#include // For Python's C API #include // Used to handle SIGTERM, SIGINT, SIGKILL #include //for standard int types #include //for i/o diff --git a/systemd/runtime_update.service b/systemd/runtime_update.service index 34d0f35d..d4648fda 100644 --- a/systemd/runtime_update.service +++ b/systemd/runtime_update.service @@ -3,9 +3,9 @@ Description=Update process for Runtime [Service] Type=oneshot -User=pi -WorkingDirectory=/home/pi/runtime -ExecStart=/home/pi/runtime/scripts/update.sh +User=ubuntu +WorkingDirectory=/home/ubuntu/runtime +ExecStart=/home/ubuntu/runtime/scripts/update.sh KillSignal=SIGINT [Install] From 0e9c15e73dcd0a07773d31059ba66ce48a90479b Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Fri, 14 Mar 2025 16:44:39 -0700 Subject: [PATCH 18/18] [EXECUTOR] returned python version to 3.12 to github CI tests --- executor/Makefile | 2 +- executor/executor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/Makefile b/executor/Makefile index 43411b8e..2065917b 100755 --- a/executor/Makefile +++ b/executor/Makefile @@ -5,7 +5,7 @@ LIBS=-pthread -lrt -Wall -export-dynamic -fPIC SRCS = executor.c gamestate_filter.c ../logger/logger.c ../runtime_util/runtime_util.c ../shm_wrapper/shm_wrapper.c # Python compilation definitions -PY_VER = python3.11 +PY_VER = python3.12 PY_LIB = -l$(PY_VER) CFLAGS = $(shell $(PY_VER)-config --cflags) diff --git a/executor/executor.c b/executor/executor.c index 473f3e98..e1b96df6 100644 --- a/executor/executor.c +++ b/executor/executor.c @@ -1,7 +1,7 @@ #define PY_SSIZE_T_CLEAN #include //for networking #include //for POSIX threads -#include // For Python's C API +#include // For Python's C API #include // Used to handle SIGTERM, SIGINT, SIGKILL #include //for standard int types #include //for i/o