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 time import time
be_bryan 0:b74591d5ab33 19
be_bryan 0:b74591d5ab33 20 class WaitusTest():
be_bryan 0:b74591d5ab33 21 """ This test is reading single characters from stdio
be_bryan 0:b74591d5ab33 22 and measures time between their occurrences.
be_bryan 0:b74591d5ab33 23 """
be_bryan 0:b74591d5ab33 24 TICK_LOOP_COUNTER = 13
be_bryan 0:b74591d5ab33 25 TICK_LOOP_SUCCESSFUL_COUNTS = 10
be_bryan 0:b74591d5ab33 26 DEVIATION = 0.10 # +/-10%
be_bryan 0:b74591d5ab33 27
be_bryan 0:b74591d5ab33 28 def test(self, selftest):
be_bryan 0:b74591d5ab33 29 test_result = True
be_bryan 0:b74591d5ab33 30 # First character to start test (to know after reset when test starts)
be_bryan 0:b74591d5ab33 31 if selftest.mbed.set_serial_timeout(None) is None:
be_bryan 0:b74591d5ab33 32 return selftest.RESULT_IO_SERIAL
be_bryan 0:b74591d5ab33 33 c = selftest.mbed.serial_read(1)
be_bryan 0:b74591d5ab33 34 if c is None:
be_bryan 0:b74591d5ab33 35 return selftest.RESULT_IO_SERIAL
be_bryan 0:b74591d5ab33 36 if c == '$': # target will printout TargetID e.g.: $$$$1040e649d5c09a09a3f6bc568adef61375c6
be_bryan 0:b74591d5ab33 37 #Read additional 39 bytes of TargetID
be_bryan 0:b74591d5ab33 38 if selftest.mbed.serial_read(39) is None:
be_bryan 0:b74591d5ab33 39 return selftest.RESULT_IO_SERIAL
be_bryan 0:b74591d5ab33 40 c = selftest.mbed.serial_read(1) # Re-read first 'tick'
be_bryan 0:b74591d5ab33 41 if c is None:
be_bryan 0:b74591d5ab33 42 return selftest.RESULT_IO_SERIAL
be_bryan 0:b74591d5ab33 43 start_serial_pool = time()
be_bryan 0:b74591d5ab33 44 start = time()
be_bryan 0:b74591d5ab33 45
be_bryan 0:b74591d5ab33 46 success_counter = 0
be_bryan 0:b74591d5ab33 47
be_bryan 0:b74591d5ab33 48 for i in range(0, self.TICK_LOOP_COUNTER):
be_bryan 0:b74591d5ab33 49 c = selftest.mbed.serial_read(1)
be_bryan 0:b74591d5ab33 50 if c is None:
be_bryan 0:b74591d5ab33 51 return selftest.RESULT_IO_SERIAL
be_bryan 0:b74591d5ab33 52 delta = time() - start
be_bryan 0:b74591d5ab33 53 deviation = abs(delta - 1)
be_bryan 0:b74591d5ab33 54 # Round values
be_bryan 0:b74591d5ab33 55 delta = round(delta, 2)
be_bryan 0:b74591d5ab33 56 deviation = round(deviation, 2)
be_bryan 0:b74591d5ab33 57 # Check if time measurements are in given range
be_bryan 0:b74591d5ab33 58 deviation_ok = True if delta > 0 and deviation <= self.DEVIATION else False
be_bryan 0:b74591d5ab33 59 success_counter = success_counter+1 if deviation_ok else 0
be_bryan 0:b74591d5ab33 60 msg = "OK" if deviation_ok else "FAIL"
be_bryan 0:b74591d5ab33 61 selftest.notify("%s in %.2f sec (%.2f) [%s]"% (c, delta, deviation, msg))
be_bryan 0:b74591d5ab33 62 start = time()
be_bryan 0:b74591d5ab33 63 if success_counter >= self.TICK_LOOP_SUCCESSFUL_COUNTS:
be_bryan 0:b74591d5ab33 64 break
be_bryan 0:b74591d5ab33 65 measurement_time = time() - start_serial_pool
be_bryan 0:b74591d5ab33 66 selftest.notify("Consecutive OK timer reads: %d"% success_counter)
be_bryan 0:b74591d5ab33 67 selftest.notify("Completed in %.2f sec" % (measurement_time))
be_bryan 0:b74591d5ab33 68 test_result = True if success_counter >= self.TICK_LOOP_SUCCESSFUL_COUNTS else False
be_bryan 0:b74591d5ab33 69 return selftest.RESULT_SUCCESS if test_result else selftest.RESULT_FAILURE