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.
This commit is contained in:
parent
e5d8a716b0
commit
de76cce706
@ -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 {
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user