|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
This looks really cool. I've worked on a very similar project (https://github.com/dicarlo236/AutonomousPlanner) that has a similar end result to yours- you draw in some points and headings, and it generates a path for the left and right wheels.
I have a few questions/comments about the paths that this generates. How exactly are you generating the curves? I see from the examples that you don't need to have headings at individual waypoints, and that the path needs to only come close to the waypoints, rather than cross. I'd like to figure out how to do this for my code, as picking headings for each waypoint can be frustrating. If you take the inverse tangent of the derivative of y position with respect to x, you get the heading of the robot. If you take the derivative of this function with respect to time, you get how fast the robot is rotating. One of my biggest challenges was keeping this function continuous, so that the path doesn't change from a sharp left turn to a sharp right instantly (think of an "S" where the top and bottom sections are half-circles). From looking at your paths, it seems that your curves do not have these issues. How did you solve this? I don't follow your code for generating the velocity profile very well, but I don't know how it would deal with sharp turns. From my tests, I needed to create a "maximum velocity" function for my path which told me what the fastest possible speed the robot could go at any point. I took into account the centripetal acceleration required to turn a 150 lb robot, the actual maximum speed of the robot, and the maximum speed of the wheel on the outside of the turn. Then, I generated a smooth velocity function that was always less than the maximum velocity function. It seems like you do have ways to correct your smooth velocity to be within limits, but I don't see how it works. |
|
#2
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
Ether posted a math quiz on here a little while ago that basically required someone to lay out the mathematics of how to calculate the left and right path trajectory of a robot given it's route.
http://www.chiefdelphi.com/forums/sh...d.php?t=126639 How I solved the problem was some simple calculus. I download a symbolic-numeric library that allowed me to take the derivative of my original function (the path), and then I found the function that at point x gives the slope of the normal line of my derivative function. Then I solve a system of linear equations. I want to "march out" n units from my original function, so I have the equation of the normal line and a circle around my point x (x^2 + y^2 = n^2). Then I solve the system. I do that for every point, then compile the points and fit a function to it. I feel as though there is a much better way of doing this though. (This method has proven to be quick enough for it's purpose. It takes about 10ms to go through a function with precision of 1,000 points to solve for) Could either of you explain your mathematics? Last edited by faust1706 : 09-10-2014 at 22:23. |
|
#3
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
Quote:
Code:
leftSegments.x = segment.x - r * sin(atan(s.dydx)); leftSegment.y = segment.y + r*sin(atan(dydx)); Code:
double ds = Math.sqrt((l.get(i).x - l.get(i-1).x) * (l.get(i).x - l.get(i-1).x) + (l.get(i).y - l.get(i-1).y) * (l.get(i).y - l.get(i-1).y)) Code:
l.get(i).distance = l.get(i-1).distance + dp; Code:
l.get(i).vel = dp/s.dt; Code:
l.get(i).acc = (l.get(i).vel - l.get(i - 1).vel) / s.dt; Code:
l.get(i).jerk = (l.get(i).acc - l.get(i - 1).acc) / s.dt; |
|
#4
|
|||
|
|||
|
Re: Smooth Path Generator for RoboRio 2015
Please take a read of the ReadMe on github, i try to explain the overall workings of the algorithm. But the general idea is this:
1. The original path is a collection of straight lines (the waypoint path) 2. We can interject any number of intermediate points in a straight line without changing the line equation itself (we inject the correct number of points so that there is one sample per robot timeStep) 3. Now that we have all of these injected points, we can push and pull on them to coerce them into a smooth path. The result is a bunch of straight lines, which appears smooth globally, and has smooth transitions. 4. We use gradient descent which is a first order optimization algorithm to push or pull each point just the right amount, I have "tuned" the parameters to converge very quickly so as to be useful for near real-time applications. If tuned incorrectly, the algorithm may never converge. The default parameters, should always converge, let me know if they do not. Take a look at the ReadMe for more info. Quote:
Quote:
It is up to the user to determine if the robot can sustain the max velocoity produced by the path, or if the speed controller on the robot can keep up with the velocity transitions (most important), The velocity can be reduced by increasing the time requirement to the calculate method. I did this on purpose, because it is important to understand when the path will end for autonomous routines, so by forcing the user to specify that parameter, they too will be able to see that they may or may not be able to achieve what they want in auto because the velocity profile is too high. The difference is that you are trying to solve for a continuously smooth path. Which requires a lot of computation. The path algorithm I supplied uses the ideas behind integration to generate a smooth path from smaller straight lines. Each line has a deterministic slope for the entire line duration, You can calculate left and right paths based on a little trig and determining the point +/- 90 degrees from your original point and slope. You do not need thousands of points to travel a few feet in a match. So you can safely reduce the number of points needed to speed up computation time. Please take a look at the readme entirely, it should answer a lot of your questions. I also left my pseudo code in each algorithm to help others understand the theory better. I will try to put together some slides on how it works, but in the mean time, try it out and let me know how its working for you. I may be out of touch for a while, We have an off-season competition next sat, we are also a 2015 alpha/beta test team, and we also have a bunch of off season work we are doing. Regards, Kevin |
|
#5
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
Quote:
Kevin, +1 for using gradient descent. I love that algorithm. Noob question: why not use the normal equation: (XX')^-1 X'y to solve for you thetas? I am too lazy to add in your quote the clean way, but... "The result is a bunch of straight lines, which appears smooth globally, and has smooth transitions." I don't think I understand how mathematically this produces a smooth transition. I guess this doesn't matter if your outputted paths are smooth. That's a really clever approach to the problem. You mentioned this was part of you PhD thesis (first of all, that's really impressive. Some of my lab mates are working on theirs and it looks incredibly stressful). For your project of "developing a controller for an Autonomous Car," are you given a path already? I'm curious because I wrote a pathfinding algorithm (really just an adaption of a*) over the summer and I'm taking the path generated from that and putting it into my program that generates velocity profiles of the left and right side for the robot. I am just wondering if you're doing a similar thing. "If the algorithm does not converge, the program will simply never finish, so it is pretty easy to identify." Luckily for an autonomous period, everything will be calculated long before the match starts, unless you develop a new path moments before the match, so you'll have ample time investigate why it fails to converge. |
|
#6
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
Accuracy and Stability of Numerical Algorithms Second Edition Nicholas J. Higham QA297 .H53 2002 |
|
#7
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
I am no expert in data science, or computational mathematics, it was an amateur question. Since his program is iterative, there does exist a point when taking the inverse of a matrix is faster than n interations, I believe.
|
|
#8
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
Correct me if I'm wrong:
The code generates an array of velocities which the robot has to reach at specific times of the auto (each side independently) and with encoders on each side and a PID loop I need to make the wheels actually get to that velocity. Did I get it right? If so, what is the best way to use PID for velocity control? Last edited by GuyM142 : 14-10-2014 at 14:15. |
|
#9
|
|||
|
|||
|
Re: Smooth Path Generator for RoboRio 2015
Kevin, can you talk a little more about the convergence of Alpha and Beta combinations? How did you determine whether or not certain parameters converge? And would convergence be related with the original path (Like would a path with an right or acute angle between segments have different convergence properties than a closer to straight path)?
Last edited by artK : 14-10-2014 at 16:47. Reason: Better answer to question I answered |
|
#10
|
|||||
|
|||||
|
Re: Smooth Path Generator for RoboRio 2015
Quote:
Code:
// For each side of the drive...
while (following) {
// desired_position, desired_velocity, and desired_acceleration are all generated by your profile.
position_error = desired_position[i] - actual_position;
command[i] = Kv * desired_velocity[i] + Ka * desired_acceleration[i] + Kp * position_error;
}
1) Generate an impulse response. From a stop, slam the sticks forward until you max out at your full robot speed. You may require a long distance to get up to speed, so plan accordingly. Stop the robot once it hits full speed (...or the back wall of your shop). 2) You can now analyze your charts to obtain a couple useful quantities: max_speed: The maximum speed (maximum slope) of the position vs. time plot. accel_time: How long from when you started until you hit the maximum speed (it is a bit of a judgement call since the curve is smooth, but try to get it in the right ballpark). max_accel ~= max_speed / accel_time 4) Set Kp = Ka = 0, and Kv = 1/max_speed. 5) Generate a motion profile with a maximum velocity of about 80% of your max speed and a maximum acceleration of about 80% of your max acceleration. The 80% is to be conservative and robust to batteries, etc. 6) Attempt to follow the profile with the gains from step 4. Watch your plots vs. the profile (yep...also plot the commanded positions/velocities). It is likely that you lag the profile initially, and lead it (or overshoot) at the end due to the robot's inertia. 7) Next, we will tune Ka to have the robot compensate for this lag/lead. The idea is that when you are accelerating heavily, you can add or subtract from your command to compensate for the robot's inertia. Tune Ka by adjusting and repeating the experiment in 6 until you are following the profile as close as possible. The right value of Ka will be between 0 and 1/max_accel. 1/(2*max_accel) is a reasonable first guess. 8) At this point, you should be following profiles reasonably well, but it is not perfectly repeatable, probably doesn't drive straight, etc. Let's add some feedback. The units of Kp are in (% of power per unit of error). If you have tuned Kv and Ka pretty well, you can get away with a Kp on the order of 1 or 2 if your units are meters (1/3 to 2/3 if using feet, etc). 9) You should follow the trajectories really, really well now. They should be somewhat straighter and quite repeatable. At this point, things are probably working decently well. Here are a few more options if you want to keep tweaking: 1) Add an integral term based on the sum of position error to get even more precision in final distance. We found this totally unnecessary last year, but YMMV. 2) Add a gyro to help stay straight. Each side of the drive is totally independent, so you can add a simple gyro controller that adds or subtracts from the velocity command being fed to each in order to compensate for accumulated errors. 3) Add trajectory replanning so that if you get bumped to the side, you instantly regenerate a new trajectory to smoothly get you back on track. If necessary for our strategy, 254 might do this in 2015 ![]() 4) Better characterize your drive train. The calculated left and right velocities are actually assuming a two wheeled vehicle with no slip...4, 6, and 8 wheel drives always have some scrub that results in the vehicle turning less than commanded. You can attempt to measure this and adjust your trajectories accordingly. Last edited by Jared Russell : 14-10-2014 at 16:39. |
|
#11
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
This software is quite similar to what I have been planning to implement. I think I will try to decompose this code and rewrite it so I can learn how it works. I have been working on a way to generate a path on the field. The problem with my approach is that no algorithm is perfect. Even though I am using greedy's algorithm because it seems like it will work perfectly for an FRC setup, it every once in a while will generate some sudden turn, often for no purpose. This type of algorithm would help smoothen it out so It can be transformed into motor powers to control the robot.
Kevin, Thank you for sharing this with me as now I have an almost identical piece of software that works, so I can have an example to learn off of. |
|
#12
|
||||||
|
||||||
|
Re: Smooth Path Generator for RoboRio 2015
Quote:
Quote:
Quote:
Quote:
Let me think more about your second question. My hunch right now is that valid path data regardless of its actual shape should have no affect on the convergence rate of a set of parameters. But let me think about it some more, and possibly do some calcs on it and get back to you. I would assume we are talking about valid, realistic paths only, and nothing which is intentionally malformed. Quote:
Quote:
Regards, Kevin Last edited by NotInControl : 16-10-2014 at 17:11. |
|
#13
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
Sorry to revive an rather old thread, but since this is a continuation of @notincontrol's work, I felt it needed to be tied with it.
Here is my attempt at converting his code to work with swerve: https://github.com/faust1706/Smooth-Swerve I based the calculations off Ether's materials, but that doesn't mean I miss typed or something. How to use: define set of waypoints, x and y, and then a set of angles you want the robot to be facing at each way point. A known thing that is broken is the output velocity per motor. Last edited by faust1706 : 30-04-2015 at 13:31. |
|
#14
|
||||
|
||||
|
Re: Smooth Path Generator for RoboRio 2015
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|