Documentation
¶
Overview ¶
Package motion will own semantic motion targets, plans, sampling, retargeting, and active motion state.
Index ¶
- Constants
- func UsesExactImportedCurve(definition PatternDefinition) bool
- type ActiveMotionState
- type AreaFocus
- type Curve
- type CurveMetrics
- type CurvePoint
- type DynamicAnchor
- type DynamicDefinition
- type Engine
- func (e *Engine) AdmissionGeneration() uint64
- func (e *Engine) ApplyTarget(ctx context.Context, target MotionTarget, reason string) (ActiveMotionState, error)
- func (e *Engine) Pause(ctx context.Context, reason string) (ActiveMotionState, error)
- func (e *Engine) RefreshSettings(ctx context.Context, settings config.MotionSettings, reason string) (ActiveMotionState, error)
- func (e *Engine) Resume(ctx context.Context, reason string) (ActiveMotionState, error)
- func (e *Engine) Snapshot() ActiveMotionState
- func (e *Engine) Start(ctx context.Context, target MotionTarget, settings config.MotionSettings) (ActiveMotionState, error)
- func (e *Engine) StartAtGeneration(ctx context.Context, target MotionTarget, settings config.MotionSettings, ...) (ActiveMotionState, error)
- func (e *Engine) Stop(ctx context.Context, reason string) (ActiveMotionState, error)
- type EngineOptions
- type MediaTimelineDefinition
- type MotionPlan
- func (p MotionPlan) CompleteAt(streamMillis int64) bool
- func (p MotionPlan) DirectionAt(streamMillis int64) int
- func (p MotionPlan) PhaseAt(streamMillis int64) float64
- func (p MotionPlan) Retarget(id string, target MotionTarget, settings config.MotionSettings, ...) MotionPlan
- func (p MotionPlan) SampleAt(streamMillis int64) MotionSample
- func (p MotionPlan) VelocityAt(streamMillis int64) float64
- type MotionSample
- type MotionTarget
- type PatternDefinition
- type PatternID
- type ProgramDefinition
- type SoftAnchor
Constants ¶
const ( // RoutineCycleFloorMillis is the hardware-derived minimum stored authoring // cycle. Runtime playback may retime that curve through the shared plan. RoutineCycleFloorMillis int64 = 6600 // PatternKindRoutine identifies a normal repeating pattern. PatternKindRoutine = "routine" // PatternKindBurst identifies a deliberately short shape exempt from the // routine cycle floor. PatternKindBurst = "burst" // MaximumMediaTimelinePoints keeps feature-length funscripts bounded while // leaving normal pattern and program authoring on the smaller content cap. MaximumMediaTimelinePoints = 100_000 // TagExperimental marks catalog content that is fully playable in the // library but exposed to the model only behind the user's // experimental-patterns capability gate. TagExperimental = "experimental" // TagCurated marks user-selected curves promoted into the built-in catalog. TagCurated = "curated" )
const ( // DynamicMotionName is the user-facing content label for model-authored loops. DynamicMotionName = "Creative" // MinimumDynamicSpanPercent prevents narrow model targets from collapsing // into whole-percent device stalls at slow speeds. MinimumDynamicSpanPercent = 20 )
const MinimumPatternReversalProminence = 2.0
MinimumPatternReversalProminence is the smallest adjacent swing treated as an intentional loop reversal. Smaller extrema are positional chatter.
const TargetSourceManualUI = "manual_ui"
TargetSourceManualUI identifies motion explicitly started by the diagnostic manual-test controls. Autonomous modes use their mode identifier as source.
const TargetSourceMedia = "media"
TargetSourceMedia identifies a clock-locked paired-funscript run.
Variables ¶
This section is empty.
Functions ¶
func UsesExactImportedCurve ¶
func UsesExactImportedCurve(definition PatternDefinition) bool
UsesExactImportedCurve marks the explicit allowlist of imported timing that intentionally preserves holds and bypasses generated-pattern fitting. A bulk-imported filename is never sufficient evidence.
Types ¶
type ActiveMotionState ¶
type ActiveMotionState struct {
Running bool `json:"running"`
Starting bool `json:"starting"`
Completing bool `json:"completing"`
Paused bool `json:"paused"`
RunningMillis int64 `json:"running_ms"`
Generation uint64 `json:"generation"`
StreamID string `json:"stream_id,omitempty"`
PlanID string `json:"plan_id,omitempty"`
Target MotionTarget `json:"target"`
Settings config.MotionSettings `json:"settings"`
StartedAt string `json:"started_at,omitempty"`
Phase float64 `json:"phase"`
NextSampleMillis int64 `json:"next_sample_ms"`
RecentCommandLatencyMillis int64 `json:"recent_command_latency_ms"`
CurrentSample *MotionSample `json:"current_sample,omitempty"`
LastSample *MotionSample `json:"last_sample,omitempty"`
LastResult *transport.CommandResult `json:"last_result,omitempty"`
LastError string `json:"last_error,omitempty"`
}
ActiveMotionState is a safe snapshot of the current motion loop. CurrentSample follows the playback clock; LastSample is the accepted transport-buffer tail and may be ahead of playback.
type Curve ¶
type Curve struct {
// contains filtered or unexported fields
}
Curve is a validated time-parameterized sampler. Pattern curves use monotone cubic interpolation; media timelines preserve linear segments.
func NewCurve ¶
func NewCurve(points []CurvePoint, durationMillis int64, loop bool) (Curve, error)
NewCurve validates points and builds PCHIP-style wall-time derivatives. Authoring, preview, and budget measurement use unscaled playback; only the engine plan knows the speed and focus a curve will actually be played at.
func (Curve) Preview ¶
func (c Curve) Preview(intervalMillis int64) []CurvePoint
Preview returns backend-sampled points including the final endpoint.
type CurveMetrics ¶
type CurveMetrics struct {
MaxAccelerationPercentPerSecond2 float64 `json:"max_acceleration_percent_per_second2"`
MinReversalGapMillis int64 `json:"min_reversal_gap_ms"`
}
CurveMetrics exposes generator budget measurements for tests and diagnostics.
func MeasureCurve ¶
func MeasureCurve(points []CurvePoint, durationMillis int64, loop bool) (CurveMetrics, error)
MeasureCurve reports the wall-time acceleration and reversal spacing.
type CurvePoint ¶
type CurvePoint struct {
TimeMillis int64 `json:"time_ms"`
PositionPercent float64 `json:"position_percent"`
}
CurvePoint is one relative 0..100 motion sample at wall-clock time.
func StabilizePatternReversals ¶
func StabilizePatternReversals(points []CurvePoint, minimumProminence float64) []CurvePoint
StabilizePatternReversals removes rapid, insignificant extrema while preserving monotonic detail, endpoints, dwell timing, and slow subtle motion.
type DynamicAnchor ¶
type DynamicAnchor struct {
Name string `json:"name"`
PositionPercent int `json:"position_percent"`
}
DynamicAnchor is one semantic pass-through target in a model-authored loop.
type DynamicDefinition ¶
type DynamicDefinition struct {
CenterPercent int `json:"center_percent"`
SpanPercent int `json:"span_percent"`
Anchors []DynamicAnchor `json:"anchors,omitempty"`
VariationPercent int `json:"variation_percent"`
SegmentSeconds int `json:"segment_seconds"`
}
DynamicDefinition is bounded geometry authored by the LLM and compiled by the backend into ordinary MotionPlan content. It is not a transport payload.
func NormalizeDynamicDefinition ¶
func NormalizeDynamicDefinition(definition DynamicDefinition) DynamicDefinition
NormalizeDynamicDefinition returns concrete, bounded geometry suitable for engine sampling. Named anchors take precedence over center/span geometry.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine owns one active semantic motion loop.
func NewEngine ¶
func NewEngine(options EngineOptions) (*Engine, error)
NewEngine creates a motion engine bound to one transport dispatcher.
func (*Engine) AdmissionGeneration ¶
AdmissionGeneration snapshots the Stop epoch used to reject work admitted before a concurrent Emergency Stop.
func (*Engine) ApplyTarget ¶
func (e *Engine) ApplyTarget(ctx context.Context, target MotionTarget, reason string) (ActiveMotionState, error)
ApplyTarget retargets active motion without stopping the active stream.
func (*Engine) Pause ¶
Pause stops dispatch and the device while freezing the plan phase, so Resume can continue the same pattern where it left off. It is not the safety path: Stop clears everything, Pause deliberately retains state.
func (*Engine) RefreshSettings ¶
func (e *Engine) RefreshSettings(ctx context.Context, settings config.MotionSettings, reason string) (ActiveMotionState, error)
RefreshSettings applies active speed, stroke-window, and direction updates.
func (*Engine) Resume ¶
Resume continues paused motion with the same target and preserved phase on a fresh stream.
func (*Engine) Snapshot ¶
func (e *Engine) Snapshot() ActiveMotionState
Snapshot returns the current active motion state.
func (*Engine) Start ¶
func (e *Engine) Start(ctx context.Context, target MotionTarget, settings config.MotionSettings) (ActiveMotionState, error)
Start begins continuous motion against the configured transport.
func (*Engine) StartAtGeneration ¶
func (e *Engine) StartAtGeneration(ctx context.Context, target MotionTarget, settings config.MotionSettings, admission uint64) (ActiveMotionState, error)
StartAtGeneration starts only when no Stop has occurred since admission.
type EngineOptions ¶
type EngineOptions struct {
Transport transport.Transport
Traces *diagnostics.TraceRing
Now func() time.Time
ChunkSize int
DispatchInterval time.Duration
SampleInterval time.Duration
StreamIDPrefix string
}
EngineOptions configures a motion engine instance.
type MediaTimelineDefinition ¶
type MediaTimelineDefinition struct {
ID string `json:"id"`
Name string `json:"name"`
DurationMillis int64 `json:"duration_ms"`
Points []CurvePoint `json:"points"`
}
MediaTimelineDefinition is finite, clock-locked motion authored against a media file. It is deliberately separate from ProgramDefinition: feature- length funscripts need a larger bound and linear interpolation, and they are never persisted in the pattern library.
func NormalizeMediaTimelineDefinition ¶
func NormalizeMediaTimelineDefinition(definition MediaTimelineDefinition) (MediaTimelineDefinition, error)
NormalizeMediaTimelineDefinition validates a bounded feature-length media curve without applying pattern-library normalization or loop closure.
type MotionPlan ¶
type MotionPlan struct {
ID string `json:"id"`
Target MotionTarget `json:"target"`
PatternID PatternID `json:"pattern_id,omitempty"`
ProgramID string `json:"program_id,omitempty"`
MediaID string `json:"media_id,omitempty"`
PeriodMillis int64 `json:"period_ms"`
HandoffMillis int64 `json:"handoff_ms"`
PhaseOffset float64 `json:"phase_offset"`
PhasePreserved bool `json:"phase_preserved"`
Loop bool `json:"loop"`
CreatedAt string `json:"created_at"`
// contains filtered or unexported fields
}
MotionPlan is repeatable or finite semantic content sampled over stream time.
func NewMotionPlan ¶
func NewMotionPlan( id string, target MotionTarget, settings config.MotionSettings, phaseOffset float64, handoffMillis int64, createdAt time.Time, ) MotionPlan
NewMotionPlan returns a normalized plan for a target.
func (MotionPlan) CompleteAt ¶
func (p MotionPlan) CompleteAt(streamMillis int64) bool
CompleteAt reports whether finite program content reached its final point.
func (MotionPlan) DirectionAt ¶
func (p MotionPlan) DirectionAt(streamMillis int64) int
DirectionAt estimates current semantic travel direction.
func (MotionPlan) PhaseAt ¶
func (p MotionPlan) PhaseAt(streamMillis int64) float64
PhaseAt returns semantic phase at the given stream-relative time.
func (MotionPlan) Retarget ¶
func (p MotionPlan) Retarget( id string, target MotionTarget, settings config.MotionSettings, streamMillis int64, createdAt time.Time, ) MotionPlan
Retarget returns a replacement plan, preserving phase for the same content.
func (MotionPlan) SampleAt ¶
func (p MotionPlan) SampleAt(streamMillis int64) MotionSample
SampleAt samples the plan at the given stream-relative time.
func (MotionPlan) VelocityAt ¶
func (p MotionPlan) VelocityAt(streamMillis int64) float64
VelocityAt estimates played semantic velocity in percent per second. It is used only to choose a smooth retarget phase; transports still receive the normal sampled plan.
type MotionSample ¶
type MotionSample struct {
PlanID string `json:"plan_id"`
PatternID PatternID `json:"pattern_id,omitempty"`
ProgramID string `json:"program_id,omitempty"`
MediaID string `json:"media_id,omitempty"`
PositionPercent float64 `json:"position_percent"`
TimeMillis int64 `json:"time_ms"`
Phase float64 `json:"phase"`
}
MotionSample is one transport-neutral semantic sample.
type MotionTarget ¶
type MotionTarget struct {
Label string `json:"label,omitempty"`
Source string `json:"source,omitempty"`
PatternID PatternID `json:"pattern_id,omitempty"`
PatternName string `json:"pattern_name,omitempty"`
ProgramID string `json:"program_id,omitempty"`
MediaID string `json:"media_id,omitempty"`
SpeedPercent int `json:"speed_percent"`
MediaSpeedLimitEnabled bool `json:"media_speed_limit_enabled,omitempty"`
AreaFocus *AreaFocus `json:"area_focus,omitempty"`
SoftAnchor *SoftAnchor `json:"soft_anchor,omitempty"`
Dynamic *DynamicDefinition `json:"dynamic,omitempty"`
// Resolved content is backend-owned and never serialized to clients. The
// public IDs above remain the authoritative snapshot vocabulary.
Pattern *PatternDefinition `json:"-"`
Program *ProgramDefinition `json:"-"`
Media *MediaTimelineDefinition `json:"-"`
}
MotionTarget is the app-level semantic motion intent.
func NormalizeTarget ¶
func NormalizeTarget(target MotionTarget, settings config.MotionSettings) MotionTarget
NormalizeTarget clamps semantic intent without applying physical stroke settings.
type PatternDefinition ¶
type PatternDefinition struct {
ID PatternID `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Kind string `json:"kind"`
CycleMillis int64 `json:"cycle_ms"`
Points []CurvePoint `json:"points"`
Tags []string `json:"tags,omitempty"`
}
PatternDefinition is reusable loop content. Positions are always relative and are projected into the configured stroke window only by the transport.
func BuiltinPatternDefinition ¶
func BuiltinPatternDefinition(id PatternID) (PatternDefinition, bool)
BuiltinPatternDefinition resolves one generated built-in pattern.
func BuiltinPatternDefinitions ¶
func BuiltinPatternDefinitions() []PatternDefinition
BuiltinPatternDefinitions returns the parametrically generated catalog.
func NormalizePatternDefinition ¶
func NormalizePatternDefinition(definition PatternDefinition) (PatternDefinition, error)
NormalizePatternDefinition validates, closes, and floor-stretches loop data.
func PromotedBuiltinPatternDefinitions ¶
func PromotedBuiltinPatternDefinitions() []PatternDefinition
PromotedBuiltinPatternDefinitions returns defensive copies of user-tested curves promoted into the catalog.
type PatternID ¶
type PatternID string
PatternID identifies a repeatable semantic motion pattern.
const ( // PatternStroke is the default full-stroke triangle pattern. PatternStroke PatternID = "stroke" // PatternPulse is a fixed double-peak pattern. PatternPulse PatternID = "pulse" // PatternTease is a fixed shallow-to-deep pattern. PatternTease PatternID = "tease" // PatternWaves identifies a retired swelling-amplitude pattern. PatternWaves PatternID = "waves" // PatternClimb identifies a retired ratcheting-build pattern. PatternClimb PatternID = "climb" // PatternFlutter is the shallow-flutter-with-sweep pattern. PatternFlutter PatternID = "flutter" // PatternSway identifies a retired asymmetric broad-arc pattern. PatternSway PatternID = "sway" // PatternDrift migrates a consistent stroke window across a cycle. PatternDrift PatternID = "drift" // PatternDoubleTap identifies a retired paired-accent pattern. PatternDoubleTap PatternID = "double-tap" // PatternCascade identifies a retired descending-peak pattern. PatternCascade PatternID = "cascade" // PatternPendulum identifies a retired alternating centered-arc pattern. PatternPendulum PatternID = "pendulum" // PatternCradle identifies the retired restrained centered-arcs pattern. PatternCradle PatternID = "cradle" // PatternSurge identifies a retired decaying-echo pattern. PatternSurge PatternID = "surge" // PatternRolling identifies a retired layered medium-and-deep pattern. PatternRolling PatternID = "rolling" // PatternSyncopate identifies a retired uneven-rhythm pattern. PatternSyncopate PatternID = "syncopate" // PatternFourLevelCircuit cycles full and partial strokes across both zones. PatternFourLevelCircuit PatternID = "four-level-circuit" // PatternHighLowBlocks groups upper and lower zone pulses. PatternHighLowBlocks PatternID = "high-low-blocks" // PatternDeepShallowSequence mixes deep and medium upper-anchored strokes. PatternDeepShallowSequence PatternID = "deep-shallow-sequence" // PatternShortMediumSteps identifies a retired lower-anchored step pattern. PatternShortMediumSteps PatternID = "short-medium-steps" // PatternTopAnchoredDepths identifies a retired upper-return catalog pattern. PatternTopAnchoredDepths PatternID = "top-anchored-depths" // PatternDeepBookends identifies a retired lower-return catalog pattern. PatternDeepBookends PatternID = "deep-bookends" // PatternOneDeepThreeShallow identifies a retired shallow-pulse catalog pattern. PatternOneDeepThreeShallow PatternID = "one-deep-three-shallow" // PatternLowerMidrangeMix identifies a retired lower-midrange catalog pattern. PatternLowerMidrangeMix PatternID = "lower-midrange-mix" // PatternMidTopSwitch identifies a retired upper-pulse catalog pattern. PatternMidTopSwitch PatternID = "mid-top-switch" // PatternSlowFastFull changes from slow full strokes to fast full strokes. PatternSlowFastFull PatternID = "slow-fast-full" // PatternMidrangeFullFinish identifies a retired repeated-midrange pattern. PatternMidrangeFullFinish PatternID = "midrange-full-finish" // PatternDeepPartialSequence mixes full and partial lower-anchored strokes. PatternDeepPartialSequence PatternID = "deep-partial-sequence" // PatternDeepMediumShortPairs identifies a retired paired reach-band pattern. PatternDeepMediumShortPairs PatternID = "deep-medium-short-pairs" // PatternFallingCrest identifies a retired lowering-reversal pattern. PatternFallingCrest PatternID = "falling-crest" // PatternThreeDeepOneShort identifies a retired grouped broad-stroke pattern. PatternThreeDeepOneShort PatternID = "three-deep-one-short" // PatternDescendingLadder identifies a retired stepped-endpoint pattern. PatternDescendingLadder PatternID = "descending-ladder" // PatternWanderingSwell identifies a retired migrating center-and-reach pattern. PatternWanderingSwell PatternID = "wandering-swell" // PatternRisingReach progressively extends alternating upper reversals. PatternRisingReach PatternID = "rising-reach" // PatternHardAndRegular is a promoted user-curated full-range rhythm. PatternHardAndRegular PatternID = "hard-and-regular" // PatternPlayfulJerk is a promoted user-curated staggered full-range rhythm. PatternPlayfulJerk PatternID = "playful-jerk" // PatternEasingDown steps the whole stroke window lower at a held pace. PatternEasingDown PatternID = "easing-down" // PatternBuildingUp steps the whole stroke window higher at a held pace. PatternBuildingUp PatternID = "building-up" // PatternBroadAndTight answers one wide sweep with tight centered strokes. PatternBroadAndTight PatternID = "broad-and-tight" // PatternUpperAccents keeps quick accents in the upper range. PatternUpperAccents PatternID = "upper-accents" // PatternLowerAccents keeps quick accents in the lower range. PatternLowerAccents PatternID = "lower-accents" // PatternSteadyDrift holds one pace while the window wanders. PatternSteadyDrift PatternID = "steady-drift" // PatternOffbeat breaks even strokes with one displaced deeper reach. PatternOffbeat PatternID = "offbeat" // PatternNarrowing converges stroke width toward the center. PatternNarrowing PatternID = "narrowing" // PatternOpeningUp diverges stroke width away from the center. PatternOpeningUp PatternID = "opening-up" // PatternLongReturn pairs a quick reach with an unhurried return. PatternLongReturn PatternID = "long-return" // PatternSwell carries the window up and back across one long arc. PatternSwell PatternID = "swell" // PatternRocking repeats one even mid-range stroke at a fixed pace. PatternRocking PatternID = "rocking" // PatternSurgeAndSettle follows one full sweep with a long settled run. PatternSurgeAndSettle PatternID = "surge-and-settle" // PatternThreeAndOne resolves tight upper strokes with one full plunge. PatternThreeAndOne PatternID = "three-and-one" // PatternCrosscut trades long blocks of broad and tight strokes. PatternCrosscut PatternID = "crosscut" )
func RetiredBuiltinPatternIDs ¶
func RetiredBuiltinPatternIDs() []PatternID
RetiredBuiltinPatternIDs returns catalog IDs removed after physical feedback.
type ProgramDefinition ¶
type ProgramDefinition struct {
ID string `json:"id"`
Name string `json:"name"`
DurationMillis int64 `json:"duration_ms"`
Points []CurvePoint `json:"points"`
}
ProgramDefinition is finite, non-looping motion content.
func NormalizeProgramDefinition ¶
func NormalizeProgramDefinition(definition ProgramDefinition) (ProgramDefinition, error)
NormalizeProgramDefinition validates finite program content without looping it.
type SoftAnchor ¶
type SoftAnchor struct {
PositionPercent int `json:"position_percent"`
WeightPercent int `json:"weight_percent"`
}
SoftAnchor gently biases sampled positions toward one semantic point.