Skip to content

Commit

Permalink
Adding test suite with simple output.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklik committed Jun 17, 2024
1 parent 3925e13 commit c6338a5
Showing 1 changed file with 13 additions and 43 deletions.
56 changes: 13 additions & 43 deletions sw/pymlab/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
config.Config(
i2c = {
"port": port,
"device": "smbus",
"device": "hid",
},
bus = [
{
Expand All @@ -43,62 +43,30 @@
windgauge.initialize()
time.sleep(0.1)

if cal > 0:
windgauge.calib_mag(cal)

# windgauge.calib_mag(cal)

#### Measurement ###################################################
log_index = 0
meas_freq = 10; #rough frequency of diff. pressure measurement (gps data frequency is 1 Hz)
gps_raw = ""
first = True
meas_freq = 1; #rough frequency of diff. pressure measurement (gps data frequency is 1 Hz)

while True:

try:
if error == True:
windgauge.reset()
windgauge.initialize()
error = False

time.sleep(0.01)
time.sleep(1/meas_freq)

mag_hdg_comp = windgauge.get_mag_hdg()
new_hdg = mag_hdg_comp
hdg_ma, hdg_vect, prev_hdg_ma = heading_ma(new_hdg, hdg_vect, ma_len, prev_hdg_ma)
hdg_ma = mag_hdg_comp

dp, spd_from_dp = windgauge.get_dp_spd()
temp = windgauge.get_temp()

ts = datetime.datetime.utcfromtimestamp(time.time()).isoformat()

# print ("Heading: %6.2f [deg]; Diff. P: %7.2f [Pa]; Speed from diff. P: %5.2f [km/h]" % (hdg_ma, dp, spd_from_dp))
if gps:

gps_data = gpsd.get_current()
# gps_heading = gps_data.get_time().timestamp()
gps_heading = gps_data.track
gps_time = gps_data.time
gps_gspd = gps_data.hspeed
# gps_pos= gps_data.position()
lat, lon, alt = gps_data.lat, gps_data.lon, gps_data.alt
print(lat, lon, alt)

msg = ("%d;%s;%0.2f;%0.2f;%0.2f;%0.3f;%s;%s;%s;%s;%s;%f\n"% (log_index, ts, dp, hdg_ma, spd_from_dp, temp, gps_time, gps_heading, gps_gspd, lat, lon, alt))
# print(msg)
log_file.write(msg)
sys.stdout.write("%s; %s; Dp: %+4.2f [Pa]; T: %2.3f [degC];" % (str(log_index).zfill(4), ts, dp, temp))
sys.stdout.write(" gps_heading: %s; GPS_HDG: %s [deg]; GPS_GS: %s [m/s]\n" % (gps_heading, gps_time, gps_gspd))
sys.stdout.write(" MAG_HDG: %+4.2f; SPD_W_DP: %+4.2f [km/h]\n" % (hdg_ma, spd_from_dp))
sys.stdout.flush()

else:
msg = ("%d;%s;%0.2f;%0.2f;%0.2f;%0.3f\n"% (log_index, ts, dp, hdg_ma, spd_from_dp, temp))
sys.stdout.write("%s; %s; Dp: %+4.2f [Pa]; T: %2.3f [degC]; " % (str(log_index).zfill(4), ts, dp, temp))
sys.stdout.write("MAG_HDG: %+4.2f; SPD_W_DP: %+4.2f [km/h]\n" % (hdg_ma, spd_from_dp))
sys.stdout.flush()
log_file.write(msg)

log_index += 1
msg = ("%d;%s;%0.2f;%0.2f;%0.2f;%0.3f\n"% (log_index, ts, dp, hdg_ma, spd_from_dp, temp))
sys.stdout.write("%s; %s; Dp: %+4.2f [Pa]; T: %2.3f [degC]; " % (str(log_index).zfill(4), ts, dp, temp))
sys.stdout.write("MAG_HDG: %+4.2f; SPD_W_DP: %+4.2f [km/h]\n" % (hdg_ma, spd_from_dp))
sys.stdout.flush()

except KeyboardInterrupt:
windgauge.stop()
Expand All @@ -110,4 +78,6 @@

sys.stdout.write("\r\n************ I2C Error\r\n\n")
time.sleep(0.1)
error = True
windgauge.reset()
windgauge.initialize()

0 comments on commit c6338a5

Please sign in to comment.