AME 3623: Project 2: Serial Communication and Compass Interface
- All components of the project are due by Thursday, March 31st
at 5:00pm. Note: your 48 hours grace period (with penalty)
accumulates over the weekend.
- Discussion within groups is fine.
- Discussion across groups may not be about the specifics of the
solution (general programming/circuit issues are fine to
discuss).
Project Objectives
At the end of this project, you should be able to:
- implement in code serial communication protocols for
interacting with sensors,
- compute errors between desired and actual state variables, and
- convey information about sensors using a set of LEDs.
Project Components
All components are required to receive full credit for the project.
Part 1: Microcontroller Circuit
Add the compass to your circuit:
- Connect power and ground directly to the battery (not to
the +5V power supply)
- Connect the compass transmit line to your Mega2560 receive
line of one of your serial ports (RXD1, specifically)
- Connect the compass receive line (green wire with a knot) to
your Mega2560 transmit line (TXD1)
- Connect a second switch to a digital input of your Mega2560
- When mounting the compass to your hovercraft, mount it as far
away as possible from the motors and from other wires. The
best solution is to mount a boom out the back of the craft and
to mount the compass to the end (25-30 cm should do).
- Note: you have already mounted a set of 4 LEDs to your circuit
(these form a circle). We will use these to display the craft
orientation or orientation error (depending on the state of the
switch).
Part 2: Serial Interface
Note: this part will count for one personal programming credit
Create a software interface to the craft. Implement the following
functionality:
- int16_t get_orientation(void) will send the necessary
command to request the current heading from the compass device.
This function will then wait for the serial response and return
the heading as an integer in 1/10's of a degree (so "100" means
10 degrees). Return values must range between -1799 and
1800, with 0 degrees corresponding to North. Use a
left-handed coordinate system to be consistent with the
compass.
In order to query the compass, your program must transmit on the
serial line:
c
The compass responds with:
cXXX\n\r
Where XXX is the ASCII representation of a 3-digit
hexadecimal number that gives the orientation of the craft in
tenths of a degree. Each digit X is 0..9 or A .. F. Note that "\n" is the newline character '\n', not the characters '\' and 'n'. "\r"
is the carriage return character, not the characters '\' and 'r'.
- Modify the while(1) loop in your main function to:
- read the current orientation (calling the above function)
- compute an error (using the function described below)
- display either the current orientation (Switch state ==
0) or the orientation error (Switch state == 1) using
the function described below
Part 3: Sensor Processing and Display
Note: this part will count for one personal programming credit
Implement the following functions:
Part 4: Hovercraft Layout
Mount the following to your Frisbee:
- Batteries
- Forward thrust fans
- Breadboard
- Compass
- Distance sensors
Let us know if you need any additional components for mounting.
References
Hints
- Serial port 0 on the Mega2560 is connected to the USB
connector that you plug into your laptop. You can use hyperterm to receive/send serial data
from/to the Mega2560 (via fprintf, fputc, fputs and fgetc).
You may use this serial interface to receive information from
your program and to respond to commands from your laptop. To configure hyperterm, you will need to
select the port (findable from the hardware section of your
control panel) and serial bit (or baud) rate. In this case, it
is 38400.
- The baud rate of your compass is 9600, which you have connected
to serial port 1 of the Mega2560.
What to Hand In
All components of the project are due by Thursday, March 31st at 5:00pm.
Grading
Group grade distribution:
- 35%: Project implementation
- 30%: Demonstration/presentation of working project (to either
of the TA or the instructor)
- 35%: Code documentation and group report
Grades for individuals will be based on the group grade, but weighted
by the assessed contributions of the group members.
fagg [[at]] cs.ou.edu
Last modified: Tue Mar 29 11:00:52 2011