blob: df5a251bcec62d416ac377617dd1a4eb245a87c4 [file] [log] [blame]
# Copyright 2018 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""A factory test for gyroscopes calibration.
Description
-----------
This is a calibration test for tri-axis (x, y, and z) gyroscopes.
Test Procedure
--------------
1. Put the device (base/lid) on a static plane then press space.
2. Wait for completion.
Dependency
----------
- Device API (``cros.factory.device.gyroscope``).
Examples
--------
To run calibration on base gyroscope::
{
"pytest_name": "gyroscope_calibration",
"args": {
"location": "base"
}
}
"""
import factory_common # pylint: disable=unused-import
from cros.factory.device import device_utils
from cros.factory.test.i18n import _
from cros.factory.test import test_case
from cros.factory.test import test_ui
from cros.factory.utils.arg_utils import Arg
class Gyroscope(test_case.TestCase):
ARGS = [
Arg('capture_count', int,
'Number of records to read to compute the average.',
default=100),
Arg('sample_rate', int,
'Sample rate in Hz to read data from the gyroscope sensor.',
default=20),
Arg('setup_time_secs', int,
'Seconds to wait before starting the test.',
default=2),
Arg('autostart', bool, 'Auto start this test.',
default=True),
Arg('location', str, 'Gyro is located in "base" or "lid".',
default='base')]
def setUp(self):
self.dut = device_utils.CreateDUTInterface()
self.gyroscope = self.dut.gyroscope.GetController(
location=self.args.location)
self.ui.ToggleTemplateClass('font-large', True)
def runTest(self):
if not self.args.autostart:
self.ui.SetState(
_('Please put device on a static plane then press space to '
'start calibration.'))
self.ui.WaitKeysOnce(test_ui.SPACE_KEY)
for i in xrange(self.args.setup_time_secs):
self.ui.SetState(
_('Calibration will be started within {secs} seconds.'
'Please do not move the device.',
secs=self.args.setup_time_secs - i))
self.Sleep(1)
self.ui.SetState(_('Please do not move the device.'))
self.gyroscope.CleanUpCalibrationValues()
raw_data = self.gyroscope.GetData(self.args.capture_count,
self.args.sample_rate)
calib_bias = self.gyroscope.CalculateCalibrationBias(raw_data)
self.gyroscope.UpdateCalibrationBias(calib_bias)