-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrotary_ctrl_test.py
executable file
·75 lines (60 loc) · 2.04 KB
/
rotary_ctrl_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
#!/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-11-13
# modified: 2020-11-13
#
import pytest
import sys, traceback
from colorama import init, Fore, Style
init()
from lib.config_loader import ConfigLoader
from lib.rate import Rate
from lib.logger import Logger, Level
from lib.rotary_ctrl import RotaryControl
# ..............................................................................
@pytest.mark.unit
def test_rot_control():
_log = Logger("rot-ctrl-test", Level.INFO)
_rot_ctrl = None
try:
# read YAML configuration
_loader = ConfigLoader(Level.INFO)
filename = 'config.yaml'
_config = _loader.configure(filename)
# def __init__(self, config, minimum, maximum, step, level):
# _min = -127
# _max = 127
# _step = 1
_min = 0
_max = 10
_step = 0.5
_rot_ctrl = RotaryControl(_config, _min, _max, _step, Level.INFO)
_rate = Rate(20)
_log.info(Fore.WHITE + Style.BRIGHT + 'waiting for changes to rotary encoder...')
while True:
_value = _rot_ctrl.read()
_log.info(Fore.YELLOW + ' value: {:5.2f}'.format(_value))
_rate.wait()
finally:
if _rot_ctrl:
_log.info('resetting rotary encoder...')
_rot_ctrl.reset()
# main .........................................................................
_rot = None
def main(argv):
try:
test_rot_control()
except KeyboardInterrupt:
print(Fore.CYAN + 'caught Ctrl-C; exiting...' + Style.RESET_ALL)
except Exception:
print(Fore.RED + 'error starting ros: {}'.format(traceback.format_exc()) + Style.RESET_ALL)
# call main ....................................................................
if __name__== "__main__":
main(sys.argv[1:])
#EOF