|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools | Rate Thread | Display Modes |
|
#3
|
||||
|
||||
|
Re: Speed limiting code from last year in C?
Well, I just spent 18 minutes re-writing the code on here (my laptop isn't with me) and it didn't post!
I'm sorry, I'm exhausted, and I'm going to bed now, but here's what I'm trying to do, with topspeed instead of p1_wheel: p1_wheel = (((p1_wheel*154)/254)+100) MAX 254 'adjust wheel to 154-254 IF drive_R < 127 THEN drive_R_reverse: 'is the right drive forward drive_R = (drive_R - 127) MIN 0 'subract 127 to get the forward value drive_R = (drive_R * p1_wheel)/254 'multiply by the wheel percentage drive_R = (drive_R + 127) MAX 254 'add 127 back for proper output GOTO drive_R_done: 'exit the drive right section drive_R_reverse: 'the right drive is reverse drive_R = (127 - drive_R) MIN 0 'invert drive-R to get a forward value drive_R = (drive_R * p1_wheel)/254 'multiply by the wheel percentage drive_R = (127 - drive_R) MIN 0 'invert drive_R back to normal drive_R_done: 'drive_R section complete IF drive_L < 127 THEN drive_L_reverse: 'is the left drive forward drive_L = (drive_L - 127) MIN 0 'subract 127 to get the forward value drive_L = (drive_L * p1_wheel)/254 'multiply by the wheel percentage drive_L = (drive_L + 127) MAX 254 'add 127 back for proper output GOTO drive_L_done: 'exit the left right section drive_L_reverse: 'the left drive is reverse drive_L = (127 - drive_L) MIN 0 'invert drive-L to get a forward value drive_L = (drive_L * p1_wheel)/254 'multiply by the wheel percentage drive_L = (127 - drive_L) MIN 0 'invert drive_R back to normal drive_L_done: 'drive_L section complete Edit: Okay, so I lied, I'm not going to bed just yet . I have to get this programming bug out of my system!;Does this look like it would work? Its should be the same as above, except without the error protection (min 0/max 254) Code:
unsigned int topspeed = 127;
if (pwm01 > 127) {
pwm01 = ((((pwm01 - 127)*topspeed)/254)+127);
}
if (pwm02 > 127) {
pwm02 = ((((pwm02 - 127)*topspeed)/254)+127);
}
if (pwm01 < 127) {
pwm01 = (127-(((127 - pwm01)*topspeed)/254));
}
if (pwm02 < 127) {
pwm02 = (127-(((127 - pwm02)*topspeed)/254));
}
Last edited by Josh Siegel : 28-03-2004 at 23:29. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Great year. | archiver | 1999 | 0 | 23-06-2002 22:46 |
| Wow! what a year | archiver | 2000 | 8 | 23-06-2002 22:43 |
| 2000 not a new Millenium | archiver | 2000 | 7 | 23-06-2002 22:17 |
| "Motors and Drive train edition" of Fresh From the Forum | Ken Leung | CD Forum Support | 6 | 29-01-2002 12:32 |
| speed control | punarhero | Technical Discussion | 11 | 24-01-2002 18:03 |