Skip to content

trackerstate

MotionTrackerController(config) ¤

Bases: StateMachine

State machine for webserver

Source code in motiontracker\trackerstate.py
 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
def __init__(self, config: Config):
    StateMachine.__init__(self)
    self.config = config
    camera_config = config["motion_tracker"]["camera"]
    if "video_fpath" in camera_config:
        self.camera = CameraVideo(
            **camera_config,
            callback_thread_closed=self.callback_camera_thread_closed,
        )
    else:
        self.camera = CameraCV(
            **camera_config,
            callback_thread_closed=self.callback_camera_thread_closed,
        )
    self.tracker = Tracker(
        camera=self.camera,
        callback_thread_closed=self.callback_tracking_thread_closed,
    )

    # all states that indicate the camera is on
    self.camera_on_states = [
        self.calibrating.id,
        self.calibrated.id,
        self.tracking.id,
        self.experiment.id,
        self.recording.id,
    ]
    # states where tracking is happening
    self.tracking_on_states = [
        self.tracking.id,
        self.experiment.id,
        self.recording.id,
    ]

    self.recording_main_directory = Path(CONFIG["motion_tracker"]["recording"]["save_directory"])
    if not self.recording_main_directory.exists():
        log.info(f"Creating {self.recording_main_directory}")
        self.recording_main_directory.mkdir(parents=True, exist_ok=True)

on_enter_calibrated(event, state) ¤

This event should be called only after the calibration_points_pixels have been received and updated

Parameters:

Name Type Description Default
event _type_

description

required
state _type_

description

required
Source code in motiontracker\trackerstate.py
154
155
156
157
158
159
160
161
162
163
164
165
def on_enter_calibrated(self, event, state):
    """This event should be called only after the calibration_points_pixels have been received and updated

    Args:
        event (_type_): _description_
        state (_type_): _description_
    """
    self.dlt = find_transition_matrix(
        self.calibration_coordinates_px,
        CONFIG["motion_tracker"]["calibration_stickers"]["coordinates_local"],
    )
    log.info(f"Updating DLT matrix: {self.dlt}")

on_enter_tracking(event, state, start=None) ¤

This event should be called only after the calibration_points_pixels have been received and updated

Parameters:

Name Type Description Default
event _type_

description

required
state _type_

description

required
Source code in motiontracker\trackerstate.py
171
172
173
174
175
176
177
178
179
def on_enter_tracking(self, event, state, start: PointInt = None):
    """This event should be called only after the calibration_points_pixels have been received and updated

    Args:
        event (_type_): _description_
        state (_type_): _description_
    """
    log.info(f"Entering tracking state with start coordinates: {start}")
    self.tracker.start_tracking(start.x, start.y, self.dlt)