mirror of
https://github.com/okalachev/flix.git
synced 2025-07-27 17:49:33 +00:00
Code cleanups
This commit is contained in:
parent
aaa8f70166
commit
1019d6d4bb
@ -35,14 +35,10 @@ Vector acc; // accelerometer data, m/s/s
|
|||||||
Quaternion attitude; // estimated attitude
|
Quaternion attitude; // estimated attitude
|
||||||
bool calibrating; // flag we're calibrating
|
bool calibrating; // flag we're calibrating
|
||||||
|
|
||||||
void setupDebug();
|
|
||||||
void lowPowerMode();
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(SERIAL_BAUDRATE);
|
Serial.begin(SERIAL_BAUDRATE);
|
||||||
Serial.println("Initializing flix");
|
Serial.println("Initializing flix");
|
||||||
setupTime();
|
|
||||||
setupLED();
|
setupLED();
|
||||||
setupMotors();
|
setupMotors();
|
||||||
setLED(true);
|
setLED(true);
|
||||||
|
@ -59,7 +59,7 @@ static void calibrateGyro()
|
|||||||
Serial.println("Calibrating gyro, stand still");
|
Serial.println("Calibrating gyro, stand still");
|
||||||
delay(500);
|
delay(500);
|
||||||
int status = IMU.calibrateGyro();
|
int status = IMU.calibrateGyro();
|
||||||
Serial.println("Calibration status: " + String(status));
|
Serial.printf("Calibration status: %d\n", status);
|
||||||
Serial.print("Gyro bias: ");
|
Serial.print("Gyro bias: ");
|
||||||
Serial.print(IMU.getGyroBiasX_rads(), 10); Serial.print(" ");
|
Serial.print(IMU.getGyroBiasX_rads(), 10); Serial.print(" ");
|
||||||
Serial.print(IMU.getGyroBiasY_rads(), 10); Serial.print(" ");
|
Serial.print(IMU.getGyroBiasY_rads(), 10); Serial.print(" ");
|
||||||
|
28
flix/led.ino
28
flix/led.ino
@ -1,18 +1,7 @@
|
|||||||
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
||||||
// Repository: https://github.com/okalachev/flix
|
// Repository: https://github.com/okalachev/flix
|
||||||
|
|
||||||
#define LED_PIN 2
|
#define BLINK_PERIOD 500000
|
||||||
#define BLINK_FAST_PERIOD 300000
|
|
||||||
#define BLINK_SLOW_PERIOD 1000000
|
|
||||||
|
|
||||||
static bool state;
|
|
||||||
|
|
||||||
static enum {
|
|
||||||
OFF,
|
|
||||||
ON,
|
|
||||||
BLINK_FAST,
|
|
||||||
BLINK_SLOW
|
|
||||||
} LEDscheme = OFF;
|
|
||||||
|
|
||||||
void setupLED()
|
void setupLED()
|
||||||
{
|
{
|
||||||
@ -24,20 +13,7 @@ void setLED(bool on)
|
|||||||
digitalWrite(LED_BUILTIN, on ? HIGH : LOW);
|
digitalWrite(LED_BUILTIN, on ? HIGH : LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void proceedLED()
|
|
||||||
{
|
|
||||||
// TODO: this won't work
|
|
||||||
// TODO:: just check is current second even or odd
|
|
||||||
if (LEDscheme == BLINK_FAST && stepTime % BLINK_FAST_PERIOD == 0) {
|
|
||||||
state != state;
|
|
||||||
digitalWrite(LED_BUILTIN, state ? HIGH : LOW);
|
|
||||||
} else if (LEDscheme == BLINK_SLOW && stepTime % BLINK_SLOW_PERIOD == 0) {
|
|
||||||
state != state;
|
|
||||||
digitalWrite(LED_BUILTIN, state ? HIGH : LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void blinkLED()
|
void blinkLED()
|
||||||
{
|
{
|
||||||
setLED(micros() / 500000 % 2);
|
setLED(micros() / BLINK_PERIOD % 2);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
||||||
// Repository: https://github.com/okalachev/flix
|
// Repository: https://github.com/okalachev/flix
|
||||||
|
|
||||||
|
// PID controller implementation
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class PID
|
class PID
|
||||||
|
@ -7,11 +7,6 @@ const uint32_t S = 1000000;
|
|||||||
static uint32_t stepsPerSecondCurrent;
|
static uint32_t stepsPerSecondCurrent;
|
||||||
static uint32_t stepsPerSecondCurrentLast;
|
static uint32_t stepsPerSecondCurrentLast;
|
||||||
|
|
||||||
void setupTime()
|
|
||||||
{
|
|
||||||
startTime = micros();
|
|
||||||
}
|
|
||||||
|
|
||||||
void step() {
|
void step() {
|
||||||
steps++;
|
steps++;
|
||||||
auto time = micros();
|
auto time = micros();
|
||||||
|
@ -13,11 +13,6 @@ float mapff(float x, float in_min, float in_max, float out_min, float out_max)
|
|||||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
// float hypot3(float x, float y, float z)
|
|
||||||
// {
|
|
||||||
// return sqrt(x * x + y * y + z * z);
|
|
||||||
// }
|
|
||||||
|
|
||||||
int8_t sign(float x)
|
int8_t sign(float x)
|
||||||
{
|
{
|
||||||
return (x > 0) - (x < 0);
|
return (x > 0) - (x < 0);
|
||||||
@ -28,19 +23,4 @@ float randomFloat(float min, float max)
|
|||||||
return min + (max - min) * (float)rand() / RAND_MAX;
|
return min + (max - min) * (float)rand() / RAND_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// === printf ===
|
|
||||||
// https://github.com/jandelgado/log4arduino/blob/master/src/log4arduino.cpp#L51
|
|
||||||
// https://webhamster.ru/mytetrashare/index/mtb0/16381244680p5beet5d6
|
|
||||||
|
|
||||||
#ifdef ARDUINO
|
|
||||||
#define PRINTF_MAX_STRING_LEN 200
|
|
||||||
void printf(const __FlashStringHelper *fmt, ...)
|
|
||||||
{
|
|
||||||
char buf[PRINTF_MAX_STRING_LEN];
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vsnprintf(buf, PRINTF_MAX_STRING_LEN, (PGM_P)fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
Serial.print(buf);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
// https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
|
// https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiAccessPoint/WiFiAccessPoint.ino
|
||||||
// https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiClient/WiFiClient.ino
|
// https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiClient/WiFiClient.ino
|
||||||
|
// https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiUDPClient/WiFiUDPClient.ino
|
||||||
|
|
||||||
#if WIFI_ENABLED == 1
|
#if WIFI_ENABLED == 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user