Skip to content

Instantly share code, notes, and snippets.

@luizsaluti
Last active September 25, 2020 05:18
Show Gist options
  • Save luizsaluti/bf1a404a04b0f490be4e5fb2e927b0a4 to your computer and use it in GitHub Desktop.
Save luizsaluti/bf1a404a04b0f490be4e5fb2e927b0a4 to your computer and use it in GitHub Desktop.
########################
########################
########################
# PLEASE READ THIS
# A newer and improved version of this filter was developed by WhiteMagic grab it at
# https://www.dropbox.com/s/2kdmku7tznbj42r/average_filter.py?dl=0
import math
import time
import gremlin
from gremlin.spline import CubicSpline
from collections import deque
# Device creation
#new way
wingman = gremlin.input_devices.JoystickDecorator(
"Wingman",
"{3DC8CDC0-6AAC-11E9-8002-444553540000}",
"Default"
)
_threshold = 0.95 #safety measure to reach axis end
_last_values_x = [0] * 5 # define number of samples that will go into average (for both axes)
_last_values_y = [0] * 5
last_values_x = deque(_last_values_x)
last_values_y = deque(_last_values_y)
curve = CubicSpline([ #the expected result here is a curve along with smoothing
(-1.0, -1.0),
(-0.74, -0.52),
( -0.176, -0.14),
( 0.176, 0.14),
( 0.74, 0.52),
( 1.0, 1.0)
])
def averageAxis(axisval, last_values):
global _threshold
last_values.popleft()
last_values.append(axisval)
if abs(curve(axisval)) < _threshold:
return curve((sum(last_values) / len(last_values)))
else:
return curve(axisval)
@wingman.axis(1)
def roll(event, vjoy):
global last_values
vjoy[1].axis(1).value = averageAxis(event.value, last_values_x)
@wingman.axis(2)
def roll(event, vjoy):
global last_values
vjoy[1].axis(2).value = averageAxis(event.value, last_values_y)
@hon0
Copy link

hon0 commented Apr 8, 2020 via email

@luizsaluti
Copy link
Author

luizsaluti commented Apr 8, 2020 via email

@luizsaluti
Copy link
Author

luizsaluti commented Apr 8, 2020 via email

@danw-eth
Copy link

Hi @luizsaluti,
Did you ever get the attachment from hon0?
Or have a script that works in the new Gremlin?
Thanks!

@hon0
Copy link

hon0 commented May 15, 2020

Hi @luizsaluti,
Did you ever get the attachment from hon0?
Or have a script that works in the new Gremlin?
Thanks!

Here it is! https://www.dropbox.com/s/2kdmku7tznbj42r/average_filter.py?dl=0 (Modified by WhiteMagic).

@danw-eth
Copy link

Thanks hon0!

@luizsaluti
Copy link
Author

luizsaluti commented May 15, 2020 via email

@ttsigg
Copy link

ttsigg commented Sep 25, 2020

The file was deleted, anyone have a copy?

@danw-eth
Copy link

The file was deleted, anyone have a copy?

Yep, added to my dropbox share: https://www.dropbox.com/s/4dz1ibrav2e11ci/Plugins.zip?dl=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment