View Single Post
  #9   Spotlight this post!  
Unread 16-11-2009, 02:35
NickE's Avatar
NickE NickE is offline
_
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Mar 2008
Rookie Year: 2008
Location: San Jose, CA
Posts: 620
NickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond reputeNickE has a reputation beyond repute
Re: [FTC]: Slow Down Max Speed!!

Instead of using variables as in l0jec's example, you could use #define statements to reduce memory usage and potentially speed up the program execution some. With a #define statement, the compiler in RobotC will replace all instances of 'MAX_JOY_VAL', for instance, with the value defined in the statement. The robot will see the defined values and not the names for the values defined in the statements. Be sure not to use either equals signs or semicolons in these lines.

Here's the same code he posted, except with #define statments:
Code:
int simpleScale(int joyVal) {
  
#define MAX_JOY_VAL 127
#define MAX_MOTOR_VAL 100
#define DEADZONE 5
  
  //check for deadzone
  if(abs(joyVal) < DEADZONE) {
    return 0;
  }
  
  //calculate ratio based on max motor speed and max analog stick value
  float ratio = (MAX_MOTOR_VAL/MAX_JOY_VAL);
  //apply ratio to actual joystick value
  int result = (joyVal)*ratio;
  return result;  
 
}
Reply With Quote