Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure ManipulatorPosition is set in a thread-safe context #318

Merged
merged 1 commit into from
Nov 19, 2024
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
5 changes: 3 additions & 2 deletions src/Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFramework>net48</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bonsai.Core" Version="2.8.4" />
<PackageReference Include="Bonsai.Core" Version="2.8.5" />
<PackageReference Include="OpenCV.Net" Version="3.4.2" />
<PackageReference Include="YamlDotNet" Version="12.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Bonsai.Harp" Version="3.5.0" />
<PackageReference Include="MathNet.Numerics" Version="4.15.0" />
<PackageReference Include="Harp.Olfactometer" Version="0.1.0-build231127" />
<PackageReference Include="AllenNeuralDynamics.AindManipulator" Version="0.1.6" />
</ItemGroup>
</Project>
27 changes: 27 additions & 0 deletions src/Extensions/ModifyManipulatorPosition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Bonsai;
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using AllenNeuralDynamics.AindManipulator;

[Combinator]
[Description("Modifies a single axis of the ManipulatorPosition object given a specified value.")]
[WorkflowElementCategory(ElementCategory.Transform)]
public class ModifyManipulatorPosition
{
public Axis Axis { get; set; }
public IObservable<ManipulatorPosition> Process(IObservable<Tuple<ManipulatorPosition, double>> source)
{
return source.Select(value => {
var newPosition = new ManipulatorPosition(){
X = value.Item1.X,
Y1 = value.Item1.Y1,
Y2 = value.Item1.Y2,
Z = value.Item1.Z
};
newPosition[Axis] = value.Item2;
return newPosition;
});
}
}
27 changes: 15 additions & 12 deletions src/vr-foraging.bonsai
Original file line number Diff line number Diff line change
Expand Up @@ -3513,18 +3513,21 @@ Item3 as Right)</scr:Expression>
<Expression xsi:type="MemberSelector">
<Selector>RetractingDistance</Selector>
</Expression>
<Expression xsi:type="SubscribeSubject">
<Name>SpoutAxis</Name>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="scr:ExpressionSink">
<scr:Name>Assign</scr:Name>
<scr:Expression>Item1[Item3] = Item2</scr:Expression>
<Expression xsi:type="SubscribeSubject">
<Name>SpoutAxis</Name>
</Expression>
<Expression xsi:type="MemberSelector">
<Selector>Item1</Selector>
<Expression xsi:type="PropertyMapping">
<PropertyMappings>
<Property Name="Axis" />
</PropertyMappings>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p16:ModifyManipulatorPosition">
<p16:Axis>None</p16:Axis>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
Expand All @@ -3546,13 +3549,13 @@ Item3 as Right)</scr:Expression>
<Edge From="7" To="18" Label="Source1" />
<Edge From="8" To="9" Label="Source1" />
<Edge From="9" To="10" Label="Source1" />
<Edge From="10" To="15" Label="Source1" />
<Edge From="10" To="14" Label="Source1" />
<Edge From="11" To="12" Label="Source1" />
<Edge From="12" To="13" Label="Source1" />
<Edge From="13" To="15" Label="Source2" />
<Edge From="14" To="15" Label="Source3" />
<Edge From="13" To="14" Label="Source2" />
<Edge From="14" To="17" Label="Source1" />
<Edge From="15" To="16" Label="Source1" />
<Edge From="16" To="17" Label="Source1" />
<Edge From="16" To="17" Label="Source2" />
<Edge From="17" To="18" Label="Source2" />
<Edge From="18" To="19" Label="Source1" />
<Edge From="19" To="20" Label="Source1" />
Expand Down