mirror of
https://github.com/okalachev/flix.git
synced 2025-08-17 17:16:10 +00:00
Implement RC calibration, common for the real drone and the simulation
This commit is contained in:
@@ -52,6 +52,10 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t print(int n) {
|
||||
return printf("%d", n);
|
||||
}
|
||||
|
||||
size_t print(float n, int digits = 2) {
|
||||
return printf("%.*f", digits, n);
|
||||
}
|
||||
|
13
gazebo/SBUS.h
Normal file
13
gazebo/SBUS.h
Normal file
@@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2023 Oleg Kalachev <okalachev@gmail.com>
|
||||
// Repository: https://github.com/okalachev/flix
|
||||
|
||||
// SBUS library mock to make it possible to compile simulator with rc.ino
|
||||
|
||||
#include "joystick.h"
|
||||
|
||||
class SBUS {
|
||||
public:
|
||||
SBUS(HardwareSerial& bus) {};
|
||||
void begin() {};
|
||||
bool read(int16_t* channels, bool* failsafe, bool* lostFrame) { joystickGet(); return true; }; // NOTE: on the hardware channels is uint16_t
|
||||
};
|
@@ -39,6 +39,7 @@ void controlTorque();
|
||||
void showTable();
|
||||
bool motorsActive();
|
||||
void cliTestMotor(uint8_t n);
|
||||
void printRCCal();
|
||||
|
||||
// mocks
|
||||
void setLED(bool on) {};
|
||||
|
@@ -7,10 +7,9 @@
|
||||
#include <gazebo/gazebo.hh>
|
||||
#include <iostream>
|
||||
|
||||
// NOTE: this should be changed to the actual calibration values
|
||||
const int16_t channelNeutralMin[] = {-1290, -258, -26833, 0, 0, 0};
|
||||
const int16_t channelNeutralMax[] = {-1032, -258, -27348, 3353, 0, 0};
|
||||
const int16_t channelMax[] = {27090, 27090, 27090, 27090, 0, 0};
|
||||
// simulation calibration overrides, NOTE: use `cr` command and replace with the actual values
|
||||
const int channelNeutralOverride[] = {-258, -258, -27349, 0, 0, 1};
|
||||
const int channelMaxOverride[] = {27090, 27090, 27090, 27090, 0, 1};
|
||||
|
||||
#define RC_CHANNEL_ROLL 0
|
||||
#define RC_CHANNEL_PITCH 1
|
||||
@@ -34,6 +33,12 @@ void joystickInit() {
|
||||
gzwarn << "Joystick not found, begin waiting for joystick..." << std::endl;
|
||||
warnShown = true;
|
||||
}
|
||||
|
||||
// apply calibration overrides
|
||||
extern int channelNeutral[RC_CHANNELS];
|
||||
extern int channelMax[RC_CHANNELS];
|
||||
memcpy(channelNeutral, channelNeutralOverride, sizeof(channelNeutralOverride));
|
||||
memcpy(channelMax, channelMaxOverride, sizeof(channelMaxOverride));
|
||||
}
|
||||
|
||||
void joystickGet() {
|
||||
@@ -52,14 +57,3 @@ void joystickGet() {
|
||||
|
||||
normalizeRC();
|
||||
}
|
||||
|
||||
void normalizeRC() {
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
if (channels[i] >= channelNeutralMin[i] && channels[i] <= channelNeutralMax[i]) {
|
||||
controls[i] = 0;
|
||||
} else {
|
||||
controls[i] = mapf(channels[i], (channelNeutralMin[i] + channelNeutralMax[i]) / 2, channelMax[i], 0, 1);
|
||||
}
|
||||
}
|
||||
controls[RC_CHANNEL_THROTTLE] = constrain(controls[RC_CHANNEL_THROTTLE], 0, 1);
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@
|
||||
#include "flix.h"
|
||||
#include "util.h"
|
||||
#include "util.ino"
|
||||
#include "joystick.h"
|
||||
#include "rc.ino"
|
||||
#include "time.ino"
|
||||
#include "estimate.ino"
|
||||
#include "control.ino"
|
||||
|
Reference in New Issue
Block a user