Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Built with Unity 6.5

### Added

- Windows Open Pinball Device support for Pinscape Pico with named nudge axes, firmware scale presets and preassigned cabinet buttons. The updated NativeInput library is required for OPD discovery.

- Shared Pinscape joystick nudge setup and sampled rest calibration in the editor and Player, with explicit velocity presets, device-axis selection, editable SI scales, and sensor state reset on disconnect.

- Closed shared cabinet output roles with independent LCD/HD game display routing and preserved custom scene bindings.

- Cabinet output content rotation, mirroring, and explicit-load inset composition with asymmetric GPU validation.
Expand Down
2 changes: 1 addition & 1 deletion VisualPinball.Engine/VisualPinball.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageProjectUrl>https://visualpinball.org</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<VisualPinballNativeInputVersion>0.0.5</VisualPinballNativeInputVersion>
<VisualPinballNativeInputVersion>0.0.6</VisualPinballNativeInputVersion>
</PropertyGroup>
<!-- Give an initial value based on the operating system where it's currently running on -->
<PropertyGroup Condition="'$(RuntimeIdentifier)' == ''">
Expand Down
47 changes: 27 additions & 20 deletions VisualPinball.Unity/Documentation~/creators-guide/manual/nudging.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,33 @@ Sensor types mean:
Most Xbox-style controllers do not provide accelerometer data for nudging. Map
their sticks as `GamepadIntent`.

KL25Z/Pinscape boards are cabinet sensors. Map their acceleration axes, then use
mount rotation and mirror to match how the board is installed in the cabinet.
The available rotations are 0, 90, 180, and 270 degrees. Mirror flips the board X
axis before rotation.

## Editor Calibration

For direct play in the editor, use the `SimulationThreadComponent` inspector:

1. Enter Play Mode with the cabinet sensor connected.
2. Use auto-configuration if the first device should be mapped as the cabinet
sensor.
3. Set mount rotation and mirror until graph movement matches cabinet movement.
4. Keep the cabinet still and calibrate sensor centers.
5. Nudge the cabinet lightly and watch the input graph.

Calibration captures the current resting raw value as zero. It does not remove
spikes, pick better axes, or tune the overall gain. If the graph spikes while the
cabinet is still, check the mapped axes, increase dead zone, reduce scale, or
inspect the physical board/device signal.
KL25Z/Pinscape boards are cabinet sensors. Map their acceleration axes, then use mount rotation and mirror to match how the board is installed in the cabinet. The available rotations are 0, 90, 180, and 270 degrees. Mirror flips the board X axis before rotation.

### Pinscape Joystick Setup

On Windows, recognized Pinscape joystick layouts offer acceleration and velocity presets in the Player's Nudge settings and the `SimulationThreadComponent` inspector. Acceleration uses X/Y with an initial full-scale value of 9.80665 m/s² (1 g). Set the scale to match the range configured in firmware. The Player offers 1, 2, 4, and 8 g presets and an editable custom scale. Negative scale reverses an axis.

Velocity setup uses RX/RY with the default Pinscape joystick full-scale value of 0.2048 m/s. Enable velocity reporting in firmware before selecting this preset. Pinscape Pico can assign arbitrary signals to joystick axes, so use the named axis selectors and custom scales when its layout differs from the standard Pinscape layout. Velocity mode uses the reported integrated velocity directly through VPE's cabinet sensor model.

Auto-map recognizes cabinet layouts and explicitly typed accelerometer axes. Generic joystick X/Y axes require manual assignment. The Player adds a sensor slot when auto-mapping and preserves existing slots. The inspector's setup buttons configure its first sensor slot. Player settings are saved in the cabinet profile and applied to loaded tables.

### Pinscape Pico Open Pinball Device Setup

Enable Open Pinball Device in the Pico firmware. With an OPD-capable Windows NativeInput library, VPE lists the Pico with an OPD suffix and named nudge axes. Auto-map prefers OPD when both interfaces are present. If you already mapped the Pico's joystick axes, select the OPD preset in that sensor slot to switch interfaces and then calibrate again.

Auto-map uses acceleration. Choose the velocity preset if the firmware reports integrated X/Y nudge velocity. The Pico velocity preset uses 0.32768 m/s at full scale, matching the default firmware `vscale` of 100 counts per mm/s. Set custom scales if you use a different `vscale` or accelerometer range. The report format allows firmware to send zero for unused fields, so confirm which signals your firmware exposes.

Preassigned OPD buttons use the existing VPE cabinet actions, including digital nudge and physical tilt. Physical tilt follows the table's tilt-bob routing and the Player's Tilt Source setting. OPD also exposes plunger position and speed for diagnostics. Mechanical plunger gameplay and generic OPD button assignments need their own input routing.

