Skip to content

Commit

Permalink
Complete UCLA miniscope V4 support
Browse files Browse the repository at this point in the history
- Tested on OEPS miniscope V4.4
- To finalize this, we must test on a large batch of scopesto ensure
functionality of all features and reliablity of datastream
  • Loading branch information
jonnew committed Aug 30, 2024
1 parent 550ae0c commit dc4cf82
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 128 deletions.
7 changes: 4 additions & 3 deletions OpenEphys.Onix1/Bno055DataFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace OpenEphys.Onix1
{
/// <summary>
/// A class that contains 3D orientation data produced by a Bosch BNO055 9-axis inertial measurement unit (IMU).
/// A class that contains 3D orientation data produced by a Bosch BNO055 9-axis inertial measurement unit
/// (IMU).
/// </summary>
public class Bno055DataFrame : DataFrame
{
Expand Down Expand Up @@ -51,14 +52,14 @@ internal unsafe Bno055DataFrame(ulong clock, Bno055DataPayload* payload)
/// <summary>
/// Gets the 3D orientation in Euler angle format with units of degrees.
/// </summary>
/// <remark>
/// <remarks>
/// The Tait-Bryan formalism is used:
/// <list type="bullet">
/// <item><description>Yaw: 0 to 360 degrees.</description></item>
/// <item><description>Roll: -180 to 180 degrees</description></item>
/// <item><description>Pitch: -90 to 90 degrees</description></item>
/// </list>
/// </remark>
/// </remarks>
public Vector3 EulerAngle { get; }

/// <summary>
Expand Down
52 changes: 50 additions & 2 deletions OpenEphys.Onix1/ConfigureUclaMiniscopeV4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,56 @@

namespace OpenEphys.Onix1
{
/// <summary>
/// Configures a UCLA Miniscope V4 on the specified port.
/// </summary>
/// <remarks>
/// The UCLA Miniscope V4 is a e miniaturized fluorescent microscope for performing single-photon calcium
/// imaging in freely moving animals. It has the following features:
/// <list type="bullet">
/// <item><description>A Python-480 0.48 Megapixel CMOS image sensor.</description></item>
/// <item><description>A BNO055 9-axis IMU for real-time, 3D orientation tracking.</description></item>
/// <item><description>An electrowetting lens for remote focal plane adjustment.</description></item>
/// <item><description>An excitation LED with adjustable brightness control and optional exposure-driven
/// interleaving to reduce photobleaching.</description></item>
/// </list>
/// </remarks>
public class ConfigureUclaMiniscopeV4 : MultiDeviceFactory
{
PortName port;
readonly ConfigureUclaMiniscopeV4PortController PortControl = new();

/// <summary>
/// Initialize a new instance of a <see cref="ConfigureUclaMiniscopeV4"/> class.
/// </summary>
public ConfigureUclaMiniscopeV4()
{
Port = PortName.PortA;
PortControl.HubConfiguration = HubConfiguration.Passthrough;
}

/// <summary>
/// Gets or sets the Miniscope camera configuration.
/// </summary>
[Category(DevicesCategory)]
[TypeConverter(typeof(SingleDeviceFactoryConverter))]
public ConfigureUclaMiniscopeV4Camera Camera { get; set; } = new();

/// <summary>
/// Gets or sets the Bno055 9-axis inertial measurement unit configuration.
/// </summary>
[Category(DevicesCategory)]
[TypeConverter(typeof(SingleDeviceFactoryConverter))]
public ConfigureUclaMiniscopeV4Bno055 Bno055 { get; set; } = new();

/// <summary>
/// Gets or sets the port.
/// </summary>
/// <remarks>
/// The port is the physical connection to the ONIX breakout board and must be specified prior to operation.
/// </remarks>
[Description("Specifies the physical connection of the miniscope to the ONIX breakout board.")]
[Category(ConfigurationCategory)]
public PortName Port
{
get { return port; }
Expand All @@ -36,9 +67,26 @@ public PortName Port
}
}

/// <summary>
/// Gets or sets the port voltage override.
/// </summary>
/// <remarks>
/// <para>
/// If defined, it will override automated voltage discovery and apply the specified voltage to the miniscope.
/// If left blank, an automated headstage detection algorithm will attempt to communicate with the miniscope and
/// apply an appropriate voltage for stable operation. Because ONIX allows any coaxial tether to be used, some of
/// which are thin enough to result in a significant voltage drop, its may be required to manually specify the
/// port voltage.
/// </para>
/// <para>
/// Warning: this device requires 5.0V to 6.0V, measured at the miniscope, for proper operation. Supplying higher
/// voltages may result in damage.
/// </para>
/// </remarks>
[Description("If defined, it will override automated voltage discovery and apply the specified voltage" +
"to the headstage. Warning: this device requires 5.0V to 6.0V for proper operation." +
"Supplying higher voltages may result in damage to the headstage.")]
"to the miniscope. Warning: this device requires 5.0V to 6.0V for proper operation." +
"Supplying higher voltages may result in damage to the miniscope.")]
[Category(ConfigurationCategory)]
public double? PortVoltage
{
get => PortControl.PortVoltage;
Expand Down
37 changes: 36 additions & 1 deletion OpenEphys.Onix1/ConfigureUclaMiniscopeV4Bno055.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,41 @@

namespace OpenEphys.Onix1
{
/// <summary>
/// Configures the Bno055 inertial measurement unit (IMU) on a UCLA Miniscope V4.
/// </summary>
public class ConfigureUclaMiniscopeV4Bno055 : SingleDeviceFactory
{
/// <summary>
/// Initialize a new instance of a <see cref="ConfigureUclaMiniscopeV4Bno055"/> class.
/// </summary>
public ConfigureUclaMiniscopeV4Bno055()
: base(typeof(UclaMiniscopeV4Bno055))
{
}

/// <summary>
/// Gets or sets the device enable state.
/// </summary>
/// <remarks>
/// If set to true, <see cref="UclaMiniscopeV4Bno055Data"/> will produce data. If set to false,
/// <see cref="UclaMiniscopeV4Bno055Data"/> will not produce data.
/// </remarks>
[Category(ConfigurationCategory)]
[Description("Specifies whether the BNO055 device is enabled.")]
public bool Enable { get; set; } = true;

/// <summary>
/// Configures the Bno055 inertial measurement unit (IMU) on a UCLA Miniscope V4.
/// </summary>
/// <remarks>
/// This will schedule configuration actions to be applied by a <see cref="StartAcquisition"/> node
/// prior to data acquisition.
/// </remarks>
/// <param name="source">A sequence of <see cref="ContextTask"/> instances that holds all configuration actions.</param>
/// <returns>
/// The original sequence but with each <see cref="ContextTask"/> instance now containing configuration actions required to use the miniscope's Bno055 IMU.
/// </returns>
public override IObservable<ContextTask> Process(IObservable<ContextTask> source)
{
var enable = Enable;
Expand All @@ -25,7 +49,7 @@ public override IObservable<ContextTask> Process(IObservable<ContextTask> source
var device = context.GetPassthroughDeviceContext(deviceAddress, typeof(DS90UB9x));
ConfigureDeserializer(device);
ConfigureBno055(device);
var deviceInfo = new DeviceInfo(context, DeviceType, deviceAddress);
var deviceInfo = new UclaMiniscopeV4Bno055DeviceInfo(context, DeviceType, deviceAddress, enable);
return DeviceManager.RegisterDevice(deviceName, deviceInfo);
});
}
Expand Down Expand Up @@ -66,4 +90,15 @@ public NameConverter()
}
}
}

class UclaMiniscopeV4Bno055DeviceInfo : DeviceInfo
{
public UclaMiniscopeV4Bno055DeviceInfo(ContextTask context, Type deviceType, uint deviceAddress, bool enable)
: base(context, deviceType, deviceAddress)
{
Enable = enable;
}

public bool Enable { get; }
}
}
Loading

0 comments on commit dc4cf82

Please sign in to comment.