Use FlixPeriph library for SBUS

This commit is contained in:
Oleg Kalachev
2024-03-17 02:29:37 +03:00
parent f782f647cb
commit 646fa46f6b
6 changed files with 19 additions and 16 deletions

View File

@@ -26,7 +26,7 @@
float t = NAN; // current step time, s
float dt; // time delta from previous step, s
float loopFreq; // loop frequency, Hz
uint16_t channels[16]; // raw rc channels
int16_t channels[16]; // raw rc channels
float controls[RC_CHANNELS]; // normalized controls in range [-1..1] ([0..1] for throttle)
Vector rates; // angular rates, rad/s
Vector acc; // accelerometer data, m/s/s

View File

@@ -5,7 +5,7 @@
#include <SBUS.h>
// NOTE: use `cr` command and replace with the actual values
// NOTE: use 'cr' command to calibrate the RC and put the values here
int channelNeutral[] = {995, 883, 200, 972, 512, 512};
int channelMax[] = {1651, 1540, 1713, 1630, 1472, 1472};
@@ -14,14 +14,12 @@ SBUS RC(Serial2);
void setupRC() {
Serial.println("Setup RC");
RC.begin();
Serial2.setRxInvert(true); // SBUS uses inverted signal
}
void readRC() {
bool failsafe, lostFrame;
if (RC.read(channels, &failsafe, &lostFrame)) {
if (failsafe) { return; } // TODO:
if (lostFrame) { return; }
if (RC.read()) {
SBUSData data = RC.data();
memcpy(channels, data.ch, sizeof(channels)); // copy channels data
normalizeRC();
}
}