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:
2024-07-11 19:15:11 -07:00
parent e5d8a716b0
commit 2afb88ef5f

View File

@@ -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) u8 {
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,23 @@ 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(
"az: {d:.1}° ({d:.2} V) {d:.1}° => {c}, el: {d:.1}° ({d:.2} V) {d:.1}° => {c}",
.{
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 {