Go to Post This exercise in thanking the hand that teaches you brought to you by the Unsung FIRST Heroes Award. Have you thanked your mentor lately? - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 8 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 12-02-2011, 10:40
SeanTeags's Avatar
SeanTeags SeanTeags is offline
Tigger
AKA: Sean
FRC #1403 (Cougar Robotics)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2008
Location: New Jersey
Posts: 4
SeanTeags is an unknown quantity at this point
Acceleration based on position

On this years robot we are using an Encoder to tell the Elevator that is placing the tubes the distance it's going up and down, We want the Elevator to slow down when it reaches X height/# of rotations of the motor AKA a Speed Curve. I have no idea how to code this I don't know how to approch this or where to start , if you have some sample code to help me get started that would be greatly appriciated.

-Thanks
Sean Teager
__________________
FIRST Team 1403 Cougar Robotics

2008,2009- Programmer
2010,2011- Programming Team Captain
2010,2011- Safety Captain
2010,2011- Drive Team
2012-Present -Mentor

Reply With Quote
  #2   Spotlight this post!  
Unread 12-02-2011, 11:03
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,833
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Acceleration based on position

That's what PID does. The (P)roportional term causes a slow down as the target setpoint is approached.
Here's an example of a motor position slaved to the position of a joystick.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 12-02-2011 at 11:27.
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2011, 11:14
Mtg Ruler Mtg Ruler is offline
Registered User
FRC #1986 (Team Titanium)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Lee's Summit, MO
Posts: 21
Mtg Ruler is an unknown quantity at this point
Re: Acceleration based on position

I would recommend PID to control this. Our team is doing a similar thing, and this is working well.

Quick overview of PID.
P-Proportional Gain-Bases motor output based off of how far away from the target you are. The higher the number, the faster you approach your goal, but it is less accurate at holding that position

I-Integral Change-Look at how error has accumulated over time, and correct for it. The higher the number, the further back it looks, which will slow down your approach as you get closer (but will hold it closer to where you want).

D-Derivative Time- Look at how fast the rate is changing and compensate so it does not overshoot your goal. The higher the number, the further ahead it looks, which will slow down your approach


Most likely, you will only need the P part, which should hold it close enough to where you want. I would increase the number until the elevator has a visible shake to it. (from the P part over-correcting)

If this is confusing, try messing with the "General Auto PID Simulator" in the FRC examples. Its a good way to figure out the relationship between P,I, and D


Once you start actually testing your elevator, be sure to have preprogrammed upper and lower limits so you dont break your elevator as well as a few setpoints to move to. If the elevator does not seem to slow down as it approaches a setpoint, you may have the motor wired inversely with the encoder output. Either reverse the motor, or change the P value to be negative instead of positive.
Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2011, 11:38
SeanTeags's Avatar
SeanTeags SeanTeags is offline
Tigger
AKA: Sean
FRC #1403 (Cougar Robotics)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2008
Location: New Jersey
Posts: 4
SeanTeags is an unknown quantity at this point
Re: Acceleration based on position

Thank you all for your quick responses! However, our team mentor says that we cannot use PID controllers because it would lead to a host of other problems . Are there other alternative solutions for the aforementioned problem?

Thanks in advance,
Sean Teager
__________________
FIRST Team 1403 Cougar Robotics

2008,2009- Programmer
2010,2011- Programming Team Captain
2010,2011- Safety Captain
2010,2011- Drive Team
2012-Present -Mentor

Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2011, 11:53
Vikesrock's Avatar
Vikesrock Vikesrock is offline
Team 2175 Founder
AKA: Kevin O'Connor
no team
Team Role: Engineer
 
Join Date: Mar 2006
Rookie Year: 2007
Location: Manchester, NH
Posts: 3,305
Vikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond reputeVikesrock has a reputation beyond repute
Send a message via AIM to Vikesrock Send a message via MSN to Vikesrock Send a message via Yahoo to Vikesrock
Re: Acceleration based on position

