Исправления набора инструкций, теперь они корректно работают с автоприведением типов от компилятора
This commit is contained in:
127
scheduler.c
127
scheduler.c
@@ -271,48 +271,50 @@ void debug_print_robot1_code() {
|
||||
// printf("INFO: code length is %d\n", cmd_index);
|
||||
printf("Code for R0, B%d:\n", robot1_code.barrel_id);
|
||||
for (int i = 0; i < 16; i++) {
|
||||
const short cmd_arg = robot1_code.code[i] & (~ROBOT_CMD_MASK);
|
||||
const short cmd_arg = (short)(robot1_code.code[i] & (short)(~ROBOT_CMD_MASK));
|
||||
|
||||
if ((robot1_code.code[i] & ROBOT_CMD_MASK) == ROBOT_CMD_END) {
|
||||
printf(" %3d: 0x%04X", i, robot1_code.code[i] & 0xFFFF);
|
||||
|
||||
if ((robot1_code.code[i] & ROBOT_CMD_MASK) == ROBOT_CMD_END_code) {
|
||||
printf(" END\n");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (robot1_code.code[i] & ROBOT_CMD_MASK) {
|
||||
case ROBOT_CMD_MOVE_TO_ZONE:
|
||||
switch ((short)(robot1_code.code[i] & (short)ROBOT_CMD_MASK)) {
|
||||
case ROBOT_CMD_MOVE_TO_ZONE_code:
|
||||
printf(" move to zone %d (with barrel: %d)\n", cmd_arg & (~ROBOT_WITH_BARREL), (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_MOVE_OFF:
|
||||
printf(" move to offset pos\n");
|
||||
case ROBOT_CMD_MOVE_OFF_code:
|
||||
if (cmd_arg) {
|
||||
printf(" move to offset pos\n");
|
||||
} else {
|
||||
printf(" move to accurate pos\n");
|
||||
}
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_UP:
|
||||
case ROBOT_CMD_UP_code:
|
||||
printf(" up (with barrel: %d)\n", (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
||||
break;
|
||||
|
||||
// в эмуляторе не важно где я, поэтому тут обе команды вниз обрабатываются одинаково
|
||||
case ROBOT_CMD_DOWN:
|
||||
case ROBOT_CMD_DOWN_code:
|
||||
printf(" down (with barrel: %d)\n", (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_DOWN_2:
|
||||
printf(" down 2 (with barrel: %d)\n", (cmd_arg & ROBOT_WITH_BARREL) != 0);
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_WAIT:
|
||||
case ROBOT_CMD_WAIT_code:
|
||||
printf(" wait %d secs\n", cmd_arg);
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_TMR_SET:
|
||||
printf(" set barrel timer %d secs\n", robot1_code.code[++i]);
|
||||
case ROBOT_CMD_TMR_SET_code:
|
||||
printf(" set barrel timer %d secs\n", cmd_arg);
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_SET_LOCK_ZONE:
|
||||
case ROBOT_CMD_SET_LOCK_ZONE_code:
|
||||
printf(" set lock zone %d\n", cmd_arg);
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_CORRECT_AXIS:
|
||||
case ROBOT_CMD_CORRECT_AXIS_code:
|
||||
if (cmd_arg == ROBOT_AXIS_X) {
|
||||
printf(" correct axis: X\n");
|
||||
} else if (cmd_arg == ROBOT_AXIS_Z) {
|
||||
@@ -322,18 +324,18 @@ void debug_print_robot1_code() {
|
||||
}
|
||||
break;
|
||||
|
||||
case ROBOT_CMD_INC_ZONE:
|
||||
if (cmd_arg == ROBOT_ZONE_ETCH) {
|
||||
printf(" increment: etching\n");
|
||||
} else if (cmd_arg == ROBOT_ZONE_GAL) {
|
||||
printf(" increment: galvanic\n");
|
||||
case ROBOT_CMD_INC_ZONE_code:
|
||||
if (cmd_arg == ROBOT_ZONE_GAL) {
|
||||
printf(" increment zone: galvanic\n");
|
||||
} else if (cmd_arg == ROBOT_ZONE_ETCH) {
|
||||
printf(" increment zone: etching\n");
|
||||
} else {
|
||||
printf(" increment: INVALID (%d)\n", cmd_arg);
|
||||
printf(" increment zone: INVALID (0x%4X)\n", cmd_arg);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf(" UNKNOWN: 0x(%04X)\n", cmd_arg);
|
||||
printf(" UNKNOWN: 0x%04X\n", robot1_code.code[i] & 0xFFFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -363,45 +365,41 @@ void schedule_robot_1() {
|
||||
short cmd_index = 0;
|
||||
|
||||
// первым делом добавляем команду опустить траверсу
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN();
|
||||
|
||||
if (tasks[target_task].dest_zone == ZONE_PASSIVATION) {
|
||||
// пассивация, тут все просто
|
||||
if (robot1.dx.current_zone != tasks[target_task].start_zone) {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE | ZONE_WASHING_3B;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE(ZONE_WASHING_3B);
|
||||
}
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP_WITH_BARREL;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE_WITH_BARREL | ZONE_PASSIVATION;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_WITH_BARREL;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP_WITH_BARREL();
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE_WITH_BARREL(ZONE_PASSIVATION);
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_WITH_BARREL();
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_TMR_SET;
|
||||
robot1_code.code[cmd_index++] = barrels[target_task].time_passivation;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_TMR_SET(barrels[target_task].time_passivation);
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP_WITH_BARREL;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE_WITH_BARREL | ZONE_WASHING_4A;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_WITH_BARREL;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP_WITH_BARREL();
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE_WITH_BARREL(ZONE_WASHING_4A);
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_WITH_BARREL();
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_TMR_SET;
|
||||
robot1_code.code[cmd_index++] = barrels[target_task].time_washing_4a;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_TMR_SET(barrels[target_task].time_washing_4a);
|
||||
} else {
|
||||
// любой другой случай
|
||||
if (robot1.dx.current_zone != tasks[target_task].start_zone) {
|
||||
if (tasks[target_task].start_zone != 22) {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE | tasks[target_task].start_zone;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE(tasks[target_task].start_zone);
|
||||
} else {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_OFF;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP;
|
||||
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;
|
||||
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(22);
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_OFF();
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN();
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_ACCURATE();
|
||||
}
|
||||
}
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP_WITH_BARREL;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP_WITH_BARREL();
|
||||
|
||||
// теперь надо определиться с тем, сколько ждать скапывания
|
||||
switch (tasks[target_task].start_zone) {
|
||||
@@ -418,7 +416,7 @@ void schedule_robot_1() {
|
||||
case ZONE_GALVANIZING_8:
|
||||
// время скапывания реактивов
|
||||
// TODO добавить переменные времен скапывания
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_WAIT | 30;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_WAIT(30);
|
||||
break;
|
||||
|
||||
case ZONE_WASHING_1A:
|
||||
@@ -426,7 +424,7 @@ void schedule_robot_1() {
|
||||
case ZONE_WASHING_3A:
|
||||
case ZONE_WASHING_4A:
|
||||
// время скапывания 1-го каскада промывок
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_WAIT | 3;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_WAIT(3);
|
||||
break;
|
||||
|
||||
case ZONE_WASHING_1B:
|
||||
@@ -434,21 +432,30 @@ void schedule_robot_1() {
|
||||
case ZONE_WASHING_3B:
|
||||
case ZONE_WASHING_4B:
|
||||
// время скапывания 2-го каскада промывок
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_WAIT | 20;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_WAIT(20);
|
||||
break;
|
||||
}
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE_WITH_BARREL | tasks[target_task].dest_zone;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE_WITH_BARREL(tasks[target_task].dest_zone);
|
||||
|
||||
// инкремент зоны (если травление или цинкование)
|
||||
if (tasks[target_task].dest_zone == ZONE_ETCHING_1 || tasks[target_task].dest_zone == ZONE_ETCHING_2) {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_INC_ZONE(ROBOT_ZONE_ETCH);
|
||||
} else if (tasks[target_task].dest_zone >= ZONE_GALVANIZING_1 && tasks[target_task].dest_zone <= ZONE_GALVANIZING_8) {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_INC_ZONE(ROBOT_ZONE_GAL);
|
||||
}
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_WITH_BARREL();
|
||||
|
||||
if (tasks[target_task].dest_zone == 22) {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_2_WITH_BARREL;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE | 21;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_MOVE_TO_ZONE(21);
|
||||
// NOTE старая механика не позволяет просто опустить траверсу до конца, для новой изменить поведение
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_UP();
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN();
|
||||
} else {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_DOWN_WITH_BARREL;
|
||||
|
||||
if (tasks[target_task].dest_zone != 0) {
|
||||
|
||||
// установка времени ожидания барабана
|
||||
short tmp = -1;
|
||||
switch (tasks[target_task].dest_zone) {
|
||||
@@ -499,15 +506,17 @@ void schedule_robot_1() {
|
||||
break;
|
||||
}
|
||||
|
||||
if (tmp != -1) {
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_TMR_SET;
|
||||
robot1_code.code[cmd_index++] = tmp;
|
||||
if (tmp > 0) {
|
||||
if (tmp > 8000) {
|
||||
tmp = 8000;
|
||||
}
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_TMR_SET(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_END;
|
||||
robot1_code.code[cmd_index++] = ROBOT_CMD_END();
|
||||
robot1_code.PC = 0;
|
||||
|
||||
printf("INFO: code length is %d\n", cmd_index);
|
||||
|
||||
Reference in New Issue
Block a user