4.2
Control Loop Frequency
4
SOFTWARE INTRODUCTION
the Spin interpreter, must fit in 496 instructions or less in order to fit into
the COG RAM. The Propeller does not have provisions for fetching PASM
instructions from other locations besides COG RAM. For Spin code the compiled
interpretable bytes are stored in the HUB RAM, and are fetched and decoded
by the Spin interpreter.
4.1.2
Programming
The Propeller is programmed in PASM and a high level language called Spin.
In general, PASM is used when speed is required. At 100MHz, the Propeller
can execute 25,000,000 assembly instructions each second (each instruction takes
40ns). By contrast, the interpreted Spin language is about 100x slower. Because
of this contrast Spin is used where ease of programming is important, and PASM
is used where speed is important.
Spin is officially called an object oriented programming language, but there
are some subtle differences compared to mainstream object oriented terminol-
ogy. Spin OOP is used to organize code into logical blocks much like an import
statement in C++ or Python. Spin objects do not use techniques such as class
instances, inheritance, or subtype polymorphism.
A Spin object is used to
group related functions together into a unit that can be included in multiple
Spin programs.
Typically, Spin objects are used for interfacing with external devices. For
example, a typical Spin program might have an object for serial communication,
an object for VGA signal generation, and an object for I2C communication. The
Parallax Object Exchange ([18]) hosts Parallax written objects and community
written objects under the open source MIT licence.
Spin syntax is very similar to Python. To denote a new scope Spin uses in-
dentation instead of curly braces (familiar to C/C++ and Java programmers).
Spin code is divided into blocks: CON (constant), VAR (variable), OBJ (ob-
ject), DAT (data), PUB (public function), and PRI (private function). Most
typical programming constructs are a part of the Spin language: conditional IF
statements, FOR loops (called REPEAT), boolean conditions, and so on.
All variables in the Propeller are integers. Variables are typically 32 bit
signed integers called longs, but in Spin it is possible to create 16 bit or 8 bit
sized variables as well (called words and bytes, respectively). Global variables
are declared in the VAR block, and global constants are declared in the CON
block. PRI and PUB functions can declare local variables, along with function
parameters.
4.2
Control Loop Frequency
For our software, the critical portion is the main control loop that keeps the
quadrotor flying at the desired attitude (roll, pitch, yaw) and altitude. It is
essential that this control loop operates fast enough to respond to disturbances.
From our research into what other quadrotor groups have done we have found
16