-
Notifications
You must be signed in to change notification settings - Fork 0
/
ia-activate.cpp
188 lines (157 loc) · 5.24 KB
/
ia-activate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
Copyright (C) 2011 Georgia Institute of Technology
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A mARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Generates square pulse current commands.
*/
#include <ia-activate.h>
extern "C" Plugin::Object *createRTXIPlugin(void) {
return new IAact();
}
static DefaultGUIModel::variable_t vars[] =
{
{ "Vin", "", DefaultGUIModel::INPUT, },
{ "Output_To_OTA", "", DefaultGUIModel::OUTPUT, },
{ "Period (s)", "Duration of one cycle", DefaultGUIModel::PARAMETER
| DefaultGUIModel::DOUBLE, },
{ "Delay (s)", "Time until step starts from beginning of cycle",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE, },
{ "Current Range Start (pA)", "Starting current of the steps",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE, },
{ "Current Range End (pA)", "Ending current of the steps", DefaultGUIModel::PARAMETER
| DefaultGUIModel::DOUBLE, },
{ "Increments", "How many steps to take between min and max",
DefaultGUIModel::PARAMETER | DefaultGUIModel::UINTEGER, },
{ "Cycles (#)", "How many times to repeat the protocol",
DefaultGUIModel::PARAMETER | DefaultGUIModel::UINTEGER, },
{ "Duty Cycle (%)", "On time of the step during a single cycle",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE, },
{ "Max Amplitude (pA)", "Value of the maximum amplitude",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE, },
{ "Depolarization Time (s)", "Time current is at depolarized value",
DefaultGUIModel::PARAMETER | DefaultGUIModel::DOUBLE, },
{ "Offset (mA)", "DC offset to add", DefaultGUIModel::PARAMETER
| DefaultGUIModel::DOUBLE, },
};
static size_t num_vars = sizeof(vars) / sizeof(DefaultGUIModel::variable_t);
IAact::IAact(void) : DefaultGUIModel("IA Activation", ::vars, ::num_vars), dt(RT::System::getInstance()->getPeriod() * 1e-6), period(1.0), delay(0.0), rStart(0), rEnd(-210.0), Nsteps(8), Ncycles(1), duty(15), maxAmp(15.0), depolTime(1.0), offset(0.0) {
setWhatsThis("<p><b>I-Step:</b><br>This module generates a series of currents in a designated range followed by a fixed maximum current.</p>");
createGUI(vars, num_vars);
update(INIT);
refresh();
resizeMe();
}
IAact::~IAact(void) {}
void IAact::execute(void) {
V = input(0);
Iout = offset;
if (cycle < Ncycles) {
//Do all time keeping in seconds.
if (step < Nsteps) {
if (age >= delay && age < delay + period * (duty / 100) - EPS) {
Iout = Iout + rStart - step * deltaI;
age += dt / 1000;
}
else if(interage<depolTime) {
Iout = maxAmp;
interage += dt / 1000;
}
else{
age += dt/1000;
}
if (age >= (period - EPS)) {
step++;
interage = 0;
age = 0;
}
}
if (step == Nsteps) {
cycle++;
step = 0;
}
}
Output_to_mV = Iout * .5e-3;
output(0) = Output_to_mV;
}
void IAact::update(DefaultGUIModel::update_flags_t flag) {
switch (flag) {
case INIT:
setParameter("Period (s)", period);
setParameter("Delay (s)", delay);
setParameter("Current Range Start (pA)", rStart);
setParameter("Current Range End (pA)", rEnd);
setParameter("Increments", Nsteps);
setParameter("Cycles (#)", Ncycles);
setParameter("Duty Cycle (%)", duty);
setParameter("Max Amplitude (pA)", maxAmp);
setParameter("Depolarization Time (s)", depolTime);
setParameter("Offset (mA)", offset);
break;
case MODIFY:
period = getParameter("Period (s)").toDouble();
delay = getParameter("Delay (s)").toDouble();
rStart = getParameter("Current Range Start (pA)").toDouble();
rEnd = getParameter("Current Range End (pA)").toDouble();
Nsteps = getParameter("Increments").toInt();
Ncycles = getParameter("Cycles (#)").toInt();
duty = getParameter("Duty Cycle (%)").toDouble();
maxAmp = getParameter("Max Amplitude (pA)").toDouble();
depolTime = getParameter("Depolarization Time (s)").toDouble();
offset = getParameter("Offset (mA)").toDouble();
break;
case PAUSE:
output(0) = 0;
case PERIOD:
dt = RT::System::getInstance()->getPeriod() * 1e-6;
default:
break;
}
// Some Error Checking for fun
if (period <= 0) {
period = 1;
setParameter("Period (sec)", period);
}
if (rStart < rEnd) {
rStart = rEnd;
setParameter("Min Amp (mA)", rEnd);
setParameter("Max Amp (mA)", rStart);
}
if (Ncycles < 1) {
Ncycles = 1;
setParameter("Cycles (#)", Ncycles);
}
if (Nsteps < 0) {
Nsteps = 0;
setParameter("Increments", Nsteps);
}
if (duty < 0 || duty > 100) {
duty = 0;
setParameter("Duty Cycle (%)", duty);
}
if (delay <= 0 || delay > period * duty / 100) {
delay = 0;
setParameter("Delay (sec)", delay);
}
//Define deltaI based on mArams
if (Nsteps > 1) {
deltaI = (rStart - rEnd) / (Nsteps - 1);
}
else {
deltaI = 0;
}
//Initialize counters
age = 0;
step = 0;
cycle = 0;
interage = 0;
}