View Single Post
  #6   Spotlight this post!  
Unread 04-02-2007, 19:44
Shinigami2057 Shinigami2057 is offline
Slackware Is Your New God (Mentor)
AKA: Harry Bock
FRC #1350 (Rambots)
Team Role: Programmer
 
Join Date: Oct 2006
Rookie Year: 2006
Location: Johnston, RI
Posts: 106
Shinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really niceShinigami2057 is just really nice
Re: Code to have speed of motors dependent on how hard you push the joystick

What did you edit it to? It should be easy for you to take what you changed and adapt it to match the joystick mapping in the default code.

You can directly map the joystick value to a PWM, as they are both in the 0-255 range with 127 being "neutral" or "off." If you need to reverse the direction of a joystick to match your CIM configuration, you can just subtract the joystick axis from 255, like so:

Code:
pwm01 = p1_y; /* Left drive train maps directly from port 1 y axis to pwm01. */
pwm02 = 255 - p2_y; /* Right drive train does the same, but in reverse. */
To make things smoother (eliminate noise etc) you could use a lookup table to map joystick values.
__________________
One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs.