![robotc code robotc code](http://www.cs.csi.cuny.edu/~imberman/csc126/ROBOLABnxt_files/image006.jpg)
This behavior is called canyoning and seems to happen often. This is useful, for instance, when a robot gets stuck in a corner, bumping left and them bumping right and repeating.
ROBOTC CODE UPDATE
I have been working to update my framework lately and I ran across and interesting concept that can be used by robots to track recurring events and store them in a short-term memory that eventually fades.
![robotc code robotc code](https://jschoolcraft.github.io/robotc-programming-tutorial/images/ch1/Moving_Forward_Sample_Program_in_Editor.png)
You can download the code here: WeightedAverage.c This class can help filter sensor data to a robot, making it react more slowly to large value changes. Weighted Average = New Sample * %wt + (1-%wt)*Previous Average In other words, I don’t care what the actual average is I care that the trend of values over time reduces the spikes and provides usable information to the robot with less error. I am sure this method is not as accurate as averaging the last n values, but the goal is not so much precision, but reducing spikes and anomalies. I found a shortcut to all of that where an average value is maintained in the background, and a weighted percentage is applied to the newest input value and the previous average. It also means you have create some sort of queue so the values can shift such that the n most current samples are available for calculation. Creating a running average of a stream of numbers can be complicated, and consume many variables (depending on how many samples make up the average). Continuing on my current fascination with math and code to implement it, I decided to write a class for weighted average monitoring.