|
|
|
![]() |
|
|||||||
|
||||||||
|
|
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 : 04-10-2015 at 10:22 PM. |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|