Go to Post I've always believed that being who I was will not limit me to who I will be. That's what keeps me trying to learn more and become a better person. Otherwise I would've settled being someone ordinary and not care about anything around my life. - Ken Leung [more]
Home
Go Back   Chief Delphi > Technical > Motors
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 2 votes, 3.00 average. Display Modes
Prev Previous Post   Next Post Next
  #14   Spotlight this post!  
Unread 06-02-2007, 00:14
Matt Krass's Avatar
Matt Krass Matt Krass is offline
"Old" and Cranky. Get off my lawn!
AKA: Dark Ages
FRC #0263 (Sachem Aftershock)
Team Role: Mentor
 
Join Date: Oct 2002
Rookie Year: 2002
Location: Long Island, NY
Posts: 1,187
Matt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond reputeMatt Krass has a reputation beyond repute
Send a message via AIM to Matt Krass
Re: Save the Gearbox, Save the Game

Quote:
Originally Posted by Abwehr View Post
We put a low-pass filter on the motor speed command almost every year. A more compact way to accomplish this follows. Note that you can (and I always do) use integers for the fractional part, but it's quicker to show you what's going on with floats:

Code:
// Put this at the top of "user_routines.c"
#define K_LP .2

// Put these at the top of Default_Routine()
static unsigned char pwm01_old = 127;

// Put these in your drive code
pwm01 = (your drive code here)
pwm01 = (unsigned char)(K_LP*pwm01) + (unsigned char)((1.0-K_LP)*pwm01_old);
pwm01_old = pwm01;
Adjust the "K_LP" parameter to change the response of the filter. Higher numbers make the system more responsive, but with more noise. Lower numbers make the system smoother, but with more lag.
Actually, that's going to make the motors go full reverse, since you're handling everything as an 8-bit integer value calculation, anything between 1 and 0 as a decimal defaults to zero, and you're multiplying both sides of the plus by 0, so you'd end with 0 + 0 = 0.

The concept is right but might I suggest a better execution?

Code:
// Put this at the top of "user_routines.c"
#define K_LP 2
unsigned int temp_pwm01;

// Put these in your drive code
pwm01 = (your drive code here)
temp_pwm01 = (unsigned int)((K_LP*pwm01)/10) + (unsigned int)(((10-K_LP)*pwm01_old)/10);
if(temp_pwm01 > 255)
{
   temp_pwm01 = 255;
}
pwm01_old = pwm01 = (unsigned char)temp_pwm01;
This scales everything up for the calculations to avoid floating point (MUCH FASTER, and the extra int we used is still less memory than a float), then divides it back down to minimize rounding errors, then checks to make sure its not too large for a char and sets pwm01 to it.
__________________
Matt Krass
If I suggest something to try and fix a problem, and you don't understand what I mean, please PM me!

I'm a FIRST relic of sorts, I remember when we used PBASIC and we got CH Flightsticks in the KoP. In my day we didn't have motorized carts, we pushed our robots uphill, both ways! (Houston 2003!)
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[wiki]: how to save more than one prog. in the RC Edourdo FIRSTwiki 1 04-02-2007 17:29
Save a variable dawonn Programming 7 23-04-2005 08:30
SCRRF Save the Regional Redhead Jokes Southern California Regional Robotics Forum 0 03-05-2003 14:54
Duel on the Delaware - Save $$$ Now MOEWidow Off-Season Events 11 30-04-2003 21:28
Save the rookies!!! Please help us to design a crate... Eugene Technical Discussion 7 05-02-2002 20:22


All times are GMT -5. The time now is 22:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi