16 Commits
Author SHA1 Message Date
Oleg Kalachev bbe753add0 Enable motor pins only for classic esp32 by default
Also simplify flix2 config code.
2026-08-16 01:26:34 +03:00
Oleg Kalachev 815ccfc08f Docs fix 2026-08-16 00:10:19 +03:00
Oleg Kalachev 3f11fa11e8 Test simulation run 2026-08-14 09:41:35 +03:00
Oleg Kalachev a05e35540e Bring back simpler version of Value::set 2026-08-14 06:18:17 +03:00
Oleg Kalachev 6098293776 Utilize Value class in parameters for
Now bool parameters also may be used.
2026-08-14 06:11:43 +03:00
Oleg Kalachev 2d1efac05f Change type hints of the most List arguments to Sequence in pyflix
These arguments are effectively immutable, so Sequence makes more sense - the user may use tuples in addition to lists.
2026-08-14 05:57:58 +03:00
Oleg Kalachev f99a9998b1 Add rates_extra argument to pyflix' set_attitude method
For controlling rates feed forward.
2026-08-14 05:32:39 +03:00
Oleg Kalachev 4d77c6c369 Simply set_attitude_target handler
Rates ignore flags are efficiently the same as zeros, so can be ignored.
2026-08-14 05:21:45 +03:00
Oleg Kalachev 94c70994b6 Fix simulation run 2026-08-14 04:19:25 +03:00
Oleg Kalachev 78be5b3a8d Minor changes 2026-08-14 03:15:27 +03:00
Oleg Kalachev 9b1f0bd593 Remove test line 2026-08-14 03:04:00 +03:00
Oleg Kalachev b72a10dd7b Trigger build 2026-08-14 02:25:29 +03:00
Oleg Kalachev d2d1c74842 Update all used actions
Some of them were deprecated.
2026-08-14 01:51:21 +03:00
Oleg Kalachev 7308159b74 Show cloc diff with the previous commit 2026-08-14 01:41:57 +03:00
Oleg Kalachev 87ce9c20cb Count and print sloc count in tools workflow 2026-08-14 01:30:51 +03:00
Oleg Kalachev d6b9228282 Fix default windup value in pid
INFINITY makes much more sense, since otherwise i term would be ineffective at all by default
2026-08-13 02:21:03 +03:00
14 changed files with 103 additions and 70 deletions
+16 -7
View File
@@ -13,7 +13,7 @@ jobs:
env: env:
ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES: 1 ARDUINO_SKETCH_ALWAYS_EXPORT_BINARIES: 1
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install Arduino CLI - name: Install Arduino CLI
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
- name: Build firmware for ESP32 - name: Build firmware for ESP32
@@ -29,7 +29,7 @@ jobs:
- name: Build firmware for Flix2 - name: Build firmware for Flix2
run: make BOARD=esp32:esp32:esp32s3:FlashSize=4M,CDCOnBoot=cdc,PSRAM=opi FLAGS=-DFLIX2 EXTRA=--output-dir=flix/build/esp32.esp32.flix2 run: make BOARD=esp32:esp32:esp32s3:FlashSize=4M,CDCOnBoot=cdc,PSRAM=opi FLAGS=-DFLIX2 EXTRA=--output-dir=flix/build/esp32.esp32.flix2
- name: Upload binaries - name: Upload binaries
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v7
with: with:
name: firmware-binary name: firmware-binary
path: flix/build path: flix/build
@@ -41,7 +41,7 @@ jobs:
build_macos: build_macos:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install Arduino CLI - name: Install Arduino CLI
run: brew install arduino-cli run: brew install arduino-cli
- name: Build firmware - name: Build firmware
@@ -52,7 +52,7 @@ jobs:
build_windows: build_windows:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install Arduino CLI - name: Install Arduino CLI
run: choco install arduino-cli run: choco install arduino-cli
- name: Install Make - name: Install Make
@@ -73,7 +73,7 @@ jobs:
DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget build-essential cmake g++ pkg-config gnupg2 lsb-release sudo DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget build-essential cmake g++ pkg-config gnupg2 lsb-release sudo
- name: Install Arduino CLI - name: Install Arduino CLI
run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install Gazebo - name: Install Gazebo
run: | run: |
sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list' sudo sh -c 'echo "deb http://packages.osrfoundation.org/gazebo/ubuntu-stable `lsb_release -cs` main" > /etc/apt/sources.list.d/gazebo-stable.list'
@@ -84,7 +84,16 @@ jobs:
run: sudo apt-get install -y libsdl2-dev run: sudo apt-get install -y libsdl2-dev
- name: Build simulator - name: Build simulator
run: make build_simulator run: make build_simulator
- uses: actions/upload-artifact@v4 - name: Run simulator
env:
GAZEBO_MODEL_PATH: ${{ github.workspace }}/gazebo/models
GAZEBO_PLUGIN_PATH: ${{ github.workspace }}/gazebo/build
run: |
OUT=$(timeout -k 10s 120s gzserver --verbose gazebo/flix.world 2>&1 | tee /dev/stderr)
if echo "$OUT" | grep -Pq "\[Err\](?! \[RenderEngine)"; then
exit 1
fi
- uses: actions/upload-artifact@v7
with: with:
name: gazebo-plugin-binary name: gazebo-plugin-binary
path: gazebo/build/*.so path: gazebo/build/*.so
@@ -96,7 +105,7 @@ jobs:
steps: steps:
- name: Install Arduino CLI - name: Install Arduino CLI
run: brew install arduino-cli run: brew install arduino-cli
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Clean up python binaries # Workaround for https://github.com/actions/setup-python/issues/577 - name: Clean up python binaries # Workaround for https://github.com/actions/setup-python/issues/577
run: | run: |
rm -f /usr/local/bin/2to3* rm -f /usr/local/bin/2to3*
+6 -6
View File
@@ -16,7 +16,7 @@ jobs:
markdownlint: markdownlint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install markdownlint - name: Install markdownlint
run: npm install -g markdownlint-cli2 run: npm install -g markdownlint-cli2
- name: Run markdownlint - name: Run markdownlint
@@ -28,7 +28,7 @@ jobs:
env: env:
BINARIES: ${{ github.event_name == 'push' && (github.ref_name == 'master' || github.ref_name == 'dev') && github.repository == 'okalachev/flix' }} BINARIES: ${{ github.event_name == 'push' && (github.ref_name == 'master' || github.ref_name == 'dev') && github.repository == 'okalachev/flix' }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install mdBook - name: Install mdBook
run: cargo install mdbook --vers 0.4.43 --locked run: cargo install mdbook --vers 0.4.43 --locked
- name: Build book - name: Build book
@@ -51,7 +51,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Download firmware binaries - name: Download firmware binaries
if: ${{ env.BINARIES }} if: ${{ env.BINARIES }}
uses: actions/download-artifact@v4 uses: actions/download-artifact@v7
with: with:
github-token: ${{ secrets.GITHUB_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }} repository: ${{ github.repository }}
@@ -70,12 +70,12 @@ jobs:
ln -s "$FQBN/flix.ino.bootloader.bin" "flix.$BOARD.bootloader.bin" ln -s "$FQBN/flix.ino.bootloader.bin" "flix.$BOARD.bootloader.bin"
done done
- name: Upload artifact - name: Upload artifact
uses: actions/upload-pages-artifact@v3 uses: actions/upload-pages-artifact@v5
with: with:
path: docs/build path: docs/build
deploy: deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} if: ${{ github.event_name == 'push' && github.ref_name == 'master' }}
concurrency: concurrency:
group: "pages" group: "pages"
cancel-in-progress: true cancel-in-progress: true
@@ -87,4 +87,4 @@ jobs:
steps: steps:
- name: Deploy to GitHub Pages - name: Deploy to GitHub Pages
id: deployment id: deployment
uses: actions/deploy-pages@v4 uses: actions/deploy-pages@v5
+24 -4
View File
@@ -10,7 +10,7 @@ jobs:
csv_to_ulog: csv_to_ulog:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Build csv_to_ulog - name: Build csv_to_ulog
run: cd tools/csv_to_ulog && mkdir build && cd build && cmake .. && make run: cd tools/csv_to_ulog && mkdir build && cd build && cmake .. && make
- name: Test csv_to_ulog - name: Test csv_to_ulog
@@ -22,13 +22,13 @@ jobs:
pyflix: pyflix:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install Python build tools - name: Install Python build tools
run: pip install build run: pip install build
- name: Build pyflix - name: Build pyflix
run: python3 -m build tools run: python3 -m build tools
- name: Upload artifacts - name: Upload artifacts
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v7
with: with:
name: pyflix name: pyflix
path: | path: |
@@ -37,7 +37,7 @@ jobs:
python_tools: python_tools:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v7
- name: Install Python dependencies - name: Install Python dependencies
run: pip install -r tools/requirements.txt run: pip install -r tools/requirements.txt
- name: Test csv_to_mcap tool - name: Test csv_to_mcap tool
@@ -46,3 +46,23 @@ jobs:
echo -e "t,x,y,z\n0,1,2,3\n1,4,5,6" > log.csv echo -e "t,x,y,z\n0,1,2,3\n1,4,5,6" > log.csv
./csv_to_mcap.py log.csv ./csv_to_mcap.py log.csv
test $(stat -c %s log.mcap) -eq 883 test $(stat -c %s log.mcap) -eq 883
sloc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: sudo apt-get install -y cloc jq
- name: Print source lines of code
run: cloc --by-file-by-lang flix
- name: Checkout previous revision
uses: actions/checkout@v7
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
path: prev
- name: Annotate total source lines
run: |
SLOC_CURR=$(cloc flix --json | jq -r '.SUM.code')
SLOC_PREV=$(cloc prev/flix --json | jq -r '.SUM.code')
DIFF=$(printf '%+d' "$((SLOC_CURR - SLOC_PREV))")
echo "* Current SLOC: $SLOC_CURR" >> $GITHUB_STEP_SUMMARY
echo "* Previous SLOC: $SLOC_PREV" >> $GITHUB_STEP_SUMMARY
echo "* Diff: $DIFF" >> $GITHUB_STEP_SUMMARY
+1 -1
View File
@@ -31,7 +31,7 @@
* [`vector.h`](https://github.com/okalachev/flix/blob/master/flix/vector.h), [`quaternion.h`](https://github.com/okalachev/flix/blob/master/flix/quaternion.h) — библиотеки векторов и кватернионов. * [`vector.h`](https://github.com/okalachev/flix/blob/master/flix/vector.h), [`quaternion.h`](https://github.com/okalachev/flix/blob/master/flix/quaternion.h) — библиотеки векторов и кватернионов.
* [`pid.h`](https://github.com/okalachev/flix/blob/master/flix/pid.h) — ПИД-регулятор. * [`pid.h`](https://github.com/okalachev/flix/blob/master/flix/pid.h) — ПИД-регулятор.
* [`lpf.h`](https://github.com/okalachev/flix/blob/master/flix/lpf.h) — фильтр нижних частот. * [`filter.h`](https://github.com/okalachev/flix/blob/master/flix/filter.h) — фильтр нижних частот.
### Подсистема управления ### Подсистема управления
+2 -2
View File
@@ -34,7 +34,7 @@ Utility files:
* [`vector.h`](../flix/vector.h), [`quaternion.h`](../flix/quaternion.h) — vector and quaternion libraries. * [`vector.h`](../flix/vector.h), [`quaternion.h`](../flix/quaternion.h) — vector and quaternion libraries.
* [`pid.h`](../flix/pid.h) — generic PID controller. * [`pid.h`](../flix/pid.h) — generic PID controller.
* [`lpf.h`](../flix/lpf.h) — generic low-pass filter. * [`filter.h`](../flix/filter.h) — generic low-pass filter.
### Control subsystem ### Control subsystem
@@ -73,7 +73,7 @@ Parameters subsystem (`parameters.ino`) uses standard [Preferences.h](https://do
To add a new parameter: To add a new parameter:
1. Define a global variable for the parameter, two types are supported: `float` and `int`. 1. Define a global variable for the parameter, three types are supported: `float`, `int`, and `bool`.
2. Add an entry to the `parameters` array, with the parameter name, a pointer to the variable, and optionally a callback function to call when the parameter is changed. 2. Add an entry to the `parameters` array, with the parameter name, a pointer to the variable, and optionally a callback function to call when the parameter is changed.
3. Everything else will be handled automatically. 3. Everything else will be handled automatically.
+1 -1
View File
@@ -105,7 +105,7 @@ void doCommand(String str, bool echo = false) {
if (success) { if (success) {
print("%s = %g\n", arg0.c_str(), getParameter(arg0.c_str())); print("%s = %g\n", arg0.c_str(), getParameter(arg0.c_str()));
} else { } else {
print("Parameter not found: %s\n", arg0.c_str()); print("Cannot set parameter: %s\n", arg0.c_str());
} }
} else if (command == "preset") { } else if (command == "preset") {
resetParameters(); resetParameters();
+12 -6
View File
@@ -12,16 +12,22 @@ void setDefaults() {
pwmFrequency = 38000; pwmFrequency = 38000;
#endif #endif
#ifdef CONFIG_IDF_TARGET_ESP32
// classic esp32 configuration
motorPins[0] = 12;
motorPins[1] = 13;
motorPins[2] = 14;
motorPins[3] = 15;
#endif
#ifdef FLIX2 #ifdef FLIX2
imuModel = 4; // ICM-40609-D imuModel = 4; // ICM-40609-D
imuIntPin = 10; imuIntPin = 10;
imuCsPin = 14; imuCsPin = 14;
motorPins[MOTOR_REAR_LEFT] = 41;
motorPins[MOTOR_REAR_RIGHT] = 7;
motorPins[MOTOR_FRONT_RIGHT] = 18;
motorPins[MOTOR_FRONT_LEFT] = 38;
voltagePin = 3; voltagePin = 3;
motorPins[0] = 41;
motorPins[1] = 7;
motorPins[2] = 18;
motorPins[3] = 38;
#endif #endif
} }
+7 -7
View File
@@ -227,17 +227,17 @@ void handleMavlink(const void *_msg) {
// Attitude control // Attitude control
attitudeTarget.w = m.q[0]; attitudeTarget.w = m.q[0];
attitudeTarget.x = m.q[1]; attitudeTarget.x = m.q[1];
attitudeTarget.y = -m.q[2]; attitudeTarget.y = -m.q[2]; // convert to flu
attitudeTarget.z = -m.q[3]; attitudeTarget.z = -m.q[3];
ratesExtra.x = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_ROLL_RATE_IGNORE ? 0 : m.body_roll_rate; ratesExtra.x = m.body_roll_rate;
ratesExtra.y = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_PITCH_RATE_IGNORE ? 0 : -m.body_pitch_rate; // convert to flu ratesExtra.y = -m.body_pitch_rate;
ratesExtra.z = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_YAW_RATE_IGNORE ? 0 : -m.body_yaw_rate; ratesExtra.z = -m.body_yaw_rate;
} else { } else {
// Rates control // Rates control
attitudeTarget.invalidate(); attitudeTarget.invalidate();
ratesTarget.x = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_ROLL_RATE_IGNORE ? ratesTarget.x : m.body_roll_rate; ratesTarget.x = m.body_roll_rate;
ratesTarget.y = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_PITCH_RATE_IGNORE ? ratesTarget.y : -m.body_pitch_rate; ratesTarget.y = -m.body_pitch_rate;
ratesTarget.z = m.type_mask & ATTITUDE_TARGET_TYPEMASK_BODY_YAW_RATE_IGNORE ? ratesTarget.z : -m.body_yaw_rate; ratesTarget.z = -m.body_yaw_rate;
} }
thrustTarget = valid(m.thrust) ? m.thrust : thrustTarget; thrustTarget = valid(m.thrust) ? m.thrust : thrustTarget;
+1 -1
View File
@@ -7,7 +7,7 @@
float motors[4]; // normalized motor thrusts in range [0..1] float motors[4]; // normalized motor thrusts in range [0..1]
int motorPins[4] = {12, 13, 14, 15}; // default pin numbers int motorPins[4] = {-1, -1, -1, -1}; // default pin numbers
int pwmFrequency = 78000; int pwmFrequency = 78000;
int pwmResolution = 10; int pwmResolution = 10;
int pwmStop = 0; int pwmStop = 0;
+16 -21
View File
@@ -20,15 +20,11 @@ Preferences storage;
struct Parameter { struct Parameter {
const char *name; // max length is 15 const char *name; // max length is 15
bool integer; Value value; // pointer to the variable
union { float *f; int *i; }; // pointer to the variable float initial; // default value
float inital; // default value
float cache; // what's stored in flash float cache; // what's stored in flash
void (*callback)(); // called after parameter change void (*callback)(); // called after parameter change
Parameter(const char *name, float *variable, void (*callback)() = nullptr) : name(name), integer(false), f(variable), callback(callback) {}; Parameter(const char *name, Value value, void (*callback)() = nullptr) : name(name), value(value), callback(callback) {};
Parameter(const char *name, int *variable, void (*callback)() = nullptr) : name(name), integer(true), i(variable), callback(callback) {};
float getValue() const { return integer ? *i : *f; };
void setValue(const float value) { if (integer) *i = value; else *f = value; };
}; };
Parameter parameters[] = { Parameter parameters[] = {
@@ -168,11 +164,11 @@ void setupParameters() {
storage.begin("flix"); storage.begin("flix");
// Read parameters from storage // Read parameters from storage
for (auto &parameter : parameters) { for (auto &parameter : parameters) {
parameter.inital = parameter.getValue(); parameter.initial = parameter.value.get();
if (storage.isKey(parameter.name)) { if (storage.isKey(parameter.name)) {
parameter.setValue(storage.getFloat(parameter.name)); parameter.value.set(storage.getFloat(parameter.name));
} }
parameter.cache = parameter.getValue(); parameter.cache = parameter.value.get();
} }
} }
@@ -187,13 +183,13 @@ const char *getParameterName(int index) {
float getParameter(int index) { float getParameter(int index) {
if (index < 0 || index >= parametersCount()) return NAN; if (index < 0 || index >= parametersCount()) return NAN;
return parameters[index].getValue(); return parameters[index].value.get();
} }
float getParameter(const char *name) { float getParameter(const char *name) {
for (auto &parameter : parameters) { for (auto &parameter : parameters) {
if (strcasecmp(parameter.name, name) == 0) { if (strcasecmp(parameter.name, name) == 0) {
return parameter.getValue(); return parameter.value.get();
} }
} }
return NAN; return NAN;
@@ -202,10 +198,9 @@ float getParameter(const char *name) {
bool setParameter(const char *name, const float value) { bool setParameter(const char *name, const float value) {
for (auto &parameter : parameters) { for (auto &parameter : parameters) {
if (strcasecmp(parameter.name, name) == 0) { if (strcasecmp(parameter.name, name) == 0) {
if (parameter.integer && !isfinite(value)) return false; // can't set integer to NaN or Inf bool success = parameter.value.set(value);
parameter.setValue(value);
if (parameter.callback) parameter.callback(); if (parameter.callback) parameter.callback();
return true; return success;
} }
} }
return false; return false;
@@ -217,10 +212,10 @@ void syncParameters() {
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
for (auto &parameter : parameters) { for (auto &parameter : parameters) {
if (floatEquals(parameter.getValue(), parameter.cache)) continue; // no change if (floatEquals(parameter.value.get(), parameter.cache)) continue; // no change
storage.putFloat(parameter.name, parameter.getValue()); storage.putFloat(parameter.name, parameter.value.get());
parameter.cache = parameter.getValue(); // update cache parameter.cache = parameter.value.get(); // update cache
} }
} }
@@ -229,10 +224,10 @@ void printParameters(const char *filter) {
for (auto &parameter : parameters) { for (auto &parameter : parameters) {
if (strncasecmp(parameter.name, filter, strlen(filter))) continue; if (strncasecmp(parameter.name, filter, strlen(filter))) continue;
if (floatEquals(parameter.getValue(), parameter.inital)) { // parameter changed if (floatEquals(parameter.value.get(), parameter.initial)) { // parameter changed
print("%-15s %-13g\n", parameter.name, parameter.getValue()); print("%-15s %-13g\n", parameter.name, parameter.value.get());
} else { } else {
print("%-15s %-13g [%g]\n", parameter.name, parameter.getValue(), parameter.inital); print("%-15s %-13g [%g]\n", parameter.name, parameter.value.get(), parameter.initial);
} }
} }
} }
+1 -1
View File
@@ -18,7 +18,7 @@ public:
LowPassFilter<float> lpf; // low pass filter for derivative term LowPassFilter<float> lpf; // low pass filter for derivative term
PID(float p, float i = 0, float d = 0, float windup = 0, float dAlpha = 1, float dtMax = 0.1) : PID(float p, float i = 0, float d = 0, float windup = INFINITY, float dAlpha = 1, float dtMax = 0.1) :
p(p), i(i), d(d), windup(windup), lpf(dAlpha), dtMax(dtMax) {} p(p), i(i), d(d), windup(windup), lpf(dAlpha), dtMax(dtMax) {}
float update(float error) { float update(float error) {
+5 -4
View File
@@ -99,14 +99,15 @@ struct Value {
} }
}; };
void set(float value) const { bool set(float value) const {
switch (type) { switch (type) {
case FLOAT: *_float = value; break; case FLOAT: *_float = value; break;
case INT: *_int = value; break; case INT: if (!isfinite(value)) return false; *_int = value; break;
case BOOL: *_bool = (value != 0); break; case BOOL: *_bool = (value != 0); break;
default: break; default: return false;
} }
}; return true;
}
}; };
// Rate limiter // Rate limiter
+1
View File
@@ -14,6 +14,7 @@
// Mocks // Mocks
int wifiMode = 1; int wifiMode = 1;
int wifiLongRange = 0; int wifiLongRange = 0;
int wifiBroadcast = 0;
int espnowChannel = 6; int espnowChannel = 6;
const int W_DISABLED = 0, W_AP = 1, W_STA = 2, W_ESPNOW = 3; const int W_DISABLED = 0, W_AP = 1, W_STA = 2, W_ESPNOW = 3;
+10 -9
View File
@@ -243,7 +243,7 @@ class Flix:
time.sleep(1) time.sleep(1)
@staticmethod @staticmethod
def _mavlink_to_flu(v: List[float]) -> List[float]: def _mavlink_to_flu(v: Sequence[float]) -> List[float]:
if len(v) == 3: # vector if len(v) == 3: # vector
return [v[0], -v[1], -v[2]] return [v[0], -v[1], -v[2]]
elif len(v) == 4: # quaternion elif len(v) == 4: # quaternion
@@ -252,8 +252,8 @@ class Flix:
raise ValueError(f'List must have 3 (vector) or 4 (quaternion) elements') raise ValueError(f'List must have 3 (vector) or 4 (quaternion) elements')
@staticmethod @staticmethod
def _flu_to_mavlink(v: List[float]) -> List[float]: def _flu_to_mavlink(v: Sequence[float]) -> List[float]:
return Flix._mavlink_to_flu(v) return Flix._mavlink_to_flu(v) # flu to mavlink is the same as mavlink to flu
def _command_send(self, command: int, params: Sequence[float]): def _command_send(self, command: int, params: Sequence[float]):
if len(params) != 7: if len(params) != 7:
@@ -320,13 +320,13 @@ class Flix:
def set_armed(self, armed: bool): def set_armed(self, armed: bool):
self._command_send(mavlink.MAV_CMD_COMPONENT_ARM_DISARM, (1 if armed else 0, 0, 0, 0, 0, 0, 0)) self._command_send(mavlink.MAV_CMD_COMPONENT_ARM_DISARM, (1 if armed else 0, 0, 0, 0, 0, 0, 0))
def set_position(self, position: List[float], yaw: Optional[float] = None, wait: bool = False, tolerance: float = 0.1): def set_position(self, position: Sequence[float], yaw: Optional[float] = None, wait: bool = False, tolerance: float = 0.1):
raise NotImplementedError('Position control is not implemented yet') raise NotImplementedError('Position control is not implemented yet')
def set_velocity(self, velocity: List[float], yaw: Optional[float] = None): def set_velocity(self, velocity: Sequence[float], yaw: Optional[float] = None):
raise NotImplementedError('Velocity control is not implemented yet') raise NotImplementedError('Velocity control is not implemented yet')
def set_attitude(self, attitude: List[float], thrust: float): def set_attitude(self, attitude: Sequence[float], thrust: float, rates_extra: Sequence[float] = (0, 0, 0)):
if len(attitude) == 3: if len(attitude) == 3:
attitude = Quaternion([attitude[0], attitude[1], attitude[2]]).q # type: ignore attitude = Quaternion([attitude[0], attitude[1], attitude[2]]).q # type: ignore
elif len(attitude) != 4: elif len(attitude) != 4:
@@ -334,12 +334,13 @@ class Flix:
if not (0 <= thrust <= 1): if not (0 <= thrust <= 1):
raise ValueError('Thrust must be in range [0, 1]') raise ValueError('Thrust must be in range [0, 1]')
attitude = self._flu_to_mavlink(attitude) attitude = self._flu_to_mavlink(attitude)
rates_extra = self._flu_to_mavlink(rates_extra)
for _ in range(2): # duplicate to ensure delivery for _ in range(2): # duplicate to ensure delivery
self.mavlink.set_attitude_target_send(0, self.system_id, 0, 0, self.mavlink.set_attitude_target_send(0, self.system_id, 0, 0,
[attitude[0], attitude[1], attitude[2], attitude[3]], [attitude[0], attitude[1], attitude[2], attitude[3]],
0, 0, 0, thrust) rates_extra[0], rates_extra[1], rates_extra[2], thrust)
def set_rates(self, rates: List[float], thrust: float): def set_rates(self, rates: Sequence[float], thrust: float):
if len(rates) != 3: if len(rates) != 3:
raise ValueError('Rates must be [roll_rate, pitch_rate, yaw_rate]') raise ValueError('Rates must be [roll_rate, pitch_rate, yaw_rate]')
if not (0 <= thrust <= 1): if not (0 <= thrust <= 1):
@@ -351,7 +352,7 @@ class Flix:
[1, 0, 0, 0], [1, 0, 0, 0],
rates[0], rates[1], rates[2], thrust) rates[0], rates[1], rates[2], thrust)
def set_motors(self, motors: List[float]): def set_motors(self, motors: Sequence[float]):
if len(motors) != 4: if len(motors) != 4:
raise ValueError('motors must have 4 values') raise ValueError('motors must have 4 values')
if not all(0 <= m <= 1 for m in motors): if not all(0 <= m <= 1 for m in motors):