AME 3623: Project 7: Compasses and Position Control
- All components of the project are due by Thursday, April 9th
at 8:00 am
- Groups are the same as for project 1.
- 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).
At the end of this project, you should be able to:
- extract hovercraft orientation from a magnetometer sensor, and
- use the sensory data to drive the motors in such a way that the
craft will orient toward a goal.
Component 1: Circuit
Connect a compass to your circuit. We have two different types of
sensors for the class; your group will receive one.
Combined Compass/Gyro/Accelerometer
For those of you who have the "long-stem" gyros for project 6 (labeled
MPU-9150 or MPU-9250), then you already have a compass. You do not
need to do additional wiring.
Access:
- Copy new versions of the following files into your include and
lib folders,
respectively: mpu9150.h and libimu_mpu9150_atmega2560.a
- Initialization is the same process as for project 6.
- The new library also provides:
void imu_calibrate_compass(FILE *fp); will go
through a calibration procedure that you must use to ensure
quality compass headings. When you call this function, it will
ask you to begin to slowly turn your sensor (about the Z axis); your goal is to
make two complete rotations in about 15 seconds (remember to
keep the sensor flat during this time). Once complete, this
function reports two parameters: offset0 and offset1; these are
automatically installed for later use. However, you can also
set these values directly with the function below.
void imu_set_compass_offsets(int16_t offset0, int16_t
offset1); will set the magnetometer offsets provided by
imu_calibrate_compass();
uint16_t imu_read_compass(void); returns the compass
heading in units of 1/(2^16) of a full rotation (i.e, fixed
point "0.16" format) in a left-handed coordinate frame.
Specifically: 0 = magnetic north, 0x8000 = PI, and 0xFFFF = PI * (2 - 1/32768).
Notes:
- The IMU sensor should be mounted such that it stays flat at all
times.
- You should only calibrate your compass after it is mounted.
- Once you receive the offset values from the calibration
function, you can use these directly with
imu_set_compass_offsets(). This means that you won't have to
recalibrate the compass every time you start your program.
- If you have one of our "early-release" sensors (just bare wire
at the end of the cable), please return
it to us so that we can solder an additional connector to the
wires and add some insulation.
Compass-Only Sensor
These compass modules also have "long-stems" (we will hand these out
with the assignment).
- Connect the compass module to your microcontroller. The compass pin assignment is as follows:
- Ground
- space (no pin)
- Power (5v)
- SDA
- SCL
- When mounting the compass to your hovercraft, you must mount it
at least 12" off the ground and as far away as possible from
the motors and from other wires. In addition, the compass must
be flat and steady. Feel free to add structure to your
hovercraft as necessary (make sure that it is light, however).
Access:
- Save the following files into your include and lib folders,
respectively: compass.h, i2c_isr.h and libcompass_atmega2560.a
- Set up your new project in Atmel Studio as you normally would.
However:
- Add compass.h and i2c_isr.h to your list of includes (Solution Explorer)
- Add #include "compass.h" to the top of your C file.
- Add compass_atmega2560 to your list of libraries
(Project Properties / Libraries)
- If you are using OSX: replace the following line in your
makefile:
OU_LIB = -L$(OULIB_DIR)/lib -lou_$(MCU)
with:
OU_LIB = -L$(OULIB_DIR)/lib -lcompass_$(MCU) -lou_$(MCU)
Don't forget to add #include "compass.h" to the top of your C file.
- This new library provides an initialization function:
void compass_init(void); initializes the compass
interface. Call this toward the top of your main() function.
- The library also allows you to read from the compass:
int16_t compass_query(void) returns the current
heading of the compass. The return value is in 1/10's of a
degree in a left-handed coordinate system, and the range is 0
... 3599. A value of zero
corresponds to magnetic North.
- There are also calibration functions, but each of the compasses
we have distributed already have calibration data saved on
them. If you are experiencing odd headings, then please see
the instructor.
Component 2: Software
Implement the following function:
Copy all of your functions from project 6, and copy the following
function from project 1:
- void display_orientation(int16_t theta)
Structure your main() function as you did for project 6. Except:
- Add other necessary initialization.
- Within your loop, make calls to read and display your current
orientation error.
- Call your p\_control() function (replacing d\_control()).
Your main function should still ramp-up the middle fan, stopping once
the craft begins to turn. Afterwards, perform 30 seconds of hovering
while maintaining a heading toward the selected goal. (Note: the
hovercraft will oscillate around its goal since we do not have damping
turned on; this is OK for this lab).
Component 3: Testing
- Slowly decrease the divisor until the craft aggressively
tries to maintain the goal orientation.
- At this point, you can place the craft on the floor (or a
table, if you are careful).
- The craft should produce a thrust to the left hand fan if the goal
is anywhere to the right and a thrust to the right hand fan if the
goal is anywhere to the left.
What to Hand In
All components of the project are due by Thursday, April 9th at
8:00 am.
- Demonstration/Code Review: All group
members must be present. Given time, this can be done during class.
- Check in the following to your
group dropbox on D2L for project 7:
- Personal report: fill out the CATME survey. This is due
by Monday, April 13th at 11:59pm.
Grading
Personal programming credit:
- Each person must accumulate at least three personal programming
credits over the course of the semester (this project offers
two). This can be one
person or split across two people. Their individual
contributions must be clearly documented.
- To receive credit, you must be the primary designer,
implementer and debugger of the component. This does
not mean that your other group members should not be looking
over your shoulder. But: you must do the "driving."
Group grade distribution:
- 35%: Project implementation
- 30%: Demonstration of working project (to either
of the TA or the instructor)
- 35%: Documentation
Group Grading Rubric
Grades for individuals will be based on the group grade, but weighted
by the assessed contributions of the group members to the non-personal programming items.
References
andrewhfagg -- gmail.com
Last modified: Mon Apr 6 15:23:08 2015