Skip to content
Snippets Groups Projects
Commit 3a041a00 authored by Maxence Grand's avatar Maxence Grand
Browse files

add launcher file

parent fbb6f3c7
No related branches found
No related tags found
No related merge requests found
Showing
with 386 additions and 78 deletions
# tobii
# Tobii
## Driver installation
All dependencies and installation scripts and deb files are tested for Ubuntu 20.04
## Getting started
> This section is based on the Ubuntu 16.04 installer from https://github.com/Eitol/tobii_eye_tracker_linux_installer adapted to Ubuntu 20.04. For ubuntu 16.04 and 18.04, please contact the original author
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
### Tobii 4C Driver
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
Tobii USD Host
## Add your files
sudo apt install tobiiusbservice_l64U14_2.1.5-28fd4a.deb
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
Tobii Engine Daemon
```
cd existing_repo
git remote add origin https://gricad-gitlab.univ-grenoble-alpes.fr/eyesofcobot/tobii.git
git branch -M main
git push -uf origin main
```
sudo apt install tobii_engine_linux-0.1.6.193_rc-Linux.deb
## Integrate with your tools
Tobii Config
- [ ] [Set up project integrations](https://gricad-gitlab.univ-grenoble-alpes.fr/eyesofcobot/tobii/-/settings/integrations)
sudo dpkg -i tobii_config_0.1.6.111_amd64.deb
## Collaborate with your team
### Tobii Pro Eye Tracker Manager
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
The manager is obtained at https://developer.tobiipro.com/eyetrackermanager.html
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
See
sudo apt install /path/to/manager/TobiiProEyeTrackerManager-2.4.11
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
File added
File added
File added
File added
File added
File added
File added
File added
File added
import time
import tobii_research as tr
import sys
import math
from tobiiresearch.interop import interop
from tobiiresearch.implementation.Calibration import _calibration_status
from tobiiresearch.implementation.Calibration import CALIBRATION_STATUS_SUCCESS, CALIBRATION_STATUS_FAILURE
from tobiiresearch.implementation.Calibration import CALIBRATION_STATUS_SUCCESS_LEFT_EYE
from tobiiresearch.implementation.Calibration import CALIBRATION_STATUS_SUCCESS_RIGHT_EYE
labels = {
(0.5, 0.5):"BLUE CENTER (1)",\
(0.1, 0.9):"BLUE BOTTOM LEFT (2)",\
(0.1,0.5):"BLUE LEFT (3)",\
(0.1, 0.1):"BLUE TOP LEFT (4)",\
(0.5, 0.1):"BLUE TOP (5)",\
(0.9, 0.1):"BLUE TOP RIGHT (6)",\
(0.9,0.5):"BLUE RIGHT (7)",\
(0.9,0.9):"BLUE BOTTOM RIGHT (8)",\
(0.5, 0.9):"BLUE BOTTOM (9)"
}
class Calibrator:
def __init__(self, eyetracker):
print("Initialize calibrator")
self.points_to_calibrate = [(0.5, 0.5), \
(0.1, 0.9), (0.1,0.5), (0.1, 0.1),\
(0.5, 0.1), (0.9, 0.1),\
(0.9,0.5), (0.9,0.9), (0.5, 0.9)]
if eyetracker is None:
sys.exit(1)
self.eyetracker = eyetracker
def calibrate_point(self, point):
while True:
input("Press ENTER to collect data for calibration point {0}.".format(labels[point]))
# Wait a little for user to focus.
time.sleep(0.7)
x, y = (float(_) for _ in (point[0], point[1]))
status = _calibration_status[interop.screen_based_calibration_collect_data(\
self.eyetracker._EyeTracker__core_eyetracker, x, y)]
if (status != CALIBRATION_STATUS_SUCCESS):
print("Fail to collect data")
continue
else:
break
def calibrate(self):
# Enter calibration mode.
interop.calibration_enter_calibration_mode(self.eyetracker._EyeTracker__core_eyetracker)
print("Entered calibration mode for eye tracker with serial number {0}.".format(self.eyetracker.serial_number))
for point in self.points_to_calibrate:
self.calibrate_point(point)
print("Computing and applying calibration.")
interop_result = interop.screen_based_calibration_compute_and_apply(self.eyetracker._EyeTracker__core_eyetracker)
position = None
calibration_points = []
calibration_samples = []
for interop_point in interop_result[1]:
cur_position = interop_point.position
if position is not None and cur_position != position:
calibration_points.append(tr.CalibrationPoint(position, tuple(calibration_samples)))
calibration_samples = []
calibration_samples.append(tr.CalibrationSample(
tr.CalibrationEyeData(interop_point.left_sample_position, interop_point.left_validity),
tr.CalibrationEyeData(interop_point.right_sample_position, interop_point.right_validity)))
position = cur_position
calibration_points.append(tr.CalibrationPoint(position, tuple(calibration_samples)))
self.calibration_result = tr.CalibrationResult(CALIBRATION_STATUS_SUCCESS, tuple(calibration_points))
print("Compute and apply returned {0} and collected at {1} points.".
format(self.calibration_result.status, len(self.calibration_result.calibration_points)))
# The calibration is done. Leave calibration mode.
interop.calibration_leave_calibration_mode(self.eyetracker._EyeTracker__core_eyetracker)
print("Left calibration mode")
import time
import tobii_research as tr
import sys
import math
class Calibrator:
def __init__(self, eyetracker, nb_points):
print("Initialize calibrator")
if(nb_points == 5):
self.points_to_calibrate = [(0.5, 0.5), (0.1, 0.1), (0.1, 0.9), (0.9, 0.1), (0.9, 0.9)]
elif(nb_points == 9):
self.points_to_calibrate = [(0.5, 0.5), \
(0.1, 0.1), (0.1,0.5), (0.5, 0.1),\
(0.1, 0.9), (0.9, 0.1),\
(0.5,0.9), (0.9,0.5), (0.9, 0.9)]
elif(nb_points == 13):
self.points_to_calibrate = [(0.5, 0.5), \
(0.1, 0.1), (0.1,0.5), (0.25,0.25) ,(0.5, 0.1),\
(0.1, 0.9), (0.25, 0.75), (0.75,0.25), (0.9, 0.1),\
(0.5,0.9), (0.75,0.75), (0.9,0.5), (0.9, 0.9)]
else:
print("Bad points number (5,9,13)")
sys.exit(1)
# self.test_point = [(0.5, 0.1), (0.1, 0.5), (0.9, 0.5), (0.5, 0.9)]
if eyetracker is None:
sys.exit(1)
self.eyetracker = eyetracker
# <BeginExample>
self.calibration = tr.ScreenBasedCalibration(eyetracker)
# Enter calibration mode.
self.calibration.enter_calibration_mode()
print("Entered calibration mode for eye tracker with serial number {0}.".format(eyetracker.serial_number))
def calibrate_point(self, point):
input("Press ENTER to collect data at {0}.".format(point))
# Wait a little for user to focus.
time.sleep(0.7)
if self.calibration.collect_data(point[0], point[1]) != tr.CALIBRATION_STATUS_SUCCESS:
print("Fail to collect data")
self.calibrate_point(point)
def calibrate(self):
for point in self.points_to_calibrate:
self.calibrate_point(point)
print("Computing and applying calibration.")
self.calibration_result = self.calibration.compute_and_apply()
print("Compute and apply returned {0} and collected at {1} points.".
format(self.calibration_result.status, len(self.calibration_result.calibration_points)))
# The calibration is done. Leave calibration mode.
self.calibration.leave_calibration_mode()
print("Left calibration mode")
#!/usr/bin/env python3.8
import tobii_research as tr
from utils import timestamp
from utils import sleep
import math
import csv
global all_data
all_data = []
class Recorder:
def __init__(self, tracker, filename="tmp.csv"):
self.tracker = tracker
self.tracker.subscribe_to(tr.EYETRACKER_GAZE_DATA,\
self.gaze_data_callback,\
as_dictionary=True)
self.filename = filename
self.continueToGet = True
def gaze_data_callback(self, gaze_data):
gaze_data['timestamp'] = timestamp()
"""Fonction qui est appelée à l'acquisition de chaque frame"""
if (gaze_data['left_gaze_point_validity'] == 1 and gaze_data['right_gaze_point_validity']):
gaze_data['x'] = round(
(gaze_data['left_gaze_point_on_display_area'][0] + gaze_data['right_gaze_point_on_display_area'][0]) / 2, 2)
gaze_data['y'] = round(
(gaze_data['left_gaze_point_on_display_area'][1] + gaze_data['right_gaze_point_on_display_area'][1]) / 2, 2)
elif (gaze_data['left_gaze_point_validity'] == 1 and gaze_data['right_gaze_point_validity'] == 0):
gaze_data['x'] = gaze_data['left_gaze_point_on_display_area'][0]
gaze_data['y'] = gaze_data['left_gaze_point_on_display_area'][1]
elif (gaze_data['left_gaze_point_validity'] == 0 and gaze_data['right_gaze_point_validity'] == 1):
gaze_data['x'] = gaze_data['right_gaze_point_on_display_area'][0]
gaze_data['y'] = gaze_data['right_gaze_point_on_display_area'][1]
else:
gaze_data['x'] = float("nan")
gaze_data['y'] = float("nan")
all_data.append([gaze_data["timestamp"], gaze_data["x"], gaze_data["y"]])
return
all_data.append([gaze_data["timestamp"], gaze_data["x"], gaze_data["y"]])
print([gaze_data["timestamp"], gaze_data["x"], gaze_data["y"]])
return
def finish(self):
print("Write data to file %s ...\n" % self.filename)
self.tracker.unsubscribe_from(tr.EYETRACKER_GAZE_DATA,\
self.gaze_data_callback)
with open(self.filename, 'w') as f:
writer = csv.writer(f)
writer.writerow(["Timestamp", "x", "y"])
for row in all_data:
if len(row) > 0:
writer.writerow(row)
print("Done.\n")
def record(tracker, filename="tmp.csv"):
recorder = Recorder(tracker, filename=filename)
while(recorder.continueToGet):
try:
sleep()
continue
except KeyboardInterrupt:
recorder.continueToGet = False
recorder.finish()
#!/usr/bin/env python3.10
import tobii_research as tr
import sys
from calibration import Calibrator
from validation import validate
from gazerecording import record
import os
class Tracker:
def __init__(self, log = 0):
self.data = None
print("Get tracker")
found_eyetrackers = tr.find_all_eyetrackers()
if(len(found_eyetrackers) == 0):
if(log > 0):
print("No eyetracker")
sys.exit(1)
else:
self.tracker = found_eyetrackers[0]
if(log > 0):
print("Address: " + self.tracker.address)
print("Model: " + self.tracker.model)
print("Name (It's OK if this is empty): " + self.tracker.device_name)
print("Serial number: " + self.tracker.serial_number)
def get_track_box(self):
track_box = self.tracker.get_track_box()
print("Back Lower Left: {0}".format(track_box.back_lower_left))
print("Back Lower Right: {0}".format(track_box.back_lower_right))
print("Back Upper Left: {0}".format(track_box.back_upper_left))
print("Back Upper Right: {0}".format(track_box.back_upper_right))
print("Front Lower Left: {0}".format(track_box.front_lower_left))
print("Front Lower Right: {0}".format(track_box.front_lower_right))
print("Front Upper Left: {0}".format(track_box.front_upper_left))
print("Front Upper Right: {0}".format(track_box.front_upper_right))
def continue_test(question, yes=True):
while (True):
str = input(question)
if(str == "y" or str == "Y" or str == "yes" or str == ""):
return yes
elif (str == "n" or str == "N" or str == "no"):
return not yes
break
else:
print("Bad argument %s" % str)
continue
def run(dir="."):
tracker = Tracker()
calibrator = Calibrator(tracker.tracker)
do_calibration = True
first = True
continue_experiment = True
while(continue_experiment):
while(do_calibration):
calibrator.calibrate()
validate(tracker.tracker)
do_calibration = continue_test("\nKeep this calibration? (Y/n)", yes=False)
csvfile = input("What is the name of the structure?")
record(tracker.tracker, "%s/TOBII-%s.csv" % (dir, csvfile) )
continue_experiment = continue_test("Continue experiment? (Y/n)", yes=True)
if(continue_experiment):
validate(tracker.tracker)
do_calibration = continue_test("\nKeep this calibration? (Y/n)", yes=False)
if __name__ == '__main__':
print("Welcome to the eye-tracking experiment\n")
in_experiment = True
while(in_experiment):
id = input("What is the participant's ID?")
savedir = input("In which directory should the data be saved for the user %s?" % id)
dir = "%s\%s" % (savedir, id)
if os.path.isdir(dir):
print("The experiment can now begin\n")
run(dir=dir)
in_experiment = False
else:
print("The %s directory does not exist\n" % dir)
print("\nThe experiment is over.\nThank you for your participation.\n")
sys.exit(0)
import time
from math import sqrt
def timestamp():
return int(round(time.time() * 1000))
def sleep():
time.sleep(2)
def sqr(x):
return x * x
def distance(p1,p2):
return sqrt(sqr(p2[1]-p1[1])+sqr(p2[0]-p1[0]))
import time
import tobii_research as tr
import sys
import math
from utils import distance
from utils import sleep
from utils import timestamp
from tobiiresearch.interop import interop
from tobiiresearch.implementation.Calibration import _calibration_status
from tobiiresearch.implementation.Calibration import CALIBRATION_STATUS_SUCCESS, CALIBRATION_STATUS_FAILURE
from tobiiresearch.implementation.Calibration import CALIBRATION_STATUS_SUCCESS_LEFT_EYE
from tobiiresearch.implementation.Calibration import CALIBRATION_STATUS_SUCCESS_RIGHT_EYE
labels = {
(0.25,0.75):"GREEN BOTTOM LEFT (A)",\
(0.25,0.25):"GREEN TOP LEFT (B)",\
(0.75,0.25):"GREEN TOP RIGHT (C)",\
(0.75,0.75):"GREEN BOTTOM RIGHT (D)"
}
global data
data = None
class Validator:
def __init__(self, tracker):
self.tracker = tracker
# self.data = None
def init_callback(self):
self.tracker.subscribe_to(tr.EYETRACKER_GAZE_DATA,\
self.gaze_data_callback,\
as_dictionary=True)
def remove_callback(self):
self.tracker.unsubscribe_from(tr.EYETRACKER_GAZE_DATA,\
self.gaze_data_callback)
def gaze_data_callback(self, gaze_data):
global data
gaze_data['timestamp'] = timestamp()
if (gaze_data['left_gaze_point_validity'] == 1 and gaze_data['right_gaze_point_validity']):
gaze_data['x'] = round(
(gaze_data['left_gaze_point_on_display_area'][0] + gaze_data['right_gaze_point_on_display_area'][0]) / 2, 2)
gaze_data['y'] = round(
(gaze_data['left_gaze_point_on_display_area'][1] + gaze_data['right_gaze_point_on_display_area'][1]) / 2, 2)
elif (gaze_data['left_gaze_point_validity'] == 1 and gaze_data['right_gaze_point_validity'] == 0):
gaze_data['x'] = gaze_data['left_gaze_point_on_display_area'][0]
gaze_data['y'] = gaze_data['left_gaze_point_on_display_area'][1]
elif (gaze_data['left_gaze_point_validity'] == 0 and gaze_data['right_gaze_point_validity'] == 1):
gaze_data['x'] = gaze_data['right_gaze_point_on_display_area'][0]
gaze_data['y'] = gaze_data['right_gaze_point_on_display_area'][1]
else:
gaze_data['x'] = float("nan")
gaze_data['y'] = float("nan")
data = gaze_data
return
def validate(tracker):
validator = Validator(tracker)
validator.init_callback()
for point in labels.keys():
str = input("\nPress ENTER to get data for validation point {0}:".format(labels[point]))
sleep()
print(data)
print("Gaze position : ({0},{1})\n".format(data["x"], data["y"]))
if(not (math.isnan(data["x"]) or math.isnan(data["y"]))):
print("\tDistance: {0}\n".format(distance(point, [data["x"], data["y"]])))
validator.remove_callback()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment