mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 """
be_bryan 0:b74591d5ab33 2 mbed SDK
be_bryan 0:b74591d5ab33 3 Copyright (c) 2011-2013 ARM Limited
be_bryan 0:b74591d5ab33 4
be_bryan 0:b74591d5ab33 5 Licensed under the Apache License, Version 2.0 (the "License");
be_bryan 0:b74591d5ab33 6 you may not use this file except in compliance with the License.
be_bryan 0:b74591d5ab33 7 You may obtain a copy of the License at
be_bryan 0:b74591d5ab33 8
be_bryan 0:b74591d5ab33 9 http://www.apache.org/licenses/LICENSE-2.0
be_bryan 0:b74591d5ab33 10
be_bryan 0:b74591d5ab33 11 Unless required by applicable law or agreed to in writing, software
be_bryan 0:b74591d5ab33 12 distributed under the License is distributed on an "AS IS" BASIS,
be_bryan 0:b74591d5ab33 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
be_bryan 0:b74591d5ab33 14 See the License for the specific language governing permissions and
be_bryan 0:b74591d5ab33 15 limitations under the License.
be_bryan 0:b74591d5ab33 16 """
be_bryan 0:b74591d5ab33 17
be_bryan 0:b74591d5ab33 18 from mbed_host_tests import BaseHostTest
be_bryan 0:b74591d5ab33 19 import time
be_bryan 0:b74591d5ab33 20
be_bryan 0:b74591d5ab33 21
be_bryan 0:b74591d5ab33 22 class TimingDriftSync(BaseHostTest):
be_bryan 0:b74591d5ab33 23 """
be_bryan 0:b74591d5ab33 24 This works as master-slave fashion
be_bryan 0:b74591d5ab33 25 1) Device says its booted up and ready to run the test, wait for host to respond
be_bryan 0:b74591d5ab33 26 2) Host sends the message to get the device current time i.e base time
be_bryan 0:b74591d5ab33 27
be_bryan 0:b74591d5ab33 28 #
be_bryan 0:b74591d5ab33 29 # *
be_bryan 0:b74591d5ab33 30 # * |
be_bryan 0:b74591d5ab33 31 #<---* DUT<- base_time | - round_trip_base_time ------
be_bryan 0:b74591d5ab33 32 # * | |
be_bryan 0:b74591d5ab33 33 # * - |
be_bryan 0:b74591d5ab33 34 # - |
be_bryan 0:b74591d5ab33 35 # | |
be_bryan 0:b74591d5ab33 36 # | |
be_bryan 0:b74591d5ab33 37 # | - measurement_stretch | - nominal_time
be_bryan 0:b74591d5ab33 38 # | |
be_bryan 0:b74591d5ab33 39 # | |
be_bryan 0:b74591d5ab33 40 # - |
be_bryan 0:b74591d5ab33 41 # * - |
be_bryan 0:b74591d5ab33 42 # * | |
be_bryan 0:b74591d5ab33 43 #<---* DUT <-final_time | - round_trip_final_time------
be_bryan 0:b74591d5ab33 44 # * |
be_bryan 0:b74591d5ab33 45 # * -
be_bryan 0:b74591d5ab33 46 #
be_bryan 0:b74591d5ab33 47 #
be_bryan 0:b74591d5ab33 48 # As we increase the measurement_stretch, the error because of transport delay diminishes.
be_bryan 0:b74591d5ab33 49 # The values of measurement_stretch is propotional to round_trip_base_time(transport delays)
be_bryan 0:b74591d5ab33 50 # by factor time_measurement_multiplier.This multiplier is used is 80 to tolerate 2 sec of
be_bryan 0:b74591d5ab33 51 # transport delay and test time ~ 180 secs
be_bryan 0:b74591d5ab33 52 #
be_bryan 0:b74591d5ab33 53 # Failure in timing can occur if we are ticking too fast or we are ticking too slow, hence we have
be_bryan 0:b74591d5ab33 54 # min_range and max_range. if we cross on either side tests would be marked fail. The range is a function of
be_bryan 0:b74591d5ab33 55 # tolerance/acceptable drift currently its 5%.
be_bryan 0:b74591d5ab33 56 #
be_bryan 0:b74591d5ab33 57
be_bryan 0:b74591d5ab33 58 """
be_bryan 0:b74591d5ab33 59 __result = None
be_bryan 0:b74591d5ab33 60 mega = 1000000.0
be_bryan 0:b74591d5ab33 61 max_measurement_time = 180
be_bryan 0:b74591d5ab33 62
be_bryan 0:b74591d5ab33 63 # this value is obtained for measurements when there is 0 transport delay and we want accurancy of 5%
be_bryan 0:b74591d5ab33 64 time_measurement_multiplier = 80
be_bryan 0:b74591d5ab33 65
be_bryan 0:b74591d5ab33 66 def _callback_timing_drift_check_start(self, key, value, timestamp):
be_bryan 0:b74591d5ab33 67 self.round_trip_base_start = timestamp
be_bryan 0:b74591d5ab33 68 self.send_kv("base_time", 0)
be_bryan 0:b74591d5ab33 69
be_bryan 0:b74591d5ab33 70 def _callback_base_time(self, key, value, timestamp):
be_bryan 0:b74591d5ab33 71 self.round_trip_base_end = timestamp
be_bryan 0:b74591d5ab33 72 self.device_time_base = float(value)
be_bryan 0:b74591d5ab33 73 self.round_trip_base_time = self.round_trip_base_end - self.round_trip_base_start
be_bryan 0:b74591d5ab33 74
be_bryan 0:b74591d5ab33 75 self.log("Device base time {}".format(value))
be_bryan 0:b74591d5ab33 76 measurement_stretch = (self.round_trip_base_time * self.time_measurement_multiplier) + 5
be_bryan 0:b74591d5ab33 77
be_bryan 0:b74591d5ab33 78 if measurement_stretch > self.max_measurement_time:
be_bryan 0:b74591d5ab33 79 self.log("Time required {} to determine device timer is too high due to transport delay, skipping".format(measurement_stretch))
be_bryan 0:b74591d5ab33 80 else:
be_bryan 0:b74591d5ab33 81 self.log("sleeping for {} to measure drift accurately".format(measurement_stretch))
be_bryan 0:b74591d5ab33 82 time.sleep(measurement_stretch)
be_bryan 0:b74591d5ab33 83 self.round_trip_final_start = time.time()
be_bryan 0:b74591d5ab33 84 self.send_kv("final_time", 0)
be_bryan 0:b74591d5ab33 85
be_bryan 0:b74591d5ab33 86 def _callback_final_time(self, key, value, timestamp):
be_bryan 0:b74591d5ab33 87 self.round_trip_final_end = timestamp
be_bryan 0:b74591d5ab33 88 self.device_time_final = float(value)
be_bryan 0:b74591d5ab33 89 self.round_trip_final_time = self.round_trip_final_end - self.round_trip_final_start
be_bryan 0:b74591d5ab33 90 self.log("Device final time {} ".format(value))
be_bryan 0:b74591d5ab33 91
be_bryan 0:b74591d5ab33 92 # compute the test results and send to device
be_bryan 0:b74591d5ab33 93 results = "pass" if self.compute_parameter() else "fail"
be_bryan 0:b74591d5ab33 94 self.send_kv(results, "0")
be_bryan 0:b74591d5ab33 95
be_bryan 0:b74591d5ab33 96 def setup(self):
be_bryan 0:b74591d5ab33 97 self.register_callback('timing_drift_check_start', self._callback_timing_drift_check_start)
be_bryan 0:b74591d5ab33 98 self.register_callback('base_time', self._callback_base_time)
be_bryan 0:b74591d5ab33 99 self.register_callback('final_time', self._callback_final_time)
be_bryan 0:b74591d5ab33 100
be_bryan 0:b74591d5ab33 101 def compute_parameter(self, failure_criteria=0.05):
be_bryan 0:b74591d5ab33 102 t_max = self.round_trip_final_end - self.round_trip_base_start
be_bryan 0:b74591d5ab33 103 t_min = self.round_trip_final_start - self.round_trip_base_end
be_bryan 0:b74591d5ab33 104 t_max_hi = t_max * (1 + failure_criteria)
be_bryan 0:b74591d5ab33 105 t_max_lo = t_max * (1 - failure_criteria)
be_bryan 0:b74591d5ab33 106 t_min_hi = t_min * (1 + failure_criteria)
be_bryan 0:b74591d5ab33 107 t_min_lo = t_min * (1 - failure_criteria)
be_bryan 0:b74591d5ab33 108 device_time = (self.device_time_final - self.device_time_base) / self.mega
be_bryan 0:b74591d5ab33 109
be_bryan 0:b74591d5ab33 110 self.log("Compute host events")
be_bryan 0:b74591d5ab33 111 self.log("Transport delay 0: {}".format(self.round_trip_base_time))
be_bryan 0:b74591d5ab33 112 self.log("Transport delay 1: {}".format(self.round_trip_final_time))
be_bryan 0:b74591d5ab33 113 self.log("DUT base time : {}".format(self.device_time_base))
be_bryan 0:b74591d5ab33 114 self.log("DUT end time : {}".format(self.device_time_final))
be_bryan 0:b74591d5ab33 115
be_bryan 0:b74591d5ab33 116 self.log("min_pass : {} , max_pass : {} for {}%%".format(t_max_lo, t_min_hi, failure_criteria * 100))
be_bryan 0:b74591d5ab33 117 self.log("min_inconclusive : {} , max_inconclusive : {}".format(t_min_lo, t_max_hi))
be_bryan 0:b74591d5ab33 118 self.log("Time reported by device: {}".format(device_time))
be_bryan 0:b74591d5ab33 119
be_bryan 0:b74591d5ab33 120 if t_max_lo <= device_time <= t_min_hi:
be_bryan 0:b74591d5ab33 121 self.log("Test passed !!!")
be_bryan 0:b74591d5ab33 122 self.__result = True
be_bryan 0:b74591d5ab33 123 elif t_min_lo <= device_time <= t_max_hi:
be_bryan 0:b74591d5ab33 124 self.log("Test inconclusive due to transport delay, retrying")
be_bryan 0:b74591d5ab33 125 self.__result = False
be_bryan 0:b74591d5ab33 126 else:
be_bryan 0:b74591d5ab33 127 self.log("Time outside of passing range. Timing drift seems to be present !!!")
be_bryan 0:b74591d5ab33 128 self.__result = False
be_bryan 0:b74591d5ab33 129 return self.__result
be_bryan 0:b74591d5ab33 130
be_bryan 0:b74591d5ab33 131 def result(self):
be_bryan 0:b74591d5ab33 132 return self.__result
be_bryan 0:b74591d5ab33 133
be_bryan 0:b74591d5ab33 134 def teardown(self):
be_bryan 0:b74591d5ab33 135 pass