def test_create_from_log_msg_with_stamp(self): seconds_since_epoch = 100 msg = Log() msg.header.stamp = rospy.Time(secs=seconds_since_epoch, nsecs=0) msg.level = Log.DEBUG entry = Entry.from_ros_msg(msg) self.assertEqual(entry.date_time.toSecsSinceEpoch(), seconds_since_epoch)
def test_create_from_info_log_msg(self): content = 'test' msg = Log() msg.msg = content msg.level = Log.INFO entry = Entry.from_ros_msg(msg) self.assertEqual(entry.content, content) self.assertFalse(entry.is_error) self.assertAlmostEqual(entry.date_time.toSecsSinceEpoch(), QDateTime.currentSecsSinceEpoch(), 10)
def check_usv(self): output = subprocess.check_output("sudo /opt/susvd/susv -status", shell=True) for item in output.split("\n"): if "Charging circuit: ONLINE" in item: if self.percentage > 0.9: self.state_charging = BatteryState.POWER_SUPPLY_STATUS_FULL else: self.state_charging = BatteryState.POWER_SUPPLY_STATUS_CHARGING elif "Charging circuit: OFFLINE" in item: self.state_charging = BatteryState.POWER_SUPPLY_STATUS_DISCHARGING if "Charging current" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Charging current: ", '') charging_current = float(e.replace("mA", '')) self.charging_current = (charging_current / 1000.0) if "Power Battery" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Power Battery: ", '') power_battery = float(e.replace("mA", '')) self.power_battery = (power_battery / 1000.0) if self.power_battery > 0: self.power_battery *= -1.0 if "Battery voltage" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Battery voltage: ", '') voltage = float(e.replace("V", '')) self.voltage = voltage if "Battery capacity" in item: string = item.strip() string = string.replace('*', '') string = " ".join(string.split()) e = string.replace("Battery capacity: ", '') percentage = float(e.replace("%",'')) # send event msg if something changed if abs(percentage - self.percentage) > 5: log = Log() log.msg = str(string) log.level = log.INFO self.pub_event.publish(log) self.percentage = percentage
def _rosout(level, msg): global _in_rosout try: if _rosout_pub is not None: # protect against infinite recursion if not _in_rosout: try: _in_rosout = True msg = str(msg) topics = get_topic_manager().get_topics() l = Log(level=level, name=str(rospy.names.get_caller_id()), msg=str(msg), topics=topics) l.header.stamp = Time.now() _rosout_pub.publish(l) finally: _in_rosout = False except Exception as e: #traceback.print_exc() # don't use logerr in this case as that is recursive here logger = logging.getLogger("rospy.rosout") logger.error("Unable to report rosout: %s\n%s", e, traceback.format_exc()) return False
def _rosout(level, msg, fname, line, func): global _in_rosout try: if _rosout_pub is not None: # protect against infinite recursion if not _in_rosout: try: _in_rosout = True msg = str(msg) # check parameter server/cache for omit_topics flag # the same parameter is checked in rosout_appender.cpp for the same purpose # parameter accesses are cached automatically in python if rospy.has_param("/rosout_disable_topics_generation"): disable_topics_ = rospy.get_param("/rosout_disable_topics_generation") else: disable_topics_ = False if not disable_topics_: topics = get_topic_manager().get_topics() else: topics = "" l = Log(level=level, name=str(rospy.names.get_caller_id()), msg=str(msg), topics=topics, file=fname, line=line, function=func) l.header.stamp = Time.now() _rosout_pub.publish(l) finally: _in_rosout = False except Exception as e: #traceback.print_exc() # don't use logerr in this case as that is recursive here logger = logging.getLogger("rospy.rosout") logger.error("Unable to report rosout: %s\n%s", e, traceback.format_exc()) return False
def define(self): self.period = rospy.Duration(1) self.state_define = { GoalStatus.ACTIVE: 'ACTIVE: TASK goal is currently being processed by the server, PLEASE WAIT for SUCCEEDED', GoalStatus.SUCCEEDED: 'SUCCEEDED: TASK goal was achieved successfully by the server, PLEASE SEND A NEW GOAL' } self.error_state_define = { GoalStatus.PENDING: 'PENDING: TASK goal has yet to be processed by the server, PLEASE WAIT', GoalStatus.PREEMPTED: 'PREEMPTED: TASK goal received a cancel request after it started executing and has since completed its execution, PLEASE SEND A NEW GOAL', GoalStatus.ABORTED: 'ABORTED: TASK goal was aborted during execution by the server due to some failure, PLEASE SEND A NEW GOAL', GoalStatus.REJECTED: 'REJECTED: TASK goal was rejected by the server without being processed, because the goal was unattainable or invalid, PLEASE SEND A NEW GOAL', GoalStatus.PREEMPTING: 'PREEMPTING: TASK goal received a cancel request after it started executing and has not yet completed execution, PLEASE SEND A NEW GOAL', GoalStatus.RECALLING: 'RECALLING: TASK goal received a cancel request before it started executing, but the server has not yet confirmed that the goal is canceled, PLEASE SEND A NEW GOAL', GoalStatus.RECALLED: 'RECALLED: TASK goal received a cancel request before it started executing and was successfully cancelled, PLEASE SEND A NEW GOAL', GoalStatus.LOST: 'LOST: TASK is determineed that a goal is LOST. This should not be sent over the wire by an server, PLEASE SEND A NEW GOAL' } self.last_position = Point() self.current_position = Point() self.move_base = actionlib.SimpleActionClient('move_base', MoveBaseAction) self.move_base.wait_for_server() self.log_info = Log() self.current_odom = PoseWithCovarianceStamped()
def __init__(self, filename, function, line, name, level, msg): self.msg = msg self.log = Log() self.log.level = level self.log.name = name self.log.file = '/home/tallest/workspaces/gir/src/' + filename self.log.function = function
def test_insert_log_msg(self): msg = 'test' log_msg = Log(msg=msg) self.model.insert_log_msg(log_msg) self.assertEqual(self.model.rowCount(), 1) index = self.model.createIndex(0, 1) self.assertEqual(self.model.data(index), msg)
def _rosout(level, msg, fname, line, func): global _in_rosout try: if _rosout_pub is not None: # protect against infinite recursion if not _in_rosout: try: _in_rosout = True msg = str(msg) # check parameter server/cache for omit_topics flag # the same parameter is checked in rosout_appender.cpp for the same purpose disable_topics_ = rospy.get_param_cached( "/rosout_disable_topics_generation", False) # if not disable_topics_: # topics = get_topic_manager().get_topics() # else: # topics = "" ros_master_uri = "" ros_ip = "" ros_hostname = "" if "ROS_MASTER_URI" in os.environ: ros_master_uri = os.environ["ROS_MASTER_URI"] if "ROS_IP" in os.environ: ros_ip = os.environ["ROS_IP"] if "ROS_HOSTNAME" in os.environ: ros_hostname = os.environ["ROS_HOSTNAME"] l = Log( level=level, name=str(rospy.names.get_caller_id()), msg=str(msg), # topics=topics, file=fname, line=line, function=func, username=getpass.getuser(), ros_master_uri=ros_master_uri, ros_ip=ros_ip, ros_hostname=ros_hostname, ) l.header.stamp = Time.now() _rosout_pub.publish(l) finally: _in_rosout = False except Exception as e: # traceback.print_exc() # don't use logerr in this case as that is recursive here logger = logging.getLogger("rospy.rosout") logger.error("Unable to report rosout: %s\n%s", e, traceback.format_exc()) return False
def map_log(values): """ Map the values generated with the hypothesis-ros log strategy to a rospy header type. """ if not isinstance(values, _Log): raise TypeError('Wrong type. Use appropriate hypothesis-ros type.') ros_log = Log() ros_log.header = values.header ros_log.level = values.level ros_log.name = values.name ros_log.msg = values.msg ros_log.file = values.file ros_log.function = values.function ros_log.topics = values.topics return ros_log
def onMessageCallback(msg): """ Given a NAOqi dict message, publish it in /rosout :param msg: dict corresponding to a NAOqi log message """ file, function, line = msg['source'].split(':') if line: line = int(line) # adapt the category to what a topic is (kindof). l = Log(level=LEVELS[msg['level']], name=str(msg['category']), msg=msg['message'], file=file, line=line, function=function) l.header.stamp = rospy.Time(msg['timestamp']['tv_sec'], msg['timestamp']['tv_usec']) ROSOUT_PUB.publish(l)
def emit(self, record: logging.LogRecord) -> None: try: node_ = node.get() rosout_logger.get().publish( Log( level=level_map[record.levelno], name=node_.full_name, msg=self.format(record), file=record.filename, line=record.lineno, function=record.funcName, header=Header(stamp=node_.get_time()), )) except LookupError: pass
def emit(self, record): if record.levelname in roslevel: level = roslevel[record.levelname] else: level = 2 # Default to 'INFO'. Should be improved to default to closest 'symbolic' level log = Log(level = level, name = record.name, msg = record.msg, file = record.filename, function = record.funcName, line = record.lineno) log.header.stamp = rospy.rostime.Time.now() self.pub.publish(log)
def test_get_topic_class(self): import rostopic self.assertEquals((None, None, None), rostopic.get_topic_class('/fake')) from rosgraph_msgs.msg import Log c, n, f = rostopic.get_topic_class('/rosout') self.assertEquals(Log, c) self.assertEquals('/rosout', n) self.assert_(f is None) c, n, f = rostopic.get_topic_class('/rosout/name') self.assertEquals(c, Log) self.assertEquals('/rosout', n) self.failIf(f is None) self.assertEquals("bob", f(Log(name="bob")))
def test_get_topic_type(self): import rostopic self.assertEquals((None, None, None), rostopic.get_topic_type('/fake', blocking=False)) t, n, f = rostopic.get_topic_type('/rosout', blocking=False) self.assertEquals('rosgraph_msgs/Log', t) self.assertEquals('/rosout', n) self.assert_(f is None) t, n, f = rostopic.get_topic_type('/rosout/name', blocking=False) self.assertEquals('rosgraph_msgs/Log', t) self.assertEquals('/rosout', n) self.failIf(f is None) from rosgraph_msgs.msg import Log self.assertEquals("bob", f(Log(name="bob")))
def __init__(self, topic = "/rosout"): logging.Handler.__init__(self) rospy.sleep(0.5) # wait a bit to make sure our ROS node is up self.pub = rospy.Publisher(topic, Log) self.log = Log() self.level = logging.DEBUG self.log.level = 2 self.log.name = "pyrobots logger" self.log.msg = "Welcome in pyRobots" self.log.file = "" self.log.function = "" self.log.line = 0 self.log.header.stamp = rospy.rostime.Time.now() self.pub.publish(self.log)
def rosout_callback(self, rosout_data): if rosout_data.level == Log().ERROR: if rosout_data.name == str("/move_base"): self.obj_error = True print str(rosout_data.msg)
def test_fuzz_log_message(self, header): log = Log() log.header = header self.pub.publish(log)
def main(): rospy.init_node("test") pub = Publisher(".+", queue_size=1) pub.publish(Log(msg="this is test message"))
def test_create_from_error_log_msg(self): msg = Log() msg.level = Log.ERROR entry = Entry.from_ros_msg(msg) self.assertTrue(entry.is_error)
def test_create_from_fatal_log_msg(self): msg = Log() msg.level = Log.FATAL entry = Entry.from_ros_msg(msg) self.assertTrue(entry.is_error)
def setUp(self): self.filter_map = FilterMap() self.log_msg = Log()
def handle_message(data): log = Log() log = data check_rosout(log)