-
Notifications
You must be signed in to change notification settings - Fork 87
One parameter world python client #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """ | ||
| Loads the existing world from saved config and flies a drone. | ||
| """ | ||
|
|
||
| import asyncio | ||
| from projectairsim import ProjectAirSimClient, Drone, World | ||
| from projectairsim.utils import projectairsim_log | ||
| from projectairsim.image_utils import ImageDisplay | ||
|
|
||
| CONFIG_PATH = "./world_config.json" | ||
|
|
||
| async def main(): | ||
| client = ProjectAirSimClient() | ||
| image_display = ImageDisplay() | ||
|
|
||
| try: | ||
| client.connect() | ||
| world = World(client) # sin argumentos | ||
| drone = Drone(client, world, "Drone1") | ||
|
|
||
| # --- Set up image windows --- | ||
| chase_cam_window = "ChaseCam" | ||
| image_display.add_chase_cam(chase_cam_window) | ||
| client.subscribe( | ||
| drone.sensors["Chase"]["scene_camera"], | ||
| lambda _, chase: image_display.receive(chase, chase_cam_window), | ||
| ) | ||
|
|
||
| rgb_name = "RGB-Image" | ||
| image_display.add_image(rgb_name, subwin_idx=0) | ||
| client.subscribe( | ||
| drone.sensors["DownCamera"]["scene_camera"], | ||
| lambda _, rgb: image_display.receive(rgb, rgb_name), | ||
| ) | ||
|
|
||
| depth_name = "Depth-Image" | ||
| image_display.add_image(depth_name, subwin_idx=2) | ||
| client.subscribe( | ||
| drone.sensors["DownCamera"]["depth_camera"], | ||
| lambda _, depth: image_display.receive(depth, depth_name), | ||
| ) | ||
|
|
||
| image_display.start() | ||
|
|
||
| # --- Flight demo --- | ||
| drone.enable_api_control() | ||
| drone.arm() | ||
|
|
||
| await (await drone.takeoff_async()) | ||
| await (await drone.move_by_velocity_async(v_north=0.0, v_east=0.0, v_down=-1.0, duration=4.0)) | ||
| await (await drone.move_by_velocity_async(v_north=0.0, v_east=0.0, v_down=1.0, duration=4.0)) | ||
| await (await drone.land_async()) | ||
|
|
||
| drone.disarm() | ||
| drone.disable_api_control() | ||
|
|
||
| except Exception as err: | ||
| projectairsim_log().error(f"❌ Exception: {err}", exc_info=True) | ||
| finally: | ||
| client.disconnect() | ||
| image_display.stop() | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """ | ||
| Creates the world and saves its configuration to shared volume. | ||
| """ | ||
|
|
||
| import asyncio | ||
| import os | ||
| from projectairsim import ProjectAirSimClient, World | ||
| from projectairsim.utils import projectairsim_log | ||
|
|
||
| CONFIG_PATH = "./world_config.json" | ||
|
|
||
| async def main(): | ||
| client = ProjectAirSimClient() | ||
|
|
||
| try: | ||
| client.connect() | ||
| world = World(client, "scene_basic_drone.jsonc", delay_after_load_sec=2) | ||
| projectairsim_log().info(f"✅ World created") | ||
| except Exception as err: | ||
| projectairsim_log().error(f"❌ Exception: {err}", exc_info=True) | ||
| finally: | ||
| client.disconnect() | ||
|
|
||
| if __name__ == "__main__": | ||
| asyncio.run(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
translate comment