test_custom_entity.py 2.13 KB
Newer Older
1
2
# Olivier Stasse
# 2019 CNRS
3
#
Guilhem Saurel's avatar
Guilhem Saurel committed
4
import os
5
6
import time

7
from custom_entity import CustomEntity
Guilhem Saurel's avatar
Guilhem Saurel committed
8
9
10
from dynamic_graph import (addLoggerCoutOutputStream, addLoggerFileOutputStream, closeLoggerFileOutputStream,
                           real_time_logger_destroy, real_time_logger_spin_once)
from dynamic_graph.entity import VerbosityLevel
11
12

print(os.getcwd())
13
14

# Starts the real time logger instance
15
16

aCustomEntity = CustomEntity("a_custom_entity")
17
18

addLoggerFileOutputStream("/tmp/output.dat")
19
aCustomEntity.signals()
20
21
22
23
24
25

aCustomEntity.setTimeSample(0.001)
print(aCustomEntity.getTimeSample())
aCustomEntity.setStreamPrintPeriod(0.002)
print(aCustomEntity.getStreamPrintPeriod())

26
27
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_INFO_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
Guilhem Saurel's avatar
Guilhem Saurel committed
28
29
for i in range(0, 5):
    aCustomEntity.in_double.value = i
30
31
32
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
    print(i)
33
time.sleep(1)
34

35
36
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
Guilhem Saurel's avatar
Guilhem Saurel committed
37
38
for i in range(5, 10):
    aCustomEntity.in_double.value = i
39
40
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
41
time.sleep(1)
42

43
44
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
Guilhem Saurel's avatar
Guilhem Saurel committed
45
46
for i in range(10, 15):
    aCustomEntity.in_double.value = i
47
48
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
49
time.sleep(1)
50
addLoggerCoutOutputStream()
51
time.sleep(1)
52
53
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_NONE)
print(aCustomEntity.getLoggerVerbosityLevel())
Guilhem Saurel's avatar
Guilhem Saurel committed
54
55
for i in range(15, 20):
    aCustomEntity.in_double.value = i
56
57
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
58
time.sleep(1)
59

60
61
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ALL)
print(aCustomEntity.getLoggerVerbosityLevel())
Guilhem Saurel's avatar
Guilhem Saurel committed
62
63
for i in range(20, 25):
    aCustomEntity.in_double.value = i
64
65
66
67
68
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()

# End the real time logger
real_time_logger_destroy()
69

70
71
# Close all the output stream
closeLoggerFileOutputStream()