For a local checkout, build the matching NativeInput branch and install its Windows DLL in `VisualPinball.Unity/Plugins/win-x64` before starting Unity. The default NuGet dependency supplies OPD after an OPD-capable NativeInput release is published and pinned. Linux and macOS use their existing keyboard backends.

### Rest Calibration

In the Player, open the Nudge settings and choose Calibrate under Rest Calibration. This works from the main menu before loading a table. In the editor, enter Play Mode and choose Calibrate Centers in the `SimulationThreadComponent` inspector.

Keep the cabinet still for about one second. Calibration averages fresh input reports for every active mapped channel. It checks sample count, sample duration, and input variation before updating any center. A disconnected device, stale reports, or excessive motion causes calibration to fail with the saved centers intact. Changing settings or leaving the tab cancels a running calibration.

Calibration adjusts neutral centers. Gain, axis selection, mount orientation, and dead zone remain explicit settings. Use the signed raw input labels to check side and forward directions, then check the cabinet acceleration/offset graph while a table runs. A disconnected sensor is cleared on the physics thread and resumes from rest when all of its mapped devices reconnect.

## Shipping Tables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ description: Proposed architecture for adding accelerometer-based nudging to VPE

# Accelerometer Input Design

This page describes the proposed design for adding accelerometer-based nudging to VPE. It covers the intended runtime architecture, where the work should land in the codebase, how Open Pinball Device support should fit into the plan, and how calibration should work for both velocity-capable and legacy-style devices.
This page records an earlier design proposal. VPE now has Windows HID joystick and Open Pinball Device input, cabinet sensor fusion, editor and Player setup, and sampled rest calibration. See [Nudging](xref:nudging) and [Nudge System](nudge-system.md) for the implementation. Cross-platform analog backends are follow-up work.

The proposal below describes the original design for adding accelerometer-based nudging to VPE. It covers the intended runtime architecture, where the work should land in the codebase, how Open Pinball Device support should fit into the plan, and how calibration should work for both velocity-capable and legacy-style devices.

## Summary

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public sealed class SimulationThreadComponentInspector : UnityEditor.Editor
private MessageType _statusType = MessageType.Info;
private GUIStyle _graphLegendStyle;
private double _lastGraphSampleTime;
private NudgeSensorCalibration _calibration;
private List<NudgeSensorConfig> _calibrationSensors;
private double _calibrationStart;

/// <summary>
/// Draws default simulation fields plus live nudge calibration controls for
Expand All @@ -65,6 +68,7 @@ public override void OnInspectorGUI()
serializedObject.ApplyModifiedProperties();

