Main Page
Namespaces
Classes
Files
File List
File Members
test
test_hz_measure.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
import
unittest
5
6
import
numpy
as
np
7
8
import
rospy
9
try
:
10
from
std_msgs.msg
import
Float32
11
except
:
12
import
roslib
13
roslib.load_manifest(
"jsk_topic_tools"
)
14
from
std_msgs.msg
import
Float32
15
16
17
PKG =
'jsk_topic_tools'
18
NAME =
'test_hz_measure'
19
20
21
def
eps_equal
(a, b, err=0.001):
22
return
abs(a - b) < err
23
24
25
class
TestHzMeasure
(unittest.TestCase):
26
27
def
__init__
(self, *args):
28
super(TestHzMeasure, self).
__init__
(*args)
29
self.
hz_msg
=
None
30
rospy.init_node(NAME)
31
rospy.Subscriber(
'/hz/output'
, Float32, self.
topic_cb
)
32
33
def
topic_cb
(self, msg):
34
self.
hz_msg
= msg
35
36
def
test_hz
(self):
37
while
self.
hz_msg
is
None
:
38
rospy.loginfo(
'wait for msg...'
)
39
if
not
rospy.is_shutdown():
40
rospy.sleep(5.0)
# wait for 5 sec
41
# should be 30Hz
42
msgs = []
43
while
len(msgs) < 30:
44
msgs.append(self.hz_msg.data)
45
# rospy.loginfo('hz of msg %s'%hz_msg.data)
46
rospy.sleep(0.1)
47
hz = np.median(msgs)
48
rospy.loginfo(
'average hz of msg %s'
% np.mean(msgs))
49
rospy.loginfo(
'median hz of msg %s'
% hz)
50
self.assertTrue(
eps_equal
(hz, 30, 1))
51
52
53
if
__name__ ==
"__main__"
:
54
import
rostest
55
rostest.rosrun(PKG, NAME, TestHzMeasure)
test_hz_measure.TestHzMeasure.__init__
def __init__(self, args)
Definition:
test_hz_measure.py:27
test_hz_measure.eps_equal
def eps_equal(a, b, err=0.001)
Definition:
test_hz_measure.py:21
test_hz_measure.TestHzMeasure
Definition:
test_hz_measure.py:25
test_hz_measure.TestHzMeasure.hz_msg
hz_msg
Definition:
test_hz_measure.py:29
test_hz_measure.TestHzMeasure.test_hz
def test_hz(self)
Definition:
test_hz_measure.py:36
test_hz_measure.TestHzMeasure.topic_cb
def topic_cb(self, msg)
Definition:
test_hz_measure.py:33
jsk_topic_tools
Author(s): Kei Okada
, Yusuke Furuta
autogenerated on Tue Feb 6 2018 03:45:19