Go to Post Honestly, I can't understand why anyone wouldn't want to be a mentor. The fools don't know what they are missing. - Steven Smith [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 18-02-2006, 14:33
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
How Can I aim at the Vision Target Faster but without overshooting?

We are using the camera so that the robot goes into a loop and moves the drive wheels until the camera tells us that it is centered. this lets us aim the robot at the light. I can get it to work but I can't get it to do it very fast. this is what i have so far right know.
Code:
  if  (aiming == 1 | p1_sw_trig == 1)
  {
    aiming = 1;
    Switch1_LED = 1;        // aiming light turns on when aiming
	if (p4_sw_trig == 1)
	{
      Switch1_LED = 0;
	  printf("override button pressed");
      aiming = 0;
    }
	else if (T_Packet_Data.confidence < 5)
    {
      Switch1_LED = 0;
	  printf("lost light lock");
      aiming = 0;
    }
    if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT + 20)
    {
      pwm03 = 127 - aim_gain;
      pwm04 = 127 + aim_gain;
    } 
    else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT - 20)
    {
      pwm03 = 127 + aim_gain;
      pwm04 = 127 - aim_gain;
    } 
    else if (PAN_SERVO < PAN_CENTER_PWM_DEFAULT + 21 & PAN_SERVO > PAN_CENTER_PWM_DEFAULT)
    {
      pwm03 = 127 + aim_soft_gain;
      pwm04 = 127 - aim_soft_gain;
    }
    else if (PAN_SERVO > PAN_CENTER_PWM_DEFAULT - 21 & PAN_SERVO < PAN_CENTER_PWM_DEFAULT)
    {
      pwm03 = 127 - aim_soft_gain;
      pwm04 = 127 + aim_soft_gain;
    } 
    else 
    {
      Switch1_LED = 0;
	  printf("TARGET ACQUIRED");
      aiming = 0;
    }
  }
note that
aim_gain = 22 and aim_soft_gain = 15

The code makes the robot overshoot and oscillate back and forth. it takes ten or more seconds to get it to center and this is not very good.

I know there is a way to use a linear or even quadratic formula to increase the speed and to reduce the amount of overshoot instead of what i have i just don't know how to go about programming it. Any help would be vary much appreciated.
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website

  #2   Spotlight this post!  
Unread 18-02-2006, 14:47
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

you have discovered the world of PID control loops.

When your system overshoots that means the gain on your Proportional (the P part) is too high

you can fix this by lowering the gain, or adding the D part (differential) to the feedback algorithm.

If you think of it in terms of distance, velocity and acceleration (of your robot to point towards the target) then the P is like distance (how far off are we from where we want to be)

the D is like velocity (how fast are we moving towards the place we want to be)

and the I is something you use to make fine adjustments to the P (how far off we are times how long we have been 'off').

This is a whole semister in college - a very deep subject. To be honest the best approach is to keep turning your gain down until you stop overshooting, or you overshoot just a little and then center on one 'bounce'.

Adding the I and D to the loop is more complex, and it will only make your response time slightly better than the slight-overshoot response time.
  #3   Spotlight this post!  
