1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-30 08:24:11 +01:00

rcvr activity: Speed up activity acquisition

Activity detection logic can now move through
the active receivers more quickly.
This commit is contained in:
Stacey Sheldon 2011-08-24 08:49:34 -04:00
parent 6514fd95c7
commit a72c657e21
2 changed files with 92 additions and 70 deletions

View File

@ -89,7 +89,7 @@ static bool okToArm(void);
static bool validInputRange(int16_t min, int16_t max, uint16_t value); static bool validInputRange(int16_t min, int16_t max, uint16_t value);
#define RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP 12 #define RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP 12
#define RCVR_ACTIVITY_MONITOR_MIN_RANGE 5 #define RCVR_ACTIVITY_MONITOR_MIN_RANGE 10
struct rcvr_activity_fsm { struct rcvr_activity_fsm {
ManualControlSettingsChannelGroupsOptions group; ManualControlSettingsChannelGroupsOptions group;
uint16_t prev[RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP]; uint16_t prev[RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP];
@ -347,6 +347,66 @@ static void resetRcvrActivity(struct rcvr_activity_fsm * fsm)
fsm->sample_count = 0; fsm->sample_count = 0;
} }
static void updateRcvrActivitySample(uint32_t rcvr_id, uint16_t samples[], uint8_t max_channels) {
for (uint8_t channel = 0; channel < max_channels; channel++) {
samples[channel] = PIOS_RCVR_Read(rcvr_id, channel);
}
}
static bool updateRcvrActivityCompare(uint32_t rcvr_id, struct rcvr_activity_fsm * fsm)
{
bool activity_updated = false;
/* Compare the current value to the previous sampled value */
for (uint8_t channel = 0;
channel < RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP;
channel++) {
uint16_t delta;
uint16_t prev = fsm->prev[channel];
uint16_t curr = PIOS_RCVR_Read(rcvr_id, channel);
if (curr > prev) {
delta = curr - prev;
} else {
delta = prev - curr;
}
if (delta > RCVR_ACTIVITY_MONITOR_MIN_RANGE) {
/* Mark this channel as active */
ReceiverActivityActiveGroupOptions group;
/* Don't assume manualcontrolsettings and receiveractivity are in the same order. */
switch (fsm->group) {
case MANUALCONTROLSETTINGS_CHANNELGROUPS_PWM:
group = RECEIVERACTIVITY_ACTIVEGROUP_PWM;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_PPM:
group = RECEIVERACTIVITY_ACTIVEGROUP_PPM;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM1:
group = RECEIVERACTIVITY_ACTIVEGROUP_SPEKTRUM1;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM2:
group = RECEIVERACTIVITY_ACTIVEGROUP_SPEKTRUM2;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_SBUS:
group = RECEIVERACTIVITY_ACTIVEGROUP_SBUS;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_GCS:
group = RECEIVERACTIVITY_ACTIVEGROUP_GCS;
break;
default:
PIOS_Assert(0);
break;
}
ReceiverActivityActiveGroupSet(&group);
ReceiverActivityActiveChannelSet(&channel);
activity_updated = true;
}
}
return (activity_updated);
}
static bool updateRcvrActivity(struct rcvr_activity_fsm * fsm) static bool updateRcvrActivity(struct rcvr_activity_fsm * fsm)
{ {
bool activity_updated = false; bool activity_updated = false;
@ -362,82 +422,44 @@ static bool updateRcvrActivity(struct rcvr_activity_fsm * fsm)
goto group_completed; goto group_completed;
} }
/* Sample the channel */ if (fsm->sample_count == 0) {
for (uint8_t channel = 0; /* Take a sample of each channel in this group */
channel < RCVR_ACTIVITY_MONITOR_CHANNELS_PER_GROUP; updateRcvrActivitySample(pios_rcvr_group_map[fsm->group],
channel++) { fsm->prev,
if (fsm->sample_count == 0) { NELEMENTS(fsm->prev));
fsm->prev[channel] = PIOS_RCVR_Read(pios_rcvr_group_map[fsm->group], channel); fsm->sample_count++;
} else { return (false);
uint16_t delta;
uint16_t prev = fsm->prev[channel];
uint16_t curr = PIOS_RCVR_Read(pios_rcvr_group_map[fsm->group], channel);
if (curr > prev) {
delta = curr - prev;
} else {
delta = prev - curr;
}
if (delta > RCVR_ACTIVITY_MONITOR_MIN_RANGE) {
/* Mark this channel as active */
ReceiverActivityActiveGroupOptions group;
/* Don't assume manualcontrolsettings and receiveractivity are in the same order. */
switch (fsm->group) {
case MANUALCONTROLSETTINGS_CHANNELGROUPS_PWM:
group = RECEIVERACTIVITY_ACTIVEGROUP_PWM;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_PPM:
group = RECEIVERACTIVITY_ACTIVEGROUP_PPM;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM1:
group = RECEIVERACTIVITY_ACTIVEGROUP_SPEKTRUM1;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_SPEKTRUM2:
group = RECEIVERACTIVITY_ACTIVEGROUP_SPEKTRUM2;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_SBUS:
group = RECEIVERACTIVITY_ACTIVEGROUP_SBUS;
break;
case MANUALCONTROLSETTINGS_CHANNELGROUPS_GCS:
group = RECEIVERACTIVITY_ACTIVEGROUP_GCS;
break;
default:
PIOS_Assert(0);
break;
}
ReceiverActivityActiveGroupSet(&group);
ReceiverActivityActiveChannelSet(&channel);
activity_updated = true;
}
}
} }
if (++fsm->sample_count < 2) { /* Compare with previous sample */
return (activity_updated); activity_updated = updateRcvrActivityCompare(pios_rcvr_group_map[fsm->group], fsm);
}
group_completed:
/* Reset the sample counter */ /* Reset the sample counter */
fsm->sample_count = 0; fsm->sample_count = 0;
/* /* Find the next active group, but limit search so we can't loop forever here */
* Group Completed for (uint8_t i = 0; i < MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE; i++) {
*/ /* Move to the next group */
fsm->group++;
group_completed: if (fsm->group >= MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) {
/* Start over at channel zero */ /* Wrap back to the first group */
if (++fsm->group < MANUALCONTROLSETTINGS_CHANNELGROUPS_NONE) { fsm->group = 0;
return (activity_updated); }
if (pios_rcvr_group_map[fsm->group]) {
/*
* Found an active group, take a sample here to avoid an
* extra 20ms delay in the main thread so we can speed up
* this algorithm.
*/
updateRcvrActivitySample(pios_rcvr_group_map[fsm->group],
fsm->prev,
NELEMENTS(fsm->prev));
fsm->sample_count++;
break;
}
} }
/*
* All groups completed
*/
/* Start over at group zero */
fsm->group = 0;
return (activity_updated); return (activity_updated);
} }

View File

@ -542,7 +542,7 @@ void ConfigInputWidget::identifyControls()
++debounce; ++debounce;
lastChannel.group= currentChannel.group; lastChannel.group= currentChannel.group;
lastChannel.number=currentChannel.number; lastChannel.number=currentChannel.number;
if(!usedChannels.contains(lastChannel) && debounce>5) if(!usedChannels.contains(lastChannel) && debounce>1)
{ {
debounce=0; debounce=0;
usedChannels.append(lastChannel); usedChannels.append(lastChannel);