// Code by Rustom Jehangir: [email protected]12#include "Sub.h"34// Count total vehicle turns to avoid tangling tether5void Sub::update_turn_counter()6{7// Determine state8// 0: 0-90 deg, 1: 90-180 deg, 2: -180--90 deg, 3: -90--0 deg9uint8_t turn_state;10if (ahrs.get_yaw_rad() >= 0.0f && ahrs.get_yaw_rad() < radians(90)) {11turn_state = 0;12} else if (ahrs.get_yaw_rad() >= radians(90)) {13turn_state = 1;14} else if (ahrs.get_yaw_rad() < -radians(90)) {15turn_state = 2;16} else {17turn_state = 3;18}1920// If yaw went from negative to positive (right turn)21if (turn_state == (last_turn_state + 1) % 4) {22quarter_turn_count++;23} else if (turn_state == (uint8_t)(last_turn_state - 1) % 4) {24quarter_turn_count--;25}26last_turn_state = turn_state;27}282930