-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathioe_test.py
executable file
·101 lines (87 loc) · 3.86 KB
/
ioe_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020-2021 by Murray Altheim. All rights reserved. This file is part
# of the Robot Operating System project, released under the MIT License. Please
# see the LICENSE file included as part of this package.
#
# author: Murray Altheim
# created: 2020-04-30
# modified: 2020-05-24
#
# This tests the five infrared sensors and three bumper sensors of the
# KR01's Integrated Front Sensor (IFS). Its signals are returned via a
# Pimoroni IO Expander Breakout Garden board, an I²C-based microcontroller.
#
import pytest
import time, traceback
from colorama import init, Fore, Style
init(autoreset=True)
from core.logger import Logger, Level
from core.config_loader import ConfigLoader
from hardware.io_expander import IoExpander
# ..............................................................................
@pytest.mark.unit
def test_ioe():
'''
Test the basic functionality of the IO Expander's connections to the IR
and bumper sensors.
'''
_log = Logger("test-ioe", Level.INFO)
# read YAML configuration
_loader = ConfigLoader(Level.INFO)
filename = 'config.yaml'
_config = _loader.configure(filename)
_ioe = IoExpander(_config, Level.INFO)
assert _ioe is not None
_show_ir = True
_show_bmp = False # not currently using bumpers on the IO Expander
# _bmp_port_triggered = False
# _bmp_cntr_triggered = False
# _bmp_stbd_triggered = False
for i in range(100000):
# infrared sensors .........................................................
if _show_ir:
_ir_port_side_value = _ioe.get_raw_port_side_ir_value()
_ir_port_value = _ioe.get_raw_port_ir_value()
_ir_cntr_value = _ioe.get_raw_cntr_ir_value()
_ir_stbd_value = _ioe.get_raw_stbd_ir_value()
_ir_stbd_side_value = _ioe.get_raw_stbd_side_ir_value()
_log.info(Fore.RED + 'IR {:8.5f}\t'.format(_ir_port_side_value) \
+ '{:8.5f}\t'.format(_ir_port_value) \
+ Fore.BLUE + '{:8.5f}\t'.format(_ir_cntr_value) \
+ Fore.GREEN + '{:8.5f}\t'.format(_ir_stbd_value) \
+ '{:8.5f}'.format(_ir_stbd_side_value))
# # bumpers ..................................................................
if _show_bmp:
_bmp_port_value = _ioe.get_raw_port_bmp_value()
_bmp_cntr_value = _ioe.get_raw_cntr_bmp_value()
_bmp_stbd_value = _ioe.get_raw_stbd_bmp_value()
# if _bmp_port_value == 0:
# _bmp_port_triggered = True
# if _bmp_cntr_value == 0:
# _bmp_cntr_triggered = True
# if _bmp_stbd_value == 0:
# _bmp_stbd_triggered = True
# _log.info(Fore.RED + 'BMP Triggered? {}\t'.format(_bmp_port_value) \
# + Fore.BLUE + '{}\t'.format(_bmp_cntr_value) \
# + Fore.GREEN + '{}'.format(_bmp_stbd_value))
# _log.info(Fore.RED + 'BMP \t\t{:5.2f}\t\t\t'.format(_bmp_port_value) \
# + Fore.BLUE + '{:5.2f}\t\t\t'.format(_bmp_cntr_value) \
# + Fore.GREEN + '{:5.2f}'.format(_bmp_stbd_value))
_log.info(Fore.RED + 'BMP \t\t{:<d}\t\t\t'.format(_bmp_port_value) \
+ Fore.BLUE + '{:<d}\t\t\t'.format(_bmp_cntr_value) \
+ Fore.GREEN + '{:<d}'.format(_bmp_stbd_value))
_log.info('i={:d}\n'.format(i))
time.sleep(0.33)
# ..............................................................................
def main():
try:
test_ioe()
except KeyboardInterrupt:
print(Fore.RED + 'Ctrl-C caught; exiting...')
except Exception as e:
print(Fore.RED + Style.BRIGHT + 'error testing ifs: {}\n{}'.format(e, traceback.format_exc()))
if __name__== "__main__":
main()
#EOF