View Single Post
  #8   Spotlight this post!  
Unread 14-02-2008, 13:32
RyanW RyanW is offline
Registered User
FRC #0449 (Blair Robot Project)
Team Role: Programmer
 
Join Date: Feb 2007
Rookie Year: 2007
Location: MD
Posts: 40
RyanW has a spectacular aura aboutRyanW has a spectacular aura about
Re: Code For Mecanum Wheels

Lesman,

The Jester Drive code posted by Adam takes three inputs instead of 2 - strafe (X) , forward/back (Y), and turn (Z), from -127 (full power backwards in that direction) to 127 (full power forwards in that direction). If any particular direction is 0, it ignores it. Otherwise, it takes the power in each direction, and figures out which way each wheel needs to go (for turning, left wheels and right wheels are opposite; for strafing, diagonal pairs of wheels are opposite).

Each wheel gives a diagonal vector when told to move forward or backwards, so you simply combine the vectors to get the direction you want.
The wheels should give output along the following lines:
/ \
\ /

So, for example,
127 X gives left front and right rear wheels at 127, left rear and right front wheels at -127, which would strafe to the right.
127 Y gives all wheels at 127, which would go forward.
127 Z gives left wheels at -127, right wheels at 127, which would turn left.

The rest of the code simply combines the three directions through addition, then divides by the number of directional inputs you are giving so that the final result goes from -127 to 127. Presumably, the next bit of code adds 127 to make the output an unsigned char (which is what PWMs actually take), and then sets each wheel motor to the respective variable.