|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools |
Rating:
|
Display Modes |
|
|
|
#1
|
||||
|
||||
|
Tired of tuning pesty PID loops for hours? Try Neural Networks!
Per a few requests, and my personal objective to have FRC as a whole have more focus trying new things when it comes to software, I decided to make a generic Neural network code that can be easily adjusted to suit whatever control needs you desire.
How does it work? 1. Simply define your network topology as a vector of integers. For example, <2, 4, 3, 2> will create a network with 2 input nodes, 2 layers of hidden nodes with 4 and 3 nodes respectively, and 2 output nodes. 2. Get your data. I set it up to read data from a file, as you generally train a network off data after the fact instead of in real time. An example of a compatible data file is included in the git linked at the end of this post. 3. Send the data through the neural network until the weights of the nodes converge. 4. ???? 5. Profit. Let's use an example: You have an omni-wheeled robot that wants to center itself in a hallway such that it is the same distance to each wall. You put 2 range finders on each side of the robot to arrange for this. What should your architecture be? This is a little bit of a tricky problem. You can have either 1 or 2 inputs. Let's stick with the 1 input route. The input would be the difference of the two range finders. The output you care about is the 4 motor values, but the output that the neural network is trying to achieve is a single value: zero. A possible architecture could be <1, 4, 4, 1>. Your second hidden layer is actually your motor values. So how do you use this computational engine you just created? You can do it two ways, in real time, or gather random data and train it on that. I personally find it much more enjoyable to watch the robot learn to center itself. What you'd need to do is set up your robot anywhere (even in the center of the hallway!). Get the sensor data, feed it forward into your neural network, get your motor values, apply them for a duration of x ms, get the new sensor data (which is the output of the network), then train it on that value. Repeat until your weights converge. Once the network converges, save the state of it (as in the node weights). Now you have a robot that taught itself how to center itself in a hallway. I'm not going to go under the hood of neural networks as this post is already rather lengthy. Code: https://github.com/faust1706/Neural-Network I accidentally pushed built code to the repo, my mistake. Something really cool that can be done with this is have your battery voltage as an input. The network will generalize to work at any functioning voltage. Last edited by faust1706 : 10-04-2015 at 22:22. |
|
#2
|
|||||
|
|||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
Would it be possible to take a video of the realtime learning in action?
|
|
#3
|
||||
|
||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
I'm don't have access to a simple navigation robot anymore...it got scrapped for parts. I'll see if I can put something together one day in the lab.
|
|
#4
|
||||
|
||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
Have you tried learning parameters for a PID controller?
Any thoughts on using recurrent neural networks to add some memory to your controller? |
|
#5
|
||||
|
||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
The goal of releasing this code was that teams would have an easier time with machine control as well as show them that there is more than one way to do things, and a lot of times the first solution you have (the PID controller given to each team), isn't always the best.
By learning parameters, are you talking about setting them yourself, or a PID controller that finds parameters itself? The latter already exists, but it is more complex than a neural network in my opinion. RNNs do wonders, but I wanted to keep things simple for an introductory post. This would be a great topic for a team to explore for themselves, as well as Elman Networks and others of the like. |
|
#6
|
|||
|
|||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
Saw you mention this on r/FRC, I'm definitely eager to check this out!
EDIT: could you post a more detailed example implementation? Last edited by JohnSmooth42 : 12-04-2015 at 19:15. |
|
#7
|
||||
|
||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
Of course. It'd be easier for me to do so if you give me an example that you want me to go through, do you have any in mind?
|
|
#8
|
|||
|
|||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
An example of this in actual robot code (e.g. teaching it how to center itself like you mentioned) would help a lot. Also if there's any way I can help contribute to this I would be glad to help.
|
|
#9
|
||||
|
||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
I added a case for real time training called realtime. It is not integrated with anything, but it is laid out to be embedded easily. There are plenty of comments which should allow for fast integration of any system, so long as you can give this code the sensor data and send the motor values to wherever they are needed. I feel it'd be easier to add this into whatever that you want to train instead of sending values over serial or something, but that's just me.
The code is a little messy, I apologize. The messy part is the training from a file, I'll work on it when I have more time. If you need help integrating it into FRC code, don't hesitate to ask me. Edit* also worked on the readme a bit. Still unsure of how specific I want it, but it's a start. Last edited by faust1706 : 13-04-2015 at 01:58. |
|
#10
|
|||
|
|||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
It looks very nice, I forked it and I'm trying to make an implementation of a basic neural network for use with encoders.
|
|
#11
|
|||
|
|||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
This looks really cool, and I'm planning to try to hack on it over April vacation (when I finally have some time). Since our team uses Java, I'm going to try to port it, which will hopefully help me understand the code better.
I have no previous experience with neural networks, so I'll probably have a lot of questions in the future, but for now I was wondering if there is some way to decide how to structure the hidden layers. In your example, you use 4 nodes, one for each wheel and two layers. What is the reason for this? Thanks. |
|
#12
|
|||
|
|||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
Here is my implementation of your library for use with encoders on a robot.
https://github.com/DannyMoses/Neural..._implementaion It's definitely not very polished(I basically copied your example). Am I doing it right? I don't have a robot to test this on right now so I would value any feedback. I also just want to say that I think this is probably the future of FRC programming right here. |
|
#13
|
|||
|
|||
|
I have gotten the saving and loading functionality working on my Java port. I modified your file format a little to make my parser simpler. I think most of my problems are caused by the robot code.
|
|
#14
|
||||
|
||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
That's good to hear for me at least...It might be that there is too much influence from new data (alpha), something to look into, but it is unlikely if it is <.20. A simple cheat would be to dampen the motor values outputted by the net if it comes down to that.
1706 is investigating into swerve this summer. I can't wait to see what @cmastudios is able to do with it along with our swerve trajectory planner code. |
|
#15
|
||||
|
||||
|
Re: Tired of tuning pesty PID loops for hours? Try Neural Networks!
Wow, I really want to have a chance to mess with all of this.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|