Go to Post ...if the penalties were not significant and match-deciding then there would not be much incentive to pay attention to them, would there? - dtengineering [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 20-11-2011, 17:45
theNerd's Avatar
theNerd theNerd is offline
Registered User
FRC #3329 (Cam Bots)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2110
Location: St. Marys
Posts: 51
theNerd is an unknown quantity at this point
Motion Profiling

I've been starting to research into some more advanced techniques for robot controlling and I stumbled upon what's called motion profiling. I looked a little more on this on the internet and I found out a little about the trapezoidal and s-curve profiles. However all I know is the kinematic relationships (velocity, acceleration...) and I'm confused about how to take this to the useful level. Could the awesome robotics community out there help me in learning the basics of motion profiling and how to implement it into a robot design - especially a drive system?
  #2   Spotlight this post!  
Unread 28-11-2011, 20:04
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Motion Profiling

FYI, 254's code uses trapezoidal motion profiles for all drivetrain moves. If you are willing to dredge through the code, you can see how a team used them last year.

I like to conceptually visualize motion profiles as a filter (even though it is not LTI, so this is an abuse of terminology to me). You tell the filter that you want to go to position "10", and it tells you what to do for the next time step to get closer to "10" while only moving with a maximum acceleration and velocity that you configure the filter with. This is essentially how we implemented it.

I would start by writing code on your local machine to generate motion profiles and debug it by plotting the output to see if it works or not. It is quite hard to debug this type of stuff on a running robot.
  #3   Spotlight this post!  
Unread 29-11-2011, 08:11
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,064
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Motion Profiling

To echo what Austin said: This is a great example of something you can develop and test without a running robot. Write the code to generate a trapezoidal motion profile using J2SE or on a desktop using C++, debug using Excel, Matlab, or Gnu plots, and you will be able to port it to your robot code with ease.

Of course, once you are generating your trapezoidal motion profiles, you will need a controller that makes sure the bot actually follows it! Here are a few ideas on how you could do this:

1. Use a PID loop on your drive motors (in distance mode). Use the speed output of your motion profile to limit the maximum command that PID is allowed to send to your motors.

2. Use a PID loop on your drive motors (in speed mode). As long as your speed loop has an integral term (the I gain is nonzero), this should get you where you are going.

3. Use both (1) and (2) to control both speed and distance; there is also a specialized "PIV" controller used in industrial servos that mixes both speed and distance to command the motors.

4. Just use the speed command you generated to drive the motors directly (open loop), but switch to a PID controller when you get close to the goal to go the last few inches.

5. Make a full-state controller using control theory and simulation; if you go this route you are either insane or 254
  #4   Spotlight this post!  
Unread 03-12-2011, 02:46
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Motion Profiling

Good point Jared. Once you have a profile, you need to follow it.

My favorite controller for following trajectories is as follows (I think this is a modification of 3). I used it before I got tired of hand-tuning the PD for the drivetrain and switched to state feedback.

pwm = P * error + D * ((error - prev_error) / dt - goal_velocity) + Kv * goal_velocity + Ka * goal_acceleration

This is close to a PD controller, but with some feed forward terms. The idea behind feed forwards is that if you have a pretty good idea about how much power it will take to do something, go ahead and add it in. The control loop will take up the slop from there when you are wrong, or someone bumped the bot.

The D term is special in that you subtract off the goal velocity. This falls out from the state feedback controllers. Think about it this way. If you are at the goal, and moving at the right speed, you don't want to apply corrective power to decelerate the robot (This is what D would do if you weren't trying to move but were moving and at the goal.)

The Kv and Ka feed forwards terms make a lot of sense. It takes power to move at a velocity, so add that power on... Same for acceleration. It takes power to accelerate, so just add the power right on. You can get the goal velocity and acceleration from your profile.

A properly tuned controller with motion profiles will produce some very nice and smooth motion.
  #5   Spotlight this post!  
Unread 19-12-2012, 12:44
winchymatt winchymatt is offline
Registered User
no team
 
Join Date: Dec 2012
Location: United Kingdom
Posts: 3
winchymatt is an unknown quantity at this point
Re: Motion Profiling

Quote:
Originally Posted by AustinSchuh View Post
Good point Jared. Once you have a profile, you need to follow it.

My favorite controller for following trajectories is as follows (I think this is a modification of 3). I used it before I got tired of hand-tuning the PD for the drivetrain and switched to state feedback.

pwm = P * error + D * ((error - prev_error) / dt - goal_velocity) + Kv * goal_velocity + Ka * goal_acceleration
Hi,

Realise this is an old thread, but hopefully you will pick this up..

I have been working with PID controllers for a while now, but have never looked at adding feed forward terms. This looks really interesting for a hydraulic system I'm currently working on.

I have a few questions with regards to your controller above:

1) What is your (dt) term within the D part of your controller.

2) Do you determine the goal_velocity and goal_acceleration from the goal position within the controller, or do you send these in from your trajectroy planner?

3) Can you point me to a code example of this controller?

I have a bunch of other questions but figured I would start with this..

Matt.
  #6   Spotlight this post!  
