At the end of this project, you should be able to:
This sensor has short leads that plug directly into your breadboard. The pin-outs for this board are as follows:
Rotation rate is linearly related to the voltage as follows:
This sensor contains not only a 3-axis rate gyro, but also a 3-axis accelerometer and magnetometer. In the next project, we will use the magnetometer (as a compass). Hence, this sensor must be mounted high enough to not "see" magnetic interference from sources embedded in the floor.
We will add connectors later, but for now, plug the four wires into your breadboard. The lines are connected as follows:
Don't forget: connect the red line to +3.3V power (anything else could damage the chip).
When mounted, the wires should extend straight up and the board should be horizontal. If anyone can provide a good idea for a 3D-printed mount to keep the vertical wires straight (and not wobbly), we can implement it pretty quickly.
Did I mention that the red line must only be connected to +3.3V?
Access:
OU_LIB = -L$(OULIB_DIR)/lib -lou_$(MCU)
with:
OU_LIB = -L$(OULIB_DIR)/lib -limu_mpu9150_$(MCU) -lou_$(MCU)
Don't forget to add #include "imu_mpu9150.h" to the top of your C file.
int8_t ret;
A return value of zero means that everything is OK. Otherwise,
there was an error. If you print out this code, then it will
help us diagnose any problems (they are most likely due to
connection problems).
int16_t gyro[3];
gyro[2] corresponds to rotation about the vertical
axis. This is a 16-bit twos-complement number. The maximum
value ((2^15) -1 or 0x7FFF) corresponds to a rotation rate of
500 deg/sec. The negative of this number (-(2^15)+1 or
0x8001) corresponds to -500 deg/sec. These values are measured
in a right-handed coordinate frame.
ret = imu_init(0);
ret = imu_read_gyro(gyro);
Remember, only connect the red wire to +3.3V.
Implement the following function:
int16_t thrust = rotation_rate / #PICK AN APPROPRIATE DIVISOR#; set_side_motor_magnitudes(-thrust, thrust);
Copy the following function from project 1:
Structure the rest of your code as follows (we will talk about what this means in class):
// Global flag volatile uint8_t flag_timing = 0; // Interrupt service routine: called every time // the timer 0 counter transitions from 0xFF to 0. // Period of flag_timing is 3 * 256 * 1024 / 16000000 = 49.152 ms ISR(TIMER0_OVF_vect) { static uint8_t count = 0; // Set to zero at beginning of program only if(++count == 3){ // Set the flag to indicate that the period has passed flag_timing = 1; count = 0; } }; int main(void) { int16_t counter = 0; int16_t rotation_rate; #APPROPRIATE VARIABLE DECLARATIONS HERE# #APPROPRIATE INITIALIZATIONS HERE, INCLUDING YOUR FILE POINTER# timer0_config(TIMER0_PRE_1024); // Prescale by 1024 timer0_enable(); // Enable the timer 0 overflow interrupt sei(); // Enable global interrupts // Begin to lift off the ground set_lift_motor_direction(HOVER); #RAMP UP LIFT THRUST TO HOVER. STOP RAMPING AS SOON AS THE CRAFT BEGINS TO ROTATE AT AN INTERESTING RATE# // Loop for ~30 seconds while(counter < 20*30) { rotation_rate = get_rotation_rate(); // Display #APPROPRIATE CODE FOR DISPLAYING ROTATION RATE WITH YOUR 10 LEDS# // Control d_control(rotation_rate); // Increment time ++counter; if(flag_timing) { // Error condition: your while body is taking too much // time. #Indicate this with an LED display of some form# } // Wait for the flag to be set (happens once every ~50 ms) while(flag_timing == 0) {}; // Clear the flag for next time. flag_timing = 0; } #RAMP DOWN LIFT THRUST TO ZERO# while(1){}; // Spin forever }
The hovercraft will work best when its center of mass is at the center of the Frisbee. Adjust the positions of your batteries and breadboard to achieve this.
Note that steering of the craft will work best if the lateral fans are placed a little ahead of the middle fan (too far forward and the craft will steer in a sluggish way; behind the middle fan and the craft will be unstable).
Remember that documentation is about helping you and others looking at your code to understand what it is doing. Therefore, it will generally describe the logic of the code (and not-necessarily the low-level details). For this class:
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.
Last modified: Thu Apr 2 01:38:16 2015