From 1daf2597996461274279910a3a2597168de0e5c9 Mon Sep 17 00:00:00 2001 From: RoboDoig Date: Thu, 31 Oct 2024 13:25:18 +0100 Subject: [PATCH 1/4] Update direct pulses workflow to log data --- src/Workflows/DirectPulsesTest.bonsai | 13 +++++++ src/Workflows/DirectPulsesTest.bonsai.layout | 36 ++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/Workflows/DirectPulsesTest.bonsai b/src/Workflows/DirectPulsesTest.bonsai index 352dda2..96e8405 100644 --- a/src/Workflows/DirectPulsesTest.bonsai +++ b/src/Workflows/DirectPulsesTest.bonsai @@ -235,6 +235,18 @@ H2Commands + + D:\EncoderTest + 1 + + + H2 Events + + + HarpData + H2 Events + + @@ -242,6 +254,7 @@ + \ No newline at end of file diff --git a/src/Workflows/DirectPulsesTest.bonsai.layout b/src/Workflows/DirectPulsesTest.bonsai.layout index d431e41..3e43a0d 100644 --- a/src/Workflows/DirectPulsesTest.bonsai.layout +++ b/src/Workflows/DirectPulsesTest.bonsai.layout @@ -102,4 +102,40 @@ Normal + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + \ No newline at end of file From 88ce1eeb314aeedcc30a23518bdf94f33b6f8d9e Mon Sep 17 00:00:00 2001 From: RoboDoig Date: Thu, 31 Oct 2024 13:33:48 +0100 Subject: [PATCH 2/4] Revert from debug motion mode --- src/Workflows/MainExperiment/Main.bonsai | 70 ++++++++++++------------ 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/src/Workflows/MainExperiment/Main.bonsai b/src/Workflows/MainExperiment/Main.bonsai index f894c09..203efe4 100644 --- a/src/Workflows/MainExperiment/Main.bonsai +++ b/src/Workflows/MainExperiment/Main.bonsai @@ -4275,19 +4275,49 @@ + + FlowSensor1 + + + X + + + Y + + + + + + new ( + it.Item1 as X, + it.Item2 as Y +) + + + MovementDelta + - - FlowSensor1 + + - - X + + Convert.ToInt16(it) - - Y + + + 25 + + + + + + + 25 + @@ -4308,34 +4338,6 @@ MovementDelta - - - - - Convert.ToInt16(it) - - - - 25 - - - - - 25 - - - - - - - new ( - it.Item1 as X, - it.Item2 as Y -) - - - MovementDelta - From a0a7bfadc42d730eb8661052053f9f496f4b7757 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 31 Oct 2024 16:04:52 +0000 Subject: [PATCH 3/4] Add motion smoothing parameter to schema --- src/DataSchema.Generated.cs | 1077 +++++++++++++++++ .../Extensions/DataSchema.Generated.cs | 21 + src/schema.json | 6 + 3 files changed, 1104 insertions(+) create mode 100644 src/DataSchema.Generated.cs diff --git a/src/DataSchema.Generated.cs b/src/DataSchema.Generated.cs new file mode 100644 index 0000000..f096102 --- /dev/null +++ b/src/DataSchema.Generated.cs @@ -0,0 +1,1077 @@ +//---------------------- +// +// Generated using the NJsonSchema v10.9.0.0 (Newtonsoft.Json v9.0.0.0) (http://NJsonSchema.org) +// +//---------------------- + + +namespace DataSchema +{ + #pragma warning disable // Disable all warnings + + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] + public partial class Block + { + + private string _alias = "unnamed"; + + private StimulusProtocol _stimulus; + + private double _totalRuntime = 120D; + + private double _runThreshold = 100D; + + private double _decayTimestep = 0.1D; + + private double _runThresholdDecay = -1D; + + private double _haltProbability = 0D; + + private HaltProtocol _haltProtocol; + + private int _flowSmoothing = 1; + + private double _flowXToRunGain = 0D; + + private double _flowYToRunGain = 0D; + + private double _playbackToRunGain = 0D; + + private double _flowXToVisualGain = 0D; + + private double _flowYToVisualGain = 0D; + + private double _flowXToMotorGain = 0D; + + private double _flowYToMotorGain = 0D; + + private double _rotaryToVisualGain = 0D; + + private double _playbackToVisualGain = 0D; + + private double _playbackToMotorGain = 0D; + + private double _blockGainModifier = 1D; + + private double _initialVisualMovementDelta = 1D; + + private double _initialMotorMovementDelta = 1D; + + private string _playbackFilePath = ""; + + /// + /// The user-defined name of this block. + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="alias")] + [System.ComponentModel.DescriptionAttribute("The user-defined name of this block.")] + public string Alias + { + get + { + return _alias; + } + set + { + _alias = value; + } + } + + /// + /// The visual stimulus to use + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="stimulus")] + [System.ComponentModel.DescriptionAttribute("The visual stimulus to use")] + public StimulusProtocol Stimulus + { + get + { + return _stimulus; + } + set + { + _stimulus = value; + } + } + + /// + /// How long (in seconds) this block should run for + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="totalRuntime")] + [System.ComponentModel.DescriptionAttribute("How long (in seconds) this block should run for")] + public double TotalRuntime + { + get + { + return _totalRuntime; + } + set + { + _totalRuntime = value; + } + } + + /// + /// The value (in position units) to reach before a halt decision is applied + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="runThreshold")] + [System.ComponentModel.DescriptionAttribute("The value (in position units) to reach before a halt decision is applied")] + public double RunThreshold + { + get + { + return _runThreshold; + } + set + { + _runThreshold = value; + } + } + + /// + /// On each timestep (in seconds) the runThresholdDecay is applied + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="decayTimestep")] + [System.ComponentModel.DescriptionAttribute("On each timestep (in seconds) the runThresholdDecay is applied")] + public double DecayTimestep + { + get + { + return _decayTimestep; + } + set + { + _decayTimestep = value; + } + } + + /// + /// Distance to threshold is decayed by this amount (in position units) per decayTimestep + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="runThresholdDecay")] + [System.ComponentModel.DescriptionAttribute("Distance to threshold is decayed by this amount (in position units) per decayTime" + + "step")] + public double RunThresholdDecay + { + get + { + return _runThresholdDecay; + } + set + { + _runThresholdDecay = value; + } + } + + /// + /// The probability that a halt decision is made after a running threshold has been reached + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="haltProbability")] + [System.ComponentModel.DescriptionAttribute("The probability that a halt decision is made after a running threshold has been r" + + "eached")] + public double HaltProbability + { + get + { + return _haltProbability; + } + set + { + _haltProbability = value; + } + } + + /// + /// The halt protocol to use on a positive halt decision + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="haltProtocol")] + [System.ComponentModel.DescriptionAttribute("The halt protocol to use on a positive halt decision")] + public HaltProtocol HaltProtocol + { + get + { + return _haltProtocol; + } + set + { + _haltProtocol = value; + } + } + + /// + /// Size of the buffer used to produce rolling average of flow values. Minimum 1 = no smoothing, n>1 = rolling average of n values + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowSmoothing")] + [System.ComponentModel.DescriptionAttribute("Size of the buffer used to produce rolling average of flow values. Minimum 1 = no" + + " smoothing, n>1 = rolling average of n values")] + public int FlowSmoothing + { + get + { + return _flowSmoothing; + } + set + { + _flowSmoothing = value; + } + } + + /// + /// flow --> run distance traveled gain (X dimension) + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowXToRunGain")] + [System.ComponentModel.DescriptionAttribute("flow --> run distance traveled gain (X dimension)")] + public double FlowXToRunGain + { + get + { + return _flowXToRunGain; + } + set + { + _flowXToRunGain = value; + } + } + + /// + /// flow --> run distance traveled gain (Y dimension) + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowYToRunGain")] + [System.ComponentModel.DescriptionAttribute("flow --> run distance traveled gain (Y dimension)")] + public double FlowYToRunGain + { + get + { + return _flowYToRunGain; + } + set + { + _flowYToRunGain = value; + } + } + + /// + /// playback --> run distance traveled gain + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="playbackToRunGain")] + [System.ComponentModel.DescriptionAttribute("playback --> run distance traveled gain")] + public double PlaybackToRunGain + { + get + { + return _playbackToRunGain; + } + set + { + _playbackToRunGain = value; + } + } + + /// + /// flow --> visual stimulus motion gain (X dimension) + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowXToVisualGain")] + [System.ComponentModel.DescriptionAttribute("flow --> visual stimulus motion gain (X dimension)")] + public double FlowXToVisualGain + { + get + { + return _flowXToVisualGain; + } + set + { + _flowXToVisualGain = value; + } + } + + /// + /// flow --> visual stimulus motion gain (Y dimension) + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowYToVisualGain")] + [System.ComponentModel.DescriptionAttribute("flow --> visual stimulus motion gain (Y dimension)")] + public double FlowYToVisualGain + { + get + { + return _flowYToVisualGain; + } + set + { + _flowYToVisualGain = value; + } + } + + /// + /// flow --> motor motion gain (X dimension) + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowXToMotorGain")] + [System.ComponentModel.DescriptionAttribute("flow --> motor motion gain (X dimension)")] + public double FlowXToMotorGain + { + get + { + return _flowXToMotorGain; + } + set + { + _flowXToMotorGain = value; + } + } + + /// + /// flow --> motor motion gain (Y dimension) + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowYToMotorGain")] + [System.ComponentModel.DescriptionAttribute("flow --> motor motion gain (Y dimension)")] + public double FlowYToMotorGain + { + get + { + return _flowYToMotorGain; + } + set + { + _flowYToMotorGain = value; + } + } + + /// + /// rotary --> visual stimulus motion gain + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="rotaryToVisualGain")] + [System.ComponentModel.DescriptionAttribute("rotary --> visual stimulus motion gain")] + public double RotaryToVisualGain + { + get + { + return _rotaryToVisualGain; + } + set + { + _rotaryToVisualGain = value; + } + } + + /// + /// playback source --> visual stimulus motion gain + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="playbackToVisualGain")] + [System.ComponentModel.DescriptionAttribute("playback source --> visual stimulus motion gain")] + public double PlaybackToVisualGain + { + get + { + return _playbackToVisualGain; + } + set + { + _playbackToVisualGain = value; + } + } + + /// + /// playback source --> motor motion gain + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="playbackToMotorGain")] + [System.ComponentModel.DescriptionAttribute("playback source --> motor motion gain")] + public double PlaybackToMotorGain + { + get + { + return _playbackToMotorGain; + } + set + { + _playbackToMotorGain = value; + } + } + + /// + /// Block specific gain coefficient to apply + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="blockGainModifier")] + [System.ComponentModel.DescriptionAttribute("Block specific gain coefficient to apply")] + public double BlockGainModifier + { + get + { + return _blockGainModifier; + } + set + { + _blockGainModifier = value; + } + } + + /// + /// Global visual gain to apply when a block's closed-loop period begins. Can be updated during halt period. + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="initialVisualMovementDelta")] + [System.ComponentModel.DescriptionAttribute("Global visual gain to apply when a block\'s closed-loop period begins. Can be upda" + + "ted during halt period.")] + public double InitialVisualMovementDelta + { + get + { + return _initialVisualMovementDelta; + } + set + { + _initialVisualMovementDelta = value; + } + } + + /// + /// Global motor gain to apply when a block's closed-loop period begins. Can be updated during halt period. + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="initialMotorMovementDelta")] + [System.ComponentModel.DescriptionAttribute("Global motor gain to apply when a block\'s closed-loop period begins. Can be updat" + + "ed during halt period.")] + public double InitialMotorMovementDelta + { + get + { + return _initialMotorMovementDelta; + } + set + { + _initialMotorMovementDelta = value; + } + } + + /// + /// Path to the playback file to be used in this block + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="playbackFilePath")] + [System.ComponentModel.DescriptionAttribute("Path to the playback file to be used in this block")] + public string PlaybackFilePath + { + get + { + return _playbackFilePath; + } + set + { + _playbackFilePath = value; + } + } + + public System.IObservable Process() + { + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return( + new Block + { + Alias = _alias, + Stimulus = _stimulus, + TotalRuntime = _totalRuntime, + RunThreshold = _runThreshold, + DecayTimestep = _decayTimestep, + RunThresholdDecay = _runThresholdDecay, + HaltProbability = _haltProbability, + HaltProtocol = _haltProtocol, + FlowSmoothing = _flowSmoothing, + FlowXToRunGain = _flowXToRunGain, + FlowYToRunGain = _flowYToRunGain, + PlaybackToRunGain = _playbackToRunGain, + FlowXToVisualGain = _flowXToVisualGain, + FlowYToVisualGain = _flowYToVisualGain, + FlowXToMotorGain = _flowXToMotorGain, + FlowYToMotorGain = _flowYToMotorGain, + RotaryToVisualGain = _rotaryToVisualGain, + PlaybackToVisualGain = _playbackToVisualGain, + PlaybackToMotorGain = _playbackToMotorGain, + BlockGainModifier = _blockGainModifier, + InitialVisualMovementDelta = _initialVisualMovementDelta, + InitialMotorMovementDelta = _initialMotorMovementDelta, + PlaybackFilePath = _playbackFilePath + })); + } + } + + + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] + public partial class StimulusProtocol + { + + private StimulusProtocolType _type = DataSchema.StimulusProtocolType.Grating; + + private double _spatialFrequency = 0.1D; + + private string _textureName = ""; + + private double _offset1 = -90D; + + private double _extent1 = 180D; + + private double _offset2 = 90D; + + private double _extent2 = 180D; + + /// + /// The type and parameters of the visual stimulus to use + /// + [System.Xml.Serialization.XmlIgnoreAttribute()] + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="type")] + [System.ComponentModel.DescriptionAttribute("The type and parameters of the visual stimulus to use")] + public StimulusProtocolType Type + { + get + { + return _type; + } + set + { + _type = value; + } + } + + /// + /// Spatial frequency for stimuli where this is a parameter + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="spatialFrequency")] + [System.ComponentModel.DescriptionAttribute("Spatial frequency for stimuli where this is a parameter")] + public double SpatialFrequency + { + get + { + return _spatialFrequency; + } + set + { + _spatialFrequency = value; + } + } + + /// + /// Name of texture resource to load if required + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="textureName")] + [System.ComponentModel.DescriptionAttribute("Name of texture resource to load if required")] + public string TextureName + { + get + { + return _textureName; + } + set + { + _textureName = value; + } + } + + /// + /// Offset (in degrees) for primary visual stimulus + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="offset1")] + [System.ComponentModel.DescriptionAttribute("Offset (in degrees) for primary visual stimulus")] + public double Offset1 + { + get + { + return _offset1; + } + set + { + _offset1 = value; + } + } + + /// + /// X screen extent (in degrees) for primary visual stimulus + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="extent1")] + [System.ComponentModel.DescriptionAttribute("X screen extent (in degrees) for primary visual stimulus")] + public double Extent1 + { + get + { + return _extent1; + } + set + { + _extent1 = value; + } + } + + /// + /// Offset (in degrees) for secondary visual stimulus + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="offset2")] + [System.ComponentModel.DescriptionAttribute("Offset (in degrees) for secondary visual stimulus")] + public double Offset2 + { + get + { + return _offset2; + } + set + { + _offset2 = value; + } + } + + /// + /// X screen extent (in degrees) for secondary visual stimulus + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="extent2")] + [System.ComponentModel.DescriptionAttribute("X screen extent (in degrees) for secondary visual stimulus")] + public double Extent2 + { + get + { + return _extent2; + } + set + { + _extent2 = value; + } + } + + public System.IObservable Process() + { + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return( + new StimulusProtocol + { + Type = _type, + SpatialFrequency = _spatialFrequency, + TextureName = _textureName, + Offset1 = _offset1, + Extent1 = _extent1, + Offset2 = _offset2, + Extent2 = _extent2 + })); + } + } + + + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] + public partial class HaltProtocol + { + + private double _minumumDelay = 0.1D; + + private double _randomDelay = 0.5D; + + private double _haltTime = 2D; + + private double _haltGain = 0D; + + private double _haltMotorGain = 1D; + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="minumumDelay")] + public double MinumumDelay + { + get + { + return _minumumDelay; + } + set + { + _minumumDelay = value; + } + } + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="randomDelay")] + public double RandomDelay + { + get + { + return _randomDelay; + } + set + { + _randomDelay = value; + } + } + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="haltTime")] + public double HaltTime + { + get + { + return _haltTime; + } + set + { + _haltTime = value; + } + } + + /// + /// Gain applied to visual closed-loop during halt + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="haltGain")] + [System.ComponentModel.DescriptionAttribute("Gain applied to visual closed-loop during halt")] + public double HaltGain + { + get + { + return _haltGain; + } + set + { + _haltGain = value; + } + } + + /// + /// Gain applied to motor closed-loop during halt + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="haltMotorGain")] + [System.ComponentModel.DescriptionAttribute("Gain applied to motor closed-loop during halt")] + public double HaltMotorGain + { + get + { + return _haltMotorGain; + } + set + { + _haltMotorGain = value; + } + } + + public System.IObservable Process() + { + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return( + new HaltProtocol + { + MinumumDelay = _minumumDelay, + RandomDelay = _randomDelay, + HaltTime = _haltTime, + HaltGain = _haltGain, + HaltMotorGain = _haltMotorGain + })); + } + } + + + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] + public partial class VestibularVrSession + { + + private Metadata _metadata; + + private System.Collections.Generic.List _blocks = new System.Collections.Generic.List(); + + private MotorSettings _motorSettings; + + [System.Xml.Serialization.XmlIgnoreAttribute()] + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="metadata")] + public Metadata Metadata + { + get + { + return _metadata; + } + set + { + _metadata = value; + } + } + + [System.Xml.Serialization.XmlIgnoreAttribute()] + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="blocks")] + public System.Collections.Generic.List Blocks + { + get + { + return _blocks; + } + set + { + _blocks = value; + } + } + + [System.Xml.Serialization.XmlIgnoreAttribute()] + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="motorSettings")] + public MotorSettings MotorSettings + { + get + { + return _motorSettings; + } + set + { + _motorSettings = value; + } + } + + public System.IObservable Process() + { + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return( + new VestibularVrSession + { + Metadata = _metadata, + Blocks = _blocks, + MotorSettings = _motorSettings + })); + } + } + + + public enum StimulusProtocolType + { + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="grating")] + Grating = 0, + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="texture")] + Texture = 1, + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="cloud")] + Cloud = 2, + } + + + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] + public partial class Metadata + { + + private string _animalId = ""; + + private string _rootPath = ""; + + private double _runGain = 1D; + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="animalId")] + public string AnimalId + { + get + { + return _animalId; + } + set + { + _animalId = value; + } + } + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="rootPath")] + public string RootPath + { + get + { + return _rootPath; + } + set + { + _rootPath = value; + } + } + + /// + /// Coefficient applied to movement delta (e.g. from flow sensor) to calculate running speed in visual environment. + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="runGain")] + [System.ComponentModel.DescriptionAttribute("Coefficient applied to movement delta (e.g. from flow sensor) to calculate runnin" + + "g speed in visual environment.")] + public double RunGain + { + get + { + return _runGain; + } + set + { + _runGain = value; + } + } + + public System.IObservable Process() + { + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return( + new Metadata + { + AnimalId = _animalId, + RootPath = _rootPath, + RunGain = _runGain + })); + } + } + + + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Source)] + public partial class MotorSettings + { + + private int _nominalPulseInterval = 200; + + private int _initialPulseInterval = 200; + + private int _pulseStepInterval = 2; + + private int _pulsePeriod = 10; + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="nominalPulseInterval")] + public int NominalPulseInterval + { + get + { + return _nominalPulseInterval; + } + set + { + _nominalPulseInterval = value; + } + } + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="initialPulseInterval")] + public int InitialPulseInterval + { + get + { + return _initialPulseInterval; + } + set + { + _initialPulseInterval = value; + } + } + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="pulseStepInterval")] + public int PulseStepInterval + { + get + { + return _pulseStepInterval; + } + set + { + _pulseStepInterval = value; + } + } + + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="pulsePeriod")] + public int PulsePeriod + { + get + { + return _pulsePeriod; + } + set + { + _pulsePeriod = value; + } + } + + public System.IObservable Process() + { + return System.Reactive.Linq.Observable.Defer(() => System.Reactive.Linq.Observable.Return( + new MotorSettings + { + NominalPulseInterval = _nominalPulseInterval, + InitialPulseInterval = _initialPulseInterval, + PulseStepInterval = _pulseStepInterval, + PulsePeriod = _pulsePeriod + })); + } + } + + + /// + /// Serializes a sequence of data model objects into YAML strings. + /// + [Bonsai.CombinatorAttribute()] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Transform)] + [System.ComponentModel.DescriptionAttribute("Serializes a sequence of data model objects into YAML strings.")] + public partial class SerializeToYaml + { + + private System.IObservable Process(System.IObservable source) + { + return System.Reactive.Linq.Observable.Defer(() => + { + var serializer = new YamlDotNet.Serialization.SerializerBuilder().Build(); + return System.Reactive.Linq.Observable.Select(source, value => serializer.Serialize(value)); + }); + } + + public System.IObservable Process(System.IObservable source) + { + return Process(source); + } + + public System.IObservable Process(System.IObservable source) + { + return Process(source); + } + + public System.IObservable Process(System.IObservable source) + { + return Process(source); + } + + public System.IObservable Process(System.IObservable source) + { + return Process(source); + } + + public System.IObservable Process(System.IObservable source) + { + return Process(source); + } + + public System.IObservable Process(System.IObservable source) + { + return Process(source); + } + } + + + /// + /// Deserializes a sequence of YAML strings into data model objects. + /// + [System.ComponentModel.DefaultPropertyAttribute("Type")] + [Bonsai.WorkflowElementCategoryAttribute(Bonsai.ElementCategory.Transform)] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.Xml.Serialization.XmlIncludeAttribute(typeof(Bonsai.Expressions.TypeMapping))] + [System.ComponentModel.DescriptionAttribute("Deserializes a sequence of YAML strings into data model objects.")] + public partial class DeserializeFromYaml : Bonsai.Expressions.SingleArgumentExpressionBuilder + { + + public DeserializeFromYaml() + { + Type = new Bonsai.Expressions.TypeMapping(); + } + + public Bonsai.Expressions.TypeMapping Type { get; set; } + + public override System.Linq.Expressions.Expression Build(System.Collections.Generic.IEnumerable arguments) + { + var typeMapping = (Bonsai.Expressions.TypeMapping)Type; + var returnType = typeMapping.GetType().GetGenericArguments()[0]; + return System.Linq.Expressions.Expression.Call( + typeof(DeserializeFromYaml), + "Process", + new System.Type[] { returnType }, + System.Linq.Enumerable.Single(arguments)); + } + + private static System.IObservable Process(System.IObservable source) + { + return System.Reactive.Linq.Observable.Defer(() => + { + var serializer = new YamlDotNet.Serialization.DeserializerBuilder().Build(); + return System.Reactive.Linq.Observable.Select(source, value => + { + var reader = new System.IO.StringReader(value); + var parser = new YamlDotNet.Core.MergingParser(new YamlDotNet.Core.Parser(reader)); + return serializer.Deserialize(parser); + }); + }); + } + } +} \ No newline at end of file diff --git a/src/Workflows/MainExperiment/Extensions/DataSchema.Generated.cs b/src/Workflows/MainExperiment/Extensions/DataSchema.Generated.cs index 5da84be..f096102 100644 --- a/src/Workflows/MainExperiment/Extensions/DataSchema.Generated.cs +++ b/src/Workflows/MainExperiment/Extensions/DataSchema.Generated.cs @@ -30,6 +30,8 @@ public partial class Block private HaltProtocol _haltProtocol; + private int _flowSmoothing = 1; + private double _flowXToRunGain = 0D; private double _flowYToRunGain = 0D; @@ -198,6 +200,24 @@ public HaltProtocol HaltProtocol } } + /// + /// Size of the buffer used to produce rolling average of flow values. Minimum 1 = no smoothing, n>1 = rolling average of n values + /// + [YamlDotNet.Serialization.YamlMemberAttribute(Alias="flowSmoothing")] + [System.ComponentModel.DescriptionAttribute("Size of the buffer used to produce rolling average of flow values. Minimum 1 = no" + + " smoothing, n>1 = rolling average of n values")] + public int FlowSmoothing + { + get + { + return _flowSmoothing; + } + set + { + _flowSmoothing = value; + } + } + /// /// flow --> run distance traveled gain (X dimension) /// @@ -451,6 +471,7 @@ public System.IObservable Process() RunThresholdDecay = _runThresholdDecay, HaltProbability = _haltProbability, HaltProtocol = _haltProtocol, + FlowSmoothing = _flowSmoothing, FlowXToRunGain = _flowXToRunGain, FlowYToRunGain = _flowYToRunGain, PlaybackToRunGain = _playbackToRunGain, diff --git a/src/schema.json b/src/schema.json index 850d75a..b47fdd8 100644 --- a/src/schema.json +++ b/src/schema.json @@ -42,6 +42,12 @@ "$ref": "#/definitions/haltProtocol", "description": "The halt protocol to use on a positive halt decision" }, + "flowSmoothing": { + "default": 1, + "description": "Size of the buffer used to produce rolling average of flow values. Minimum 1 = no smoothing, n>1 = rolling average of n values", + "type": "integer", + "minimum": 1 + }, "flowXToRunGain": { "default": 0, "description": "flow --> run distance traveled gain (X dimension)", From aea8131624ca0c1d3779fd1839c06eb122a87601 Mon Sep 17 00:00:00 2001 From: RoboDoig Date: Thu, 31 Oct 2024 17:14:39 +0100 Subject: [PATCH 4/4] Implement flow smoothing in main workflow --- src/Workflows/MainExperiment/Main.bonsai | 113 +- .../MainExperiment/Main.bonsai.layout | 1844 ++++++++++++++++- 2 files changed, 1944 insertions(+), 13 deletions(-) diff --git a/src/Workflows/MainExperiment/Main.bonsai b/src/Workflows/MainExperiment/Main.bonsai index 203efe4..10acaeb 100644 --- a/src/Workflows/MainExperiment/Main.bonsai +++ b/src/Workflows/MainExperiment/Main.bonsai @@ -14,8 +14,8 @@ xmlns:scr="clr-namespace:Bonsai.Scripting.Expressions;assembly=Bonsai.Scripting.Expressions" xmlns:vh2="clr-namespace:Harp.VestibularH2;assembly=Harp.VestibularH2" xmlns:harp="clr-namespace:Bonsai.Harp;assembly=Bonsai.Harp" - xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System" xmlns:dsp="clr-namespace:Bonsai.Dsp;assembly=Bonsai.Dsp" + xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System" xmlns:vh1="clr-namespace:Harp.VestibularH1;assembly=Harp.VestibularH1" xmlns:onix1="clr-namespace:OpenEphys.Onix1;assembly=OpenEphys.Onix1" xmlns:p4="clr-namespace:System.Reactive;assembly=System.Reactive.Core" @@ -1399,6 +1399,95 @@ + + SmoothMovementDelta + + + + MovementDelta + + + X + + + Block + + + FlowSmoothing + + + + + + + + + 1 + 1 + + + + + + + Val0 + + + Y + + + + + + + + + 1 + 1 + + + + + + + Val0 + + + + + + new ( + it.Item1 as X, + it.Item2 as Y +) + + + SmoothedMovementDelta + + + + + + + + + + + + + + + + + + + + + + + + + BlockGain @@ -1468,7 +1557,7 @@ RightPhaseProcession - MovementDelta + SmoothedMovementDelta X @@ -1484,7 +1573,7 @@ - MovementDelta + SmoothedMovementDelta Y @@ -1619,7 +1708,7 @@ MotorProcession - MovementDelta + SmoothedMovementDelta X @@ -2799,11 +2888,10 @@ - - + - + @@ -2812,19 +2900,20 @@ - + - - - + + + - + + diff --git a/src/Workflows/MainExperiment/Main.bonsai.layout b/src/Workflows/MainExperiment/Main.bonsai.layout index 50d6b32..be5d51a 100644 --- a/src/Workflows/MainExperiment/Main.bonsai.layout +++ b/src/Workflows/MainExperiment/Main.bonsai.layout @@ -1066,7 +1066,7 @@ Normal - false + true 562 151 @@ -1077,6 +1077,1848 @@ Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + true + + 3 + 3 + + + 1104 + 706 + + Normal + + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + true + + 3 + 3 + + + 1104 + 706 + + Normal + + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + + false + + 0 + 0 + + + 0 + 0 + + Normal + + false