Quote:
Originally Posted by SeanTeags View Post
Thank you all for your quick responses! However, our team mentor says that we cannot use PID controllers because it would lead to a host of other problems . Are there other alternative solutions for the aforementioned problem?

Thanks in advance,
Sean Teager
What you described in your first post is exactly a P-only controller. Whether you implement it yourself or with the built in PID VI, the same issues will still be present.
__________________


2007 Wisconsin Regional Highest Rookie Seed & Regional Finalists (Thanks 930 & 2039)
2008 MN Regional Semifinalists (Thanks 2472 & 1756)
2009 Northstar Regional Semifinalists (Thanks 171 & 525)
Reply With Quote
  #6   Spotlight this post!  
Unread 12-02-2011, 11:55
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Acceleration based on position

Tell them you only want a proportional controller, that is often all you need for position anyway. Once that is working well, it is easy to add a bit of I if the position is off a bit.

It would be useful to know if there are other reasons what the host of problems is.

Greg McKaskle
Reply With Quote
  #7   Spotlight this post!  
Unread 12-02-2011, 18:22
umangv620 umangv620 is offline
Programming Captain
AKA: Umang
FRC #1403 (Cougar Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2008
Location: New Jersey
Posts: 80
umangv620 will become famous soon enoughumangv620 will become famous soon enough
Re: Acceleration based on position

It seems that we were confused as to what a PID is. Our team mentor told us that it was something that plugged into a jaguar, while you guys were referring to PID in the code (though im still not sure what a PID actually is).

Is the code that Mark linked to using a potentiometer to slow down motor speed in the PID? Currently, we are solely using an encoder on our elevator motor. Do I need to wire a potentiometer in order to slow down the movement of the motor as it gets closer to its set points or can this be achieved without a potentiometer?
__________________
Team 1403 Cougar Robotics

2009-2011 Programming Captain

2010
NJ-Regional - Chairmans Award
Reply With Quote
  #8   Spotlight this post!  
Unread 12-02-2011, 19:01
Jon236's Avatar
Jon236 Jon236 is offline
Registered User
AKA: Jon Mittelman
FRC #2648 (Infinite Loop)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Windsor, Maine
Posts: 741
Jon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond repute
Re: Acceleration based on position

You can use the encoder you have on the elevator motor. The proportional controller that Greg is referring to can be implemented easily in any language. If you use Labview, it is available to you on the vi pallette. If you are using C++ or Java, it is easy to implement. The PIDController Class is described well here: http://www.wbrobotics.com/javadoc/ed...ontroller.html

All any of the code does is compare (subtract) your current encoder value from the desired encoder value, giving you an error value. The (P)roportional controller multiplies the P constant times the error and scales your motor output. As the error gets less, you can see that the motor value will fall, slowing down the motor.
__________________
Jon Mittelman

Senior Judge Advisor New England & Israel 2014-2015
Infinite Loop Mentor 2011-2015
TechnoTicks Mentor 2000-2011
Championship Chairman's Award 2009 Team236 TechnoTicks
Judge 2010-2015 Championships
Senior Judge Advisor New England District Championship 2014-2015
Judge Advisor Tel Aviv Regional 2007-2015
Judge Advisor Pine Tree Regional 2013
Maine Regional Planning Committee
New England District Planning Committee
Lead Inspector Microsoft Tel Aviv Regional 2006-2008
Judge & Lead Inspector GM/Technion Tel Aviv Regional 2006
Judge UTC Hartford Regional 2006
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2011, 21:51
umangv620 umangv620 is offline
Programming Captain
AKA: Umang
FRC #1403 (Cougar Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2008
Location: New Jersey
Posts: 80
umangv620 will become famous soon enoughumangv620 will become famous soon enough
Re: Acceleration based on position

I tried implementing Mark's example and my encoder into the code, and got this: http://img687.imageshack.us/img687/4504/photodtz.jpg (sorry for the bad screenshot).

There is a (-x) on Joystick 2 axis 2 because going forward gives -1 for some reason, and we have no clue how to calibrate the logitech attack 3 joysticks. It shouldn't change anything in the code, right?

