Created
November 12, 2010 17:22
-
-
Save adamgreig/674384 to your computer and use it in GitHub Desktop.
connect to fldigi via xml-rpc, get the current dial and log frequency, use it to retune the radio to keep the audio frequency at a set point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
fldigi autotuner script | |
Released into the public domain by Adam Greig in 2010 | |
""" | |
import xmlrpclib | |
import math | |
import time | |
# Desired audio frequency (Hz) | |
demand_freq = 1500 | |
# Loop time (s) | |
loop_time = 0.1 | |
# The highest step change we will retune the radio by (Hz/loop) | |
max_change = 3 | |
# How quickly we react to errors. Too high will cause oscillation. | |
error_gain = 0.1 | |
# Connect to fldigi | |
s = xmlrpclib.ServerProxy("http://localhost:7362") | |
while 1: | |
# Read current dial and signal frequencies | |
dial_freq = s.main.get_frequency() | |
signal_freq = float(s.log.get_frequency()) * 1000 | |
# Audio frequency is the difference between the two | |
audio_freq = signal_freq - dial_freq | |
# Calculate error in audio frequency | |
freq_error = demand_freq - audio_freq | |
freq_error *= error_gain | |
# Change by max_change at most | |
if freq_error > max_change: | |
freq_error = max_change | |
elif freq_error < -max_change: | |
freq_error = -max_change | |
# Set new frequency | |
new_freq = dial_freq - freq_error | |
s.main.set_frequency(new_freq) | |
# Output info | |
print "Dial", int(dial_freq) | |
print "Signal", int(signal_freq) | |
print "Audio", int(audio_freq) | |
print "Error", int(1500 - audio_freq) | |
print "Change", int(freq_error) | |
print "New Frequency", int(new_freq) | |
# Sleep a bit | |
time.sleep(loop_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment