Skip to content

Commit d57fbc7

Browse files
committed
ping360: update automatic transmit duration calculation
1 parent f7b57be commit d57fbc7

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/sensor/ping360.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,19 @@ class Ping360 : public PingSensor
383383
void adjustTransmitDuration()
384384
{
385385
if (_autoTransmitDuration) {
386-
int autoDuration = round(5.1 + 2.833*(range() - 2));
386+
/*
387+
* Per firmware engineer:
388+
* 1. Starting point is TxPulse in usec = ((one-way range in metres) * 4000) / (Velocity of sound in metres per second)
389+
* 2. Then check that TxPulse is wide enough for currently selected sample interval in usec, i.e.,
390+
* if TxPulse < (1.25 * sample interval) then TxPulse = (1.25 * sample interval)
391+
* 3. Perform limit checking
392+
*/
393+
394+
// 1
395+
int autoDuration = round(4000*range()/_speed_of_sound);
396+
// 2 (transmit duration is microseconds, samplePeriod() is nanoseconds)
397+
autoDuration = std::max(static_cast<int>(1.25*samplePeriod()/1000), autoDuration);
398+
// 3
387399
_transmit_duration = std::max(static_cast<int>(_firmwareMinTransmitDuration),
388400
std::min(transmitDurationMax(), autoDuration));
389401
emit transmitDurationChanged();

0 commit comments

Comments
 (0)