When I deployed this and clicked enable on DS, the elevator suddenly started moving up, and about halfway, it started jerking down and up. By then I rushed to click disable, but no one was moving the joystick during the deployment. Why did the elevator start moving on its own? Since the joystick wasn't moving, its value was 0, and the encoder reset its value to 0 when I clicked enable, so it shouldnt move, right?

Or did I miss something while coding the PID? (Wasn't really sure what the 3,0,0 for PID meant in mark's code, so I just tried using 1 and keeping it simple).
__________________
Team 1403 Cougar Robotics

2009-2011 Programming Captain

2010
NJ-Regional - Chairmans Award

Last edited by umangv620 : 13-02-2011 at 21:53.
Reply With Quote
  #10   Spotlight this post!  
Unread 14-02-2011, 06:36
Triapod Triapod is offline
Registered User
no team
Team Role: Programmer
 
Join Date: Mar 2010
Rookie Year: 2005
Location: NJ
Posts: 28
Triapod is an unknown quantity at this point
Re: Acceleration based on position

If i'm following the math correctly...It's probably that +1 that makes the joystick send out a value other than 0 because in this case it will only be 0 if the joystick is all the way back.

You might want to try preset heights controlled by buttons. It seems that you'll need to hold the joystick at that position in order for the hight to remain there.

Last edited by Triapod : 14-02-2011 at 06:40.
Reply With Quote
  #11   Spotlight this post!  
Unread 14-02-2011, 08:49
umangv620 umangv620 is offline
Programming Captain
AKA: Umang
FRC #1403 (Cougar Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2008
Location: New Jersey
Posts: 80
umangv620 will become famous soon enoughumangv620 will become famous soon enough
Re: Acceleration based on position

Quote:
Originally Posted by Triapod View Post
If i'm following the math correctly...It's probably that +1 that makes the joystick send out a value other than 0 because in this case it will only be 0 if the joystick is all the way back.

You might want to try preset heights controlled by buttons. It seems that you'll need to hold the joystick at that position in order for the hight to remain there.
Thanks for clearing that up!