Unread 20-12-2012, 01:12
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Motion Profiling

DT is the period of your loop.

Acceleration, velocity and position are from the trajectory planner.

254's 2011 code has this as part of the drive train autonomous code. It should be available in the whitepapers on this site.

Austin
  #7   Spotlight this post!  
Unread 20-12-2012, 07:40
winchymatt winchymatt is offline
Registered User
no team
 
Join Date: Dec 2012
Location: United Kingdom
Posts: 3
winchymatt is an unknown quantity at this point
Re: Motion Profiling

Quote:
Originally Posted by AustinSchuh View Post
DT is the period of your loop.

Acceleration, velocity and position are from the trajectory planner.

254's 2011 code has this as part of the drive train autonomous code. It should be available in the whitepapers on this site.

Austin
Great thanks, yes I should have known dt would be discrete time! I checked out the code and the trajectory planner was a great help! Imported the ContinuousAccelFilter class into my borland builder test app, works really well! Thanks for the pointers.

So on a side note, if you were sending just position information to the PID controller, and did not have velocity and acceleration data, could one derive the velocity and acceleration by differentiating the position data with the previous position.. I guess this would not produce a true goal velocity, but may give some feed forward gain??

Matt.
  #8   Spotlight this post!  
Unread 20-12-2012, 21:55
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: Motion Profiling

Quote:
Originally Posted by winchymatt View Post
So on a side note, if you were sending just position information to the PID controller, and did not have velocity and acceleration data, could one derive the velocity and acceleration by differentiating the position data with the previous position.. I guess this would not produce a true goal velocity, but may give some feed forward gain??

Matt.
You can, if and only if that signal is twice differentiable. If not, then you'll get bad spikes in your data -- if you have spots that are not twice differentiable, you'll need to differentiate on each side then use each section as a separate input, essentially "cutting out" the bad spots. This is much more useful if the position trajectory is derived via some analytical or numerical process -- you'll likely have a ton of noise if you try to do this with real sensor data.

Also, with full PID, having a feedforward on the velocity target will cause overshoot, just FYI.* If you're doing PID for position control, then having an acceleration feedforward should be fine; a velocity feedforward would be beneficial if you're doing PD.

If anyone disagrees with any of the statements in this post, please correct me -- this is operating at the edge of my knowledge of control theory.

* This statement is incorrect, please see AustinSchuh's post below.

Last edited by flameout : 21-12-2012 at 09:05.
  #9   Spotlight this post!  
Unread 21-12-2012, 01:25
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Motion Profiling

Quote:
Originally Posted by flameout View Post
Also, with full PID, having a feedforward on the velocity target will cause overshoot, just FYI. If you're doing PID for position control, then having an acceleration feedforward should be fine; a velocity feedforward would be beneficial if you're doing PD.
I disagree with this statement. I'll give you a fuzzy explanation now, and try to find time to prove it for real with the math later. I'll probably cheat and give you the continuous time proof...

You can model the velocity feed forward as a disturbance. It adds a power to the motors that the control loop is not expecting. This power is constant (at least at constant velocity), so, since the loop is stable, it will stabilize out and converge. This is very similar from the loop's perspective to changing the goal, and since both of them are happening at the same time, it shouldn't have much effect.

Differentiating the goal signal will also introduce delay into it. This won't have a huge effect on the system since the time constant of a robot is very slow compared to a good loop frequency, but this can become more and more pronounced as your system's time constant gets closer to the period of your loop.
  #10   Spotlight this post!  
Unread 21-12-2012, 02:01
Paul Copioli's Avatar Unsung FIRST Hero Woodie Flowers Award
Paul Copioli Paul Copioli is offline
President, VEX Robotics, Inc.
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Rockwall, TX
Posts: 1,381
Paul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond repute
Re: Motion Profiling

I agree with Austin on this one. Velocity feed forward (and acceleration FF, and current FF) all work to stabilize the PID loop. Instead of your proportional gain having to do all the heavy lifting, a small understanding of PWM in value vs actual rotational speed will decrease the proportional gain required. At full voltage the PID is ideally only dealing with disturbances. As the battery dies, the P will have to do a little more work since the FF mapping is no longer valid (but better than 0).

In our FRC auton application it is a huge advantage to use FF gain since you are presumably using a fully charged battery.

Put another way, the P gain is a multiplier. The smaller that multiplier is allowed to be, the less oscillation and general "what the heck just happened" sessions will happen.
__________________
In full disclosure I am the President of VEX Robotics, a division of Innovation First International.
  #11   Spotlight this post!  
Unread 21-12-2012, 09:01
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: Motion Profiling

Quote:
Originally Posted by AustinSchuh View Post
I disagree with this statement.
I think you're right -- I was making an assumption that I did not state in my post. I was assuming that the velocity feedforward gain (your Kv) is sufficient to cause essentially zero steady-state error without an integral component -- if it is less, than it is possible to have no overshoot. Also, I was not claiming that it would be unstable -- it would overshoot once then return to the setpoint in a perfectly stable manner.

Here's where I'm coming from, assuming Kv is as described above (i.e. would cause approximately 0 steady state error with no integral component):

