Skip to content

Class OpenSkyhawk::AngleSensorInput

ClassList > OpenSkyhawk > AngleSensorInput

Magnetic angle sensor (AS5600 / MT6701) as an absolute knob or axis. More...

  • #include <AngleSensorInput.h>

Inherits the following classes: OpenSkyhawk::AnalogInput

Public Static Attributes

Type Name
constexpr float COUNTS_PER_DEG = 65536.0f / 360.0f
Counts per degree: a full turn spans the 16-bit range (65536 / 360).

Public Static Attributes inherited from OpenSkyhawk::AnalogInput

See OpenSkyhawk::AnalogInput

Type Name
constexpr uint8_t DEFAULT_EWMA_SHIFT = 3
EWMA α = 1/2^3 = 1/8.
constexpr uint16_t DEFAULT_HYSTERESIS = 128
counts on the 16-bit output.
constexpr uint16_t DEFAULT_POLL_MS = 8
default min interval between ADC reads (ms).
constexpr uint8_t MAX_EWMA_SHIFT = 15
cap: scaled<<shift must fit int32 at full scale.

Public Functions

Type Name
AngleSensorInput (uint16_t controlId, PinRef pin, float centerDeg, float travelDeg, uint16_t pollMs=DEFAULT_POLL_MS)
Construct an absolute angle input.

Public Functions inherited from OpenSkyhawk::AnalogInput

See OpenSkyhawk::AnalogInput

Type Name
AnalogInput (uint16_t controlId, PinRef pin, bool reverse=false, uint16_t minRaw=0, uint16_t maxRaw=65535, uint16_t hysteresis=DEFAULT_HYSTERESIS, uint8_t ewmaShift=DEFAULT_EWMA_SHIFT, uint16_t pollMs=DEFAULT_POLL_MS)
Construct a continuous analog input.
virtual void configure () override
Configure the pin as an input. Called by PanelGroup::setup() .
virtual void forceReport () override
Sample fresh (bypassing the throttle) and emit the current value as the baseline.
virtual void poll () override
Throttled ADC read + EWMA; emit when the value clears the hysteresis or a rail.

Public Functions inherited from OpenSkyhawk::InputBase

See OpenSkyhawk::InputBase

Type Name
virtual void configure ()
Configure hardware pins for this input.
virtual void forceReport () = 0
Read hardware state and emit a CAN EVT unconditionally.
InputBase * next () const
Next input in the list; nullptr at end.
virtual void poll () = 0
Read hardware state and emit a CAN EVT if state changed.
virtual void sampleTick ()
High-rate sample hook — called from a sampling ISR when the node runs one (e.g. ShiftBus timer sampling, -DSHIFTBUS_ISR_HZ). Default no-op.

Public Static Functions inherited from OpenSkyhawk::InputBase

See OpenSkyhawk::InputBase

Type Name
InputBase * head ()
Head of the self-registered linked list.

Protected Functions

Type Name
virtual uint16_t readRaw () override
The base's reading, re-centred so centerDeg sits at mid-scale (0°/360° wraps).

Protected Functions inherited from OpenSkyhawk::AnalogInput

See OpenSkyhawk::AnalogInput

Type Name
virtual uint16_t readRaw ()
Read the raw 16-bit source value. The one hook a family member overrides.

Protected Functions inherited from OpenSkyhawk::InputBase

See OpenSkyhawk::InputBase

Type Name
InputBase ()
Registers this instance into the linked list.

Detailed Description

An AnalogInput that reads the sensor's analog output through any analog-capable PinRef — an STM32 ADC pin or an ADS1115 channel. No wiper to wear out, and a full 360° mechanical range where a pot stops around 270°. Intended for absolute DCS-BIOS knobs such as GUNSIGHT_KNB and RADAR_RETICLE; flight-control axes use linear Hall sensors on a plain AnalogInput.

The base owns everything that makes an analog input behave: EWMA smoothing, hysteresis, per-instance pollMs, and routing by controlId (DCSIN_* → absolute set_state via PanelBridge; CTRL_* → HID via SimGateway). This class adds only the angle meaning — where the travel sits on the circle, and what happens at the 0°/360° seam.

A full turn is 65536 counts, so one degree is 65536/360 ≈ 182 counts. The constructor turns centre and travel into the base's [minRaw, maxRaw] window, and readRaw() re-centres every reading so the centre angle lands at mid-scale. Unsigned arithmetic wraps for free, which is what makes a travel spanning 0°/360° (say 340°→40°) behave like any other — no rotating the magnet mount to dodge the seam.

The seam does not disappear, it moves opposite the centre. A single-turn absolute sensor reads the same angle at both ends of a full turn, so the circle cannot map onto a line without one break; re-centring puts that break as far from the knob's centre as possible. Travel is therefore up to just under a full turn: at exactly 360° the two ends would be the same sensor angle, and the output would jump full-scale there. A knob that genuinely rotates without end needs different semantics (turn counting, or a relative mode) and is not this class.

Resolution note: the analog output is coarser than the chip's I²C register and picks up ADC noise — fine for a gunsight or reticle knob. The AS5600's ZPOS/MPOS can narrow its output span to the knob's travel to win some of that back. Reading the angle register over I²C belongs in a future PinRef backend, not here, so this class keeps taking a PinRef.

Public Static Attributes Documentation

variable COUNTS_PER_DEG

Counts per degree: a full turn spans the 16-bit range (65536 / 360).

constexpr float OpenSkyhawk::AngleSensorInput::COUNTS_PER_DEG;


Public Functions Documentation

function AngleSensorInput

Construct an absolute angle input.

OpenSkyhawk::AngleSensorInput::AngleSensorInput (
    uint16_t controlId,
    PinRef pin,
    float centerDeg,
    float travelDeg,
    uint16_t pollMs=DEFAULT_POLL_MS
) 

Parameters:

  • controlId DCSIN_* or CTRL_* constant. Determines PanelBridge routing.
  • pin analog PinRef for the sensor's output (STM32 ADC pin or ADS1115 channel).
  • centerDeg sensor angle at the knob's centre position. Wraps, so 370 == 10.
  • travelDeg total mechanical travel, centred on centerDeg: the knob spans centerDeg ± travelDeg/2. Clamped to (0, 360) — up to just under a full turn, because the ends of a full turn are one sensor angle. The wrap point sits opposite centerDeg, so the closer travel comes to 360° the nearer that break sits to the ends of travel.
  • pollMs min interval between ADC reads, ms (default DEFAULT_POLL_MS). Per instance; an ADS1115 PinRef blocks ~8 ms per conversion regardless.

Protected Functions Documentation

function readRaw

The base's reading, re-centred so centerDeg sits at mid-scale (0°/360° wraps).

virtual uint16_t OpenSkyhawk::AngleSensorInput::readRaw () override

Implements OpenSkyhawk::AnalogInput::readRaw



The documentation for this class was generated from the following file Firmware/Libraries/PanelGroup/Inputs/AngleSensorInput/AngleSensorInput.h