Unread 18-02-2006, 15:27
kaszeta's Avatar
kaszeta kaszeta is offline
Registered User
FRC #0095 (Grasshoppers)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2002
Location: Lebanon, NH
Posts: 334
kaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of lightkaszeta is a glorious beacon of light
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by KenWittlief
you have discovered the world of PID control loops.
Indeed. If you search around, you can even find some sample code that people have posted (Kevin's PID.C/H last year, and I posted a Proportional-only version of our teams gyro feedback code, amongst others).
  #4   Spotlight this post!  
Unread 18-02-2006, 15:51
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

something else that might help. When using feedback control (PID) loops, your system will respond better if it is way overpowered.

This means your bot needs to be able to turn very quickly. Another way of saying this is it needs to be able to turn very easily.

If you are using tank/skid steering and it take nearly full power to turn the robot, then the PID control system wont have any room to do its stuff (any headroom to make strong adjustments).

you might need to loosen up your steering by making the front wheels turn easier.

Another thing that causes overshoot is a slow response time. Make sure you code is as efficient as possible. Comment out all printF statements, and any other code that doesn't need to be there.

Think of it this way, the control loop functions by telling the motors to do something, then looking to see what effect that had on the aim of the camera

if it takes a long time for the control loop to 'look and see' then the response will be too slow for a tight (fast) lock on target.

Last edited by KenWittlief : 18-02-2006 at 15:54.
  #5   Spotlight this post!  
Unread 18-02-2006, 18:28
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

My two cents about PID loops.

Today I tried implementing a PI loop. I've never done one before and was relying on non-proven code. I spent about three hours and called it quits. My new code that works great:

Code:
PAN_MOTOR	=	NEUTRAL + (pan_error / 5) + 11;
Adjust 5 and 11 to your needs.

Quote from my mentor: "Keep things as complex as necessary, and not a bit more."
__________________
http://www.mikesorrenti.com/
  #6   Spotlight this post!  
Unread 18-02-2006, 20:02
phrontist's Avatar
phrontist phrontist is offline
Proto-Engineer
AKA: Bjorn Westergard
FRC #1418 (Vae Victus)
Team Role: College Student
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Falls Church, VA
Posts: 828
phrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond repute
Send a message via AIM to phrontist
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by Mike
My two cents about PID loops.

Today I tried implementing a PI loop. I've never done one before and was relying on non-proven code. I spent about three hours and called it quits. My new code that works great:

Code:
PAN_MOTOR	=	NEUTRAL + (pan_error / 5) + 11;
Adjust 5 and 11 to your needs.

Quote from my mentor: "Keep things as complex as necessary, and not a bit more."
For future refrence, for an application like a turret one would typically start with just P, and D to damp, and if it's too sluggish after damping (or you have steady state error) and I. In that order.
__________________

University of Kentucky - Radio Free Lexington

"I would rather have a really big success or a really spectacular crash and failure then live out the warm eventual death of mediocrity" - Dean Kamen
  #7   Spotlight this post!  
Unread 18-02-2006, 20:26
KenWittlief KenWittlief is offline
.
no team
Team Role: Engineer
 
Join Date: Mar 2003
Location: Rochester, NY
Posts: 4,213
KenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond reputeKenWittlief has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by Mike
My two cents about PID loops.

Today I tried implementing a PI loop. I've never done one before and was relying on non-proven code. I spent about three hours and called it quits. My new code that works great:

Code:
PAN_MOTOR	=	NEUTRAL + (pan_error / 5) + 11;
Adjust 5 and 11 to your needs.

Quote from my mentor: "Keep things as complex as necessary, and not a bit more."
an excellent example! Pan error is the error signal (distance) from where you want to be. Pan error / 5 means your feedback gain is 0.2

Im not sure why you need the +11. That seems to be a zero point error, or maybe there is a zero point error in your feedback signal?
  #8   Spotlight this post!  
Unread 18-02-2006, 20:34
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
Re: How Can I aim at the Vision Target Faster but without overshooting?

yes usually a simple proportional loop is pretty effective...
i don't get the point of the +11 (recentering perhaps?)

But for us it wasn't smooth/good enough (our robot is very rocky at turning...looking into omni wheels but thats another story)
if you go to kevin.org there is a nice PID code you can use...
__________________
Team 701
  #9   Spotlight this post!  
Unread 18-02-2006, 20:55
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Cañada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Cañada, California
Posts: 1,335
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by NextPerception
The code makes the robot overshoot and oscillate back and forth. it takes ten or more seconds to get it to center and this is not very good.

I know there is a way to use a linear or even quadratic formula to increase the speed and to reduce the amount of overshoot instead of what i have i just don't know how to go about programming it. Any help would be vary much appreciated.
Here's a piece of code from the camera software (tracking.c) that implements a simple proportional controller:

-Kevin

Code:
static unsigned char pan_servo_position;
int temp_pan_servo;
int servo_step;
int pan_error;
 
// save the current pan servo PWM value into a local
// integer variable so that we can detect and correct 
// underflow and overflow conditions before we update 
// the pan servo PWM value with a new value
temp_pan_servo = (int)pan_servo_position;
 
// calculate how many image pixels we're away from the
// vertical center line.
pan_error = (int)T_Packet_Data.mx - (int)Tracking_Config_Data.Pan_Target_Pixel;
 
// Are we too far to the left or right of the vertical 
// center line? If so, calculate how far we should step
// the pan servo to reduce the error.
if(pan_error > (int)Tracking_Config_Data.Pan_Allowable_Error)
{
	// calculate how far we need to step the pan servo
	servo_step = pan_error / (int)Tracking_Config_Data.Pan_Gain;
 
	// Due to rounding error in the division calculation above,
	// the step may be calculated as zero, which will make it
	// impossible to converge on the target when x_error is
	// smaller than X_GAIN. To get around this problem, we just 
	// test for the zero case and set the step size to one. 
	if(servo_step == 0)
	{
	 servo_step = 1;
	}
}
else if(pan_error < -1 * (int)Tracking_Config_Data.Pan_Allowable_Error)
{
	// calculate how far we need to step the pan servo
	servo_step = pan_error / (int)Tracking_Config_Data.Pan_Gain;
 
	// Due to rounding error in the division calculation above,
	// the step may be calculated as zero, which will make it
	// impossible to converge on the target when x_error is
	// smaller than X_GAIN. To get around this problem, we just 
	// test for the zero case and set the step size to one. 
	if(servo_step == 0)
	{
	 servo_step = -1;
	}
}
else
{
	// if we've fallen through to here, it means that we're
	// neither too far to the left or too far to the right
	// of the vertical center line of the image and don't 
	// need to move the servo
	servo_step = 0;
}
 
// add the step to the current servo position, taking into
// account the direction set by the user in tracking.h
temp_pan_servo += ((int)Tracking_Config_Data.Pan_Rotation_Sign * servo_step);
 
// check the pan servo PWM value for under/overflow
if(temp_pan_servo < (int)Tracking_Config_Data.Pan_Min_PWM)
{
	temp_pan_servo = (int)Tracking_Config_Data.Pan_Min_PWM;
}
else if(temp_pan_servo > (int)Tracking_Config_Data.Pan_Max_PWM)
{
	temp_pan_servo = (int)Tracking_Config_Data.Pan_Max_PWM;
}
pan_servo_position = (unsigned char)temp_pan_servo;
// update pan servo PWM value
Set_Pan_Servo_Position(pan_servo_position);
__________________
Kevin Watson
Engineer at stealth-mode startup
http://kevin.org
  #10   Spotlight this post!  
Unread 18-02-2006, 22:41
Mike's Avatar
Mike Mike is offline
has common ground with Matt Krass
AKA: Mike Sorrenti
FRC #0237 (Sie-H2O-Bots (See-Hoe-Bots) [T.R.I.B.E.])
Team Role: Programmer
 
Join Date: Dec 2004
Rookie Year: 2004
Location: Watertown, CT
Posts: 1,003
Mike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond reputeMike has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by KenWittlief
an excellent example! Pan error is the error signal (distance) from where you want to be. Pan error / 5 means your feedback gain is 0.2

Im not sure why you need the +11. That seems to be a zero point error, or maybe there is a zero point error in your feedback signal?
Not sure what you mean by "zero point error" but the reasoning for the +11 is that eventually the motor would get to a point (say 133) where it was attempting to move the turret but did not have enough power too. So the +11 turns that into 144 and it moves the turret fine.
__________________
http://www.mikesorrenti.com/
  #11   Spotlight this post!  
Unread 18-02-2006, 23:34
NextPerception NextPerception is offline
Sleep-Deprived
AKA: Matt
FRC #0437 (Richardson Robotics)
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2005
Location: Richardson, TX
Posts: 69
NextPerception has a spectacular aura aboutNextPerception has a spectacular aura aboutNextPerception has a spectacular aura about
Send a message via AIM to NextPerception
Re: How Can I aim at the Vision Target Faster but without overshooting?

wow thanks this cut the time in half. this works great.
__________________
What is this S - L - E - E - P you speak of?
Battlebots - My Robotics Website

  #12   Spotlight this post!  
Unread 18-02-2006, 23:42
Rick TYler Rick TYler is offline
A VEX GUy WIth A STicky SHift KEy
VRC #0010 (Exothermic Robotics)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Redmond, Washington
Posts: 2,000
Rick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by Mike
Not sure what you mean by "zero point error" but the reasoning for the +11 is that eventually the motor would get to a point (say 133) where it was attempting to move the turret but did not have enough power too. So the +11 turns that into 144 and it moves the turret fine.
After putting Victors on a meter, we've found that they center at about 132 instead of 127. Move your center-logic to 132 and your PD solution may work better. It sure helped ours. (Kevin Watson's PID code from 2005 uses 132 as its center point, by the way.) I'm assuming that your NEUTRAL is currently set to 127. If it isn't, you can just forget I said anything.
__________________
Exothermic Robotics Club, Venturing Crew 2036
VRC 10A, 10B, 10D, 10Q, 10V, 10X, 10Z, and 575
  #13   Spotlight this post!  
