Skip to content

Commit

Permalink
Several minor improvements
Browse files Browse the repository at this point in the history
- V4 BNO axis map and axis sign now match ONIX standard
- Improve IndexConverter to filter for devices named
  MINISCOPE in index dropdown
- Update example workflows with new library namespace and to use
  OpenEphys.Commutators package
  • Loading branch information
jonnew committed Oct 22, 2024
1 parent 3d423aa commit dd5436a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 152 deletions.
8 changes: 4 additions & 4 deletions ExamplesWorkflows/UclaMiniCam.bonsai
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:OpenEphys.Bonsai.Miniscope;assembly=OpenEphys.Bonsai.Miniscope"
xmlns:p1="clr-namespace:OpenEphys.Miniscope;assembly=OpenEphys.Miniscope"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System"
xmlns:cv="clr-namespace:Bonsai.Vision;assembly=Bonsai.Vision"
Expand All @@ -10,8 +10,8 @@
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:UclaMiniCam">
<p1:Index>2</p1:Index>
<p1:LedBrightness>10</p1:LedBrightness>
<p1:Index>0</p1:Index>
<p1:LedBrightness>0</p1:LedBrightness>
<p1:SensorGain>Low</p1:SensorGain>
<p1:FramesPerSecond>Fps50</p1:FramesPerSecond>
</Combinator>
Expand Down
8 changes: 4 additions & 4 deletions ExamplesWorkflows/UclaMiniCamTriggered.bonsai
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:OpenEphys.Bonsai.Miniscope;assembly=OpenEphys.Bonsai.Miniscope"
xmlns:p1="clr-namespace:OpenEphys.Miniscope;assembly=OpenEphys.Miniscope"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System"
xmlns:cv="clr-namespace:Bonsai.Vision;assembly=Bonsai.Vision"
Expand All @@ -10,8 +10,8 @@
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:UclaMiniCam">
<p1:Index>2</p1:Index>
<p1:LedBrightness>10</p1:LedBrightness>
<p1:Index>0</p1:Index>
<p1:LedBrightness>0</p1:LedBrightness>
<p1:SensorGain>Low</p1:SensorGain>
<p1:FramesPerSecond>Fps50</p1:FramesPerSecond>
</Combinator>
Expand Down
2 changes: 1 addition & 1 deletion ExamplesWorkflows/UclaMiniscopeV4.bonsai
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:OpenEphys.Miniscope;assembly=OpenEphys.Miniscope"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
Expand Down
147 changes: 14 additions & 133 deletions ExamplesWorkflows/UclaMiniscopeV4Commutated.bonsai
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:OpenEphys.Bonsai.Miniscope;assembly=OpenEphys.Bonsai.Miniscope"
xmlns:p1="clr-namespace:OpenEphys.Miniscope;assembly=OpenEphys.Miniscope"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System"
xmlns:cv="clr-namespace:Bonsai.Vision;assembly=Bonsai.Vision"
xmlns:wie="clr-namespace:Bonsai.Windows.Input;assembly=Bonsai.Windows.Input"
xmlns:ipy="clr-namespace:Bonsai.Scripting.IronPython;assembly=Bonsai.Scripting.IronPython"
xmlns="https://bonsai-rx.org/2018/workflow">
<Workflow>
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:UclaMiniscopeV4">
<p1:Index>1</p1:Index>
<p1:Index>0</p1:Index>
<p1:LedBrightness>0</p1:LedBrightness>
<p1:Focus>0</p1:Focus>
<p1:SensorGain>Medium</p1:SensorGain>
<p1:FramesPerSecond>Fps15</p1:FramesPerSecond>
<p1:SensorGain>Low</p1:SensorGain>
<p1:FramesPerSecond>Fps30</p1:FramesPerSecond>
<p1:LedRespectsTrigger>false</p1:LedRespectsTrigger>
</Combinator>
</Expression>
Expand Down Expand Up @@ -56,130 +54,14 @@
<Expression xsi:type="MemberSelector">
<Selector>Quaternion</Selector>
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="PortName" DisplayName="Commutator Port" />
</Expression>
<Expression xsi:type="GroupWorkflow">
<Name>Commutator</Name>
<Description>Drives ONIX Commutator from BNO055 Quaterion data. Pressing down/up keys will manually turn the commutator, overrding the BNO055 heading input.
</Description>
<Workflow>
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="wie:KeyDown">
<wie:Filter>Up</wie:Filter>
<wie:SuppressRepetitions>false</wie:SuppressRepetitions>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="StringProperty">
<Value>"{turn : 0.1}"</Value>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="wie:KeyDown">
<wie:Filter>Down</wie:Filter>
<wie:SuppressRepetitions>false</wie:SuppressRepetitions>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="StringProperty">
<Value>"{turn : -0.1}"</Value>
</Combinator>
</Expression>
<Expression xsi:type="WorkflowInput">
<Name>Source1</Name>
</Expression>
<Expression xsi:type="ipy:PythonTransform">
<ipy:Name>Heading</ipy:Name>
<ipy:Script>from math import atan2
@returns(float)
def process(value):

