|
Re: Need help with ramping in VEX EasyC
The last example will solve the compile problem, but now I think you need to fix your logic.
for ( step1 = 0, step2 = 255 ; step1 < 127 && step2 > 127 ; step1 += 5, step2 += 5 )
If you want the motors to ramp from stopped to maximum speed in steps of 5, the statement would need to change to:
for ( step1 = 127, step2 = 127 ; step1 < 255 && step2 > 0 ; step1 += 5, step2 -= 5 )
You also need to consider that the system (the robot and motors) will not respond instantaneously to changes in pwm values. There needs to be some kind of delay between each new set values that are sent to the motors.
If step1 and step2 are unsigned char variables, there is also an issue with the increment/decrement by 5. The variables will wrap when the increment takes the value beyond 255 or the decrement takes the value beyond 0. It will take three passes before the for loop will end. Run the example below to see the problem:
#include "Main.h"
void main ( void )
{
unsigned char step1 = 127;
unsigned char step2 = 127;
PrintToScreen ( "Starting\n" ) ;
for ( step1 = 127, step2 = 127 ; step1 < 255 && step2 > 0 ; step1 += 5, step2 -= 5 )
{
PrintToScreen ( "Value of step1 is: %d\n" , (int)step1 ) ;
PrintToScreen ( "Value of step2 is: %d\n" , (int)step2 ) ;
}
PrintToScreen ( "Finished\n" ) ;
}
To address this problem:
Change increment/decrement to 1 or
use signed short instead of unsigned char and make sure that the value sent to the motors is within the range of 0 to 255.
__________________
FRC 623 2003,2004,2005,2006,2007,2008, 2009, 2010, 2011
FRC 1900 2007
FVC 60 and 193 2006
FVC 3271 2007
FTC 226 and 369 2008, 2009, 2010, 2011
FTC 3806 2010
Last edited by charrisTTI : 03-11-2006 at 12:15.
|