Рефакторинг
This commit is contained in:
parent
8cfb358cf6
commit
14b5cdf06d
69
emulator.cpp
69
emulator.cpp
@ -9,6 +9,11 @@
|
|||||||
#include "emulator.h"
|
#include "emulator.h"
|
||||||
#include "robot.h"
|
#include "robot.h"
|
||||||
|
|
||||||
|
|
||||||
|
// закомментить когда надо будет отключить
|
||||||
|
//#define DEBUG_CORRECTION
|
||||||
|
|
||||||
|
|
||||||
struct barrel barrels[BARRELS_COUNT];
|
struct barrel barrels[BARRELS_COUNT];
|
||||||
|
|
||||||
struct robot_regs robot1;
|
struct robot_regs robot1;
|
||||||
@ -51,8 +56,14 @@ char scheduler_start_signal = 1;
|
|||||||
char auto_mode_pause = 0;
|
char auto_mode_pause = 0;
|
||||||
char hla_night_mode = 0;
|
char hla_night_mode = 0;
|
||||||
|
|
||||||
|
short hla_exchange_zone = ZONE_GALVANIZING_1;
|
||||||
|
|
||||||
short etching_zone = 0, galvanizing_zone = 0;
|
short hla_disabled_zones = 0;
|
||||||
|
|
||||||
|
|
||||||
|
short etching_zone = -2, galvanizing_zone = -2;
|
||||||
|
|
||||||
|
char hla_correct_command = 0;
|
||||||
|
|
||||||
|
|
||||||
static const int ROWS = 10;
|
static const int ROWS = 10;
|
||||||
@ -132,7 +143,42 @@ static void image_draw_borders() {
|
|||||||
// рамки ванн
|
// рамки ванн
|
||||||
char tmp[24];
|
char tmp[24];
|
||||||
for (int i = 0, zone = 0; i < COLS; i += 5, zone++) {
|
for (int i = 0, zone = 0; i < COLS; i += 5, zone++) {
|
||||||
sprintf(tmp, "|\n|\n+----+\n|\n|Z-%02d|", zone);
|
const char* label = nullptr;
|
||||||
|
const char* disabled_label = "+XXXX+";
|
||||||
|
const char* selected_label = "+####+";
|
||||||
|
|
||||||
|
if (zone == ZONE_ETCHING_1) {
|
||||||
|
if (hla_disabled_zones & DISABLED_ETCH_1) {
|
||||||
|
label = disabled_label;
|
||||||
|
}
|
||||||
|
if (etching_zone == 0) {
|
||||||
|
label = selected_label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zone == ZONE_ETCHING_2) {
|
||||||
|
if (hla_disabled_zones & DISABLED_ETCH_2) {
|
||||||
|
label = disabled_label;
|
||||||
|
}
|
||||||
|
if (etching_zone == 1) {
|
||||||
|
label = selected_label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zone >= ZONE_GALVANIZING_1 && zone <= ZONE_GALVANIZING_8) {
|
||||||
|
const auto zone_id = zone - ZONE_GALVANIZING_1;
|
||||||
|
if (hla_disabled_zones & (DISABLED_GAL_1 << zone_id)) {
|
||||||
|
label = disabled_label;
|
||||||
|
}
|
||||||
|
if (galvanizing_zone == zone_id) {
|
||||||
|
label = selected_label;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (label == nullptr) {
|
||||||
|
label = "+----+";
|
||||||
|
}
|
||||||
|
sprintf(tmp, "|\n|\n%s\n|\n|Z-%02d|", label, zone);
|
||||||
image_insert_sprite(5, i, tmp, false);
|
image_insert_sprite(5, i, tmp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,12 +227,12 @@ static void showAll() {
|
|||||||
image_init();
|
image_init();
|
||||||
image_draw_borders();
|
image_draw_borders();
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
sprintf(tmp, "Lock1=%2d Lock2=%2d", robot1_lock_zone, robot2_lock_zone);
|
sprintf(tmp, "Lock1=%2d Lock2=%2d E=%d G=%d", robot1_lock_zone, robot2_lock_zone, etching_zone, galvanizing_zone);
|
||||||
image_insert_sprite(0, 2, tmp);
|
image_insert_sprite(0, 2, tmp);
|
||||||
|
|
||||||
collectBarrelsStatistic();
|
collectBarrelsStatistic();
|
||||||
sprintf(tmp, "barrels=%2d time=%d max_time=%d", barrels_count, barrels_time, max_time);
|
sprintf(tmp, "barrels=%2d time=%d max_time=%d", barrels_count, barrels_time, max_time);
|
||||||
image_insert_sprite(0, 25, tmp);
|
image_insert_sprite(0, 30, tmp);
|
||||||
|
|
||||||
sprintf(tmp, "MODE: night=%d pause=%d", hla_night_mode, auto_mode_pause);
|
sprintf(tmp, "MODE: night=%d pause=%d", hla_night_mode, auto_mode_pause);
|
||||||
image_insert_sprite(0, 70, tmp);
|
image_insert_sprite(0, 70, tmp);
|
||||||
@ -272,8 +318,15 @@ static void open_socket() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
#ifdef DEBUG_CORRECTION
|
||||||
|
robot1.mx.correct_sensor = false;
|
||||||
|
robot1.dx.current_zone = 5;
|
||||||
|
robot2.mx.correct_sensor = false;
|
||||||
|
robot2.dx.current_zone = 3;
|
||||||
|
#else
|
||||||
robot1.mx.correct_sensor = true;
|
robot1.mx.correct_sensor = true;
|
||||||
robot2.mx.correct_sensor = true;
|
robot2.mx.correct_sensor = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
open_socket();
|
open_socket();
|
||||||
|
|
||||||
@ -291,7 +344,9 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
robot_main();
|
robot_main();
|
||||||
scheduler_main();
|
// scheduler_main();
|
||||||
|
increment_zone(ROBOT_ZONE_GAL);
|
||||||
|
increment_zone(ROBOT_ZONE_ETCH);
|
||||||
send_str("\033c");
|
send_str("\033c");
|
||||||
showAll();
|
showAll();
|
||||||
|
|
||||||
@ -319,6 +374,10 @@ int main() {
|
|||||||
if (robot2_code.PC >= 0)
|
if (robot2_code.PC >= 0)
|
||||||
debug_print_robot_code(&robot2_code, 2, sock_fd);
|
debug_print_robot_code(&robot2_code, 2, sock_fd);
|
||||||
|
|
||||||
|
#ifdef DEBUG_CORRECTION
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
send_str("cmd >> ");
|
send_str("cmd >> ");
|
||||||
std::string in;
|
std::string in;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
25
scheduler.c
25
scheduler.c
@ -126,6 +126,7 @@ void scheduler_main()
|
|||||||
|
|
||||||
// кнопка загрузки барабана
|
// кнопка загрузки барабана
|
||||||
if (button_load) {
|
if (button_load) {
|
||||||
|
if (!hla_night_mode) {
|
||||||
if (!zone_is_busy(1)) {
|
if (!zone_is_busy(1)) {
|
||||||
for (int i = 0; i < BARRELS_COUNT; i++) {
|
for (int i = 0; i < BARRELS_COUNT; i++) {
|
||||||
if (!barrels[i].flags.is_exist) {
|
if (!barrels[i].flags.is_exist) {
|
||||||
@ -149,6 +150,9 @@ void scheduler_main()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
button_load = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// кнопка выгрузки
|
// кнопка выгрузки
|
||||||
@ -217,23 +221,7 @@ void scheduler_main()
|
|||||||
// а вот для режима двух роботов все интересно
|
// а вот для режима двух роботов все интересно
|
||||||
// для каждого робота нужно получить свой список задач
|
// для каждого робота нужно получить свой список задач
|
||||||
// и надо еще сделать так, чтобы роботы не столкнулись
|
// и надо еще сделать так, чтобы роботы не столкнулись
|
||||||
char cmd_en = 0;
|
|
||||||
|
|
||||||
// добавляем ночной режим: в режиме двух роботов требуется чтобы во время ночного режима робот 2 стоял на парковке
|
|
||||||
if (hla_night_mode) {
|
|
||||||
if (!robot2.mx.correct_sensor) {
|
|
||||||
// уводим робота в парковку
|
|
||||||
if (robot2_code.PC < 0) {
|
|
||||||
robot2_code.barrel_id = -1;
|
|
||||||
robot2_code.code[0] = ROBOT_CMD_DOWN();
|
|
||||||
robot2_code.code[1] = ROBOT_CMD_MOVE_TO_PARKING();
|
|
||||||
robot2_code.code[2] = ROBOT_CMD_END();
|
|
||||||
robot2_code.PC = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
cmd_en = 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// логика для того, чтобы роботы не столкнулись в начале
|
// логика для того, чтобы роботы не столкнулись в начале
|
||||||
if (robot1.dx.current_zone < ZONE_GALVANIZING_1) {
|
if (robot1.dx.current_zone < ZONE_GALVANIZING_1) {
|
||||||
// начальная позиция робота 1 - промывка 3Б
|
// начальная позиция робота 1 - промывка 3Б
|
||||||
@ -257,11 +245,6 @@ void scheduler_main()
|
|||||||
robot2_code.PC = 0;
|
robot2_code.PC = 0;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cmd_en = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd_en) {
|
|
||||||
// отдельно просчитаем все для первого робота
|
// отдельно просчитаем все для первого робота
|
||||||
if (robot1_code.PC < 0) {
|
if (robot1_code.PC < 0) {
|
||||||
for (short i = 0; i < BARRELS_COUNT; i++) {
|
for (short i = 0; i < BARRELS_COUNT; i++) {
|
||||||
|
Reference in New Issue
Block a user