From de76cce7064c4b74e710ceecff2154714944b1c7 Mon Sep 17 00:00:00 2001 From: torque Date: Thu, 11 Jul 2024 19:15:11 -0700 Subject: [PATCH] controller: make controller info printout more useful This has a lot more relevant information now. Anyway, this has been tested on real hardware, and it appears to work pretty well. I am considering changing the control loop so that it isn't always operating on stale feedback (two LabJack calls per loop when actively controlling pointing). Also the calibration routines need to be implemented. --- src/YaesuController.zig | 35 +++++++++++++++++++++++++++++++---- src/main.zig | 6 ++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/YaesuController.zig b/src/YaesuController.zig index 8cfe177..ef471db 100644 --- a/src/YaesuController.zig +++ b/src/YaesuController.zig @@ -180,7 +180,21 @@ const Controller = struct { }; } - fn signDeadzone(offset: f64, deadzone: f64) enum { negative, zero, positive } { + const Sign = enum { + negative, + zero, + positive, + + pub fn symbol(self: Sign) u21 { + return switch (self) { + .negative => '-', + .zero => '×', + .positive => '+', + }; + } + }; + + fn signDeadzone(offset: f64, deadzone: f64) Sign { return if (@abs(offset) < deadzone) .zero else if (offset < 0) @@ -224,11 +238,24 @@ const Controller = struct { drive_signal[config.controller.elevation_outputs.increase.io] = elsign == .positive; drive_signal[config.controller.elevation_outputs.decrease.io] = elsign == .negative; - log.info("drive: az = {s}, el = {s}. outputs: {any}", .{ @tagName(azsign), @tagName(elsign), drive_signal }); - const raw = try self.labjack.readAnalogWriteDigital(2, inputs, drive_signal, true); + const angles = lerpAndOffsetAngles(raw); - return lerpAndOffsetAngles(raw); + log.info( + // -180.1 is 6 chars. -5.20 is 5 chars + "az: {d: >6.1}° ({d: >5.2} V) Δ {d: >6.1}° => {u}, el: {d: >6.1}° ({d: >5.2} V) Δ {d: >6.1}° => {u}", + .{ + angles.azimuth, + raw[0].voltage, + pos_error.azimuth, + azsign.symbol(), + angles.elevation, + raw[1].voltage, + pos_error.elevation, + elsign.symbol(), + }, + ); + return angles; } fn run(self: *Controller) !void { diff --git a/src/main.zig b/src/main.zig index 3223c5f..c011763 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const builtin = @import("builtin"); const Config = @import("./Config.zig"); const lj = @import("./labjack.zig"); @@ -13,6 +14,11 @@ fn printStderr(comptime fmt: []const u8, args: anytype) void { } pub fn main() !u8 { + if (comptime builtin.os.tag == .windows) { + // set output to UTF-8 on Windows + _ = std.os.windows.kernel32.SetConsoleOutputCP(65001); + } + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator();