calculating acceleration

anamaria's icon

Hi Forum,

Is there a nicer way to calculate acceleration of one sensor signal. My max patch has some problems - the acceleration value does not go back to 0 when the signal stops on a certain value ...

{
    "boxes" : [         {
            "box" :             {
                "maxclass" : "comment",
                "text" : "The problem is that the number box does not always go back to 0, when I release the slider. If I update the slider value with a metro there is problems with 'stack overload'.",
                "linecount" : 3,
                "id" : "obj-4",
                "presentation_rect" : [ 98.0, 115.0, 0.0, 0.0 ],
                "fontname" : "Arial",
                "frgb" : [ 0.0, 0.14902, 1.0, 1.0 ],
                "numinlets" : 1,
                "patching_rect" : [ 73.0, 184.0, 425.0, 55.0 ],
                "fontsize" : 14.0,
                "numoutlets" : 0,
                "textcolor" : [ 0.0, 0.14902, 1.0, 1.0 ]
            }

        }
,         {
            "box" :             {
                "maxclass" : "comment",
                "text" : "Question: How do I calculate acceleration in a much easier way than this?",
                "id" : "obj-42",
                "fontname" : "Arial",
                "frgb" : [ 0.0, 0.14902, 1.0, 1.0 ],
                "numinlets" : 1,
                "patching_rect" : [ 98.0, 88.0, 482.0, 23.0 ],
                "fontsize" : 14.0,
                "numoutlets" : 0,
                "textcolor" : [ 0.0, 0.14902, 1.0, 1.0 ]
            }

        }
,         {
            "box" :             {
                "maxclass" : "slider",
                "id" : "obj-3",
                "numinlets" : 1,
                "patching_rect" : [ 16.0, 14.0, 216.0, 52.0 ],
                "numoutlets" : 1,
                "outlettype" : [ "" ]
            }

        }
,         {
            "box" :             {
                "maxclass" : "number",
                "id" : "obj-2",
                "presentation_rect" : [ 46.0, 237.0, 0.0, 0.0 ],
                "fontname" : "Arial",
                "numinlets" : 1,
                "patching_rect" : [ 16.0, 186.0, 50.0, 19.0 ],
                "fontsize" : 11.0,
                "numoutlets" : 2,
                "outlettype" : [ "int", "bang" ]
            }

        }
,         {
            "box" :             {
                "maxclass" : "newobj",
                "text" : "t i b",
                "id" : "obj-103",
                "fontname" : "Arial",
                "numinlets" : 1,
                "patching_rect" : [ 16.0, 77.0, 35.0, 21.0 ],
                "fontsize" : 13.0,
                "numoutlets" : 2,
                "outlettype" : [ "int", "bang" ]
            }

        }
,         {
            "box" :             {
                "maxclass" : "newobj",
                "text" : "-",
                "id" : "obj-106",
                "fontname" : "Arial",
                "numinlets" : 2,
                "patching_rect" : [ 16.0, 144.0, 47.0, 21.0 ],
                "fontsize" : 13.0,
                "numoutlets" : 1,
                "outlettype" : [ "int" ]
            }

        }
,         {
            "box" :             {
                "maxclass" : "newobj",
                "text" : "int",
                "id" : "obj-124",
                "fontname" : "Arial",
                "numinlets" : 2,
                "patching_rect" : [ 35.0, 111.0, 33.0, 21.0 ],
                "fontsize" : 13.0,
                "numoutlets" : 1,
                "outlettype" : [ "int" ]
            }

        }
],
    "lines" : [         {
            "patchline" :             {
                "source" : [ "obj-3", 0 ],
                "destination" : [ "obj-103", 0 ],
                "hidden" : 0,
                "midpoints" : [ ]
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-106", 0 ],
                "destination" : [ "obj-2", 0 ],
                "hidden" : 0,
                "midpoints" : [ ]
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-103", 0 ],
                "destination" : [ "obj-124", 1 ],
                "hidden" : 0,
                "midpoints" : [ 25.5, 102.0, 58.5, 102.0 ]
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-124", 0 ],
                "destination" : [ "obj-106", 1 ],
                "hidden" : 0,
                "midpoints" : [ 44.5, 136.0, 53.5, 136.0 ]
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-103", 1 ],
                "destination" : [ "obj-124", 0 ],
                "hidden" : 0,
                "midpoints" : [ ]
            }

        }
,         {
            "patchline" :             {
                "source" : [ "obj-103", 0 ],
                "destination" : [ "obj-106", 0 ],
                "hidden" : 0,
                "midpoints" : [ ]
            }

        }
]
}

brendan mccloskey's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Here's a handy utility I got from forum regular timloyd. It will give you an acceleration value which returns to zero when the number stream stops:

This should do what you need but if not, search the forum for "rate of change",
Brendan