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
35 changes: 19 additions & 16 deletions built_in_tasks/target_tracking_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class TargetTracking(Sequence):
trajectory = dict(enter_target="hold", timeout="timeout_penalty", start_pause="pause"),
hold = dict(hold_complete_go_ramp="tracking_in_ramp", hold_complete_no_ramp="tracking_in", leave_target="hold_penalty", start_pause="pause"),

tracking_in_ramp = dict(ramp_complete="tracking_in", ramp_and_trial_complete="reward", leave_target="tracking_out_ramp", start_pause="pause"),
tracking_out_ramp = dict(ramp_complete="tracking_out", ramp_and_trial_complete="reward", enter_target="tracking_in_ramp", tracking_out_timeout="tracking_out_penalty", start_pause="pause"),
tracking_in_ramp = dict(ramp_up_complete="tracking_in", ramp_and_trial_complete="reward", leave_target="tracking_out_ramp", start_pause="pause"),
tracking_out_ramp = dict(ramp_up_complete="tracking_out", ramp_and_trial_complete="reward", enter_target="tracking_in_ramp", tracking_out_timeout="tracking_out_penalty", start_pause="pause"),

tracking_in = dict(traj_complete="tracking_in_ramp", trial_complete="reward", leave_target="tracking_out", start_pause="pause"),
tracking_out = dict(traj_complete="tracking_out_ramp", trial_complete="reward", enter_target="tracking_in", tracking_out_timeout="tracking_out_penalty", start_pause="pause"),
Expand Down Expand Up @@ -116,12 +116,14 @@ def tracking_task_start_wait(self):

# trial is not finished
self.trial_timed_out = False
self.ramp_up_complete = False

# number of times this trajectory has been attempted
self.tries = 0

# index into trajectory
self.frame_index = -1
self.trajectory_start_time = None

# number of frames in trajectory
'''Nothing generic to do.'''
Expand Down Expand Up @@ -158,7 +160,7 @@ def _while_wait_retry(self):

def _start_trajectory(self):
self.tries += 1
self.frame_index += 1
self.frame_index = 0

def _while_trajectory(self):
'''Nothing generic to do.'''
Expand All @@ -181,8 +183,8 @@ def _end_hold(self):
pass

def _start_tracking_in_ramp(self):
'''Nothing generic to do.'''
pass
if self.trajectory_start_time is None:
self.trajectory_start_time = self.get_time()

def _while_tracking_in_ramp(self):
'''Nothing generic to do.'''
Expand All @@ -205,8 +207,9 @@ def _end_tracking_out_ramp(self):
pass

def _start_tracking_in(self):
'''Nothing generic to do.'''
pass
if self.trajectory_start_time is None:
self.trajectory_start_time = self.get_time()
self.ramp_up_complete = True

def _while_tracking_in(self):
'''Nothing generic to do.'''
Expand All @@ -217,8 +220,7 @@ def _end_tracking_in(self):
pass

def _start_tracking_out(self):
'''Nothing generic to do.'''
pass
self.ramp_up_complete = True

def _while_tracking_out(self):
'''Nothing generic to do.'''
Expand Down Expand Up @@ -323,21 +325,21 @@ def _test_hold_complete_no_ramp(self, time_in_state):
'''Test whether the target is held long enough and whether to go straight into the trajectory'''
return (time_in_state > self.hold_time) and (self.ramp_up_time == 0)

def _test_ramp_complete(self, time_in_state):
def _test_ramp_up_complete(self, time_in_state):
'''Test whether the ramp up is finished'''
return self.frame_index-1 == self.ramp_up_time*self.sample_rate
return (not self.ramp_up_complete) & (self.frame_index-1 >= self.ramp_up_time*self.sample_rate)

def _test_traj_complete(self, time_in_state):
'''Test whether the trajectory is finished and whether there is a ramp down before the trial ends'''
return (self.frame_index-1 == self.trajectory_length - self.ramp_down_time*self.sample_rate) and (self.ramp_down_time > 0)
return (self.frame_index-1 >= self.trajectory_length - self.ramp_down_time*self.sample_rate) and (self.ramp_down_time > 0)

def _test_ramp_and_trial_complete(self, time_in_state):
'''Test whether the ramp down is finished, ending the trial'''
return (self.frame_index > self.trajectory_length) and (self.ramp_down_time > 0)
return (self.frame_index >= self.trajectory_length) and (self.ramp_down_time > 0)

def _test_trial_complete(self, time_in_state):
'''Test whether the trajectory is finished, ending the trial'''
return (self.frame_index > self.trajectory_length) and (self.ramp_down_time == 0)
return (self.frame_index >= self.trajectory_length) and (self.ramp_down_time == 0)

def _test_tracking_out_timeout(self, time_in_state):
return time_in_state > self.tracking_out_time
Expand Down Expand Up @@ -528,7 +530,8 @@ def update_frame(self):

elif self.trajectory_type == '2d':
self.trajectory.update_mask(use_frame_index, use_frame_index+self.lookahead)
self.frame_index += 1 # increment the frame_index for the following cycle
time_in_trajectory = self.get_time() - self.trajectory_start_time
self.frame_index = min(int(time_in_trajectory * self.sample_rate), self.trajectory_length)

def setup_start_wait(self):

Expand Down Expand Up @@ -617,7 +620,7 @@ def setup_start_tracking_out(self):

def setup_while_tracking(self):
# Check whether there are no more target frames to display
if self.frame_index == self.trajectory_length:
if self.frame_index >= self.trajectory_length:
self.trial_timed_out = True
self.pos_offset = [0,0,0]
self.vel_offset = [0,0,0]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ def test_example_task(self):
@unittest.skip("")
def test_tracking(self):
print("Running tracking task test")
seq = TrackingTask.tracking_target_chain(nblocks=1, ntrials=2, time_length=5, ramp=1, ramp_down=1,
seq = TrackingTask.tracking_target_chain(nblocks=1, ntrials=2, time_length=5, ramp=0, ramp_down=0,
num_primes=8, seed=42, sample_rate=60,
disturbance=False, boundaries=(-10,10,-10,10))
exp = init_exp(TrackingTask, [HideLeftTrajectory, MouseControl, Window2D], seq, window_size=(1000,800), fullscreen=False,
lookahead_time=1, screen_half_height=10)
lookahead_time=5, screen_half_height=10)
exp.rotation = 'xzy'
# exp.trajectory_type = 'space'
exp.trajectory_amplitude = 5
Expand All @@ -99,7 +99,7 @@ def test_tracking_2d(self):
limit1d=False, trajectory_amplitude=5, lookahead_time=1)
exp.stereo_mode = 'projection'
exp.rotation = 'xzy'
exp.trajectory_type = 'space'
exp.trajectory_type = '2d'
exp.run()

@unittest.skip("")
Expand Down