utils.py
Go to the documentation of this file.
1 # -*- coding: utf-8 -*-
2 # vim:set ts=4 sw=4 et:
3 #
4 # Copyright 2014 Vladimir Ermakov.
5 #
6 # This file is part of the mavros package and subject to the license terms
7 # in the top-level LICENSE file of the mavros repository.
8 # https://github.com/mavlink/mavros/tree/master/LICENSE.md
9 
10 from __future__ import print_function
11 
12 import os
13 import sys
14 
15 import rospy
16 import mavros
17 import threading
18 
19 
20 def print_if(cond, *args, **kvargs):
21  if cond:
22  print(*args, **kvargs)
23 
24 
25 def fault(*args, **kvargs):
26  kvargs['file'] = sys.stderr
27  print(*args, **kvargs)
28  sys.exit(1)
29 
30 
31 def wait_fcu_connection(timeout=None):
32  """
33  Wait until establishing FCU connection
34  """
35  from mavros_msgs.msg import State
36  try:
37  msg = rospy.wait_for_message(mavros.get_topic('state'), State, timeout)
38  if msg.connected:
39  return True
40  except rospy.ROSException as e:
41  return False
42 
43  connected = threading.Event()
44  def handler(msg):
45  if msg.connected:
46  connected.set()
47 
48  sub = rospy.Subscriber(
49  mavros.get_topic('state'),
50  State,
51  handler
52  )
53 
54  return connected.wait(timeout)
def get_topic(args)
Definition: __init__.py:49
def wait_fcu_connection(timeout=None)
Definition: utils.py:31
def print_if(cond, args, kvargs)
Definition: utils.py:20
def fault(args, kvargs)
Definition: utils.py:25


mavros
Author(s): Vladimir Ermakov
autogenerated on Mon Jul 8 2019 03:20:11