From 64d1597b96a36e65af4c069f98ef12bddcdd0a36 Mon Sep 17 00:00:00 2001 From: ayush1301 <ayush.ag1301@gmail.com> Date: Fri, 22 Oct 2021 13:32:45 +0100 Subject: [PATCH] Recovery for stuck while going up the ramp --- main/main.ino | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/main/main.ino b/main/main.ino index 586a78a..83f7bc9 100644 --- a/main/main.ino +++ b/main/main.ino @@ -3,10 +3,13 @@ //General uint8_t regions[2] = {BACKWARD, FORWARD}; uint8_t regions_opposite[2] = {FORWARD, BACKWARD}; -int region = 0; +int region = 1; #define floating_avg_num 3 int button_val = 0; int button_port = 0; +int cur_status = 0; +long cur_loop_count = 0; +bool status_repeat = false; //Motors Adafruit_MotorShield AFMS = Adafruit_MotorShield(); @@ -54,6 +57,29 @@ void loop() { if (button_val == 0) { update_IR_vals(); int IR_check_val = IR_check(IR_colours); + + //New code for stuck in a loop + if (IR_check_val != 0 && cur_status == IR_check_val) { + cur_loop_count += 1; + if (cur_loop_count > 800) { + Serial.println("RECOVERY CODE"); + status_repeat = true; + } + else { + status_repeat = false; + } + } + else { + status_repeat = false; + cur_loop_count = 0; + cur_status = IR_check_val; + } + + if (status_repeat) { + move_both(motors, 255); + continue; + } + if (IR_check_val == 0) { move_both(motors, 255); Serial.println("FORWARD"); -- GitLab