Go to Post Mark McLeod, one of the resident experts on compiler weirdness - Kevin Watson [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 12-02-2007, 14:09
benhulett benhulett is offline
Registered User
FRC #1895
 
Join Date: Feb 2007
Location: Manassas
Posts: 28
benhulett is on a distinguished road
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   Spotlight this post!  
Unread 12-02-2007, 14:21
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
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.
__________________
Eric Haskins KC9JVH

Last edited by EHaskins : 12-02-2007 at 14:25.
  #3   Spotlight this post!  
Unread 12-02-2007, 14:24
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,588
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Incrementation Code not working

You don't set RetVal in all branches of your function.
  #4   Spotlight this post!  
Unread 12-02-2007, 14:29
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
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;
    }
__________________
Eric Haskins KC9JVH
  #5   Spotlight this post!  
Unread 12-02-2007, 14:33
benhulett benhulett is offline
Registered User
FRC #1895
 
Join Date: Feb 2007
Location: Manassas
Posts: 28
benhulett is on a distinguished road
Re: Incrementation Code not working

Quote:
Originally Posted by Joe Ross
You don't set RetVal in all branches of your function.
Quote:
Originally Posted by EHaskins
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;
    }

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   Spotlight this post!  
Unread 12-02-2007, 14:46
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
Re: Incrementation Code not working

Good luck.
__________________
Eric Haskins KC9JVH
  #7   Spotlight this post!  
Unread 12-02-2007, 17:39
benhulett benhulett is offline
Registered User
FRC #1895
 
Join Date: Feb 2007
Location: Manassas
Posts: 28
benhulett is on a distinguished road
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.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 00:25.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi