You will produce a version of the classic video game Lunar Lander (example). The lander thrust will be controlled by an analog input, and the lander attitude by button pushes. There will be a fuel limit. Display will be on a TV, with sound effects.
Procedure:
You will probably want to review the description of the video code given
in Video Generation with AVR. You can use video_codeGCC644.c and multASM.S as a basis for your
program. But note that you could use any another display format described on the video page. Be sure to add the assembler source file to the project before compiling. Set the GCC project configuration (in the Project:ConfigureOptions...
menu) to:
Build the video DAC shown to the left and connect it to the yellow connector on the
TV using clip leads and a RCA phone jack. Make sure the TV is set to video input.
Test the TV connection using the example program linked above. The power supplies
on the TVs and development boards are NOT interchangable.
The lander thrust (acceleration) will be controlled by a potentiometer hooked
to an A/D input on the MCU. Use the circuit to the left to make a user-variable voltage.
I suggest setting Vref to Vcc on the A/D converter. This example
(ADCtestGCC644.c uart.c, uart.h, project zip) shows how to set up the A/D converter to read a trimpot.
You are going to be programming in the equations of motion for the lander.
Your controls will be attitude and thrust, so we will need to relate acceleration,
velocity and position. Remeber that the video coordinate system has x increasing
to the right and y increasing downward. If θ is the angle of the lander
from the vertical (and measured positive counterclockwise) then the acceleration
is:
ax=-thrust*sin(θ)
and ay=g-thrust*cos(θ)
Computing the velocity change over a short time (by the Euler method)
vx(t+dt)=vx(t)+ax*dt
and vy(t+dt)=vy+ay*dt
Computing the position change over a short time (by the Euler method)
x(t+dt)=x(t)+vx*dt
and v(t+dt)=y(t)+vy*dt
The fuel level is
fuel(t+dt)=fuel(t)-thrust(t)*dt
Clearly, v, x and fuel all need initial conditions, which you will set, according the specifications below. It is doubtful that you will have ehough time between frames to do all of the calculations in floating point. I suggest using 16 bit, signed numbers with the binary point set at the byte boundary. I also suggest scaling g and the thrust so that you can make dt=1, thereby avoiding the multiply. The example has a bouncing ball with drag done with fixed point numbers.For speed, you will have to make a table of sines and cosines for the limited number of angles that the lander can assume.
Examples of student work:
:Photo by Eric Mesa, 2005
Gus Lott (2005) hooked the Mega32 video directly to his video capture card and produced this 8 Mbyte wmv file.He and his partner decided that 8-bit fractions caused too much granularity in the controls, so they used 24-bit fractional arithmetic. Basically, a realistic feeling g was around 0x0004-0x0006 so you only had 4 to 6 levels of manipulation around that g value with a thrust. This made it really hard to control. If you turned the dial to far, you were suddenly thrusting at many times the g level. This also produced some weird quantization noise after sin/cos scaling of the thrust. So they cast all of their floating point numbers into longs (24 fractional bits) and overlaid the direct 8 bit analog value of the A/D with the most significant bit left shifted 14 bits in the long. Then max thrust the user can give is 0x003fc000 with a g of 0x00040000 and a pixel at 0x01000000. Their arithmetic was, in reality, only 22 bit, but longs were the easiest way tohandle it in C. The extra precision made for real smooth manipulations, with 256 different thrust levels from 0 to +11g as opposed to approximately 20 thrust levels in the same range.
Adam Papamarcos and Kerran Flanagan sent me this video from 2010.
Debugging hints are here.
Write a program in C and assembler for the microcontroller with these specifications:
When you demonstrate the program to a staff member, you should exercise all
the lander functions.
You should be able to actually land your craft. Your program should not need
to be reset during the demo.
Your written lab report should include the sections mentioned in the policy page, and :