本文整理汇总了Python中dronekit.connect方法的典型用法代码示例。如果您正苦于以下问题:Python dronekit.connect方法的具体用法?Python dronekit.connect怎么用?Python dronekit.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dronekit
的用法示例。
在下文中一共展示了dronekit.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_timeout
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_timeout(connpath):
v = connect(connpath, wait_ready=True)
value = v.parameters['THR_MIN']
assert_equals(type(value), float)
start = current_milli_time()
v.parameters['THR_MIN'] = value + 10
end = current_milli_time()
newvalue = v.parameters['THR_MIN']
assert_equals(type(newvalue), float)
assert_equals(newvalue, value + 10)
# Checks that time to set parameter was <1s
# see https://github.com/dronekit/dronekit-python/issues/12
assert end - start < 1000, 'time to set parameter was %s, over 1s' % (end - start, )
v.close()
示例2: test_accelerometer_calibration
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_accelerometer_calibration(connpath):
"""Request accelerometer calibration, and check for the COMMAND_ACK."""
vehicle = connect(connpath, wait_ready=True)
# The calibration is expected to fail because in the SITL we don't tilt the Vehicle.
# We just check that the command isn't denied or unsupported.
with assert_command_ack(
vehicle,
mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION,
timeout=30,
ack_result=mavutil.mavlink.MAV_RESULT_FAILED,
):
vehicle.send_calibrate_accelerometer(simple=False)
vehicle.close()
示例3: test_timeout_empty
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_timeout_empty():
# Create a dummy server.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('127.0.0.1', 5760))
s.listen(1)
try:
# Connect with timeout of 10s.
vehicle = connect('tcp:127.0.0.1:5760', wait_ready=True, heartbeat_timeout=20)
vehicle.close()
# Should not pass
assert False
except:
pass
示例4: vehicle_connect
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def vehicle_connect():
global vehicle, is_vehicle_connected
try:
vehicle = connect(connection_string, wait_ready = True, baud = connection_baudrate, source_system = 1)
except:
print('Connection error! Retrying...')
sleep(1)
if vehicle == None:
is_vehicle_connected = False
return False
else:
is_vehicle_connected = True
return True
######################################################
## Functions - D4xx cameras ##
######################################################
示例5: vehicle_connect
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def vehicle_connect():
global vehicle, is_vehicle_connected
try:
vehicle = connect(connection_string, wait_ready = True, baud = connection_baudrate, source_system = 1)
except:
print('Connection error! Retrying...')
sleep(1)
if vehicle == None:
is_vehicle_connected = False
return False
else:
is_vehicle_connected = True
return True
# List of notification events: https://github.com/IntelRealSense/librealsense/blob/development/include/librealsense2/h/rs_types.h
# List of notification API: https://github.com/IntelRealSense/librealsense/blob/development/common/notifications.cpp
示例6: vehicle_connect
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def vehicle_connect():
global vehicle
try:
vehicle = connect(connection_string, wait_ready = True, baud = connection_baudrate, source_system = 1)
except KeyboardInterrupt:
pipe.stop()
print("INFO: Exiting")
sys.exit()
except:
print('Connection error! Retrying...')
if vehicle == None:
return False
else:
return True
# Connect to the T265 through USB 3.0 (must be USB 3.0 since image streams are being consumed)
示例7: main
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def main(top_block_cls=control_gui, options=None):
from distutils.version import StrictVersion
if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
style = gr.prefs().get_string('qtgui', 'style', 'raster')
Qt.QApplication.setGraphicsSystem(style)
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls()
#connection_string = tb.sitl.connection_string()
#print connection_string
tb.connect_to_vehicle('udp:127.0.0.1:14562')
tb.start()
tb.show()
# Connect to the Vehicle.
#print("Connecting to vehicle on: %s" % (connection_string,))
#vehicle = connect(connection_string, wait_ready=True)
def quitting():
tb.stop()
tb.wait()
qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
qapp.exec_()
示例8: closeEvent
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def closeEvent(self, event):
self.settings = Qt.QSettings("GNU Radio", "control_gui")
self.settings.setValue("geometry", self.saveGeometry())
event.accept()
#def connect_to_vehicle(self,connection_string,baud_rate):
# self.connection_string=connection_string
# self.baud_rate=baud_rate
# print("Connecting to vehicle on: %s" % (self.connection_string,))
#self.vehicle = connect(self.connection_string,baud=57600, wait_ready='gps_0')
# self.mavlink_connection = mavutil.mavlink_connection(self.connection, baud=self.baud_rate)
# print("connected")
#def send_rc(master, data):
# for i in xrange(1):
# self.mavlink_connection.mav.rc_channels_override_encode (
# master.target_system, master.target_component, *data)
# print ("sending rc: %s"%data)
示例9: main
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def main(top_block_cls=control_gui, options=None):
from distutils.version import StrictVersion
if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
style = gr.prefs().get_string('qtgui', 'style', 'raster')
Qt.QApplication.setGraphicsSystem(style)
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls()
#connection_string = tb.sitl.connection_string()
#print connection_string
#tb.connect_to_vehicle('udp:127.0.0.1:14552',baud_rate)
tb.zmq_setup('tcp://127.0.0.1:14000')
tb.start()
tb.show()
# Connect to the Vehicle.
#print("Connecting to vehicle on: %s" % (connection_string,))
#vehicle = connect(connection_string, wait_ready=True)
def quitting():
tb.stop()
tb.wait()
qapp.connect(qapp, Qt.SIGNAL("aboutToQuit()"), quitting)
qapp.exec_()
示例10: test_reboot
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_reboot(connpath):
"""Tries to reboot the vehicle, and checks that the autopilot ACKs the command."""
vehicle = connect(connpath, wait_ready=True)
reboot_acks = []
def on_ack(self, name, message):
if message.command == 246: # reboot/shutdown
reboot_acks.append(message)
vehicle.add_message_listener('COMMAND_ACK', on_ack)
vehicle.reboot()
time.sleep(0.5)
vehicle.remove_message_listener('COMMAND_ACK', on_ack)
assert_equal(1, len(reboot_acks)) # one and only one ACK
assert_equal(246, reboot_acks[0].command) # for the correct command
assert_equal(0, reboot_acks[0].result) # the result must be successful
vehicle.close()
示例11: test_mavlink
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_mavlink(connpath):
vehicle = connect(connpath, wait_ready=True)
out = MAVConnection('udpin:localhost:15668')
vehicle._handler.pipe(out)
out.start()
vehicle2 = connect('udpout:localhost:15668', wait_ready=True)
result = {'success': False}
@vehicle2.on_attribute('location')
def callback(*args):
result['success'] = True
i = 20
while not result['success'] and i > 0:
time.sleep(1)
i -= 1
assert result['success']
vehicle2.close()
vehicle.close()
示例12: test_115
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_115(connpath):
"""Provide a custom status_printer function to the Vehicle and check that
the autopilot messages are correctly logged.
"""
logging_check = {'ok': False}
def errprinter_fn(msg):
if isinstance(msg, str) and "APM:Copter" in msg:
logging_check['ok'] = True
vehicle = connect(connpath, wait_ready=False, status_printer=errprinter_fn)
i = 5
while not logging_check['ok'] and i > 0:
time.sleep(1)
i -= 1
assert_true(logging_check['ok'])
vehicle.close()
# Cleanup the logger
autopilotLogger = logging.getLogger('autopilot')
autopilotLogger.removeHandler(autopilotLogger.handlers[0])
示例13: test_parameters
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_parameters(connpath):
vehicle = connect(connpath)
# When called on startup, parameter (may!) be none.
# assert_equals(vehicle.parameters.get('THR_MIN', wait_ready=False), None)
# With wait_ready, it should not be none.
assert_not_equals(vehicle.parameters.get('THR_MIN', wait_ready=True), None)
try:
assert_not_equals(vehicle.parameters['THR_MIN'], None)
except:
assert False
# Garbage value after all parameters are downloaded should be None.
assert_equals(vehicle.parameters.get('xXx_extreme_garbage_value_xXx', wait_ready=True), None)
vehicle.close()
示例14: test_set_home
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_set_home(connpath):
vehicle = connect(connpath, wait_ready=True)
# Wait for home position to be real and not 0, 0, 0
# once we request it via cmds.download()
time.sleep(10)
vehicle.commands.download()
vehicle.commands.wait_ready()
assert_not_equals(vehicle.home_location, None)
# Note: If the GPS values differ heavily from EKF values, this command
# will basically fail silently. This GPS coordinate is tailored for that
# the with_sitl initializer uses to not fail.
vehicle.home_location = LocationGlobal(-35, 149, 600)
vehicle.commands.download()
vehicle.commands.wait_ready()
assert_equals(vehicle.home_location.lat, -35)
assert_equals(vehicle.home_location.lon, 149)
assert_equals(vehicle.home_location.alt, 600)
vehicle.close()
示例15: test_227
# 需要导入模块: import dronekit [as 别名]
# 或者: from dronekit import connect [as 别名]
def test_227(connpath):
"""
Tests race condition when downloading items
"""
vehicle = connect(connpath, wait_ready=True)
def assert_commands(count):
vehicle.commands.download()
vehicle.commands.wait_ready()
assert_equals(len(vehicle.commands), count)
assert_commands(0)
vehicle.commands.add(Command(0, 0, 0, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT, 0, 0, 0, 0, 0, 0, 10, 10,
10))
vehicle.flush() # Send commands
assert_commands(1)
vehicle.close()