Unread 19-02-2006, 00:21
phrontist's Avatar
phrontist phrontist is offline
Proto-Engineer
AKA: Bjorn Westergard
FRC #1418 (Vae Victus)
Team Role: College Student
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Falls Church, VA
Posts: 828
phrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond reputephrontist has a reputation beyond repute
Send a message via AIM to phrontist
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by Rick TYler
After putting Victors on a meter, we've found that they center at about 132 instead of 127. Move your center-logic to 132 and your PD solution may work better. It sure helped ours. (Kevin Watson's PID code from 2005 uses 132 as its center point, by the way.) I'm assuming that your NEUTRAL is currently set to 127. If it isn't, you can just forget I said anything.
You shouldn't do that. You should calibrate the victors. See IFI documentation.
__________________

University of Kentucky - Radio Free Lexington

"I would rather have a really big success or a really spectacular crash and failure then live out the warm eventual death of mediocrity" - Dean Kamen
  #14   Spotlight this post!  
Unread 19-02-2006, 00:27
Rick TYler Rick TYler is offline
A VEX GUy WIth A STicky SHift KEy
VRC #0010 (Exothermic Robotics)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Redmond, Washington
Posts: 2,000
Rick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond reputeRick TYler has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by phrontist
You shouldn't do that. You should calibrate the victors. See IFI documentation.
Been there. Done that. All four Victors used for the drive system had identical outputs after calibration, and their zero value was 132. I can't speak for every Victor in the world, but our gyro autonomous code and our manual PID program both drive straight now.

