View Single Post
  #10   Spotlight this post!  
Unread 16-11-2009, 10:46
JohnFogarty's Avatar
JohnFogarty JohnFogarty is offline
Trapped under a pile of MECANUMS :P
AKA: @doctorfogarty
FTC #11444 (Garnet Squadron) & FRC#1102 (M'Aiken Magic)
Team Role: Mentor
 
Join Date: Aug 2009
Rookie Year: 2006
Location: SC
Posts: 1,573
JohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond reputeJohnFogarty has a reputation beyond repute
Re: [FTC]: Slow Down Max Speed!!

Quote:
Originally Posted by NickE View Post
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;  
 
}
Thanks i shall try these .
__________________
John Fogarty
2010 FTC World Championship Winner & 2013-2014 FRC Orlando Regional Winner
Mentor FRC Team 1102 M'Aiken Magic
"Head Bot Coach" FTC Team 11444 Garnet Squadron
Former Student & Mentor FLL 1102, FTC 1102 & FTC 3864, FRC 1772, FRC 5632
2013 FTC World Championship Guest Speaker
Reply With Quote