|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#2
|
|||||
|
|||||
|
Okay. I'm going to assume that your wheel is simply a potentiometer with a wheel attached. This means that it will simply read a value between 0 and 254, 0 all the way left, 254 all the way right. One solution to your problem of over correction would be what my team has come to call a "slew rate." We have incurred the same problem letting our joystick snap back into place, and it kind of bounces around. What you must do is ramp the speed of your rotation. I will do it with the default tank drive code, since I am not sure what your drive code is, but it should be easy to apply to your code.
pwm1_old var byte pwm2_old var byte slew_rate CON 5 'Or however much you decide it should be pwm1_old = pwm1 pwm2_old = pwm2 PWM1 = (((2000 + p1_y - p1_x + 127) Min 2000 Max 2254) -2000) PWM2 = (((2000 + p1_y + p1_x - 127) Min 2000 Max 2254) -2000) 'The above two lines could be replaced by your current code If (abs(pwm1-pwm1_old) < slew_rate) then noslew1 If pwm1>pwm1_old then pwm1=((pwm1_old+slew_rate)MAX 254) If pwm1<pwm1_old then pwm1=((pwm1_old-slew_rate)MIN 0) noslew1: If (abs(pwm2-pwm2_old) < slew_rate) then noslew2 If pwm2>pwm2_old then pwm2=((pwm2_old+slew_rate)MAX 254) If pwm2<pwm2_old then pwm2=((pwm2_old-slew_rate)MIN 0) noslew2: This code stores the old value of the motor outputs, then assigns the new motor output based on the joystick (in your case a steering wheel. It then goes on to check if the new value is "close enough" to your old value, in other words within your constant, 5 in my case. If it is not within the constant, it adds or subtracts the constant to the old value, and assigns it to your new motor output. This will, in effect, add or subtract a constant to your motor speed every loop until it reaches the correct point on your steering wheel. I hope this helps you out! |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 4 wheel steering/ Crab | Huey_Da_X-cat | Technical Discussion | 3 | 11-02-2002 22:49 |
| "Motors and Drive train edition" of Fresh From the Forum | Ken Leung | CD Forum Support | 6 | 29-01-2002 12:32 |