siny_cosp = 2 * (value.W * value.Z + value.x * value.y);
cosy_cosp = 1 - 2 * (value.y * value.y + value.z * value.z);

return atan2(siny_cosp, cosy_cosp)</ipy:Script>
</Expression>
<Expression xsi:type="io:CsvWriter">
<io:FileName>heading_.csv</io:FileName>
<io:Append>false</io:Append>
<io:Overwrite>false</io:Overwrite>
<io:Suffix>Timestamp</io:Suffix>
<io:IncludeHeader>false</io:IncludeHeader>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Timer">
<rx:DueTime>PT0S</rx:DueTime>
<rx:Period>PT0.1S</rx:Period>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Sample" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Skip">
<rx:Count>1</rx:Count>
</Combinator>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Zip" />
</Expression>
<Expression xsi:type="ipy:PythonTransform">
<ipy:Script>from math import pi

@returns(str)
def process(value):


last = value.Item2

curr = value.Item1
a1 = curr + 2 * pi
a2 = curr - 2 * pi
pos = [curr, a1, a2]

delta = [abs(x - last) for x in pos]

p = pos[delta.index(min(delta))]

turn = (p - last) / (2 * pi)

return "{turn : %s}" % turn</ipy:Script>
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="rx:Merge" />
</Expression>
<Expression xsi:type="ExternalizedMapping">
<Property Name="PortName" />
</Expression>
<Expression xsi:type="Combinator">
<Combinator xsi:type="io:SerialStringWrite">
<io:PortName>COM3</io:PortName>
<io:NewLine>\r\n</io:NewLine>
</Combinator>
</Expression>
<Expression xsi:type="WorkflowOutput" />
</Nodes>
<Edges>
<Edge From="0" To="1" Label="Source1" />
<Edge From="1" To="12" Label="Source1" />
<Edge From="2" To="3" Label="Source1" />
<Edge From="3" To="12" Label="Source2" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="5" To="6" Label="Source1" />
<Edge From="6" To="8" Label="Source1" />
<Edge From="7" To="8" Label="Source2" />
<Edge From="8" To="9" Label="Source1" />
<Edge From="8" To="10" Label="Source1" />
<Edge From="9" To="10" Label="Source2" />
<Edge From="10" To="11" Label="Source1" />
<Edge From="11" To="12" Label="Source3" />
<Edge From="12" To="14" Label="Source1" />
<Edge From="13" To="14" Label="Source2" />
<Edge From="14" To="15" Label="Source1" />
</Edges>
</Workflow>
<Expression xsi:type="IncludeWorkflow" Path="OpenEphys.Commutator:AutoCommutator.bonsai">
<RotationAxis>
<X>0</X>
<Y>0</Y>
<Z>1</Z>
</RotationAxis>
<LedEnable>true</LedEnable>
<PortName>COM3</PortName>
</Expression>
</Nodes>
<Edges>
Expand All @@ -189,8 +71,7 @@ def process(value):
<Edge From="1" To="2" Label="Source1" />
<Edge From="2" To="3" Label="Source1" />
<Edge From="4" To="5" Label="Source1" />
<Edge From="6" To="8" Label="Source1" />
<Edge From="7" To="8" Label="Source2" />
<Edge From="6" To="7" Label="Source1" />
</Edges>
</Workflow>
</WorkflowBuilder>
10 changes: 5 additions & 5 deletions ExamplesWorkflows/UclaMiniscopeV4Triggered.bonsai
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<WorkflowBuilder Version="2.8.1"
<WorkflowBuilder Version="2.8.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p1="clr-namespace:OpenEphys.Bonsai.Miniscope;assembly=OpenEphys.Bonsai.Miniscope"
xmlns:p1="clr-namespace:OpenEphys.Miniscope;assembly=OpenEphys.Miniscope"
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
xmlns:io="clr-namespace:Bonsai.IO;assembly=Bonsai.System"
xmlns:cv="clr-namespace:Bonsai.Vision;assembly=Bonsai.Vision"
Expand All @@ -10,11 +10,11 @@
<Nodes>
<Expression xsi:type="Combinator">
<Combinator xsi:type="p1:UclaMiniscopeV4">
<p1:Index>1</p1:Index>
<p1:Index>0</p1:Index>
<p1:LedBrightness>0</p1:LedBrightness>
<p1:Focus>0</p1:Focus>
<p1:SensorGain>Medium</p1:SensorGain>
<p1:FramesPerSecond>Fps15</p1:FramesPerSecond>
<p1:SensorGain>Low</p1:SensorGain>
<p1:FramesPerSecond>Fps30</p1:FramesPerSecond>
<p1:LedRespectsTrigger>false</p1:LedRespectsTrigger>
</Combinator>
</Expression>
Expand Down
21 changes: 17 additions & 4 deletions OpenEphys.Miniscope/IndexConverter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System;
using AForge.Video.DirectShow;

