Giter Site home page Giter Site logo

mattfryer / smoothed Goto Github PK

View Code? Open in Web Editor NEW
72.0 8.0 16.0 43 KB

An Arduino library that allows smoothing of a sensor input using various methods. Uses a template class to ensure sensor readings in any numerical data type can be handled. This makes it both lightweight and flexible.

License: GNU General Public License v3.0

C++ 100.00%
arduino arduino-library arduino-ide signal-processing smoothing sensor-readings

smoothed's People

Contributors

ayushsharma82 avatar floesche avatar mattfryer avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smoothed's Issues

Library does not seem to work in Arduino 1.8.7 ?

I have tried using this with a few different boards and get different messsages, here is the one when using Arduino Uno:

Build options changed, rebuilding all
Smoothed:18:1: error: 'Smoothed' is not a template

Smoothed mySensor;

^

Smoothed:19:1: error: 'Smoothed' is not a template

Smoothed mySensor2;

^

C:\Users\patri\Documents\Arduino\libraries\Smoothed\examples\Smoothed\Smoothed.ino: In function 'void loop()':

Smoothed:14:20: error: expected primary-expression before '=' token

#define SENSOR_PIN = A0; // The input pin for the sensor. In this example we are reading from an Arduino analogue pin.

                ^

C:\Users\patri\Documents\Arduino\libraries\Smoothed\examples\Smoothed\Smoothed.ino:55:41: note: in expansion of macro 'SENSOR_PIN'

float currentSensorValue = analogRead(SENSOR_PIN);

                                     ^

Smoothed:55:51: error: expected primary-expression before ')' token

float currentSensorValue = analogRead(SENSOR_PIN);

                                               ^

exit status 1
'Smoothed' is not a template

It's somehow producing a negative result when set to int16_t

It doesn't like being set to int16_t as a variable type. The code producing the serial plotted data is shown to the left in the image. The values plotted are x and smoothed x.

image

with the initialization line as

Smoothed <int16_t> movement;

it produced the result as shown in the image. The x value unsmoothed(blue line) is where it's supposed to be. But the smoothed value(red line) is showing as negative.

Initializing the function as

Smoothed <int> movement

makes it function as one would expect. and produced the following result.

image

Showing both values in the same ballpark.

I'm guessing that it's having issues somewhere converting the int16_t variable type internal. This code is running on an ESP8266. As I understand it,, int variables are stored differently on the ESP8266 which is probably where the problem lays.

reference to 'map' is ambiguous if used smoothhed.h

Hi,
You have used "using namespace std;" which may be considered as a bad practice.
Actually you even do not need std lib.
In arduino it leads to a conflict with built in function map.
Try to compile arduino program with "using namespace std;" and map function, you will get an error
reference to 'map' is ambiguous, since std:map is different from arduino ones..

Possible overflow of runningTotal

Hi,
I'm studying your source and considering using it in my project, but I spotted a potential problem in smoothed.h in the get function, added a comment next to the problem line below. I'd suggest a fix, but I'm not sure how to accomplish that without breaking the template goodness or having to make some assumptions about the datatype or array size.

template <typename T>
T Smoothed<T>::get () {
  switch (smoothMode) {
    case SMOOTHED_AVERAGE : { // SMOOTHED_AVERAGE
      T runningTotal = 0;
    
      for (int x = 0; x < smoothReadingsNum; x++) {
//possible overflow of runningTotal with large arrays or values in T
        runningTotal += smoothReading[x];  
      }

I've got quite a bit of noise in the values I need to smooth so I was considering an array size of 100 or more, which with my values will overflow the running total. I'd need a larger datatype for runningTotal, but it'd be wasteful to do that for the entire array. Not sure about an elegant way to fix this, but it seems like a potential bug in some use cases, so I thought I'd let you know. Thanks.

Simple Fix to Remove Max Exponential Smoothing Restriction

Currently, 1 = max exponential smoothing
Swapped, Higher Value = more smoothing

If you swap "smoothReadingsFactor/100" for "1/smoothReadingsFactor" in the smoothed exponential calculation, it allows for an indefinite amount of smoothness, rather than being constrained to 0.01. Not Sure if this has any downstream issues, but seems to work well with a servo.

image

Release new library version

Hi Matt,

I've been using your library to smooth out some voltage readings from a VESC motor controller. I was on the latest version (v1.1) and when using a buffer of ~3000 elements, the math simply didn't add up :) I then discovered there's a new commit that increases the buffer size to more than 255 elements.

Can you please consider releasing a v1.2 of the library? It may save other people's time.

I really like the simplicity and usefulness of your lib, it saved me quite some time by not having to write something similar from scratch. Thanks!

Andrei

compilation on Arduino Nano gives warnings

73:11: warning: unused variable 'lastValueStoredAvg' [-Wunused-variable]
float lastValueStoredAvg = mySensor.getLast();
^~~~~~~~~~~~~~~~~~
:74:11: warning: unused variable 'lastValueStoredExp' [-Wunused-variable]
float lastValueStoredExp = mySensor2.getLast();
^~~~~~~~~~~~~~~~~~
:12:0:
In instantiation of 'bool Smoothed::begin(byte, uint16_t) [with T = float; byte = unsigned char; uint16_t = unsigned int]':
39:37: required from here
56:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int thisReading = 0; thisReading < smoothReadingsNum; thisReading++) {
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
12:0:
In instantiation of 'bool Smoothed::clear() [with T = float]':
53:20: required from here
184:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int thisReading = 0; thisReading < smoothReadingsNum; thisReading++) {
~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
In instantiation of 'T Smoothed::get() [with T = float]':
65:49: required from here
127:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int x = 0; x < smoothReadingsNum; x++) {
~~^~~~~~~~~~~~~~~~~~~
In member function 'bool Smoothed::clear() [with T = float]':
199:1: warning: control reaches end of non-void function [-Wreturn-type]

begin() without arguments gives error

I have installed the latest rev. of the smoothed library.
The example says that begin() may be called without arguments, defaulting to (SMOOTHED_EXPONENTIAL, 10)
On my arduino nano, I do get an error, though, if I do not supply any argument to begin().
error: no matching function for call to 'Smoothed<unsigned int>::begin()'

Compiling Smoothed on STSTM32 gives warning

When compiling sources using Smoothed library I the the following warning:

In file included from lib/Signals/Signals.cpp:14:
.pio/libdeps/iRock_v1_1/Smoothed/src/Smoothed.h: In member function 'bool Smoothed::clear() [with T = float]':
.pio/libdeps/iRock_v1_1/Smoothed/src/Smoothed.h:199:1: warning: control reaches end of non-void function [-Wreturn-type]
199 | }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.