View Single Post
  #9   Spotlight this post!  
Unread 14-02-2008, 14:11
Steve_Alaniz Steve_Alaniz is offline
Registered User
FRC #2848 (All Sparks)
Team Role: Mentor
 
Join Date: Mar 2007
Rookie Year: 1997
Location: Dallas
Posts: 211
Steve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond reputeSteve_Alaniz has a reputation beyond repute
Re: Code For Mecanum Wheels

I was trying to program my mechanums and was worried while trying to sleep (when I do my best thinking) and reasoned a couple of things out.
First I needed scale my inputs with one of the table schemes or with a Square or Cubic Function.
but after that I came up with THIS code.
The code for single joystick that we use combines the joystick inputs and gives a resultant. If I just treat those resultants as if they were a single joystick input, I could combine them with the same formula adding the Z or Twist axis. Since the effect of the Z axis goes to different wheels I just needed to re group them... I just realized I can further reduce the last four lines to

pwm15 = pwm16 = Limit_Mix(2000 + pwm16 + p1_wheel - 127);
pwm13 = pwm14 = Limit_Mix(2000 + pwm14 - p1_wheel + 127);

and eliminate the interim values to make it a four line code,
But I wanted to give you the code as I'm actually using it.
I need to clean up my code.

The wheels are configured :
LF is pwm13 RF is pwm14
LR is pwm15 RR is pwm16

I think this is the simplest way to implement Mechanums. Since I'm not proficient enough to read everyone
else's code, I hope all this is in line with what you guys are saying.


Steve


Code:
 pwm13 = pwm16 = Limit_Mix(2000 + p1_y + p1_x - 127);
  pwm15 = pwm14 = Limit_Mix(2000 + p1_y - p1_x + 127);


  intpwm13 = pwm13;    // set to interim variable to do the twist calculation
  intpwm14 = pwm14;    // I originally set this up for debugging purposes but 
  intpwm15 = pwm15;    // this is actually an unnecessary step.  SO I can
  intpwm16 = pwm16;    // eliminate these four lines by just using the  values
                                 // to define themselves as mentioned in the post

pwm16 = Limit_Mix(2000 + intpwm16 + p1_wheel - 127); //These can be shortened but I was in a hurry and 
pwm15 = Limit_Mix(2000 + intpwm15 + p1_wheel - 127); // I'm not really a programmer anyway.
pwm14 = Limit_Mix(2000 + intpwm14 - p1_wheel + 127);
pwm13 = Limit_Mix(2000 + intpwm13 - p1_wheel + 127);


(footnote... I believe I can combine everything to this:
pwm13 = pwm16 = Limit_Mix(2000 + p1_y + p1_x - 127); //Combines X & Y Axis
pwm15 = pwm14 = Limit_Mix(2000 + p1_y - p1_x + 127);

pwm15 = pwm16 = Limit_Mix(2000 + pwm16 + p1_wheel - 127);//Combines Z Axis with previously
pwm13 = pwm14 = Limit_Mix(2000 + pwm14 - p1_wheel + 127);//calculated X & Y Axis


I'll test it later today and let you know.
Steve )

Addendum

OK final code is

Code:
pwm13 = pwm16 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = pwm14 = Limit_Mix(2000 + p1_y - p1_x + 127);



pwm16 = Limit_Mix(2000 + pwm16 + p1_wheel - 127); 
pwm15 = Limit_Mix(2000 + pwm15 + p1_wheel - 127); 
pwm14 = Limit_Mix(2000 + pwm14 - p1_wheel + 127);
pwm13 = Limit_Mix(2000 + pwm13 - p1_wheel + 127);

Last edited by Steve_Alaniz : 15-02-2008 at 11:20. Reason: new info