|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Incrementation Code not working
We were working on our Incrementation code for our control system, it just makes sure we dont' make abrupt changes in our movements that could damage something....we had it working for the Y coordinates, but then we incorporated it into a function so both Y and X could call on it. That's where everything went wrong....The servos we were testing with would move in random directions without us controlling. Here is the code we wrote:
Code:
int Incrementation_Code(int motor_curr, int motor_prev, int padd, int max_step)
{
int change = 0;
int RetVal;
change = motor_curr - motor_prev;
if (change >= padd)
{
//Accelerate
if (change > max_step)
{
RetVal = motor_prev + max_step;
printf("Motor accelerated by MAX = %d. ", max_step);
}
else
{
printf("Motor accelerated by %d. ", change);
}
if ( RetVal > 255 )
{
RetVal = 255;
printf("Detected excess of 255! ");
}
}
else if (change <= -padd)
{
//Decelerate
if (change < -max_step)
{
RetVal = motor_prev - max_step;
printf("Motor decelerated by MAX = %d. ", max_step);
}
else
{
printf("Motor decelerated by %d. ", change);
}
if (RetVal < 0)
{
RetVal = 0;
printf("Detected below-zero condition! ");
}
}
else
{
//no change
RetVal = motor_prev;
printf("No change in motor output value. ");
}
printf("\r\n");
return RetVal;
}
int last_p1x_val=128;
int last_p1y_val=128;
void Default_Routine(void)
{
int maximum_step=10;
int padding=3;
/*---------- Analog Inputs (Joysticks) to PWM Outputs-----------------------
*--------------------------------------------------------------------------
* This maps the joystick axes to specific PWM outputs. */
p1_y = Incrementation_Code(p1_y, last_p1y_val, padding, maximum_step);
last_p1y_val = p1_y;
pwm01 = p1_y;
pwm02 = p2_y;
pwm03 = p3_y;
pwm04 = p4_y;
p1_x = Incrementation_Code(p1_x, last_p1x_val, padding, maximum_step);
last_p1x_val = p1_x;
pwm05 = p1_x;
pwm06 = p2_x;
pwm07 = p3_x;
pwm08 = p4_x;
pwm09 = p1_wheel;
pwm10 = p2_wheel;
pwm11 = p3_wheel;
pwm12 = p4_wheel;
|
|
#2
|
||||
|
||||
|
Re: Incrementation Code not working
Do both servos move erratically, or only the X servo?
Did you change the Incrementation_Code function? If you have a copy that worked with only one servo try changing it so it uses the other servo/input. I will test the code tonight, and see if I can find the problem. Last edited by EHaskins : 12-02-2007 at 14:25. |
|
#3
|
||||||
|
||||||
|
Re: Incrementation Code not working
You don't set RetVal in all branches of your function.
|
|
#4
|
||||
|
||||
|
Re: Incrementation Code not working
Joe Ross is right.
Code:
//Accelerate
if (change > max_step)
{
RetVal = motor_prev + max_step;
printf("Motor accelerated by MAX = %d. ", max_step);
}
else
{
printf("Motor accelerated by %d. ", change);
RetVal = motor_prev + change;
}
.....
//Decelerate
if (change < -max_step)
{
RetVal = motor_prev - max_step;
printf("Motor decelerated by MAX = %d. ", max_step);
}
else
{
printf("Motor decelerated by %d. ", change);
RetVal = motor_prev - change;
}
|
|
#5
|
|||
|
|||
|
Re: Incrementation Code not working
Quote:
Quote:
I can't believe we didn't notice that Thanks for the help! I'll be sure to test that when I get the chance tonight. |
|
#6
|
||||
|
||||
|
Re: Incrementation Code not working
Good luck.
|
|
#7
|
|||
|
|||
|
Re: Incrementation Code not working
It works fine!! The only difference than what you provided in the code was to assign it the motor_curr rather than adding or subtracting the change.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Subscriptions not working? | Jeff Waegelin | CD Forum Support | 2 | 07-02-2007 14:11 |
| easyc demo code not working | sniggel | Programming | 5 | 28-01-2007 16:40 |
| 2007 demo code not working | thefro526 | Programming | 4 | 12-01-2007 23:43 |
| Camera code not working.... | DemonYawgmoth | Programming | 5 | 11-02-2006 09:21 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |