test_custom_entity.py 2.27 KB
Newer Older
1
2
# Olivier Stasse
# 2019 CNRS
3
#
4
import sys, os
5
6
import time

7
8
9
10
11
12
13
# Put local python module at first priority
sys.path.insert(0,os.getcwd()+'/../src')
sys.path.insert(0,os.getcwd())

print(os.getcwd())
from dynamic_graph_tests.custom_entity import *
from dynamic_graph.entity import VerbosityLevel
14
15
16
17
from dynamic_graph import addLoggerFileOutputStream, addLoggerCoutOutputStream, closeLoggerFileOutputStream
from dynamic_graph import real_time_logger_instance, real_time_logger_spin_once, real_time_logger_destroy

# Starts the real time logger instance
18
19

aCustomEntity = CustomEntity("a_custom_entity")
20
21

addLoggerFileOutputStream("/tmp/output.dat")
22
aCustomEntity.signals()
23
24
25
26
27
28

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

29
30
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_INFO_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
31
32
33
34
35
for i in range(0,5):
    aCustomEntity.in_double.value=i
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
    print(i)
36
time.sleep(1)
37

38
39
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
40
41
42
43
for i in range(5,10):
    aCustomEntity.in_double.value=i
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
44
time.sleep(1)
45

46
47
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
48
49
50
51
for i in range(10,15):
    aCustomEntity.in_double.value=i
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
52
time.sleep(1)
53
addLoggerCoutOutputStream()
54
time.sleep(1)
55
56
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_NONE)
print(aCustomEntity.getLoggerVerbosityLevel())
57
58
59
60
for i in range(15,20):
    aCustomEntity.in_double.value=i
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()
61
time.sleep(1)
62

63
64
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ALL)
print(aCustomEntity.getLoggerVerbosityLevel())
65
66
67
68
69
70
71
72
for i in range(20,25):
    aCustomEntity.in_double.value=i
    aCustomEntity.out_double.recompute(i)
    real_time_logger_spin_once()


# End the real time logger
real_time_logger_destroy()
73

74
75
# Close all the output stream
closeLoggerFileOutputStream()
76