|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Joystick filtering gone horribly wrong...help!
Hey all,
I was asked to make the robot have a curved response in the drive motors, i.e. pushing the joysticks halfway gets you about quarter speed, but pushing them full gets you full speed. I was advised that this will make the drivers' jobs easier. However, it seems to be making my job more complicated... I have a basic lookup table solution in place right now...but it doesn't work. Ideally, I want to be able to input a number of points on the curve (right now, I have 7) and have the code extrapolate the points in between. I would be able to tweak this curve, adjust the constants in code, recompile, and blast the code down again to have filtered joysticks. Now, at this point in time, I am getting strange results. The code I have is trying to set outputs to values like 360-something or greater, and I can't figure out why (I know it's out of range. I know PWMs only go up to 254...). I am seeing this code get more and more complex, and I need some help implementing KISS in this situation. Here's the code I've got right now: Code:
unsigned char DRV_GetFilteredValue(unsigned char joystick)
{
static const unsigned char lookup[] = {127,135,140,145,165,200,254};
int temp_joystick = (((int)joystick-127)/21.1);
printf("temp_joystick = %d\r\n",(int)temp_joystick);
printf("joystick is %d\r\n", (int)joystick);
if (temp_joystick >= 7) { temp_joystick = 6; }
if ((joystick < 130) && (joystick > 124)) {
return 127;
} else if (temp_joystick < 0) {
printf("lookup[temp_joystick] = %d, lookup[temp_joystick-1] = %d, output is %d\r\n", (int)lookup[temp_joystick], (int)lookup[temp_joystick-1], (int)((joystick - lookup[temp_joystick-1])*(lookup[temp_joystick] - lookup[temp_joystick-1]) / 21) + lookup[temp_joystick-1]);
return ((joystick - lookup[temp_joystick-1])*(lookup[temp_joystick] - lookup[temp_joystick-1]) / 21) + lookup[temp_joystick-1];
} else {
temp_joystick = -temp_joystick;
printf("lookup[temp_joystick] = %d, lookup[temp_joystick-1] = %d, output is %d\r\n", (int)lookup[temp_joystick], (int)lookup[temp_joystick-1], (int)254-((joystick - lookup[temp_joystick-1]) * (lookup[temp_joystick] - lookup[temp_joystick-1]) / 21) + lookup[temp_joystick-1]);
return 254-((joystick - lookup[temp_joystick-1]) * (lookup[temp_joystick] - lookup[temp_joystick-1]) / 21) + lookup[temp_joystick-1];
}
}
You don't even have to look at that code. I just need something that I can put in place to filter the joysticks. Thanks in advance for any help you can provide. And I'm willing to throw out the code I've got; I just need *something* to work. JBot |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| EMI Filtering | Mike Betts | Electrical | 1 | 06-03-2007 15:38 |
| pic: Dodgeball gone wrong. | Bharat Nain | Extra Discussion | 6 | 23-04-2006 20:11 |
| Genia and Mike's Walmart Frolic Gone Wrong | MikeyP | Chit-Chat | 25 | 20-04-2005 20:21 |
| Math Gone Wrong | psquared | Programming | 10 | 23-01-2005 12:18 |
| HELP! My 'Documents & Settings' Folder Is Gone... WITH ALL MY STUFF! | Joe Matt | Chit-Chat | 3 | 28-10-2004 21:09 |