Closed-loop plugin failed to deliver stimulation in the Loop()

27 views
Skip to first unread message

Allen Xie

unread,
Jul 2, 2016, 9:28:19 AM7/2/16
to NeuroRighter Users
Hi NR users,

Currently, we just set up the NR according to the instruction provided in the website. When we try to write the plugins for closed-loop neural network training, we have problems in delivering the stimulation in a real-time manner. 

Experiment condition:
A oscilloscope is connected to the Stim out port of the interface board to capture the stimulation.

Successful experiments:
1. Deliver stimulation using the Mannual Stim panel. We can see the stimulation delivered. Both the waveform and time is right.

2. In the plugin attached in the following context, we put the codes in the Setup() to deliver the stimulation in several fixed time. We can see the stimulation delivered. Both the waveform and time is right.

namespace StimulationTest
{
    public class Test : NRTask
    {
        double[] times = { 20, 25, 27 };
        int[] channels = { 3, 7, 9 };

        protected override void Setup()
        {
            for (int i = 1; i < num; i++)
            {
                double[] waveform = PredefinedWaveform;
                double fs = NRStimSrv.SampleFrequencyHz;
                Console.WriteLine("Stimulation frequency is {0}", fs);
                List<StimulusOutEvent> stimuli = new List<StimulusOutEvent>();
                for (int i = 0; i < times.Length; i++)
                {
                    stimuli.Add(new StimulusOutEvent(channels[i], (ulong)(times[i] * fs), waveform));
                }
                NRStimSrv.StimOut.WriteToBuffer(stimuli);
            }
                Thread.Sleep(20000);
        }

        protected override void Cleanup()
        {
            Console.WriteLine("terminating protocal");
        }
    }
}

Experiment falied to deliver stimulation:
In real experiment, we need to deliver stimulation according to the responses. We wrote codes as attached below using the NRStimSrv.StimOut.GetTime() method in the Loop(). However it failed to delivered stimulation. In the following short code, it should deliver stimulation roughly every 5 s.

namespace ResponsiveElectrodeLocating
{
    class ResponsiveElectrodeLocating : NRTask
    {
        static int ChannelNum = 64;//Total channel number\
        static double Delay = 2;//A time delay to ensure the stimulation is in the future

        protected override void Setup()
        {
            Console.WriteLine("Starting plugin");
        }

        protected override void Loop(object sender, EventArgs e)
        {
            //A delay
            Console.WriteLine("Loop");
            Thread.Sleep(3000);

            if (StimChannelNum < ChannelNum)//Run stimulation from channel 0 to ChannelNum (31 or 63), totally 32 or 64 channels
            {          
                //Writing the stimulation buffer for output stimulation in the near future
                List<StimulusOutEvent> Stimuli = new List<StimulusOutEvent>();
                double[] WaveForm = PredefinedWaveform;
                double CurrentTime = NRStimSrv.StimOut.GetTime();
double StimFreq = NRStimSrv.SampleFrequencyHz;
                ulong StimTime = (ulong) ((CurrentTime / 1000 + Delay) * StimFreq);
                Stimuli.Add(new StimulusOutEvent(StimChannelNum, StimTime, WaveForm));
                NRStimSrv.StimOut.WriteToBuffer(Stimuli);

                Console.WriteLine("Stimulation channel {0} at time {1} using predifined waveform in the UI", StimChannelNum, Time);
            }
            else
            {
                Console.WriteLine("All channels are stimulated. Please click STOP to quit the plugins");
            }

            //Upadte stimulation channel
            StimChannelNum = StimChannelNum + 1;
            //Console.WriteLine("Updating the stimulation channel number to next one");
        }

        protected override void Cleanup()
        {
            Console.WriteLine("Quiting the plugins");
        }
    }
}

Would you please troubleshoot the problem? We will appreciate your kind help! Thank you in advance.


Jon Newman