class IndexConverter : Int32Converter
Expand All @@ -17,12 +17,25 @@ public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo c
return base.ConvertFrom(context, culture, value);
}

FilterInfoCollection GetMiniscopes()
{
var deviceFilters = new FilterInfoCollection(FilterCategory.VideoInputDevice);
for (int i = deviceFilters.Count - 1; i >= 0; i--)
{
if (!deviceFilters[i].Name.Contains("MINISCOPE"))
deviceFilters.RemoveAt(i);
}

return deviceFilters;
}


public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
var index = (int)value;
var deviceFilters = new FilterInfoCollection(FilterCategory.VideoInputDevice);
var deviceFilters = GetMiniscopes();
if (index >= 0 && index < deviceFilters.Count)
{
return string.Format(culture, "{0} ({1})", index, deviceFilters[index].Name);
Expand All @@ -43,7 +56,7 @@ public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)

public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
var deviceFilters = new FilterInfoCollection(FilterCategory.VideoInputDevice);
var deviceFilters = GetMiniscopes();
return new StandardValuesCollection(Enumerable.Range(0, deviceFilters.Count).ToArray());
}
}
2 changes: 1 addition & 1 deletion OpenEphys.Miniscope/UclaMiniscopeV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public UclaMiniscopeV4()
Helpers.SendConfig(capture, Helpers.CreateCommand(176, 30, 10));
Helpers.SendConfig(capture, Helpers.CreateCommand(192, 8, 32, 238, 160, 80));
Helpers.SendConfig(capture, Helpers.CreateCommand(192, 16, 32, 238, 88, 80));
Helpers.SendConfig(capture, Helpers.CreateCommand(80, 65, 9, 5)); // BNO Axis mapping and sign
Helpers.SendConfig(capture, Helpers.CreateCommand(80, 65, 6, 7)); // BNO Axis mapping and sign
Helpers.SendConfig(capture, Helpers.CreateCommand(80, 61, 12)); // BNO operation mode is NDOF
Helpers.SendConfig(capture, Helpers.CreateCommand(254, 0)); // 0x7F
Helpers.SendConfig(capture, Helpers.CreateCommand(238, 3, 3)); // 0x77
Expand Down

0 comments on commit dd5436a

Please sign in to comment.