Skip to content

Commit

Permalink
fix return ur logic
Browse files Browse the repository at this point in the history
  • Loading branch information
EricDinging committed Apr 17, 2023
1 parent ca5bfc0 commit 59d8896
Show file tree
Hide file tree
Showing 45 changed files with 23,962 additions and 24,183 deletions.
4 changes: 2 additions & 2 deletions central_control/.settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="986316469597389502" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="250665232800275340" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand All @@ -16,7 +16,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="986316469597389502" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="250665232800275340" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
Expand Down
35 changes: 20 additions & 15 deletions central_control/Core/Src/central_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ uint8_t ball_locked = 0; // from AI
uint8_t ball_not_found = 0; // from AI
uint8_t ball_count = 0; // from IR
uint8_t ball_collected = 0; // from IR

uint8_t station_arrived = 0; // from AI
uint8_t return_near_station = 0;

uint8_t avoid_finished = 0; // from timer
uint8_t avoid_begin = 0;
uint8_t avoid_mode = 0; // 0: reverse, 1: rotate

uint8_t on_off = 0; // on_off button
uint8_t reset = 0; // reset button
Expand All @@ -36,17 +39,14 @@ uint8_t ir_on = 0;
uint8_t speaker_on = 0;
uint8_t ultrasonic_on = 0;

uint8_t avoid_mode = 0;

uint8_t return_motor_mode = 7;

const uint8_t XL = 120;
const uint8_t XR = 150;
const uint8_t Y_COLLECT = 170;
const uint8_t Y_RETURN = 50;
const float SIZE = (315 * 207) * 3.0 / 4;

const float RETURN_STOP_SIZE = (315 * 207) * 3.0 / 4;
const uint8_t Y_FILTER = 70;
const uint8_t RETURN_UROFF_SIZE = (315 * 207) * 1.0 / 2;

void dumb_loop(int time) {
for(volatile int j = 0; j < time; ++j)
Expand All @@ -69,6 +69,7 @@ void state_update() {
ball_count = 0;
ball_collected = 0;
station_arrived = 0;
return_near_station = 0;
avoid_finished = 0;
avoid_begin = 0;
reset = 0;
Expand All @@ -79,7 +80,6 @@ void state_update() {
ultrasonic_on = 0;
avoid_mode = 0;
first_rotor = 0;
return_motor_mode = 7;
}

// disable interrupt ultrasonic, ir
Expand Down Expand Up @@ -178,10 +178,10 @@ void state_update() {
reset = 1;
next_state = INIT;
} else {
if (return_motor_mode == 0) {
if (return_near_station == 1) {
__HAL_TIM_CLEAR_IT(&htim1, TIM_IT_CC1); // clear ultrasonic interrup
ultrasonic_on = 0;
} else {
__HAL_TIM_CLEAR_IT(&htim1, TIM_IT_CC1); // clear ultrasonic interrupt
ultrasonic_on = 1;
}
}
Expand Down Expand Up @@ -321,11 +321,16 @@ uint8_t return_mode() {
if(best_x < XR) {
// printf("Best_x : %d, Going to direction: %d\n", best_x, 0);
// printf("Best_y : %d \n", best_y);
if(best_size >= SIZE) {
printf("---------Return\n");
station_arrived = 1;
}
return 0;
if (best_size >= RETURN_UROFF_SIZE) {
return_near_station = 1;
} else {
return_near_station = 0;
}
if(best_size >= RETURN_STOP_SIZE) {
printf("---------Return\n");
station_arrived = 1;
}
return 0;
}
if(best_x <= 315) {
// printf("Best_x : %d, Going to direction: %d\n", best_x, 2);
Expand Down Expand Up @@ -382,7 +387,7 @@ void execute() {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_8, 1); // white led
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, 1); // blue led
printf("Green Button pressed\n");
return_motor_mode = return_mode();
uint8_t return_motor_mode = return_mode();
motor_control(return_motor_mode);
break;
case AVOID_COLLISION:
Expand Down Expand Up @@ -412,7 +417,7 @@ void execute() {
case SEARCH_TO_COLLECT : {
rotor_control(0);
motor_control(5);
dumb_loop(20000);
dumb_loop(15000);
// printf("ending search to collect\n");
break;
}
Expand Down
Binary file modified central_control/Debug/Central_control_2.elf
Binary file not shown.
Loading

0 comments on commit 59d8896

Please sign in to comment.