mirror of
https://github.com/okalachev/flix.git
synced 2026-01-10 21:16:50 +00:00
Revert t variable type to float instead of double
For the sake of simplicity and consistency.
This commit is contained in:
@@ -8,7 +8,7 @@ The firmware is a regular Arduino sketch, and it follows the classic Arduino one
|
|||||||
|
|
||||||
The main loop is running at 1000 Hz. All the dataflow goes through global variables (for simplicity):
|
The main loop is running at 1000 Hz. All the dataflow goes through global variables (for simplicity):
|
||||||
|
|
||||||
* `t` *(double)* — current step time, *s*.
|
* `t` *(float)* — current step time, *s*.
|
||||||
* `dt` *(float)* — time delta between the current and previous steps, *s*.
|
* `dt` *(float)* — time delta between the current and previous steps, *s*.
|
||||||
* `gyro` *(Vector)* — data from the gyroscope, *rad/s*.
|
* `gyro` *(Vector)* — data from the gyroscope, *rad/s*.
|
||||||
* `acc` *(Vector)* — acceleration data from the accelerometer, *m/s<sup>2</sup>*.
|
* `acc` *(Vector)* — acceleration data from the accelerometer, *m/s<sup>2</sup>*.
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
|
|
||||||
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
|
extern const int MOTOR_REAR_LEFT, MOTOR_REAR_RIGHT, MOTOR_FRONT_RIGHT, MOTOR_FRONT_LEFT;
|
||||||
extern const int ACRO, STAB, AUTO;
|
extern const int ACRO, STAB, AUTO;
|
||||||
extern float loopRate, dt;
|
extern float t, dt, loopRate;
|
||||||
extern double t;
|
|
||||||
extern uint16_t channels[16];
|
extern uint16_t channels[16];
|
||||||
extern float controlRoll, controlPitch, controlThrottle, controlYaw, controlMode;
|
extern float controlRoll, controlPitch, controlThrottle, controlYaw, controlMode;
|
||||||
extern int mode;
|
extern int mode;
|
||||||
@@ -60,7 +59,7 @@ void print(const char* format, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void pause(float duration) {
|
void pause(float duration) {
|
||||||
double start = t;
|
float start = t;
|
||||||
while (t - start < duration) {
|
while (t - start < duration) {
|
||||||
step();
|
step();
|
||||||
handleInput();
|
handleInput();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#define SERIAL_BAUDRATE 115200
|
#define SERIAL_BAUDRATE 115200
|
||||||
#define WIFI_ENABLED 1
|
#define WIFI_ENABLED 1
|
||||||
|
|
||||||
double t = NAN; // current step time, s
|
float t = NAN; // current step time, s
|
||||||
float dt; // time delta from previous step, s
|
float dt; // time delta from previous step, s
|
||||||
float controlRoll, controlPitch, controlYaw, controlThrottle; // pilot's inputs, range [-1, 1]
|
float controlRoll, controlPitch, controlYaw, controlThrottle; // pilot's inputs, range [-1, 1]
|
||||||
float controlMode = NAN;
|
float controlMode = NAN;
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#define LOG_PERIOD 1.0 / LOG_RATE
|
#define LOG_PERIOD 1.0 / LOG_RATE
|
||||||
#define LOG_SIZE LOG_DURATION * LOG_RATE
|
#define LOG_SIZE LOG_DURATION * LOG_RATE
|
||||||
|
|
||||||
float tFloat;
|
|
||||||
Vector attitudeEuler;
|
Vector attitudeEuler;
|
||||||
Vector attitudeTargetEuler;
|
Vector attitudeTargetEuler;
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ struct LogEntry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
LogEntry logEntries[] = {
|
LogEntry logEntries[] = {
|
||||||
{"t", &tFloat},
|
{"t", &t},
|
||||||
{"rates.x", &rates.x},
|
{"rates.x", &rates.x},
|
||||||
{"rates.y", &rates.y},
|
{"rates.y", &rates.y},
|
||||||
{"rates.z", &rates.z},
|
{"rates.z", &rates.z},
|
||||||
@@ -40,7 +39,6 @@ const int logColumns = sizeof(logEntries) / sizeof(logEntries[0]);
|
|||||||
float logBuffer[LOG_SIZE][logColumns];
|
float logBuffer[LOG_SIZE][logColumns];
|
||||||
|
|
||||||
void prepareLogData() {
|
void prepareLogData() {
|
||||||
tFloat = t;
|
|
||||||
attitudeEuler = attitude.toEuler();
|
attitudeEuler = attitude.toEuler();
|
||||||
attitudeTargetEuler = attitudeTarget.toEuler();
|
attitudeTargetEuler = attitudeTarget.toEuler();
|
||||||
}
|
}
|
||||||
@@ -48,7 +46,7 @@ void prepareLogData() {
|
|||||||
void logData() {
|
void logData() {
|
||||||
if (!armed) return;
|
if (!armed) return;
|
||||||
static int logPointer = 0;
|
static int logPointer = 0;
|
||||||
static double logTime = 0;
|
static float logTime = 0;
|
||||||
if (t - logTime < LOG_PERIOD) return;
|
if (t - logTime < LOG_PERIOD) return;
|
||||||
logTime = t;
|
logTime = t;
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
bool mavlinkConnected = false;
|
bool mavlinkConnected = false;
|
||||||
String mavlinkPrintBuffer;
|
String mavlinkPrintBuffer;
|
||||||
|
|
||||||
extern double controlTime;
|
extern float controlTime;
|
||||||
extern float controlRoll, controlPitch, controlThrottle, controlYaw, controlMode;
|
extern float controlRoll, controlPitch, controlThrottle, controlYaw, controlMode;
|
||||||
|
|
||||||
void processMavlink() {
|
void processMavlink() {
|
||||||
@@ -26,8 +26,8 @@ void processMavlink() {
|
|||||||
void sendMavlink() {
|
void sendMavlink() {
|
||||||
sendMavlinkPrint();
|
sendMavlinkPrint();
|
||||||
|
|
||||||
static double lastSlow = 0;
|
static float lastSlow = 0;
|
||||||
static double lastFast = 0;
|
static float lastFast = 0;
|
||||||
|
|
||||||
mavlink_message_t msg;
|
mavlink_message_t msg;
|
||||||
uint32_t time = t * 1000;
|
uint32_t time = t * 1000;
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ bool setParameter(const char *name, const float value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void syncParameters() {
|
void syncParameters() {
|
||||||
static double lastSync = 0;
|
static float lastSync = 0;
|
||||||
if (t - lastSync < 1) return; // sync once per second
|
if (t - lastSync < 1) return; // sync once per second
|
||||||
if (motorsActive()) return; // don't use flash while flying, it may cause a delay
|
if (motorsActive()) return; // don't use flash while flying, it may cause a delay
|
||||||
lastSync = t;
|
lastSync = t;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
SBUS rc(Serial2); // NOTE: Use RC(Serial2, 16, 17) if you use the old UART2 pins
|
SBUS rc(Serial2); // NOTE: Use RC(Serial2, 16, 17) if you use the old UART2 pins
|
||||||
|
|
||||||
uint16_t channels[16]; // raw rc channels
|
uint16_t channels[16]; // raw rc channels
|
||||||
double controlTime; // time of the last controls update
|
float controlTime; // time of the last controls update
|
||||||
float channelZero[16]; // calibration zero values
|
float channelZero[16]; // calibration zero values
|
||||||
float channelMax[16]; // calibration max values
|
float channelMax[16]; // calibration max values
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#define RC_LOSS_TIMEOUT 1
|
#define RC_LOSS_TIMEOUT 1
|
||||||
#define DESCEND_TIME 10
|
#define DESCEND_TIME 10
|
||||||
|
|
||||||
extern double controlTime;
|
extern float controlTime;
|
||||||
extern float controlRoll, controlPitch, controlThrottle, controlYaw;
|
extern float controlRoll, controlPitch, controlThrottle, controlYaw;
|
||||||
|
|
||||||
void failsafe() {
|
void failsafe() {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
float loopRate; // Hz
|
float loopRate; // Hz
|
||||||
|
|
||||||
void step() {
|
void step() {
|
||||||
double now = micros() / 1000000.0;
|
float now = micros() / 1000000.0;
|
||||||
dt = now - t;
|
dt = now - t;
|
||||||
t = now;
|
t = now;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ void step() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void computeLoopRate() {
|
void computeLoopRate() {
|
||||||
static double windowStart = 0;
|
static float windowStart = 0;
|
||||||
static uint32_t rate = 0;
|
static uint32_t rate = 0;
|
||||||
rate++;
|
rate++;
|
||||||
if (t - windowStart >= 1) { // 1 second window
|
if (t - windowStart >= 1) { // 1 second window
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <soc/rtc_cntl_reg.h>
|
#include <soc/rtc_cntl_reg.h>
|
||||||
|
|
||||||
const float ONE_G = 9.80665;
|
const float ONE_G = 9.80665;
|
||||||
extern double t;
|
extern float t;
|
||||||
|
|
||||||
float mapf(long x, long in_min, long in_max, float out_min, float out_max) {
|
float mapf(long x, long in_min, long in_max, float out_min, float out_max) {
|
||||||
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
|
return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#define WIFI_ENABLED 1
|
#define WIFI_ENABLED 1
|
||||||
|
|
||||||
double t = NAN;
|
float t = NAN;
|
||||||
float dt;
|
float dt;
|
||||||
float motors[4];
|
float motors[4];
|
||||||
float controlRoll, controlPitch, controlYaw, controlThrottle = NAN;
|
float controlRoll, controlPitch, controlYaw, controlThrottle = NAN;
|
||||||
|
|||||||
Reference in New Issue
Block a user