Professional Documents
Culture Documents
6, 2018
What is Python?
Python is an interpreted, object-oriented, high-level programming
language with dynamic semantics. Its high-level built in data structures,
combined with dynamic typing and dynamic binding; make it very attractive for
Rapid Application Development, as well as for use as a scripting or glue
language to connect existing components together. Python's simple, easy to
learn syntax emphasizes readability and therefore reduces the cost of program
maintenance. Python supports modules and packages, which encourages program
modularity and code reuse. The Python interpreter and the extensive standard
library are available in source or binary form without charge for all major
platforms, and can be freely distributed.
Python Syntax
The syntax of the Python programming language is the set of rules that
defines how a Python program will be written and interpreted (by both the
runtime system and by human readers).
A comment begins with a hash character(#) which is not a part of the string
literal and ends at the end of the physical line. All characters after the #
character up to the end of the line are part of the comment and the Python
interpreter ignores them. See the following example. It should be noted that
Python has no multi-lines or block comments facility.
When you want to write a long code in a single line you can break the logical
line in two or more physical lines using backslash character(\). Therefore
when a physical line ends with a backslash characters(\) and not a part of a
string literal or comment then it can join another physical line. See the
following example.
Multiple Statements on a Single Line:
You can write two separate statements into a single line using a semicolon
(;) character between two line.
Indentation:
Do not mix tabs and spaces. Tabs create confusion and it is recommended
to use only spaces.
as el if or yield
You can use the len() function to return the number of items in a list.
Adding the len() function to the print() function will print that number out.
You can pick out a single list item by referring to its index.
Remember, Python uses zero-based indexing, so start the count at 0 when doing
this.
So to find out what the second item in the planet list is, do this:
You can also select a range of items by specifying two indexes
Before you decide to sit down and write a wonderful function, ask
yourself "is there already a build-in function for this?".
1 while loop
2 for loop
3 nested loops
You can use one or more loop inside any another while, for or
do..while loop.
Loop Control Statements
Loop control statements change execution from its normal sequence. When
execution leaves a scope, all automatic objects that were created in that
scope are destroyed.
Python supports the following control statements. Click the following links
to check their detail.
1 break statement
2 continue statement
3 pass statement
This method of programming your drone uses the Felixge Node Library and is
available as free code for anyone to use. Before getting started, it is
recommended to understand the laws around flying your drone. For example, you
can fly your drone around some landmarks, but not others. You can fly your
drone in the outback or on a deserted beach, but not on Fraser Island or in
the Daintree Rainforest (in Australia). The rules can be complicated and
change often, so please ensure you read before flying.
Step 2: Node JS
Download Node JS to your computer. This isn’t a hard one. Please note,
there are a great many programming languages that can be used to interface
with your drone including Node JS, Java, C#/.Net, Python, Scala, Ruby,
Clojure as well as apps such as flyver.co, Dronekit and Tickle. For this
project, we are using Node JS.
Step 4: Testing
To be sure this has set up correctly so far, turn the drone on then connect
your laptop to the wifi from your drone. Likely called something along the
lines of “drone####.” Open the node.js program and type in the next four
lines of code, hitting enter after each line. Please note that the drone will
take off and hover after the third line.
This allows us to ensure the drone is connected, can take off and land.
Open a text editor, such as Sublime Text, open a new file and type the lines
of code in and be sure to save the file with .js at the end. This ensures it
is created as a JavaScript file. For now, we are only entering this code
(each number is a new line). We will save it as test.js
1. Node c:\Drone\test.js
You will know if this ran successfully if the drone takes off, hovers and
then lands automatically.
By now you should begin to understand the power a laptop and a drone
can have. In less than 15 minutes we have implemented a program to take off,
hover and land a drone. All of which can be done by simply pressing “enter”
after the program is written. It’s likely you will be excited and wanting to
learn and implement ever more complicated and amazing functions for your
drone. Before you do, though, bear in mind the constantly changing laws
around drone flying, as mentioned above. With that in mind, have fun and
explore the incredible capabilities of your drone.