View Single Post
  #3   Spotlight this post!  
Unread 24-04-2008, 21:59
JimWright949's Avatar
JimWright949 JimWright949 is offline
The Owen Day of Seattle
AKA: Jim Wright
FRC #4542 (Titanium Talons)
Team Role: Mentor
 
Join Date: Sep 2003
Rookie Year: 2003
Location: Redmond, WA
Posts: 94
JimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to beholdJimWright949 is a splendid one to behold
Re: Joystick Input Mapping

Um, hmm, well your getting kinda the idea, but we can replace the ifs with something smaller. Here is the code:

Put this code outside of a function (it's a long story why it needs to be outside of a function):

char curve[] = {
0, 1, 2, 4, 5, 5, 5, 5, 5, 10, 10, 10, 10, 10, 10, 10,
20, 20, 20, 20, 20, 30, 30, 30, 30, 40, 40, 40, 40, 40, 50, 50,
50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
60, 60, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 85, 85, 85, 85,
85, 85, 85, 85, 85, 85, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95,
105, 105, 105, 105, 105, 105, 105, 105, 105, 105, 110, 110, 110, 110, 110, 115,
115, 115, 115, 115, 115, 115, 115, 115, 115, 120, 120, 120, 120, 120, 120, 120,
120, 120, 120, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
127, 127, 127, 127, 127, 127, 127, 130, 130, 135, 135, 135, 135, 135, 135, 135,
135, 135, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 145, 145, 145, 145,
145, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 160, 160, 160, 160, 160,
160, 160, 160, 160, 160, 170, 170, 170, 170, 170, 170, 170, 170, 170, 170, 185,
185, 185, 185, 185, 185, 185, 185, 185, 185, 195, 195, 195, 195, 195, 195, 195,
195, 195, 195, 195, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 215, 215,
215, 215, 215, 225, 225, 225, 225, 225, 235, 235, 235, 235, 235, 245, 245, 245,
245, 245, 245, 245, 250, 250, 250, 250, 250, 251, 252, 253, 254, 255, 255, 255 };

Now in your function, replace all the if statements with:

LEFT_MOTOR = curve[p1_y];

The right motor will look like this:

RIGHT_MOTOR = curve[p2_y];

This make the p1_y into the index of the table that is in ram. The value of the table at the index p1_y will be put into LEFT_MOTOR.

You may get a linker error about being out of space if you are using MC18. If you do, find your .lkr file and open it up in MPLAB.

Find the section that looks like this:
DATABANK NAME=gpr0 START=0x60 END=0xFF PROTECTED
DATABANK NAME=gpr1 START=0x100 END=0x1FF
DATABANK NAME=gpr2 START=0x200 END=0x2FF
DATABANK NAME=gpr3 START=0x300 END=0x3FF
DATABANK NAME=gpr4 START=0x400 END=0x4FF
DATABANK NAME=gpr5 START=0x500 END=0x5FF
DATABANK NAME=gpr6 START=0x600 END=0x6FF
DATABANK NAME=gpr7 START=0x700 END=0x7FF
DATABANK NAME=gpr8 START=0x800 END=0x8FF
DATABANK NAME=gpr9 START=0x900 END=0x9FF
DATABANK NAME=gpr10 START=0xA00 END=0xAFF
DATABANK NAME=gpr11 START=0xB00 END=0xBFF
DATABANK NAME=gpr12 START=0xC00 END=0xCFF

Delete one of the lines and add 100 to the end of the line above it. Here is mine where I delete grp2 and add 100 to grp1's end tag:
DATABANK NAME=gpr0 START=0x60 END=0xFF PROTECTED
DATABANK NAME=gpr1 START=0x100 END=0x2FF
DATABANK NAME=gpr3 START=0x300 END=0x3FF
DATABANK NAME=gpr4 START=0x400 END=0x4FF
DATABANK NAME=gpr5 START=0x500 END=0x5FF
DATABANK NAME=gpr6 START=0x600 END=0x6FF
DATABANK NAME=gpr7 START=0x700 END=0x7FF
DATABANK NAME=gpr8 START=0x800 END=0x8FF
DATABANK NAME=gpr9 START=0x900 END=0x9FF
DATABANK NAME=gpr10 START=0xA00 END=0xAFF
DATABANK NAME=gpr11 START=0xB00 END=0xBFF
DATABANK NAME=gpr12 START=0xC00 END=0xCFF

Then it should link.

-Jim

Last edited by JimWright949 : 24-04-2008 at 22:18.