Hey Chris,
We are encountering somewhat rare, but critical, bugs in our Mworks code.
Background:
We use pin 12 on an Arduino device connected via Firmata bluetooth to drive a fluid delivery circuit. When it is high, the circuit runs a DC current through a pump that delivers fluid continuously. When it is low, no current flows through the pump, and it is inactive.
The bug:
While the task is running, every once in a while, the pump dispenses water continuously for an extended length of time. It then stops at some point.
Observations:
- The bug has been observed to start while the subject is doing trials.
- Stopping the experiment and performing a reload of the .mwel immediately ceases the bug.
- The bug has occurred across 3 different circuits in 3 different rigs.
- So, it seems unlikely it is due to a hardware bug.
My speculations on source of bug:
I think this has to do with the Firmata interface.
We request that pin 12 is set to high through a variable assignment (see code below). My guess is that the first assignment (pump_control_line = true) succeeds, but the second assignment and third assignment both fail.
The monkey then stops working, as the water is flowing continuously. If the monkey happens to do another trial, one of the pump_control_line = false assignments eventually succeeds, and correct code behavior resumes. My guess is this bug could happen more frequently than we have observed because of this.
This seems related to another behavior we have previously observed (and I have brought up with you earlier at some point, I think), which is that setting cur_reward_duration_ms to values around ~25 msec causes the juicer to sporadically fail to dispense juice, which can be explained by a failure of setting pin12 to high pump_control_line = true (as it is overrided by pump_control_line = false).
In our case, it’s really important that we can verify that the juicer circuit is engaged as requested. One proposal is to rewrite the Arduino interface + the firmware running on the Arduino itself, so we have the ability to send encoded pin commands (e.g., set pin 12 to high for 50 ms, then turn off), instead of trying to encode pin commands on the Mworks side. Even better to also have mworks be able to receive messages from the Arduino and verify that a pin request has succeeded before resuming mworks code.
Any workarounds would be appreciated too.
Thanks,
Michael
‘’’
firmata pump_output_device (
bluetooth_local_name = bluetooth_local_name
autostart = YES
//reconnect_interval = 5s // Not supported in current mworks version?
//connected = pump_connected
){
firmata_digital_output (
pin_number = 12
value = pump_control_line
)
}
var reward = 0 {
if (reward > 0){
play_sound (reward_sound)
pump_control_line = true
wait (
duration = cur_reward_duration_ms
duration_units = ms
)
pump_control_line = false
total_msec_pump_on = total_msec_pump_on + reward_duration_ms
report(‘Reward! ( $reward_duration_ms msec )’)
}
pump_control_line = false
}
‘‘’