View Single Post
  #4   Spotlight this post!  
Unread 24-04-2007, 23:11
Jake M Jake M is offline
void* Jake;
FRC #1178 (DURT)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Missouri
Posts: 118
Jake M has a spectacular aura aboutJake M has a spectacular aura about
Re: Default code question

The two equations that combine the X and Y values look confusing because they're simplified for space. There's actually some theory behind it. The un-simplified version looks like this.

Code:
pwm13 = pwm14 = Limit_Mix(2000 + (p1_y - 127) + (p1_x - 127) + 127);
pwm15 = pwm16 = Limit_Mix(2000 + (p1_y - 127) - (p1_x - 127) + 127);
Make more sense? There's three basic steps.

1: subtract 127 from the joystick values, so that the range is -127 to 127, rather than 0 to 254.

2: The theory behind the equation is that as Y changes, the motor outputs increase or decrease with each other. As X changes, the motor outputs become farther apart. Think about it. If Y increases, increase the output to both motors, to make them go forward. If X increases (left turn) you put one wheel forward, and the other in reverse. Thus, the basic idea of step 2 is that one wheel is Y + X, and the other is Y - X.

3: Add 127 to the final result, to make the range 0 to 254 once again.

And as for the one reversed motor, we usually just wire it in reverse, rather than make the code more complicated. For one, our main programming mentor would (bleep) about it if the code wasn't exactly perfect, and it makes it that much easier to understand months later.
__________________
Code:
void function(void)
 {
  function();
 }