mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 02:16:53 +08:00
sensors: use only as many voters as there are sensors
This saves ~1.1KB of RAM for systems with only 1 sensor of each type. If there are more sensors, they will be dynamically added, such that failover still works.
This commit is contained in:
@@ -212,7 +212,7 @@ private:
|
|||||||
SensorData()
|
SensorData()
|
||||||
: last_best_vote(0),
|
: last_best_vote(0),
|
||||||
subscription_count(0),
|
subscription_count(0),
|
||||||
voter(SENSOR_COUNT_MAX),
|
voter(1),
|
||||||
last_failover_count(0)
|
last_failover_count(0)
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < SENSOR_COUNT_MAX; i++) {
|
for (unsigned i = 0; i < SENSOR_COUNT_MAX; i++) {
|
||||||
@@ -2266,6 +2266,13 @@ Sensors::init_sensor_class(const struct orb_metadata *meta, SensorData &sensor_d
|
|||||||
for (unsigned i = 0; i < group_count; i++) {
|
for (unsigned i = 0; i < group_count; i++) {
|
||||||
if (sensor_data.subscription[i] < 0) {
|
if (sensor_data.subscription[i] < 0) {
|
||||||
sensor_data.subscription[i] = orb_subscribe_multi(meta, i);
|
sensor_data.subscription[i] = orb_subscribe_multi(meta, i);
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
/* the first always exists, but for each further sensor, add a new validator */
|
||||||
|
if (!sensor_data.voter.add_new_validator()) {
|
||||||
|
PX4_ERR("failed to add validator for sensor %s %i", meta->o_name, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t priority;
|
int32_t priority;
|
||||||
|
|||||||
Reference in New Issue
Block a user