We still want joystick control of the elevator, but i wanted to use PID to slow down motor control as it hits the upper and lower limits (which I wanted to be recognized by a specific value from the encoder.

The elevator is controlled by axis 2. Lets say the upper limit is 1000 rotations, and the elevator starts at its bottom limit - 0. I want the motor to slow down as it reaches either of those two values so we don't overshoot and blow the motor. How should I go about doing that then?
__________________
Team 1403 Cougar Robotics

2009-2011 Programming Captain

2010
NJ-Regional - Chairmans Award
Reply With Quote
  #12   Spotlight this post!  
Unread 14-02-2011, 09:27
Jon236's Avatar
Jon236 Jon236 is offline
Registered User
AKA: Jon Mittelman
FRC #2648 (Infinite Loop)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Windsor, Maine
Posts: 741
Jon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond repute
Re: Acceleration based on position

You can use the joystick to select a value, only if you use a button to take a 'snapshot' of that value. That way, you will use that value as the new setpoint and the elevator will slow as it approaches it.
__________________
Jon Mittelman

Senior Judge Advisor New England & Israel 2014-2015
Infinite Loop Mentor 2011-2015
TechnoTicks Mentor 2000-2011
Championship Chairman's Award 2009 Team236 TechnoTicks
Judge 2010-2015 Championships
Senior Judge Advisor New England District Championship 2014-2015
Judge Advisor Tel Aviv Regional 2007-2015
Judge Advisor Pine Tree Regional 2013
Maine Regional Planning Committee
New England District Planning Committee
Lead Inspector Microsoft Tel Aviv Regional 2006-2008
Judge & Lead Inspector GM/Technion Tel Aviv Regional 2006
Judge UTC Hartford Regional 2006
Reply With Quote
  #13   Spotlight this post!  
Unread 14-02-2011, 10:02
umangv620 umangv620 is offline
Programming Captain
AKA: Umang
FRC #1403 (Cougar Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2008
Location: New Jersey
Posts: 80
umangv620 will become famous soon enoughumangv620 will become famous soon enough
Re: Acceleration based on position

While that might work, I want to be able to use the joystick to freely move the elevator for when we are hanging a tube in the middle peg or maybe for some other reason.

Could I have PID start slowing down the motor when it reaches 200 rotations close to either limit point? Or should I just use a bunch of case structures and comparisons to give the elevator different speeds based on its position? I've never used or heard of PID before, so I have no clue as to what it can or cant do.

oh, and for the second option above, is there a case structure that would let me run a set of code for a range of values (such as 0<n<200)?
__________________
Team 1403 Cougar Robotics

2009-2011 Programming Captain

2010
NJ-Regional - Chairmans Award
Reply With Quote
  #14   Spotlight this post!  
Unread 14-02-2011, 10:13
Jon236's Avatar
Jon236 Jon236 is offline
Registered User
AKA: Jon Mittelman
FRC #2648 (Infinite Loop)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Windsor, Maine
Posts: 741
Jon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond repute
Re: Acceleration based on position

PID control describes the means to control a process (elevator motion) by it's measured position (encoder) and your desired position (setpoint). You can use the PID code provided in Labview or the C++ or Java libraries, starting with only a Proportional constant.

So, you must choose a setpoint for the elevator to go to. If you are changing it with the joystick, then the elevator will simply go to that value.
__________________
Jon Mittelman

Senior Judge Advisor New England & Israel 2014-2015
Infinite Loop Mentor 2011-2015
TechnoTicks Mentor 2000-2011
Championship Chairman's Award 2009 Team236 TechnoTicks
Judge 2010-2015 Championships
Senior Judge Advisor New England District Championship 2014-2015
Judge Advisor Tel Aviv Regional 2007-2015
Judge Advisor Pine Tree Regional 2013
Maine Regional Planning Committee
New England District Planning Committee
Lead Inspector Microsoft Tel Aviv Regional 2006-2008
Judge & Lead Inspector GM/Technion Tel Aviv Regional 2006
Judge UTC Hartford Regional 2006
Reply With Quote
  #15   Spotlight this post!  
Unread 14-02-2011, 13:15
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,579
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: Acceleration based on position

Quote:
Originally Posted by umangv620 View Post
I tried implementing Mark's example and my encoder into the code, and got this: http://img687.imageshack.us/img687/4504/photodtz.jpg (sorry for the bad screenshot).

There is a (-x) on Joystick 2 axis 2 because going forward gives -1 for some reason, and we have no clue how to calibrate the logitech attack 3 joysticks. It shouldn't change anything in the code, right?

When I deployed this and clicked enable on DS, the elevator suddenly started moving up, and about halfway, it started jerking down and up. By then I rushed to click disable, but no one was moving the joystick during the deployment. Why did the elevator start moving on its own? Since the joystick wasn't moving, its value was 0, and the encoder reset its value to 0 when I clicked enable, so it shouldnt move, right?

Or did I miss something while coding the PID? (Wasn't really sure what the 3,0,0 for PID meant in mark's code, so I just tried using 1 and keeping it simple).
It sounds like you have two separate issues. The first is defining the setpoint, which other people have addressed.

The second problem is the tuning of the PID constants. I recommend that you read PID without a PHD. Your problem is that your P constant is too high. With a P constant of 1, if your encoder is 1 tick away from your setpoint, the motor would be going full speed and blow right past the setpoint. When it gets 1 tick away the other direction, it would reverse direction full speed. This causes the oscillation that you see. If instead you made the P constant be 0.1, then 10 ticks away it would be full speed, but 5 ticks away it would be half speed. Think about how far away you think the elevator should start to slow down, and you can figure out an approximate value for P. From there, you will probably need to experimentally change the value so that it behaves the way you want.
Reply With Quote
Reply


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


All times are GMT -5. The time now is 20:37.

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