{"id":680,"date":"2021-11-10T17:08:24","date_gmt":"2021-11-10T15:08:24","guid":{"rendered":"https:\/\/med.upc.edu\/team4-2021\/?page_id=680"},"modified":"2021-11-15T17:17:57","modified_gmt":"2021-11-15T15:17:57","slug":"activity-12","status":"publish","type":"page","link":"https:\/\/med.upc.edu\/team4-2021\/activity-12\/","title":{"rendered":"Activity 12"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">Objective<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Dynamic flight plans are flight plans that are decided in run time (during the flight) by an on-board computer, that can receive information from on-board devices (camera, sensors, etc.) and<br>change the course of action.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">Part 1<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Start with recording the drone&#8217;s information like altitude and heading.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The idea of the code is that: first thing, we need to find a way to &#8220;connect&#8221; to the drone so that we can access its information. Luckily, with the python package dronekit, we can easily connect to the simulation. The local simulation has an IP address that we can access. Later, determine whether the drone is armed, if so, record its information.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, start the simulation and let the drone fly. Then, run the program, we can notice some printings on the terminal, they&#8217;re what we need.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Dynamic flight planning with Python + Dronekit: example 1\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/JKUTOZ-tBP0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"653\" src=\"https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_heading_north-1024x653.png\" alt=\"\" class=\"wp-image-693\" srcset=\"https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_heading_north-1024x653.png 1024w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_heading_north-300x191.png 300w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_heading_north-768x490.png 768w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_heading_north.png 1516w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\">Part 2<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Can we define a drone plan in the mission planner and use any coding to do anything else? Yes!!.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following code defines how to arm and take off action<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def arm_and_takeoff(aTargetAltitude):\n    \"\"\"\n    Arms vehicle and fly to aTargetAltitude.\n    \"\"\"\n    print(\"Basic pre-arm checks\")\n    # Don't try to arm until autopilot is ready\n    while not vehicle.is_armable:\n        print(\" Waiting for vehicle to initialise...\")\n        time.sleep(1)\n    print(\"Arming motors\")\n    # Copter should arm in GUIDED mode\n    vehicle.mode = VehicleMode(\"GUIDED\")\n    vehicle.armed = True\n    # Confirm vehicle armed before attempting to take off\n    while not vehicle.armed:\n        print(\" Waiting for arming...\")\n        time.sleep(1)\n    print(\"Taking off!\")\n    vehicle.simple_takeoff(aTargetAltitude) # Take off to target altitude\n    # Wait until the vehicle reaches a safe height before processing the goto\n    # (otherwise the command after Vehicle.simple_takeoff will execute\n    # immediately).\n    while True:\n        print(\" Altitude: \", vehicle.location.global_relative_frame.alt)\n        # Break and return from function just below target altitude.\n        if vehicle.location.global_relative_frame.alt&gt;=aTargetAltitude * 0.95:\n            print(\"Reached target altitude\")\n            break\n        time.sleep(1)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"656\" src=\"https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_takingoff-1024x656.png\" alt=\"\" class=\"wp-image-697\" srcset=\"https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_takingoff-1024x656.png 1024w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_takingoff-300x192.png 300w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_takingoff-768x492.png 768w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_takingoff.png 1396w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">All those actions are defined in the dronekit. Moreover, we can print each waypoint information when drone arrives at exact point, the result is like that:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"661\" src=\"https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_exmaple2-1024x661.png\" alt=\"\" class=\"wp-image-699\" srcset=\"https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_exmaple2-1024x661.png 1024w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_exmaple2-300x194.png 300w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_exmaple2-768x496.png 768w, https:\/\/med.upc.edu\/team4-2021\/wp-content\/uploads\/sites\/5\/2021\/11\/a12_exmaple2.png 1466w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Dynamic flight planning with Python + DroneKit: example 2\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/YoW7KvPWv-E?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">every point in the mission planner is printed by the python script.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The next part is to try a real drone instead of a simulation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Objective Dynamic flight plans are flight plans that are decided in run time (during the flight) by an on-board computer, that can receive information from on-board devices (camera, sensors, etc.) andchange the course of action. Part 1 Start with recording the drone&#8217;s information like altitude and heading. The idea of the code is that: first [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-680","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/pages\/680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/comments?post=680"}],"version-history":[{"count":16,"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/pages\/680\/revisions"}],"predecessor-version":[{"id":708,"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/pages\/680\/revisions\/708"}],"wp:attachment":[{"href":"https:\/\/med.upc.edu\/team4-2021\/wp-json\/wp\/v2\/media?parent=680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}