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

Add HS64 electrical stim and trigger nodes #66

Merged
merged 4 commits into from
Apr 3, 2024
Merged

Add HS64 electrical stim and trigger nodes #66

merged 4 commits into from
Apr 3, 2024

Conversation

glopesdev
Copy link
Collaborator

@glopesdev glopesdev commented Mar 31, 2024

This PR adds support for the HS64 electrical stimulator device. Currently the trigger node is non-functional since the ENABLE register will be set back to zero on reset. Approaches to resolve this are currently being discussed in #58 and may be incorporated here before merging.

Fixes #27
Fixes #58

@glopesdev glopesdev added the feature New planned feature label Mar 31, 2024
@glopesdev glopesdev added this to the 0.1.0 milestone Mar 31, 2024
@glopesdev glopesdev requested review from jonnew and aacuevas March 31, 2024 20:42
@jonnew
Copy link
Member

jonnew commented Apr 1, 2024

As we were discussing in discord, and related to my comments on #67, I think we probably need to make ConfigureFmcLinkController pure virtual. Then the entire headstage finding procedure needs to be impemented by the implementing class. For instance, for the time being, I changed SetPortVoltage to the following:

protected virtual bool FindPortVoltage(DeviceContext device)

With this, implementers are responsible for their own port voltage tuning algorithm and defining what a successful connection means (return value). For instance, in ConfigureHeadstage64, I created the following custom port tuning algorithm which seems to work as well as the last one but is reasonably fast so that it can potentially be used in the field. But of course, this is very specific to this headstage and I think that's going to be a common issue.

protected override bool FindPortVoltage(DeviceContext device)
            {
                // TODO: It takes a huge amount of time to get to 0, almost 10 seconds.
                // The best we can do at the moment is drive port voltage to minimum which
                // is an active process and then settle from there to zero volts.

                var minVoltage = (uint)(MinVoltage * 10);
                var maxVoltage = (uint)(MaxVoltage * 10);
                var voltageOffset = (uint)(VoltageOffset * 10);
                var voltageIncrement = (uint)(VoltageIncrement * 10);

                // Start with highest voltage
                device.WriteRegister(FmcLinkController.PORTVOLTAGE, maxVoltage);
                Thread.Sleep(200);
                if (!CheckLinkState(device)) return false;

                // Ramp it down to find lowest lock voltage
                uint voltage;
                for (voltage = maxVoltage; voltage > minVoltage && CheckLinkState(device); voltage -= voltageIncrement)
                {
                    device.WriteRegister(FmcLinkController.PORTVOLTAGE, voltage);
                    Thread.Sleep(200);
                }

                device.WriteRegister(FmcLinkController.PORTVOLTAGE, 33);
                device.WriteRegister(FmcLinkController.PORTVOLTAGE, 0);
                Thread.Sleep(1000);
                device.WriteRegister(FmcLinkController.PORTVOLTAGE, voltage + voltageOffset);
                Thread.Sleep(200);
                return CheckLinkState(device);

            }

@jonnew
Copy link
Member

jonnew commented Apr 3, 2024

This works well and was tested on hardware without issue. Feel free to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New planned feature
Projects
None yet
2 participants