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

mavfft_pid.py: handle logs using fast rate control #973

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
28 changes: 22 additions & 6 deletions tools/mavfft_pid.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from argparse import ArgumentParser
parser = ArgumentParser(description=__doc__)
parser.add_argument("--condition", default=None, help="select packets by condition")
parser.add_argument("--sample-rate", dest='sample_rate', type=int, default=400, help="sample rate of PID values")
parser.add_argument("--sample-rate", dest='sample_rate', type=int, default=0, help="sample rate of PID values")
parser.add_argument("logs", metavar="LOG", nargs="+")

args = parser.parse_args()
Expand All @@ -22,6 +22,10 @@ def fft(logfile):
'''display fft for PID data in logfile'''

sample_rate = args.sample_rate
loop_rate = 400
fstrate_enable = 0
fstrate_div = 1
gyro_rate = 0

print("Processing log %s" % filename)
mlog = mavutil.mavlink_connection(filename)
Expand All @@ -31,11 +35,23 @@ def fft(logfile):
if m is None:
break
type = m.get_type()
if type == "PARM" and m.Name == 'SCHED_LOOP_RATE':
sample_rate = int(m.Value)
break


if type == "PARM":
if m.Name == 'SCHED_LOOP_RATE':
loop_rate = int(m.Value)
elif m.Name == 'FSTRATE_ENABLE':
fstrate_enable = int(m.Value)
elif m.Name == 'FSTRATE_DIV':
fastrate_div = int(m.Value)
elif m.Name == 'INS_GYRO_RATE':
gyro_rate = int(m.Value)

if sample_rate == 0:
if fstrate_enable == 0:
sample_rate = loop_rate
else:
gyro_rate = 1000 * pow(2, gyro_rate)
sample_rate = gyro_rate / fstrate_div

mlog = mavutil.mavlink_connection(filename)

data = {'PIDR.rate' : sample_rate,
Expand Down
Loading