unread,
Jul 2, 2016, 11:26:27 AM7/2/16
to neurorigh...@googlegroups.com
Hi,

- Is loop() being called? i.e. are you seeing the text from 

Console.WriteLine("Stimulation channel {0} at time {1} using predifined waveform in the UI", StimChannelNum, Time);

being output periodically?

- Can you compare your code to one of the examples on the code respository and see if there are differences. For instance, the code that was used to test the closed loop reaction time of the StimSrv module:



--
You received this message because you are subscribed to the Google Groups "NeuroRighter Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neurorighter-us...@googlegroups.com.
To post to this group, send email to neurorigh...@googlegroups.com.
Visit this group at https://groups.google.com/group/neurorighter-users.
For more options, visit https://groups.google.com/d/optout.



--
Jonathan Newman
Postdoctoral Fellow, MIT

Allen Xie

unread,
Jul 3, 2016, 11:30:04 PM7/3/16
to NeuroRighter Users, jpne...@mit.edu
Hi Jonathan,

- I can be sure that the Loop() is called and I can see the text in the console window periodically.

- I would like to run this code. But I do not know which port should I connect the oscilloscope to. Could you advise?

- If possible, could you somehow send me a working code that can deliver electrical stimulation? So I can compare it with my code and see what went wrong. Thanks

Kai
City University of Hong Kong
To unsubscribe from this group and stop receiving emails from it, send an email to neurorighter-users+unsub...@googlegroups.com.

To post to this group, send email to neurorigh...@googlegroups.com.
Visit this group at https://groups.google.com/group/neurorighter-users.
For more options, visit https://groups.google.com/d/optout.

Riley Zeller-Townson

unread,
Jul 6, 2016, 5:18:00 PM7/6/16
to neurorigh...@googlegroups.com
Does the console text that you  see when you run your plugin indicate that 'StimChannelNum' is being incremented properly?  I don't see where it is being initialized, which could be causing issues.
The link that John sent you should work as a working example, but the first plugin you wrote is also a great starting point. 
For the oscope, just use whatever oscope configuration  you used to validate your first plugin.

To unsubscribe from this group and stop receiving emails from it, send an email to neurorighter-us...@googlegroups.com.
To post to this group, send email to neurorigh...@googlegroups.com.
Visit this group at https://groups.google.com/group/neurorighter-users.
For more options, visit https://groups.google.com/d/optout.



--
Jonathan Newman
Postdoctoral Fellow, MIT

--
You received this message because you are subscribed to the Google Groups "NeuroRighter Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neurorighter-us...@googlegroups.com.

To post to this group, send email to neurorigh...@googlegroups.com.
Visit this group at https://groups.google.com/group/neurorighter-users.
For more options, visit https://groups.google.com/d/optout.



--
Riley Zeller-Townson
PhD student, Butera lab
Laboratory for Neuroengineering
Georgia Tech/Emory University
Atlanta, GA, USA
Message has been deleted

Allen Xie

unread,
Jul 7, 2016, 11:14:00 AM7/7/16
to NeuroRighter Users
Hi Riley,

Thanks for your reply.

- For your reading convenience, I simplified my code and accidentally deleted the initializing code before. Before running my plugin, I ran the impedance test and the signals from the "Manual Stim" can be seen in the oscope. That means the stimulation should function properly, I guess. Then I ran the code in the attachment again in NR and the console text is shown here. Sadly, I still can not get stimulation signals in the oscope.



- Forgot to say one thing. Every time I open the NR and click the start button (lower right corner) for the first time, a warning jumps out as shown in the following figure. If click quit, the NR quits. If click continue, the NR shows no responses. Afterwards, when click the stop (lower right corner) to stop reading data and click the start again, data starts to show in the Spikes window. The warning detail is in the attachment. Did you have the same problem?


Kai
Dr. Shi Peng's Group
Error details.txt
ResponsiveElectrodeLocating.cs
Reply all
Reply to author
Forward
0 new messages