diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fbfdb883..72d14b04 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,13 +22,13 @@ jobs: fetch-depth: 0 - name: Install pip - run: sudo apt-get install -y python3-pip + run: sudo apt-get install -y python3-pip pipx - name: Check style run: | - python3 -m pip install pycodestyle - export PATH=$PATH:$HOME/.local/bin - pycodestyle --max-line-length=100 examples/* + pipx run ruff format --check --line-length=100 examples + pipx run ruff check --select=ASYNC,RUF006,E,F --line-length=100 examples + pipx run codespell . - name: Install prerequisites run: | diff --git a/examples/camera.py b/examples/camera.py index a6b224b3..e5e3dae4 100755 --- a/examples/camera.py +++ b/examples/camera.py @@ -17,7 +17,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print_mode_task = asyncio.ensure_future(print_mode(drone)) diff --git a/examples/camera_params.py b/examples/camera_params.py index 50b6ed88..0c4ef0e3 100755 --- a/examples/camera_params.py +++ b/examples/camera_params.py @@ -24,20 +24,22 @@ async def run(): drone = System() await drone.connect(system_address="udpin://0.0.0.0:14540") - asyncio.ensure_future(observe_current_settings(drone)) - asyncio.ensure_future(observe_camera_mode(drone)) - asyncio.ensure_future(observe_possible_setting_options(drone)) + _tasks = [ + asyncio.create_task(observe_current_settings(drone)), + asyncio.create_task(observe_camera_mode(drone)), + asyncio.create_task(observe_possible_setting_options(drone)), + ] while True: entered_input = await ainput(usage_str) if entered_input == "p": - print(f"\n=== Current settings ===\n") + print("\n=== Current settings ===\n") print_current_settings() elif entered_input == "m": - print(f"\n=== Possible modes ===\n") - print(f"1. PHOTO") - print(f"2. VIDEO") + print("\n=== Possible modes ===\n") + print("1. PHOTO") + print("2. VIDEO") try: index_mode = await make_user_choose_camera_mode() @@ -54,11 +56,11 @@ async def run(): try: await drone.camera.set_mode(chosen_mode) - print(f" --> Succeeded") + print(" --> Succeeded") except CameraError as error: print(f" --> Failed with code: {error._result.result_str}") elif entered_input == "s": - print(f"\n=== Possible settings ===\n") + print("\n=== Possible settings ===\n") print_possible_settings(possible_setting_options) try: @@ -70,10 +72,10 @@ async def run(): selected_setting = possible_setting_options[index_setting - 1] possible_options = selected_setting.options - print(f"\n=== Available options ===") + print("\n=== Available options ===") print(f"Setting: {selected_setting.setting_id}") if not selected_setting.is_range: - print(f"Options:") + print("Options:") try: print_possible_options(possible_options) index_option = await make_user_choose_option(possible_options) @@ -94,9 +96,7 @@ async def run(): continue else: try: - selected_value = await make_user_choose_option_range( - possible_options - ) + selected_value = await make_user_choose_option_range(possible_options) print(f"Setting {selected_setting.setting_id} to {selected_value}!") setting = Setting( @@ -111,7 +111,7 @@ async def run(): try: await drone.camera.set_setting(setting) - print(f" --> Succeeded") + print(" --> Succeeded") except CameraError as error: print(f" --> Failed with code: {error._result.result_str}") else: @@ -148,7 +148,7 @@ def print_current_settings(): async def make_user_choose_camera_mode(): - index_mode_str = await ainput(f"\nWhich mode do you want? [1..2] >>> ") + index_mode_str = await ainput("\nWhich mode do you want? [1..2] >>> ") index_mode = int(index_mode_str) if index_mode < 1 or index_mode > 2: raise ValueError() @@ -185,9 +185,7 @@ def print_possible_options(possible_options): async def make_user_choose_option(possible_options): n_options = len(possible_options) - index_option_str = await ainput( - f"\nWhich option do you want? [1..{n_options}] >>> " - ) + index_option_str = await ainput(f"\nWhich option do you want? [1..{n_options}] >>> ") index_option = int(index_option_str) if index_option < 1 or index_option > n_options: diff --git a/examples/failure_injection.py b/examples/failure_injection.py index 8284e7c9..2346157d 100755 --- a/examples/failure_injection.py +++ b/examples/failure_injection.py @@ -13,7 +13,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/firmware_version.py b/examples/firmware_version.py index 08dd022b..30c5fa11 100755 --- a/examples/firmware_version.py +++ b/examples/firmware_version.py @@ -15,7 +15,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break info = await drone.info.get_version() diff --git a/examples/follow_me_example.py b/examples/follow_me_example.py index 048573a8..3ec69408 100755 --- a/examples/follow_me_example.py +++ b/examples/follow_me_example.py @@ -4,7 +4,7 @@ import asyncio from mavsdk import System -from mavsdk.follow_me import Config, FollowMeError, TargetLocation +from mavsdk.follow_me import Config, TargetLocation follow_height = 8.0 # in meters @@ -32,7 +32,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/ftp_download_file.py b/examples/ftp_download_file.py index 312af188..2bb78da0 100755 --- a/examples/ftp_download_file.py +++ b/examples/ftp_download_file.py @@ -11,7 +11,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break async for update in drone.ftp.download( diff --git a/examples/ftp_list_dir.py b/examples/ftp_list_dir.py index 21fa1473..23fac385 100755 --- a/examples/ftp_list_dir.py +++ b/examples/ftp_list_dir.py @@ -11,7 +11,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("directory list", await drone.ftp.list_directory("/")) diff --git a/examples/geofence.py b/examples/geofence.py index 557a4c77..6e10fc39 100755 --- a/examples/geofence.py +++ b/examples/geofence.py @@ -26,7 +26,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break # Fetch the home location coordinates, in order to set a boundary around diff --git a/examples/gimbal.py b/examples/gimbal.py index 5680e4c3..ab2ddff8 100755 --- a/examples/gimbal.py +++ b/examples/gimbal.py @@ -107,9 +107,7 @@ async def run(): # Set the gimbal to track a region of interest (lat, lon, altitude) # Units are degrees and meters MSL respectively print("Look at a ROI (region of interest) with gimbal ID", gimbal.gimbal_id) - await drone.gimbal.set_roi_location( - gimbal.gimbal_id, 47.39743832, 8.5463316, 488 - ) + await drone.gimbal.set_roi_location(gimbal.gimbal_id, 47.39743832, 8.5463316, 488) await asyncio.sleep(4) print("Back to forward again with gimbal ID", gimbal.gimbal_id) diff --git a/examples/goto.py b/examples/goto.py index e2088a30..c5e0a340 100755 --- a/examples/goto.py +++ b/examples/goto.py @@ -15,7 +15,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/gripper.py b/examples/gripper.py index ae78e682..a2dddcb9 100644 --- a/examples/gripper.py +++ b/examples/gripper.py @@ -11,15 +11,15 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break - print(f"-- Gripper Grab") + print("-- Gripper Grab") await drone.gripper.grab(instance=1) await asyncio.sleep(1) - print(f"-- Gripper Release") + print("-- Gripper Release") await drone.gripper.release(instance=1) while True: diff --git a/examples/highres_imu.py b/examples/highres_imu.py index dd129f6b..3cc343eb 100644 --- a/examples/highres_imu.py +++ b/examples/highres_imu.py @@ -23,7 +23,7 @@ async def get_imu_data(): print("Fetching IMU data...") async for imu in telemetry.imu(): # Print data in HIGHRES_IMU format - print(f"HIGHRES_IMU (105)") + print("HIGHRES_IMU (105)") print(f"Time (us): {imu.timestamp_us}") print(f"X Acceleration (m/s^2): {imu.acceleration_frd.forward_m_s2}") print(f"Y Acceleration (m/s^2): {imu.acceleration_frd.right_m_s2}") diff --git a/examples/logfile_download.py b/examples/logfile_download.py index da67c013..d6020b66 100755 --- a/examples/logfile_download.py +++ b/examples/logfile_download.py @@ -12,7 +12,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break entries = await get_entries(drone) diff --git a/examples/manual_control.py b/examples/manual_control.py index 4a1447c8..0cf7fa34 100755 --- a/examples/manual_control.py +++ b/examples/manual_control.py @@ -40,7 +40,7 @@ async def manual_controls(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break # Checking if Global Position Estimate is ok @@ -50,9 +50,7 @@ async def manual_controls(): break # set the manual control input after arming - await drone.manual_control.set_manual_control_input( - float(0), float(0), float(0.5), float(0) - ) + await drone.manual_control.set_manual_control_input(float(0), float(0), float(0.5), float(0)) # Arming the drone print("-- Arming") @@ -64,9 +62,7 @@ async def manual_controls(): await asyncio.sleep(5) # set the manual control input after arming - await drone.manual_control.set_manual_control_input( - float(0), float(0), float(0.5), float(0) - ) + await drone.manual_control.set_manual_control_input(float(0), float(0), float(0.5), float(0)) # start manual control print("-- Starting manual control") diff --git a/examples/mission.py b/examples/mission.py index 68016340..8b42298e 100755 --- a/examples/mission.py +++ b/examples/mission.py @@ -17,7 +17,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print_mission_progress_task = asyncio.ensure_future(print_mission_progress(drone)) diff --git a/examples/mission_import.py b/examples/mission_import.py index b693ca1d..26d01863 100755 --- a/examples/mission_import.py +++ b/examples/mission_import.py @@ -3,7 +3,6 @@ import asyncio from mavsdk import System -import mavsdk.mission_raw async def run(): @@ -13,15 +12,12 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break out = await drone.mission_raw.import_qgroundcontrol_mission("example-mission.plan") - print( - f"{len(out.mission_items)} mission items and" - f"{len(out.rally_items)} rally items imported." - ) + print(f"{len(out.mission_items)} mission items and{len(out.rally_items)} rally items imported.") await drone.mission_raw.upload_mission(out.mission_items) await drone.mission_raw.upload_rally_points(out.rally_items) diff --git a/examples/offboard_attitude.py b/examples/offboard_attitude.py index 9155a108..b1ca6258 100755 --- a/examples/offboard_attitude.py +++ b/examples/offboard_attitude.py @@ -20,7 +20,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/offboard_from_csv/offboard_from_csv.py b/examples/offboard_from_csv/offboard_from_csv.py index 6510f3d1..92877e9b 100644 --- a/examples/offboard_from_csv/offboard_from_csv.py +++ b/examples/offboard_from_csv/offboard_from_csv.py @@ -78,9 +78,11 @@ import asyncio import csv +import io +import anyio from mavsdk import System from mavsdk.offboard import PositionNedYaw, VelocityNedYaw -from mavsdk.offboard import AccelerationNed, OffboardError +from mavsdk.offboard import OffboardError from mavsdk.telemetry import LandedState @@ -143,27 +145,25 @@ async def run(): await drone.action.disarm() return - waypoints = [] - # Read data from the CSV file - with open("active.csv", newline="") as csvfile: - reader = csv.DictReader(csvfile) - for row in reader: - waypoints.append( - ( - float(row["t"]), - float(row["px"]), - float(row["py"]), - float(row["pz"]), - float(row["vx"]), - float(row["vy"]), - float(row["vz"]), - float(row["ax"]), - float(row["ay"]), - float(row["az"]), - int(row["mode"]), - ) - ) + async with await anyio.open_file("active.csv", "r", newline="") as csvfile: + content = await csvfile.read() + waypoints = [ + ( + float(row["t"]), + float(row["px"]), + float(row["py"]), + float(row["pz"]), + float(row["vx"]), + float(row["vy"]), + float(row["vz"]), + float(row["ax"]), + float(row["ay"]), + float(row["az"]), + int(row["mode"]), + ) + for row in csv.DictReader(io.StringIO(content)) + ] print("-- Performing trajectory") total_duration = waypoints[-1][0] @@ -178,14 +178,11 @@ async def run(): position = current_waypoint[1:4] velocity = current_waypoint[4:7] - acceleration = current_waypoint[7:10] + _acceleration = current_waypoint[7:10] # unused mode_code = current_waypoint[-1] if last_mode != mode_code: # Print the mode number and its description - print( - " Mode number: " + f"{mode_code}, " - f"Description: {mode_descriptions[mode_code]}" - ) + print(" Mode number: " + f"{mode_code}, Description: {mode_descriptions[mode_code]}") last_mode = mode_code # set_position_velocity_acceleration_ned is not yet available # in the default build for MAVSDK-Python Installation with pip3 diff --git a/examples/offboard_position_ned.py b/examples/offboard_position_ned.py index 8997dd8a..e7b470a9 100755 --- a/examples/offboard_position_ned.py +++ b/examples/offboard_position_ned.py @@ -27,7 +27,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/offboard_position_velocity_ned.py b/examples/offboard_position_velocity_ned.py index f9a7ce8b..a209d00b 100755 --- a/examples/offboard_position_velocity_ned.py +++ b/examples/offboard_position_velocity_ned.py @@ -13,7 +13,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") @@ -44,7 +44,7 @@ async def print_z_velocity(drone): async for odom in drone.telemetry.position_velocity_ned(): print(f"{odom.velocity.north_m_s} {odom.velocity.down_m_s}") - asyncio.ensure_future(print_z_velocity(drone)) + _tasks = {asyncio.create_task(print_z_velocity(drone))} print("-- Go 0m North, 0m East, -10m Down within local coordinate system") await drone.offboard.set_position_velocity_ned( diff --git a/examples/offboard_velocity_body.py b/examples/offboard_velocity_body.py index c3ef1ce9..b2519714 100755 --- a/examples/offboard_velocity_body.py +++ b/examples/offboard_velocity_body.py @@ -16,7 +16,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/offboard_velocity_ned.py b/examples/offboard_velocity_ned.py index 2196f976..be7d88ef 100755 --- a/examples/offboard_velocity_ned.py +++ b/examples/offboard_velocity_ned.py @@ -16,7 +16,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/rtk_base_ublox.py b/examples/rtk_base_ublox.py index a2069238..abb21c4f 100755 --- a/examples/rtk_base_ublox.py +++ b/examples/rtk_base_ublox.py @@ -33,9 +33,7 @@ def read_packet(self, dev, preamble): if self.debug: print( - "UBX class id {} and message id {}".format( - ord(ubx_class_id), ord(ubx_message_id) - ) + "UBX class id {} and message id {}".format(ord(ubx_class_id), ord(ubx_message_id)) ) # The ubx message in full_data could be parsed with pyubx2.UBXReader @@ -86,7 +84,7 @@ def read_packet(self, dev, preamble): async def run(): # Init the drone. # Note that connecting directly to a drone is not very useful here. - # You probably want to set-up some MAVLink message routing inbetween + # You probably want to set-up some MAVLink message routing in-between # this script and the drone. # Good candidates for this are # 1. mavlink-router (https://github.com/mavlink-router/mavlink-router) @@ -97,11 +95,14 @@ async def run(): await drone.connect() # Start the tasks - asyncio.ensure_future(print_gps_info(drone)) - asyncio.ensure_future(send_rtcm(drone)) + _tasks = [ + asyncio.create_task(print_gps_info(drone)), + asyncio.create_task(send_rtcm(drone)), + ] - while True: - await asyncio.sleep(1) + # Keep the program running indefinitely + exit_event = asyncio.Event() + await exit_event.wait() async def print_gps_info(drone): @@ -139,9 +140,7 @@ async def send_rtcm(drone): # Convert the rtcm data to a base64, # In MAVSDK v3 the rtcm data is expected # to be base64 encoded string . - base64_rtcm_data = base64.b64encode(rtcm_correction_data).decode( - "utf-8" - ) + base64_rtcm_data = base64.b64encode(rtcm_correction_data).decode("utf-8") # Send RTCM await drone.rtk.send_rtcm_data(rtk.RtcmData(base64_rtcm_data)) @@ -167,7 +166,7 @@ async def send_rtcm(drone): # It's recommended to disable NMEA messages, so this script # does not have to differentiate between 3 kinds of messages - nmea = ublox.readline() + # nmea = ublox.readline() # print(nmea) pass diff --git a/examples/send_status_message.py b/examples/send_status_message.py index 50e4e9ed..dd4086f1 100755 --- a/examples/send_status_message.py +++ b/examples/send_status_message.py @@ -23,10 +23,8 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") - await drone.server_utility.send_status_text( - StatusTextType.INFO, "Hello world!" - ) + print("-- Connected to drone!") + await drone.server_utility.send_status_text(StatusTextType.INFO, "Hello world!") break diff --git a/examples/shell.py b/examples/shell.py index 15673bb0..5d7e0a26 100755 --- a/examples/shell.py +++ b/examples/shell.py @@ -5,17 +5,19 @@ from mavsdk import System +send_tasks = set() + async def run(): drone = System() await drone.connect(system_address="udpin://0.0.0.0:14540") - asyncio.ensure_future(observe_shell(drone)) + _tasks = {asyncio.create_task(observe_shell(drone))} print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break asyncio.get_event_loop().add_reader(sys.stdin, got_stdin_data, drone) @@ -28,7 +30,7 @@ async def observe_shell(drone): def got_stdin_data(drone): - asyncio.ensure_future(send(drone, sys.stdin.readline())) + send_tasks.add(asyncio.create_task(send(drone, sys.stdin.readline()))) async def send(drone, command): @@ -36,9 +38,7 @@ async def send(drone, command): if __name__ == "__main__": - asyncio.ensure_future(run()) - try: - asyncio.get_event_loop().run_forever() + asyncio.run(run()) except KeyboardInterrupt: pass diff --git a/examples/takeoff_and_land.py b/examples/takeoff_and_land.py index 712a9179..19a19eb4 100755 --- a/examples/takeoff_and_land.py +++ b/examples/takeoff_and_land.py @@ -18,7 +18,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break print("Waiting for drone to have a global position estimate...") diff --git a/examples/telemetry.py b/examples/telemetry.py index 0e271e08..dd973b21 100755 --- a/examples/telemetry.py +++ b/examples/telemetry.py @@ -15,13 +15,16 @@ async def run(): await drone.connect(system_address="udpin://0.0.0.0:14540") # Start the tasks - asyncio.ensure_future(print_battery(drone)) - asyncio.ensure_future(print_gps_info(drone)) - asyncio.ensure_future(print_in_air(drone)) - asyncio.ensure_future(print_position(drone)) - - while True: - await asyncio.sleep(1) + _tasks = [ + asyncio.create_task(print_battery(drone)), + asyncio.create_task(print_gps_info(drone)), + asyncio.create_task(print_in_air(drone)), + asyncio.create_task(print_position(drone)), + ] + + # Keep the program running indefinitely + exit_event = asyncio.Event() + await exit_event.wait() async def print_battery(drone): diff --git a/examples/telemetry_flight_mode.py b/examples/telemetry_flight_mode.py index 4fff2249..42ba1f3e 100755 --- a/examples/telemetry_flight_mode.py +++ b/examples/telemetry_flight_mode.py @@ -11,7 +11,7 @@ async def print_flight_mode(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break async for flight_mode in drone.telemetry.flight_mode(): diff --git a/examples/telemetry_is_armed_is_in_air.py b/examples/telemetry_is_armed_is_in_air.py index deccf67c..ce313877 100755 --- a/examples/telemetry_is_armed_is_in_air.py +++ b/examples/telemetry_is_armed_is_in_air.py @@ -8,11 +8,13 @@ async def run(): drone = System() await drone.connect(system_address="udpin://0.0.0.0:14540") - asyncio.ensure_future(print_is_armed(drone)) - asyncio.ensure_future(print_is_in_air(drone)) + tasks = [] + tasks.append(asyncio.create_task(print_is_armed(drone))) + tasks.append(asyncio.create_task(print_is_in_air(drone))) - while True: - await asyncio.sleep(1) + # Keep the program running indefinitely + exit_event = asyncio.Event() + await exit_event.wait() async def print_is_armed(drone): diff --git a/examples/telemetry_status_text.py b/examples/telemetry_status_text.py index ecdf15d5..b888dc28 100755 --- a/examples/telemetry_status_text.py +++ b/examples/telemetry_status_text.py @@ -11,7 +11,7 @@ async def print_status_text(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break async for status_text in drone.telemetry.status_text(): diff --git a/examples/telemetry_takeoff_and_land.py b/examples/telemetry_takeoff_and_land.py index e68daeaf..6a2290f6 100755 --- a/examples/telemetry_takeoff_and_land.py +++ b/examples/telemetry_takeoff_and_land.py @@ -31,7 +31,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break # Start parallel tasks diff --git a/examples/transponder.py b/examples/transponder.py index a1d454f7..d7e5fbc3 100755 --- a/examples/transponder.py +++ b/examples/transponder.py @@ -10,7 +10,7 @@ async def run(): await drone.connect() # Start the tasks - asyncio.ensure_future(print_transponders(drone)) + _tasks = {asyncio.create_task(print_transponders(drone))} # Runs the event loop until the program is canceled with e.g. CTRL-C while True: diff --git a/examples/tune.py b/examples/tune.py index 093dd886..89cacdf5 100755 --- a/examples/tune.py +++ b/examples/tune.py @@ -2,7 +2,7 @@ import asyncio from mavsdk import System -from mavsdk.tune import SongElement, TuneDescription, TuneError +from mavsdk.tune import SongElement, TuneDescription async def run(): @@ -12,7 +12,7 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break song_elements = [] diff --git a/examples/upload_params.py b/examples/upload_params.py index eab79708..ba33d103 100755 --- a/examples/upload_params.py +++ b/examples/upload_params.py @@ -2,18 +2,15 @@ import asyncio import argparse +import anyio from mavsdk import System from tqdm import tqdm def main(): parser = argparse.ArgumentParser() - parser.add_argument( - "connection", help="Connection string (e.g. udpin://0.0.0.0:14540)" - ) - parser.add_argument( - "param_file", help="Param file to be uploaded with .params format" - ) + parser.add_argument("connection", help="Connection string (e.g. udpin://0.0.0.0:14540)") + parser.add_argument("param_file", help="Param file to be uploaded with .params format") args = parser.parse_args() @@ -39,18 +36,20 @@ async def set_params(args): else: break - with open(args.param_file, "r") as param_file: + async with await anyio.open_file(args.param_file, "r") as param_file: print("Uploading Parameters... Please do not arm the vehicle!") - for line in tqdm(param_file, unit="lines"): + contents = await param_file.read() + lines = contents.splitlines() + for line in tqdm(lines, unit="lines"): if line.startswith("#"): continue columns = line.strip().split("\t") - vehicle_id = columns[0] - component_id = columns[1] + _vehicle_id = columns[0] + _component_id = columns[1] name = columns[2] value = columns[3] - type = columns[4] + _type = columns[4] if name in int_param_names: await drone.param.set_param_int(name, int(value)) elif name in float_param_names: diff --git a/examples/winch.py b/examples/winch.py index b655b949..5e40ec9d 100644 --- a/examples/winch.py +++ b/examples/winch.py @@ -11,10 +11,10 @@ async def run(): print("Waiting for drone to connect...") async for state in drone.core.connection_state(): if state.is_connected: - print(f"-- Connected to drone!") + print("-- Connected to drone!") break - print(f"-- Winch action: load payload") + print("-- Winch action: load payload") await drone.winch.load_payload(instance=1) while True: diff --git a/mavsdk/__init__.py b/mavsdk/__init__.py index 726b17f4..d8b9bb86 100644 --- a/mavsdk/__init__.py +++ b/mavsdk/__init__.py @@ -15,7 +15,7 @@ # Do asyncio specific initialization try: # Try to import uvloop, provides _MUCH_ better performance compared to the - # standart unix selector event loop + # standard unix selector event loop import uvloop asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) diff --git a/other/docker/testing/Dockerfile b/other/docker/testing/Dockerfile index 6b1a79c1..a7b2aba5 100644 --- a/other/docker/testing/Dockerfile +++ b/other/docker/testing/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:18.04 -# Prefere local python binaries over the distributed ones +# Prefer local python binaries over the distributed ones ENV PATH /usr/local/bin:$PATH # Needed for Python 3 diff --git a/setup.cfg b/setup.cfg index 49b8f1df..890ce7ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,6 @@ license_file = LICENSE.txt [bdist_wheel] universal=0 + +[codespell] +ignore-words-list = NED,PositionNed