Say you're moving steadily (tracking a target trajectory) at a velocity of 1 (arbitrary units) -- your P, I, and D terms are all approximately zero, since you are at steady state. The Kv term is the majority of your control signal.

Now suppose the target trajectory changes to a velocity of 2 -- this could happen either smoothly or instantaneously. Due to the system's inertia, it will find itself at less than the desired position. Therefore, the control system will correct, trying to bring the state towards the new setpoint.

During this time, the previously-small I term will be growing as the errors accumulate. However, due to the Kv term, the necessary I term to maintain zero steady state error at the setpoint is approximately zero. Since the I term will not begin decreasing until it has overshot, it is guaranteed to overshoot.

This overshoot may or may not be acceptable. Additionally, if Kv is less than the value I've described, then it would only decrease the Ki value necessary to prevent overshoot, and decrease the rise time of the controller, which may be desirable.
  #12   Spotlight this post!  
Unread 22-12-2012, 15:02
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Motion Profiling

Paul,

Thank you for posting your profile generator. It is fun to see how others do it and learn more.

Quote:
Originally Posted by flameout View Post
During this time, the previously-small I term will be growing as the errors accumulate. However, due to the Kv term, the necessary I term to maintain zero steady state error at the setpoint is approximately zero. Since the I term will not begin decreasing until it has overshot, it is guaranteed to overshoot.
You are missing a term. Ka will accelerate the robot as required, so it should in theory track the profile perfectly and never have any error. You are trying to get Kp and Ki to do the work of Ka.

Especially for the drivetrain, if you saturate your motors, you loose all ability to make adjustments. This quickly shows up as not having power available to correct for the robot turning. By providing a profile that will never ask for full power, you avoid this whole problem and can still steer nicely as you accelerate and decelerate.
  #13   Spotlight this post!  
Unread 20-12-2012, 21:59
Paul Copioli's Avatar Unsung FIRST Hero Woodie Flowers Award
Paul Copioli Paul Copioli is offline
President, VEX Robotics, Inc.
FRC #3310 (Black Hawk Robotics)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 2000
Location: Rockwall, TX
Posts: 1,381
Paul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond reputePaul Copioli has a reputation beyond repute
Re: Motion Profiling

Quote:
Originally Posted by winchymatt View Post
So on a side note, if you were sending just position information to the PID controller, and did not have velocity and acceleration data, could one derive the velocity and acceleration by differentiating the position data with the previous position.. I guess this would not produce a true goal velocity, but may give some feed forward gain??

Matt.
Matt,

The problem with this method is that discrete differentiation induces noise into the control loop. By using the path planning algorithm you have a pure, non noisy, velocity and acceleration profile.

Paul
__________________
In full disclosure I am the President of VEX Robotics, a division of Innovation First International.
  #14   Spotlight this post!  
Unread 21-12-2012, 17:52
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,500
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Re: Motion Profiling

Ok. After reading a bit more online, I understand some of the terms. Jerk is caused by the transition between acceleration / velocity, velocity / deceleration, or acceleration / deceleration. Those are the 'sharp' points on the graph.

To create a motion profile utilizing acceleration and deceleration, don't you have experimentally measure these to accurately determine what your robot is capable of?

From what I understand, motion profiling would seem to get you to your position point more quickly that PID. With PID, you have your drive values taper off as you get closer to your setpoint. With motion profiling, you would stay at your maximum velocity until it's time to go into maximum deceleration.

Is this accurate?
  #15   Spotlight this post!  
Unread 21-12-2012, 20:04
flameout flameout is offline
AKA Ryan Van Why
FRC #0957 (SWARM)
Team Role: Alumni
 
Join Date: Sep 2009
Rookie Year: 2009
Location: Oregon
Posts: 168
flameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to allflameout is a name known to all
Re: Motion Profiling

Quote:
Originally Posted by Tom Line View Post
Ok. After reading a bit more online, I understand some of the terms. Jerk is caused by the transition between acceleration / velocity, velocity / deceleration, or acceleration / deceleration. Those are the 'sharp' points on the graph.
Technically, it's just the derivative of acceleration, but yes, that is effectively correct.

Quote:
To create a motion profile utilizing acceleration and deceleration, don't you have experimentally measure these to accurately determine what your robot is capable of?
You just need to get them within the robot's capabilities -- if you're too close to your limits, then you'll get wheel slippage anyway, throwing off your distance measurements. You could probably get close enough just by looking at your wheel's CoF.

Quote:
From what I understand, motion profiling would seem to get you to your position point more quickly that PID. With PID, you have your drive values taper off as you get closer to your setpoint. With motion profiling, you would stay at your maximum velocity until it's time to go into maximum deceleration.
I think that motion profiling would be slower than directly doing PID or PD on position, since motion profiling usually has a more gentle acceleration. One tradeoff, however, is that where pure PID/PD would spin the wheels on acceleration, motion profiling should prevent wheel slippage.

To everyone: Please let me know if I've made any mistakes in my interpretation of "motion profiling" -- I personally see several ways to do this, so I hope I am responding with the correct interpretation in mind.
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


All times are GMT -5. The time now is 09:13.

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