top of page

How To Triangle

A lot of people like the idea and results of a dynamic offset, but don't want to work through a bunch of stuff that frankly had me pulling my hair out. So while I won't just post my offsets, I will tell you more about how I found the constants to multiply by the center angle (and another to add/subtract to it) to get my outer angles - while going a little more in depth about my assumptions. I'll again focus on the angle who's absolute value needs to be increased. That's right, it's time for Triangles 2: Electric Boogaloo. When tackling this problem, you're going to be dealing with a few different triangles while using key pieces of each triangle to solve the next one until you arrive at your offset.

This is your first triangle. This is equivalent to when the car is driving straight in its normal form; but we're setting up this fake triangle with the assumption (the most sturdy of our multiple assumptions) that as steering angle C increases, the length of line A-C decreases. And with that assumption, we can start tackling the problem of how to scale our offsets. We will be using this triangle to find the length of line A-C to be used in the next triangle. Our next major assumption here is in determining how the length of the line should decrease in response to a change in the steering angle. I personally use this formula here, while incrementing Steering Angle C for each run of my loop before plotting the results: Steering Angle B = .043 + (Steering Angle C * Steering Angle C / Max(Steering Angle C)) When I say Steering Angle B, this is not our final steering angle - this is only used in the first triangle as a tool to find our length A-C. To make it even more confusing, the Steering Angle C I'm using in this formula is the steering angle for which we want to find the offset for - not the 0 center line angle in the picture. We'll be using the Steering Angle C from this formula in the next triangle. There are a couple things going on. First is the static offset of .043, which works really well while the car is driving straight (Steering Angle C of 0) but suffers on turns. This is a key part of the formula, or else line A-C will reach near infinite levels when steering angle C is near 0. The second part scales slowly at first and then speeds up quickly as it reaches its maximum - which intuitively makes sense, as the car may make slight turns without a necessarily significantly closer goal. I'm not sure how important this is, and frankly I think there are better mathematical solutions out there - which is my hope in sharing this process. Now, this steering angle is pretty useless as is - we need to find its compliment on the inside of the triangle, so we use: Angle ABC = .5pi - Steering Angle B That part is pretty simple. Now we use the rule of tangent = opposite over adjacent, or: Line AC = Tangent(Angle ABC) * Line CB

But what is line CB? As I discussed in the other post, I made the assumption that the distance between each camera is 1 arbitrary unit if the distance to the goal for the car while driving straight is 22 of those arbitrary units (of which 1 = about half the width of the car) given how little viewing distance the neural network is given. This works well with .043 (which will be .1 in your model.py, as your offset will show up in the final equation if you use my method) being a good static offset while driving straight. So we have Line AC for a made up steering angle that we're not even going to use, what use is that?

We'll be using that same length A-C as our length for A-C in this second triangle - the one that reflects the steering angle for which we are trying to find the offset. Which means that the Steering Angle C used in this triangle is the Steering Angle C used in the formula to find our fake Steering Angle B and derive our length A-C. You'll be adding this steering angle to .5pi in order to find the interior angle ACB. The length of line C-B is still 1, or whatever you decided it should be in the previous triangle. Our goal is to find is our Steering Angle B in this triangle. So we have two sides and the angle which lies between them available as our tools. It's law of cosines time: Length A-B = square root ((A-C ^ 2) + (C-B ^ 2) - (2 * A-C * C-B * Cosine(ACB)) So now we have all three sides and an angle, and we want to find another interior angle - preferably the one which compliments our steering angle! Time to whip out our law of sines: Angle ABC = asin((A-C * sin(ACB)) / A-B) But wait, there's more! Our final steering angle given the input center angle will be equal to .5pi - Angle ABC. You can graph the final angle given the input angle by saving both into a 2D array, and from that graph create a best fit line (for the range of our minimum to maximum steering angle) from which you can derive your offset! (Note: For the side whose steering angle's absolute value is increasing as the the center angle changes only.) So that about wraps up the process. You will not (should not) be plugging all of this into your neural network; you can find the slope and offset separately, and then use it in your pre-processing to speed things up. The math I use here is all in radians, while the simulator records and transmits in degrees while automatically normalizing by dividing by the maximum - 25. This will not affect how you set up the math used here - and it won't affect your slope which you multiply by your center angle in your model, but it will mean you need to convert your static offset from radians to degrees/25. The major dangerous assumptions, which I'm not entirely comfortable with, is what you choose as the distance between cameras and how to scale the distance between the center camera and its goal (point A) as a function of the center steering angle. Please let me know if you have a better way to scale it! I'm very pleased with the results of this method though, and glad I stuck it out until the end.

Random Forest (the Blog): 

 

Big Data, Big Networks, Big Solutions. This is a blog about the challenges of machine learning geared towards those training our baby AI's.

 UPCOMING EVENTS: 

 

05/08/17:  NVIDIA GPU CONFERENCE

 FOLLOW THE ARTIFACT: 
  • Facebook B&W
  • Twitter B&W
  • Instagram B&W
 RECENT POSTS: 
 SEARCH BY TAGS: 
No tags yet.
bottom of page