Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'nodeRssiPeak' in delta5Node.ino #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/delta5node/delta5node.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ struct {
uint16_t volatile rssiPeak = 0;
// The time of the peak raw rssi for the current pass
uint32_t volatile rssiPeakRawTimeStamp = 0;
// The peak smoothed rssi seen since the node was powered on or frequency set
uint16_t volatile nodeRssiPeak = 0;

// variables to track the loop time
uint32_t volatile loopTime = 0;
Expand Down Expand Up @@ -255,6 +257,14 @@ void loop() {
state.rssiSmoothed = (settings.filterRatioFloat * (float)state.rssiRaw) + ((1.0f-settings.filterRatioFloat) * state.rssiSmoothed);
state.rssi = (int)state.rssiSmoothed;

// Keep track of peak (smoothed) rssi; set trigger as offset of peak
if (state.rssi > state.nodeRssiPeak) {
state.nodeRssiPeak = state.rssi;
state.rssiTrigger = state.nodeRssiPeak - settings.calibrationOffset;
Serial.print("New nodeRssiPeak = ");
Serial.println(state.nodeRssiPeak);
}

if (state.rssiTrigger > 0) {
if (!state.crossing && state.rssi > state.rssiTrigger) {
state.crossing = true; // Quad is going through the gate
Expand All @@ -269,14 +279,10 @@ void loop() {
}

if (state.crossing) {
int triggerThreshold = settings.triggerThreshold;

// If in calibration mode, keep raising the trigger value
if (state.calibrationMode) {
state.rssiTrigger = max(state.rssiTrigger, state.rssi - settings.calibrationOffset);
Copy link
Collaborator

@punkkills punkkills Mar 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent of auto calibration is to calculate a new trigger value for each new run. Each run may have a different pilot with different vtx output strength.

// when calibrating, use a larger threshold
triggerThreshold = settings.calibrationThreshold;
}
// when in calibration mode, use a larger threshold
int triggerThreshold = state.calibrationMode ?
settings.calibrationThreshold : settings.triggerThreshold;

state.rssiPeak = max(state.rssiPeak, state.rssi);

Expand Down Expand Up @@ -416,6 +422,7 @@ byte i2cHandleRx(byte command) { // The first byte sent by the I2C master is the
if (readAndValidateIoBuffer(0x51, 2)) {
settings.vtxFreq = ioBufferRead16();
setRxModule(settings.vtxFreq); // Shouldn't do this in Interrupt Service Routine
state.nodeRssiPeak = 0; // restart rssi peak tracking for node
success = true;
}
break;
Expand All @@ -428,7 +435,7 @@ byte i2cHandleRx(byte command) { // The first byte sent by the I2C master is the
case WRITE_CALIBRATION_MODE:
if (readAndValidateIoBuffer(WRITE_CALIBRATION_MODE, 1)) {
state.calibrationMode = ioBufferRead8();
state.rssiTrigger = state.rssi - settings.calibrationOffset;
state.rssiTrigger = state.nodeRssiPeak - settings.calibrationOffset;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it assumes that you always want to set the trigger value based on peak RSSI, not the peak of the current quad in the heat.

lastPass.rssiPeakRaw = 0;
lastPass.rssiPeak = 0;
state.rssiPeakRaw = 0;
Expand Down