View Single Post
  #6   Spotlight this post!  
Unread 14-04-2006, 16:24
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: pic: kiwi vex robot

Quote:
Originally Posted by billbo911
With Tom's permission, could you possibly post the section of code that makes the magic work? PLEASE!!!!
Well credit needs to be given where it's deserved. I got the equations for my kiwi code from the living genious, Joel Johnson.

Anyway, here's what you need to do to make it work:

PHP Code:
//Make sure variables are unsigned ints... rollovers WILL occur with signed ints
unsigned int trans_xtrans_yrot;

//Grab inputs (x,y coords in rectangular coordinates and rotation rate)
trans_x 254 PWM_in1
trans_y 254 PWM_in2
rot 254 PWM_in4;      

//Limit vector length to 127
trans_x = (unsigned int)(37+(254*trans_x)/359);
trans_y = (unsigned int)(37+(254*trans_y)/359);

//Assign and limit wheel outputs
wheel_1  = (unsigned char)limit( (((2*trans_x) + rot) / 3), 0254); 
wheel_2 = (unsigned char)limit( ((601 rot trans_x - (168*trans_y/97)) / 3), 0254); 
wheel_3 = (unsigned char)limit( ((161 rot trans_x + (168*trans_y/97)) / 3) , 0254); 
This assumes you have a limit function, which limits an input value to upper and lower bounds.

PHP Code:
signed int limit(signed int valuesigned int minsigned int max
 { 
      if (
value min
      { 
           
value min
      } else if (
value max
      { 
           
value max
      } 
  
      return 
value
 } 
That should be all you need, and it should work. (It took me about 2 hours to figure out the variables needed to be unsigned. )
Reply With Quote