From 7bd6275bac516e5bb281d975e1f9e1061084ae12 Mon Sep 17 00:00:00 2001 From: VladislavOstapov Date: Sat, 3 Dec 2022 01:22:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- emulator.cpp | 2 +- robot.cpp | 20 +++++++++++--------- scheduler.c | 17 ++++++++++------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/emulator.cpp b/emulator.cpp index 7c50deb..81cf22e 100644 --- a/emulator.cpp +++ b/emulator.cpp @@ -185,7 +185,7 @@ int main() { // b.zone = (short) abs(random() % 20); // } - barrels[5] = makeBarrel(1, 10, 3); + barrels[5] = makeBarrel(1, 21, 3); current_tic = 0; const char* message = nullptr; diff --git a/robot.cpp b/robot.cpp index 1a99b16..d4ad64e 100644 --- a/robot.cpp +++ b/robot.cpp @@ -9,15 +9,6 @@ bool robot1_offset_pos = false; bool robot2_offset_pos = false; -static short get_barrel(char robot_id) { - for (short i = 0; i < BARRELS_COUNT; i++) { - if (barrels[i].flags.robot == robot_id) { - return i; - } - } - return -1; -} - // true означает что движение закончено static bool robot_move(robot_regs& r, short target, char robot_id) { // после перемещения мы явно в точной позиции @@ -44,6 +35,12 @@ static void emulate_robot(robot_code &code, robot_regs& r, char robot_id) { if (code.PC < 0) { return; } + + // приватизируем бочку + if (code.barrel_id >= 0) { + barrels[code.barrel_id].flags.robot = robot_id; + } + const short cmd_arg = code.code[code.PC] & (~ROBOT_CMD_MASK); switch (code.code[code.PC] & ROBOT_CMD_MASK) { @@ -127,6 +124,7 @@ static void emulate_robot(robot_code &code, robot_regs& r, char robot_id) { break; case ROBOT_CMD_INC_ZONE: + // TODO сделать так, чтобы зоны переключались с учетом отключенных зон if (cmd_arg == ROBOT_ZONE_ETCH) { std::cout << "robot " << robot_id << " increment etching..." << std::endl; etching_zone = (etching_zone + 1) & 1; @@ -142,6 +140,10 @@ static void emulate_robot(robot_code &code, robot_regs& r, char robot_id) { case ROBOT_CMD_END: default: code.PC = -1; + // де-приватизируем бочку + if (code.barrel_id >= 0) { + barrels[code.barrel_id].flags.robot = 0; + } } } diff --git a/scheduler.c b/scheduler.c index 0798c54..c46afd9 100644 --- a/scheduler.c +++ b/scheduler.c @@ -159,10 +159,10 @@ short can_move(struct barrel* bar) { case ZONE_UNLOAD: // последняя промывка, нужно разрешение на выгрузку - if (schedulerOneRobotMode) { + if (schedulerOneRobotMode && schedulerUnloadButton) { // нужно промывку загрузку 0 - if (!zone_is_busy(17)) { - return 17; + if (!zone_is_busy(ZONE_LOAD_1)) { + return ZONE_LOAD_1; } } break; @@ -305,8 +305,7 @@ void debug_print_robot1_code() { break; case ROBOT_CMD_TMR_SET: - printf(" set barrel timer %d secs\n", cmd_arg); - i++; + printf(" set barrel timer %d secs\n", robot1_code.code[++i]); break; case ROBOT_CMD_SET_LOCK_ZONE: @@ -350,6 +349,7 @@ void schedule_robot_1() { tasks[i].dest_zone = can_move(barrels + i); } + // TODO добавить вставку lock-point'ов на задачах на несколько роботов // найти подходящую задачу if (schedulerOneRobotMode) { short target_task = scheduler_find_task(tasks, robot1.dx.current_zone); @@ -367,8 +367,11 @@ void schedule_robot_1() { if (tasks[target_task].start_zone == 22) { robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_OFF; robot1_code.code[cmd_index++] = ROBOT_CMD_UP; - robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE | 21; - robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_OFF; + if (robot1.dx.current_zone != 21) { + robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE | 21; + robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_OFF; + } + robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_2; robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE | 22; } else { robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE | tasks[target_task].start_zone;