Remove RC_CHANNELS macro

This commit is contained in:
Oleg Kalachev 2025-02-28 22:19:52 +03:00
parent 03c6576b72
commit d60968ea25
4 changed files with 10 additions and 12 deletions

View File

@ -10,7 +10,6 @@
#define SERIAL_BAUDRATE 115200 #define SERIAL_BAUDRATE 115200
#define WIFI_ENABLED 1 #define WIFI_ENABLED 1
#define RC_CHANNELS 16
#define RC_CHANNEL_ROLL 0 #define RC_CHANNEL_ROLL 0
#define RC_CHANNEL_PITCH 1 #define RC_CHANNEL_PITCH 1
#define RC_CHANNEL_THROTTLE 2 #define RC_CHANNEL_THROTTLE 2
@ -20,8 +19,8 @@
float 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
int16_t channels[RC_CHANNELS]; // raw rc channels int16_t channels[16]; // raw rc channels
float controls[RC_CHANNELS]; // normalized controls in range [-1..1] ([0..1] for throttle) float controls[16]; // normalized controls in range [-1..1] ([0..1] for throttle)
Vector gyro; // gyroscope data Vector gyro; // gyroscope data
Vector acc; // accelerometer data, m/s/s Vector acc; // accelerometer data, m/s/s
Vector rates; // filtered angular rates, rad/s Vector rates; // filtered angular rates, rad/s

View File

@ -28,7 +28,7 @@ void readRC() {
} }
void normalizeRC() { void normalizeRC() {
for (uint8_t i = 0; i < RC_CHANNELS; i++) { for (uint8_t i = 0; i < 16; i++) {
controls[i] = mapf(channels[i], channelNeutral[i], channelMax[i], 0, 1); controls[i] = mapf(channels[i], channelNeutral[i], channelMax[i], 0, 1);
} }
} }
@ -38,20 +38,20 @@ void calibrateRC() {
Serial.println("··o ··o\n··· ···\n··· ···"); Serial.println("··o ··o\n··· ···\n··· ···");
delay(4000); delay(4000);
for (int i = 0; i < 30; i++) readRC(); // ensure the values are updated for (int i = 0; i < 30; i++) readRC(); // ensure the values are updated
for (int i = 0; i < RC_CHANNELS; i++) { for (int i = 0; i < 16; i++) {
channelMax[i] = channels[i]; channelMax[i] = channels[i];
} }
Serial.println("Calibrate RC: move all sticks to neutral positions in 4 seconds"); Serial.println("Calibrate RC: move all sticks to neutral positions in 4 seconds");
Serial.println("··· ···\n··· ·o·\n·o· ···"); Serial.println("··· ···\n··· ·o·\n·o· ···");
delay(4000); delay(4000);
for (int i = 0; i < 30; i++) readRC(); // ensure the values are updated for (int i = 0; i < 30; i++) readRC(); // ensure the values are updated
for (int i = 0; i < RC_CHANNELS; i++) { for (int i = 0; i < 16; i++) {
channelNeutral[i] = channels[i]; channelNeutral[i] = channels[i];
} }
printRCCal(); printRCCal();
} }
void printRCCal() { void printRCCal() {
printArray(channelNeutral, RC_CHANNELS); printArray(channelNeutral, 16);
printArray(channelMax, RC_CHANNELS); printArray(channelMax, 16);
} }

View File

@ -10,14 +10,13 @@
#include "Arduino.h" #include "Arduino.h"
#include "wifi.h" #include "wifi.h"
#define RC_CHANNELS 16
#define WIFI_ENABLED 1 #define WIFI_ENABLED 1
float t = NAN; float t = NAN;
float dt; float dt;
float motors[4]; float motors[4];
int16_t channels[16]; // raw rc channels int16_t channels[16]; // raw rc channels
float controls[RC_CHANNELS]; float controls[16];
Vector acc; Vector acc;
Vector gyro; Vector gyro;
Vector rates; Vector rates;

View File

@ -38,8 +38,8 @@ bool joystickInit() {
} }
// apply calibration overrides // apply calibration overrides
extern int channelNeutral[RC_CHANNELS]; extern int channelNeutral[16];
extern int channelMax[RC_CHANNELS]; extern int channelMax[16];
memcpy(channelNeutral, channelNeutralOverride, sizeof(channelNeutralOverride)); memcpy(channelNeutral, channelNeutralOverride, sizeof(channelNeutralOverride));
memcpy(channelMax, channelMaxOverride, sizeof(channelMaxOverride)); memcpy(channelMax, channelMaxOverride, sizeof(channelMaxOverride));