Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions readme.md

This file was deleted.

4 changes: 2 additions & 2 deletions src/BasicContextList.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public UdpClient getComm() {
* ?
*/
public void sendCreateMessages() {
// comm may be null for certian subclasses of ContextList which to not
// comm may be null for certain subclasses of ContextList which to not
// need to talk to the behavior arduino
if (comm != null) {
context_info.setString("action", "create");
Expand All @@ -242,7 +242,7 @@ public void sendCreateMessages() {
int valve_pin = valves.getInt(i);
JSONObject valve_json;

// frequency causes this singal to oscillate in order to play a
// frequency causes this signal to oscillate in order to play a
// tone
if (!context_info.isNull("frequency")) {
valve_json = TreadmillController.setup_valve_json(valve_pin,
Expand Down
14 changes: 10 additions & 4 deletions src/FileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class WriterThread extends Thread {
* Placeholder
*/
public void run() {
messageBuffer = writeQueue.poll();
messageBuffer = writeQueue.peek();
while (this.run || messageBuffer != null) {
if (messageBuffer != null) {
try {
Expand All @@ -173,11 +173,17 @@ public void run() {
alert += ("\n" + elements[i].toString());
}
if (tl != null) {
tl.exception(alert);
//tl.exception(alert);
tl.alert("FileWriter: Error logging message:\n"
+ messageBuffer);
try {
Thread.sleep(25);
} catch (InterruptedException ie) {}
}
break;
}
messageBuffer = writeQueue.poll();
writeQueue.poll();
messageBuffer = writeQueue.peek();
}

try {
Expand All @@ -194,7 +200,7 @@ public void run() {
Thread.sleep(25);
} catch (InterruptedException e) {}

messageBuffer = writeQueue.poll();
messageBuffer = writeQueue.peek();
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/TimedITIContextDecorator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class TimedITIContextDecorator extends SuspendableContextDecorator {
/**
* ?
*/
protected int iti_time_min;
protected float iti_time_min;

/**
* ?
*/
protected int iti_time_max;
protected float iti_time_max;

/**
* ?
Expand Down Expand Up @@ -73,6 +73,7 @@ public TimedITIContextDecorator(TreadmillController tc,
this.random_iti = context_info.getBoolean("random_iti", false);

if (this.random_iti) {
this.random = new Random();
this.iti_time_min = context_info.getInt("iti_time_min");
this.iti_time_max = context_info.getInt("iti_time_max");
} else {
Expand Down Expand Up @@ -134,8 +135,8 @@ public boolean check_suspend(float position, float time, int lap, int lick_count
if (this.long_delay_laps.contains(this.start_lap)) {
this.next_start = time + this.long_delay;
} else if (this.random_iti) {
this.next_start = time + random.nextInt(
(this.iti_time_max - this.iti_time_min + 1)) + this.iti_time_min;
this.next_start = time + this.random.nextFloat() *
(this.iti_time_max - this.iti_time_min) + this.iti_time_min;
} else {
this.next_start = time + this.iti_time;
}
Expand Down
52 changes: 40 additions & 12 deletions src/TreadmillController.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public class TreadmillController extends PApplet {
*/
ArrayList<UdpClient> comms;

// List to store behavior comms that haven't confirmed creation. Used to verify
// system is ready to start an experiment
ArrayList<String> unset_contexts;

/**
* Time (ms) of the last comms check
*/
Expand Down Expand Up @@ -502,6 +506,10 @@ public boolean Start(String mouse_name, String experiment_group) {

testComms();

if (unset_contexts.size() > 0) {
trialListener.alert("Failed to create Contexts\n" + String.join(", ", unset_contexts));
}

trialListener.started(fWriter.getFile());

timer.startTimer();
Expand Down Expand Up @@ -922,6 +930,9 @@ void configure_rewards() throws Exception {
if (context.getString("id").equals(reward_context)) {
JSONArray valve_list = context.getJSONArray("valves");
reward_valve = valve_list.getInt(0);
if (context.getString("type").equals("operant")) {
lickport_pin = context.getInt("sensor");
}
return;
}
}
Expand All @@ -939,6 +950,10 @@ void configure_rewards() throws Exception {
reward_info.setJSONArray("valves", context_valves);
}

if (!reward_info.isNull("sensor")) {
lickport_pin = reward_info.getInt("sensor");
}

if (!reward_info.isNull("drop_size")) {
JSONArray context_duration = new JSONArray();
context_duration.append(reward_info.getInt("drop_size"));
Expand Down Expand Up @@ -1011,6 +1026,7 @@ void reload_settings(String filename, String tag) throws Exception {
*/
void startComms() throws Exception {
comms = new ArrayList<UdpClient>();
unset_contexts = new ArrayList<String>();
position_comm = null;
behavior_comm = null;
reset_comm = null;
Expand Down Expand Up @@ -1178,10 +1194,11 @@ void reconfigureExperiment() throws Exception {
}

if (!settings_json.isNull("contexts")) {
unset_contexts.clear();
delay(10);
VrContextList2 vr_context = null;
ArrayList<VrCueContextList3> cue_lists =
new ArrayList<VrCueContextList3>();
//VrContextList2 vr_context = null;
//ArrayList<VrCueContextList3> cue_lists =
// new ArrayList<VrCueContextList3>();

JSONArray contexts_array = settings_json.getJSONArray("contexts");
for (int i = 0; i < contexts_array.size(); i++) {
Expand All @@ -1199,6 +1216,10 @@ void reconfigureExperiment() throws Exception {
" failed to connect to comm");
}
display.setContextLocations(context_list);

if ((behavior_comm != null) && (context_list.getComm() == behavior_comm)) {
unset_contexts.add(context_list.getId());
}
}

for (ContextList context : this.contexts) {
Expand Down Expand Up @@ -1670,10 +1691,19 @@ protected void updateBehavior(float time) {
String action = sensorJson.getString("action", "stop");
if (action.equals("start")) {
display.setSensorState(sensor_pin, 1);
sensor_counts.put(sensor_pin,
sensor_counts.get(sensor_pin) + 1);
if (sensor_counts.containsKey(sensor_pin)) {
sensor_counts.put(sensor_pin,
sensor_counts.get(sensor_pin) + 1);
}
if (sensor_pin == lickport_pin) {
display.addLick(started);
lick_count++;
}
} else if (action.equals("stop")) {
display.setSensorState(sensor_pin, -1);
if (sensor_pin == lickport_pin) {
display.lickStop();
}
} else if (action.equals("created")) {
sensor_counts.put(sensor_pin, 0);
display.setSensorState(sensor_pin, -1);
Expand Down Expand Up @@ -1712,17 +1742,15 @@ protected void updateBehavior(float time) {
if (!context_json.isNull("id")) {
String context_id = context_json.getString("id");
if (!context_json.isNull("action")) {
String action = context_json.getString("action");
for (int j=0; j < contexts.size(); j++) {
if (contexts.get(j).getId().equals(context_id)) {
if (context_json.getString("action").equals(
"start")) {

if (action.equals("start")) {
contexts.get(j).setStatus("started");
} else if (
context_json.getString("action").equals(
"stop")) {

} else if (action.equals("stop")) {
contexts.get(j).setStatus("stopped");
} else if (action.equals("created")) {
unset_contexts.remove(context_id);
}

break;
Expand Down
Loading