neuralNetwork

I want to use neuralNetwork to simulate a robot output.
Giving it a value and predict its output, measuring robots really output and record it.
Then pass this data to neuralNetwork to learn, imitate some other force like Friction.
After that, I will get a neuralNetwork that can give it input and calculate really output. I can use this output to test pid value.
Is this possible?

I think this is a really cool idea but also not the best way to solve the actual problem. If your goal is to make a neural network to emulate physics than it’s a good project. If your goal is just to simulate a mechanism so you can guess at PID before you have a full robot, this is feasible just with relatively simple physics. I believe 254 2015 has some interesting code in this area.

2 Likes

This sounds like a really good idea, but I would argue using a neural network is rarely needed to simulate physics. In my opinion best way to go about it would be to model the physics, collect data, and extrapolate all the constants you need from the data. This book by Tyler Veness (@calcmogul) has some sections about modeling which you might find useful: https://file.tavsys.net/control/controls-engineering-in-frc.pdf. The problem with modeling friction is that, at the scale we’re interested in and can collect data in, it is a random a random variable. You can’t deterministically predict friction. What you can do is analyze how much friction affects the system. Neural Networks are inherently nonlinear, when many FRC systems are very linear other than basically just arms. And there’s already established techniques to model physics when there are non-linearities and to deal with them. The problem with neural networks is that its easy to throw them at any problem since you know it will work, when there are already solutions that are much simpler and accurate. So modeling how an input changes an output over time isn’t really something a neural network would be the best thing to use for…

That being said, going the other way around might be more promising. There are already established controllers for linear systems (PID as you mentioned), but nonlinear control laws are much harder to find. So a neural network might provide promising results for this, as their outputs are necessarily nonlinear. But then you have to think of what the weights and biases of the network should be minimizing. It’s up to you, so long as it stabilizes well. But keep in mind that this really would be overkill if it is used on a linear system, so I’d recommend trying it out on an arm or anything else that’s nonlinear.

You might also be interested in this PDF that I found on our team’s Google drive folder: https://pdfs.semanticscholar.org/c32b/b3daab958e16a4a78c8629e20c246823fb47.pdf
I’ve only skimmed through it a few months ago, but it seems like it has to do with tuning PID using NNs. If you’re going through the effort to verify if a set of PID gains will work given a large amount of data, then there’s a better way to do that. There’s no “best” set of PID gains, there’s only those that don’t work and those that work, and out of those that work, it’s important to consider which ones are acceptable (aka work fast enough). So if you already have a large amount of data, you could go through the physics I was talking about, derive a model for the system in question, and determine its stability mathematically given any set of PID constants. So while determining if a set of PID constants will work isn’t the job of a NN, finding a set of PID constants that works well might be something you can look into

1 Like

Never tried it, and haven’t heard of it in practice, though I suspect the answer is still “Yes”.

It’s non-traditional - the standard approach I see here is to build up a first-principles model of how you expect the system to interact, gather data from the real system, then curve-fit the model to the real-world data.

Echoing others here - As a learning exercise, sounds like a slick project. Even better if you can provide the code and do a brief write-up.

I’d be doubtful that it’s as easy as “set up this generic neural network, collect robot data, throw it at the NN, and you’ve instantly got a super-accurate simulation of the physics involved”. I assert it’s “not easy” simply because I haven’t seen it in common practice. If it was simple and straight-forward, it seems like it would be a great way to make plant models that “everybody” would be using.

FYI - one reason people usually use first-principles, ground-up models of mechanism physics is that they reveal details about the inner workings of the system. It’s a white box view of the world, with the added benefit that you can drive mechanism design changes. Unless they’re extremely simple, neural nets tend to produce black box results, in the context that though they produce required results, they don’t give much info about how they got the answer.

A quick bit of googling shows a few results for people applying neural networks for physics based problems:

Example 1
Example 2

The commonality I’m seeing here is the underlying problem is fundamentally particle-based. The only output that matters is the aggregate of the particles, and the complexity of solving is driven by the huge number of particles. A black-box approach works here because the “internal” data about particular particle-on-particle interaction is ultimately thrown away.

