firmware: avoid Arduino degrees macro collision
This commit is contained in:
@@ -8,16 +8,16 @@ namespace {
|
|||||||
Adafruit_BNO08x bno086(-1);
|
Adafruit_BNO08x bno086(-1);
|
||||||
sh2_SensorValue_t value;
|
sh2_SensorValue_t value;
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
float degrees(float r) { return r * 180.0f / PI; }
|
float radiansToDegrees(float r) { return r * 180.0f / PI; }
|
||||||
void updateEuler(ImuState& s) {
|
void updateEuler(ImuState& s) {
|
||||||
float sinr = 2 * (s.real * s.i + s.j * s.k);
|
float sinr = 2 * (s.real * s.i + s.j * s.k);
|
||||||
float cosr = 1 - 2 * (s.i * s.i + s.j * s.j);
|
float cosr = 1 - 2 * (s.i * s.i + s.j * s.j);
|
||||||
s.rollDegrees = degrees(atan2f(sinr, cosr));
|
s.rollDegrees = radiansToDegrees(atan2f(sinr, cosr));
|
||||||
float sinp = 2 * (s.real * s.j - s.k * s.i);
|
float sinp = 2 * (s.real * s.j - s.k * s.i);
|
||||||
s.pitchDegrees = degrees(fabsf(sinp) >= 1 ? copysignf(PI / 2, sinp) : asinf(sinp));
|
s.pitchDegrees = radiansToDegrees(fabsf(sinp) >= 1 ? copysignf(PI / 2, sinp) : asinf(sinp));
|
||||||
float siny = 2 * (s.real * s.k + s.i * s.j);
|
float siny = 2 * (s.real * s.k + s.i * s.j);
|
||||||
float cosy = 1 - 2 * (s.j * s.j + s.k * s.k);
|
float cosy = 1 - 2 * (s.j * s.j + s.k * s.k);
|
||||||
s.yawDegrees = degrees(atan2f(siny, cosy));
|
s.yawDegrees = radiansToDegrees(atan2f(siny, cosy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,4 +36,3 @@ void updateImu(ImuState& s) {
|
|||||||
s.accuracy = value.status; s.valid = true; s.lastUpdateMs = millis();
|
s.accuracy = value.status; s.valid = true; s.lastUpdateMs = millis();
|
||||||
updateEuler(s);
|
updateEuler(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ def test_loop_is_non_blocking():
|
|||||||
assert "updateGps" in loop and "updateImu" in loop and "TELEMETRY_INTERVAL_MS" in loop
|
assert "updateGps" in loop and "updateImu" in loop and "TELEMETRY_INTERVAL_MS" in loop
|
||||||
assert not re.search(r"delay\((?:[2-9]|[1-9]\d+)\)", loop)
|
assert not re.search(r"delay\((?:[2-9]|[1-9]\d+)\)", loop)
|
||||||
|
|
||||||
|
def test_imu_does_not_redeclare_arduino_degrees_macro():
|
||||||
|
imu = source("imu.cpp")
|
||||||
|
assert "float degrees(" not in imu
|
||||||
|
assert "radiansToDegrees" in imu
|
||||||
|
|
||||||
def test_node_does_not_take_cargo_or_ble_authority():
|
def test_node_does_not_take_cargo_or_ble_authority():
|
||||||
combined = "\n".join(p.read_text() for p in NODE.glob("*.*"))
|
combined = "\n".join(p.read_text() for p in NODE.glob("*.*"))
|
||||||
assert "NimBLE" not in combined and "JBD" not in combined and "server.on(" not in combined
|
assert "NimBLE" not in combined and "JBD" not in combined and "server.on(" not in combined
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user