Пример #1
0
    def message_callback(self, message):
        ROSTopicHz.callback_hz(self, message)
        with self.lock:
            self.timestamps.append(rospy.get_time())

            # FIXME: this only works for message of class AnyMsg
            #self.sizes.append(len(message._buff))
            # time consuming workaround...
            buff = StringIO()
            message.serialize(buff)
            self.sizes.append(len(buff.getvalue()))

            if len(self.timestamps) > self.window_size - 1:
                self.timestamps.pop(0)
                self.sizes.pop(0)
            assert(len(self.timestamps) == len(self.sizes))
            self.last_message = message
Пример #2
0
    def message_callback(self, message):
        ROSTopicHz.callback_hz(self, message)
        with self.lock:
            self.timestamps.append(rospy.get_time())

            # FIXME: this only works for message of class AnyMsg
            #self.sizes.append(len(message._buff))
            # time consuming workaround...
            buff = StringIO()
            message.serialize(buff)
            self.sizes.append(buff.len)

            if len(self.timestamps) > self.window_size - 1:
                self.timestamps.pop(0)
                self.sizes.pop(0)
            assert(len(self.timestamps) == len(self.sizes))

            self.last_message = message
def get_hz(topic, window_size=-1, filter_expr=None):
    rates = []
    rt = ROSTopicHz(window_size, filter_expr=filter_expr)
    sub = rospy.Subscriber(topic, Image, rt.callback_hz)
    while not rospy.is_shutdown():
        if len(rt.times) > 0:
            n = len(rt.times)
            mean = sum(rt.times) / n
            rate = 1. / mean if mean > 0. else 0
            rates.append(rate)
            if len(rates) >= 3:
                sub.unregister()
                return np.average(rates)
        rospy.sleep(1)
Пример #4
0
    def message_callback(self, message):
        ROSTopicHz.callback_hz(self, message)
        with self.lock:
            self.timestamps.append(rospy.get_time())

            # FIXME: this only works for message of class AnyMsg
            #self.sizes.append(len(message._buff))
            # time consuming workaround...
            buff = StringIO()
            message.serialize(buff)

            # patch begin
            pos = buff.tell()
            buff.seek(0, os.SEEK_END)
            self.sizes.append(buff.tell())
            buff.seek(pos)
            # patch end

            if len(self.timestamps) > self.window_size - 1:
                self.timestamps.pop(0)
                self.sizes.pop(0)
            assert (len(self.timestamps) == len(self.sizes))

            self.last_message = message
Пример #5
0
    def __init__(self, topic, metrics, window_size=1000, filter_expr=None, timer_freq=0.5, filename="freqfile"):
        """ A topic logger class, which will initiate ROS BW and HZ loggers for the specified topic
        """
        self.topic = topic.replace('/','')
        self.Metrics = metrics 

        self.rthz = ROSTopicHz(window_size, filter_expr=filter_expr)
        rospy.Subscriber(topic, rospy.AnyMsg, self.rthz.callback_hz)

        # Access the variables through "rt.times", see https://github.com/strawlab/ros_comm/blob/6f7ea2feeb3c890699518cb6eb3d33faa15c5306/tools/rostopic/src/rostopic.py#L136
        self.rtbw = ROSTopicBw() # Default window_size is 100
        rospy.Subscriber(topic, rospy.AnyMsg, self.rtbw.callback)

        # Timer to repeatedly log the values. Documentation here: http://docs.ros.org/melodic/api/rospy/html/rospy.timer.Timer-class.html
        self.timer = rospy.Timer(rospy.Duration(timer_freq), self.timer_callback)
        self.logging_df = pd.DataFrame(columns=self.Metrics).set_index("Time")
Пример #6
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-

# 注意:这是自动生成的程序,请不要做任何修改!

import rospy
import time
from std_msgs.msg import Header
from rostopic import ROSTopicHz
from rospy_test.msg import node_state
from rospy_test.msg import all_state
from rospy_test.msg import Num
from rospy_test.msg import info

hz_checker = ROSTopicHz(10, use_wtime=True)

msg_dict = {}
msg_keys = ['msg', 'hz', 'hz_state', 'param', 'param_value', 'param_state']
pub = rospy.Publisher('node_states', all_state, queue_size=10)


def func_checking_value(param, min, max):
    return param <= max and param >= min


def timer_callback(event):
    global hz_checker
    global pub

    node_msg = []
Пример #7
0
import curses

import rospy
from rostopic import ROSTopicHz
from rti_dvl.msg import DVL
from sensor_msgs.msg import Imu
from bar30_depth.msg import Depth
from sonar_oculus.msg import OculusPing

from bluerov_bridge import Bridge


OCULUS_PARTNUMBER = {0: 'NAN', 1032: 'M750d', 1042: 'M1200d'}

dvl, depth, imu, ping = DVL(), Depth(), Imu(), OculusPing()
hz = ROSTopicHz(-1)
dvl_hz, depth_hz, imu_hz, sonar_hz = 0, 0, 0, 0


def dvl_callback(msg):
    global dvl
    dvl = msg
    hz.callback_hz(msg, 'dvl')


def depth_callback(msg):
    global depth
    depth = msg
    hz.callback_hz(msg, 'depth')

Пример #8
0
 def goas(self):
     time = ROSTopicHz(-1)
     time.print_hz()
     print(time.rate)