For most FRC applications that I know if you’re looking at not millions of identical particles, but rather a small handful (~10?) of custom-designed rigid bodies interacting. Knowing the interior details of this system is critical for controls and design… much moreso than knowing the individual grain interactions in a large pile of sand.

I’d tend to think that an optimal approach would seed the neural net (through the activation functions? Maybe?) with information about at least what types of underlying relationships might exist. Frictional, air resistance, F=ma… all the quadratics and exponential that usually get found in physics equations. If you expect that these relationships should exist in some form, it seems reasonable to bake that info into the neural net, to give it the expressiveness to cover roughly where you expect the solution to lie. Granted, this makes the approach much less generic, and at an extreme would just become curve fitting again… Then again, I’ve got next to zero experience in this area, so take my advice with a nice water-softener-size brick of salt.

Because of the lack of supporting material or research, I wouldn’t recommend this problem as a first-venture into neural networks. Some more “classical” neural net solving would be better introductory material. But, if you’re already well-steeped in neural networks, I would be super interested to hear how the results go.

And the usual do-it-in-the-offseason advice… Don’t wait till kickoff to try this, and definitely don’t stake your team’s success on a successful outcome. Prove out the technique well before you try to apply it to a “production” robot.

1 Like

Multi Layer Perceptron(Sigmoid and Linear) and use Backpropagation.
It can approach a function.
I saw a instance, successfully approach “y = 1 + sin(pi * i / 4 * x)”, “i” is a constants, when it become bigger this function will become more turning point.
Just this inspire me.
http://neuroph.sourceforge.net/download.html
This contain the .jar that I import to eclipse.

You’re right in saying that a neural network will approach a function as you train it more. The Universal Approximation Theorem guarantees there will be a network that can approximate a desired function within a desired error (as long as the activation function is non polynomial, such as sigmoid). Backpropagation works to move the network’s weights and biases down the cost/loss gradient so you can maximize performance, which is why it tends to approach a desired function. That being said, NNs aren’t a magic solution for any problem. Just because it’s guaranteed a NN will exist that will reasonably approximate a function doesn’t mean any NN you choose can be trained to become that guaranteed NN. It depends on the actual structure of the network, which requires a lot of tuning many times, and a good method to initialize weights and biases. And also, the function you’re trying to model has some stochastic components - like I said earlier, friction is pretty random, and sensors have noise too. So while it’s not impossible, it’s definitely harder since it might easily lead to overfitting the data. But if you’re really enthusiastic about it, give it a try and let us know how it goes! We have a nice long summer ahead of us to experiment with. I recommend that you use the frc-characterization tool to collect data (it already sends data through NetworkTables and saves it as a JSON you can read in your program, so that work is done for you. It also gives a pretty wide range of inputs, but for a neural network it actually isn’t enough so you may want to modify the inputs it sends to motors to get randomized). You can also modify the code of the program it generates in order to send back more inputs/outputs if needed. And I’d like to reiterate what @gerthworm said - do not use this on the robot during the actual season until you have thoroughly tested it, and if possible, gotten feedback for it from others. The reason we use PID and other control laws is we know exactly what their input/output behavior is and have mathematically justified they work, but NNs are a very black box approach and you cannot guarantee it works until its tested for every input/output you could have (or at least enough to be representative). Best of luck, if you choose to do it!

Oh I just thought of something - keep in mind that computation power is an issue here. If you’re using CTRE Talons, they calculate PID inputs at 1000 times a second. If you want your own custom control law, the RIO lets you run the robot’s periodic at 50 Hz, but teams have used separate threads to run custom controls at 200 Hz. But neural networks are pretty computationally heavy which will severely limit how quickly you can run any NN calculated controls. And the slower your controls are, the less accurate. So keep that in mind if you choose to go for a NN controller

Characterization!
It’s really a good idea.
data

This is a part of characterization, does anyone know every number represent what?

Thanks.

In this order:
FPGA timestamp in seconds
Battery voltage
Commanded percent output
Left motor voltage
Right motor voltage
Left encoder position in specified units
Right encoder position in specified units
Left encoder velocity in specified units
Right encoder velocity in specified units
IMU heading in radians

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.