View Single Post
  #1   Spotlight this post!  
Unread 02-02-2008, 13:26
EHaskins EHaskins is offline
Needs to change his user title.
AKA: Eric Haskins
no team (CARD #6 (SCOE))
Team Role: College Student
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Elkhorn, WI USA
Posts: 998
EHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond reputeEHaskins has a reputation beyond repute
Send a message via MSN to EHaskins
Problem with negitive numbers

I've been working on a velocity PID for motor control, but I'm having trouble.

When the PID calculation returns a positive value the code runs fine, but when it return a negitice value the motor output begins jumping appearently randomly from very high(5 digit) to very low(-5 digit) values.

Once this happens the PID reacts correctly, but due to the values that a far outside of normal it never recovers.

Here is the code I think contains the issue, but I can't find it. I added some comments to help explain the issue.
Code:
void MotorControl (unsigned char motor)
{
         
    //The printfs in CalculateSpeed() give correct data. 

	int speed = CalculateSpeed(motor);
	int output;
	//printf("speed on motor %d = %d\r\n", motor);
	//printf("Speed Goal = %d\r\n", speedGoal[motor]);

    // Last line in PID prints the PID output, and it always appears correctly. 

	output = PID(speed, speedGoal[motor], &pidInfo[motor]);
 	currentOutput[motor] += output;

	if (loopCount == 0)
	{
          //This is where the issue is obvious. It prints strange values within
          //the same loop as PID() returns a negitive value, and then until reset.

        
		printf("Output %d = %d\r\n\r\n\r\n", motor, (int)currentOutput[motor]);
	}
	switch (motor)
	{
		case 0:
			MOTOR_ONE = LimitInput(currentOutput[motor] + 127, 0, 255);
			//printf("Motor one set during %d\r\n", motor);
			break;
		case 1:
			MOTOR_TWO = LimitInput(currentOutput[motor] + 127, 0, 255);
			//printf("Motor one set during %d\r\n", motor);
			break;
	}
}
__________________
Eric Haskins KC9JVH

Last edited by EHaskins : 03-02-2008 at 12:58.