diff --git a/.vscode/settings.json b/.vscode/settings.json index 2c8b73a0e5c057be8076c5081598b2e277b73eed..ca5760859db00cafa0e6923572c896b9515671b2 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -35,5 +35,6 @@ "*.cpp": "cpp", "*.h": "c", "*.c": "c" - } + }, + "task.allowAutomaticTasks": "on" } \ No newline at end of file diff --git a/src/main.c b/src/main.c index 0e6c2cd9e2ae9399f69a38ebe2b842f3d1a9ed22..c8b52dcaa93a3217466c9f1112a6dddc4c156bfb 100644 --- a/src/main.c +++ b/src/main.c @@ -156,14 +156,14 @@ void callback(uint gpio, uint32_t events) { distance = 0; } - if (distance > 40) + if (distance > 20) { - distance = 40; + distance = 20; } - distance = 40 - distance; + distance = 20 - distance; - volatile int percentage = (distance / 20) * 100; + volatile int percentage = (distance / 10) * 100; rollingperc[pos] = percentage; pos++; @@ -175,23 +175,23 @@ void callback(uint gpio, uint32_t events) int avg = (rollingperc[0] + rollingperc[1] + rollingperc[2] + rollingperc[3]) / 4; // if zwischen 90, 110, stop - double speed = 0.9 * ((avg - 100) * (avg - 100)) + 1500; // quadratisch + double speed = 0.5 * ((avg - 100) * (avg - 100)) + 1000; // quadratisch speed = speed + 10 * ((1.8 * avg) - 180); // double speed = abs(70 * avg) + 2000; // linear // speed += 70; set_speed(speed); - if (avg > 90 && avg < 110) + if (avg == 100) { gpio_put(20, 0); gpio_put(21, 0); } - else if (avg < 90) + if (avg < 100) { motor_forward(); } - else if (avg > 110) + else if (avg > 100) { motor_backward(); }