if (targets.Length == 1 && target is SimulationThreadComponent component) {
if (changed) _calibration = null;
if (changed && Application.isPlaying) {
component.ApplyNudgeSensorSettings();
}
Expand All @@ -90,6 +94,7 @@ private void DrawNudgeCalibration(SimulationThreadComponent component)
EditorGUILayout.LabelField("Nudge Calibration", EditorStyles.boldLabel);

if (!Application.isPlaying) {
_calibration = null;
EditorGUILayout.HelpBox("Enter Play Mode to read native input devices and calibrate the current sensor centers.", MessageType.Info);
return;
}
Expand All @@ -98,6 +103,24 @@ private void DrawNudgeCalibration(SimulationThreadComponent component)
EditorGUILayout.LabelField("Input Thread", $"{component.InputThreadActualHz:0.#} Hz / target {component.InputThreadTargetHz:0.#} Hz");

var devices = component.ListNudgeInputDevices();
UpdateCalibration(component, devices);
foreach (var device in devices) {
if (NudgeSensorSetup.TryCreateGamepadSensor(device, out _)) {
EditorGUILayout.LabelField(device.Name, EditorStyles.miniBoldLabel);
if (GUILayout.Button("Map Left Stick")) ApplyNudgePreset(component, device, false);
continue;
}
var opd = NudgeSensorSetup.IsOpenPinballDevice(device);
if (!device.IsConnected || (!opd && !NudgeSensorSetup.IsPinscape(device))) continue;
EditorGUILayout.LabelField(device.Name, EditorStyles.miniBoldLabel);
EditorGUILayout.HelpBox(opd
? "Open Pinball Device. Select Velocity if enabled in firmware. Check the configured full-scale range before play."
: "Standard Pinscape layout. Select Velocity only after enabling RX/RY velocity in firmware. Check the mapped full-scale range before play.", MessageType.Info);
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Acceleration")) ApplyNudgePreset(component, device, false);
if (GUILayout.Button("Velocity")) ApplyNudgePreset(component, device, true);
EditorGUILayout.EndHorizontal();
}
if (devices.Count == 0) {
EditorGUILayout.HelpBox("No native input devices are visible. Check that native input is enabled and that the device was connected before polling started.", MessageType.Warning);
} else {
Expand All @@ -108,7 +131,8 @@ private void DrawNudgeCalibration(SimulationThreadComponent component)
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal();
EditorGUI.BeginDisabledGroup(devices.Count == 0);
if (GUILayout.Button("Auto-map First Device")) {
if (GUILayout.Button("Auto-map Cabinet Sensor")) {
_calibration = null;
Undo.RecordObject(component, "Auto-map nudge sensor");
if (component.TryAutoConfigureFirstCabinetSensor(out var message)) {
SetStatus(message, MessageType.Info);
Expand All @@ -121,20 +145,18 @@ private void DrawNudgeCalibration(SimulationThreadComponent component)

EditorGUI.BeginDisabledGroup(devices.Count == 0 || component.NudgeSensors == null || component.NudgeSensors.Count == 0);
if (GUILayout.Button("Calibrate Centers")) {
Undo.RecordObject(component, "Calibrate nudge sensor centers");
var calibrated = component.CalibrateNudgeSensorCenters();
if (calibrated > 0) {
SetStatus($"Calibrated {calibrated} mapped nudge channel(s).", MessageType.Info);
EditorUtility.SetDirty(component);
} else {
SetStatus("No mapped channels matched the currently visible devices.", MessageType.Warning);
}
_calibrationSensors = CabinetNudgeSensorSettings.FromSimulationThreadSensors(component.NudgeSensors)
.ConvertAll(sensor => sensor.ToEngineConfig());
_calibration = new NudgeSensorCalibration(_calibrationSensors, devices);
_calibrationStart = EditorApplication.timeSinceStartup;
SetStatus("Calibrating. Keep the cabinet still...", MessageType.Info);
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();

EditorGUI.BeginDisabledGroup(component.NudgeSensors == null || component.NudgeSensors.Count == 0);
if (GUILayout.Button("Reset Centers")) {
_calibration = null;
Undo.RecordObject(component, "Reset nudge sensor centers");
var reset = component.ResetNudgeSensorCenters();
SetStatus(reset > 0 ? "Cleared nudge sensor raw centers." : "No nudge sensors to reset.", MessageType.Info);
Expand All @@ -147,6 +169,51 @@ private void DrawNudgeCalibration(SimulationThreadComponent component)
}
}

private void UpdateCalibration(SimulationThreadComponent component, IReadOnlyList<NativeInputDeviceInfo> devices)
{
if (_calibration == null) return;
_calibration.Sample(devices);
if (EditorApplication.timeSinceStartup - _calibrationStart < 1.2) return;
var success = _calibration.TryComplete(out var message);
_calibration = null;
if (success) {
Undo.RecordObject(component, "Calibrate nudge sensor centers");
component.NudgeSensors = _calibrationSensors.ConvertAll(sensor => CabinetNudgeSensorSettings.From(sensor).ToSimulationThreadConfig());
component.ApplyNudgeSensorSettings();
EditorUtility.SetDirty(component);
}
_calibrationSensors = null;
SetStatus(message, success ? MessageType.Info : MessageType.Warning);
}

private void ApplyNudgePreset(SimulationThreadComponent component, NativeInputDeviceInfo device, bool velocity)
{
var gamepad = NudgeSensorSetup.TryCreateGamepadSensor(device, out var sensor);
if (!gamepad && !NudgeSensorSetup.TryCreateCabinetPreset(device, velocity, out sensor)) {
SetStatus("The required axes are unavailable.", MessageType.Warning);
return;
}
_calibration = null;
Undo.RecordObject(component, "Map nudge sensor");
component.NudgeSensors ??= new List<SimulationThreadNudgeSensorConfig>();
if (component.NudgeSensors.Count > 0) {
var old = component.NudgeSensors[0];
if (old != null) {
sensor.mountRotation = (int)old.MountRotation;
sensor.mountMirror = old.MountMirror;
sensor.strength = old.Strength;
sensor.cabinetMassKg = old.CabinetMassKg;
}
component.NudgeSensors[0] = sensor.ToSimulationThreadConfig();
} else {
component.NudgeSensors.Add(sensor.ToSimulationThreadConfig());
}
component.ApplyNudgeSensorSettings();
EditorUtility.SetDirty(component);
SetStatus(gamepad ? "Mapped the left stick to the first sensor slot."
: "Mapped the first sensor slot. Check the range and calibrate at rest.", MessageType.Info);
}

/// <summary>
/// Lists visible native input devices and their first few axes.
/// </summary>
Expand Down
Loading
Loading