Just my opinion. Professional driver on closed course. Do not try this at home. Read the manual. Your mileage may vary.
__________________
Exothermic Robotics Club, Venturing Crew 2036
VRC 10A, 10B, 10D, 10Q, 10V, 10X, 10Z, and 575
  #15   Spotlight this post!  
Unread 19-02-2006, 01:34
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: How Can I aim at the Vision Target Faster but without overshooting?

Quote:
Originally Posted by Rick TYler
After putting Victors on a meter, we've found that they center at about 132 instead of 127. Move your center-logic to 132 and your PD solution may work better. It sure helped ours. (Kevin Watson's PID code from 2005 uses 132 as its center point, by the way.) I'm assuming that your NEUTRAL is currently set to 127. If it isn't, you can just forget I said anything.
Wow. I've been going from the official IFI documentation which says the Victor deadband is 117-137. I never gave it a second thought. But that would perfectly explain the asymmetric PID response I wrestled with a week ago.

I will take a few minutes on Monday to characterize our Victors and see if they show the same center as yours. It'll definitely make a difference if the true neutral really is 132.
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
Durability of Vision Target geeknerd99 General Forum 13 11-02-2006 14:15
Vision Target Assembly platt Kit & Additional Hardware 4 26-01-2006 17:34
Vision Target power supply AUWarEagle#1 Electrical 3 18-01-2006 22:17
Question concerning vision target Otrobotics General Forum 17 15-01-2006 15:59


All times are GMT -5. The time now is 16:47.

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