Skip to content

Commit 626f407

Browse files
committed
first version of Drone
1 parent 52a119c commit 626f407

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

Notebooks/Drone.ipynb

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 11,
6+
"id": "90ba85cb-4fd5-44ca-98b3-d06f9c23340c",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"class Drone:\n",
11+
" def __init__(self):\n",
12+
" self.x = 0\n",
13+
" self.y = 0\n",
14+
" self.z = 0\n",
15+
" self.battery = 20 * 60\n",
16+
" self.odometer_total = 0 \n",
17+
" self.odometer_partial = 0\n",
18+
" \n",
19+
" def show_level(self):\n",
20+
" print('The energy level is enough for {:.3f} seconds flying'.format(self.battery))\n",
21+
" \n",
22+
" def charge_battey(self):\n",
23+
" self.show_level()\n",
24+
" print('Charging Battery...')\n",
25+
" self.battery = 20 * 60\n",
26+
" self.odometer_partial = 0\n",
27+
" \n",
28+
" def show_coordinates(self):\n",
29+
" print('The Drone is located in: \\nX:\\t{}\\nY:\\t{}\\nZ:\\t{}'.format(self.x, self.y, self.z))\n",
30+
" print('The Drone has flown {:.3f} meters'.format(self.odometer_total))\n",
31+
" print('The Drone has flown {:.3f} meters since last battery charge'.format(self.odometer_partial))\n",
32+
" \n",
33+
" def fly_to(self,x,y):\n",
34+
" \n",
35+
" #Calculating euclidean distance\n",
36+
" distance = ((x-self.x)**2 + (y-self.y)**2)**0.5\n",
37+
" \n",
38+
" # We allow 20 seconds for the Drone to reach the cruise altitude\n",
39+
" flying_time = 20 + distance/2 + 20\n",
40+
" print('Estimated remaining flying time is {:.3f} seconds'.format(flying_time))\n",
41+
" if self.battery >= flying_time:\n",
42+
" print('Flying...')\n",
43+
" self.x = x\n",
44+
" self.y = y\n",
45+
" self.battery -= flying_time\n",
46+
" self.odometer_total += distance\n",
47+
" self.odometer_partial += distance\n",
48+
" self.show_coordinates()\n",
49+
" else:\n",
50+
" print('The energy level is enough for {:.3f} seconds flying'.format(self.battery))"
51+
]
52+
},
53+
{
54+
"cell_type": "code",
55+
"execution_count": 12,
56+
"id": "b7965e74-95f7-4eb2-bd79-ca25beafa32e",
57+
"metadata": {},
58+
"outputs": [],
59+
"source": [
60+
"f = Drone()"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 19,
66+
"id": "1f085b15-a135-466f-95ec-8f5c34aa5399",
67+
"metadata": {},
68+
"outputs": [
69+
{
70+
"name": "stdout",
71+
"output_type": "stream",
72+
"text": [
73+
"Estimated remaining flying time is 51.180 seconds\n",
74+
"Flying...\n",
75+
"The Drone is located in: \n",
76+
"X:\t12\n",
77+
"Y:\t12\n",
78+
"Z:\t0\n",
79+
"The Drone has flown 121.692 meters\n",
80+
"The Drone has flown 121.692 meters since last battery charge\n"
81+
]
82+
}
83+
],
84+
"source": [
85+
"f.fly_to(12,12)"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 17,
91+
"id": "487d5916-ee53-46c0-8f17-6793d8833774",
92+
"metadata": {},
93+
"outputs": [
94+
{
95+
"name": "stdout",
96+
"output_type": "stream",
97+
"text": [
98+
"Estimated remaining flying time is 50.000 seconds\n",
99+
"Flying...\n",
100+
"The Drone is located in: \n",
101+
"X:\t32\n",
102+
"Y:\t12\n",
103+
"Z:\t0\n",
104+
"The Drone has flown 89.331 meters\n",
105+
"The Drone has flown 89.331 meters since last battery charge\n"
106+
]
107+
}
108+
],
109+
"source": [
110+
"f.fly_to(32,12)"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": 18,
116+
"id": "84707475-4d65-4f32-8207-5164ae61937c",
117+
"metadata": {},
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"Estimated remaining flying time is 45.000 seconds\n",
124+
"Flying...\n",
125+
"The Drone is located in: \n",
126+
"X:\t32\n",
127+
"Y:\t22\n",
128+
"Z:\t0\n",
129+
"The Drone has flown 99.331 meters\n",
130+
"The Drone has flown 99.331 meters since last battery charge\n"
131+
]
132+
}
133+
],
134+
"source": [
135+
"f.fly_to(32,22)"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"id": "96670a37-d799-4005-b0e0-6ca74d0c183b",
142+
"metadata": {},
143+
"outputs": [],
144+
"source": []
145+
}
146+
],
147+
"metadata": {
148+
"kernelspec": {
149+
"display_name": "Python 3 (ipykernel)",
150+
"language": "python",
151+
"name": "python3"
152+
},
153+
"language_info": {
154+
"codemirror_mode": {
155+
"name": "ipython",
156+
"version": 3
157+
},
158+
"file_extension": ".py",
159+
"mimetype": "text/x-python",
160+
"name": "python",
161+
"nbconvert_exporter": "python",
162+
"pygments_lexer": "ipython3",
163+
"version": "3.8.10"
164+
}
165+
},
166+
"nbformat": 4,
167+
"nbformat_minor": 5
168+
}

0 commit comments

Comments
 (0)