// SPDX-License-Identifier: MIT // Copyright (c) 2026 Incoprea // Inspect a bounded PID control step // Not compiled or tested in-world // Setup: Place in a spare owned prim. Touch repeatedly to feed the next predefined measurement. Touch for owner-only output. // Stop / restore: Remove/disable. The script calculates only; no scene properties change. // Notes: A teaching controller with fixed sample time, not a ready physics controller. Real control needs measured dt, reset handling and tuning. // License: see LICENSE in this distribution. // Original Incoprea. MIT. Planning only. list MEASUREMENTS=[0.0,0.4,0.7,0.9,1.1,1.0]; integer cursor; float integral; float previousError; integer initialized; default { touch_start(integer detectedCount) { if(llDetectedKey(0)!=llGetOwner())return; float measured=llList2Float(MEASUREMENTS,cursor); cursor=(cursor+1)%llGetListLength(MEASUREMENTS); float dt=0.1; float error=1.0-measured; integral+=error*dt; if(integral>0.5)integral=0.5; if(integral< -0.5)integral=-0.5; float derivative=0.0; if(initialized)derivative=(error-previousError)/dt; previousError=error; initialized=TRUE; float output=2.0*error+0.8*integral+0.1*derivative; if(output>1.0)output=1.0; if(output< -1.0)output=-1.0; llOwnerSay("Measurement="+(string)measured+" error="+(string)error+" output="+(string)output); } }