Skip to content

Commit

Permalink
Merge pull request #332 from Mitteau/master
Browse files Browse the repository at this point in the history
Dead zone for gamepad roll and pitch
  • Loading branch information
krichardsson authored Mar 9, 2018
2 parents d6b8935 + 9628b9b commit 120c68c
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/cfclient/configs/input/Generic_OS_X.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"inputconfig": {
"inputdevice":
{"name": "Generic 2-axis gamepad on OS X", "updateperiod":10,
"rp_dead_band": 0.1,
"axis": [
{"name":"Roll", "type":"Input.AXIS", "id":3, "scale":1.0, "key":"roll"},
{"name":"Pitch", "type":"Input.AXIS", "id":4, "scale":-1.0, "key":"pitch"},
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/Joystick.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"updateperiod": 10,
"springythrottle": false,
"name": "Joystick",
"rp_dead_band": 0.1,
"axis": [
{
"scale": -1.0,
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/PS3_Mode_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"inputconfig": {
"inputdevice":
{"name": "Playstation 3 Mode 1", "updateperiod":10,
"rp_dead_band": 0.1,
"axis": [
{"name":"Roll", "type":"Input.AXIS", "id":0, "scale":1.0, "key":"roll"},
{"name":"Pitch", "type":"Input.AXIS", "id":1, "scale":-1.0, "key":"pitch"},
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/PS3_Mode_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"inputconfig": {
"inputdevice":
{"name": "Playstation 3 Mode 2", "updateperiod":10,
"rp_dead_band": 0.1,
"axis": [
{"name":"Roll", "type":"Input.AXIS", "id":2, "scale":1.0, "key":"roll"},
{"name":"Pitch", "type":"Input.AXIS", "id":3, "scale":-1.0, "key":"pitch"},
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/PS3_Mode_3.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"inputdevice": {
"updateperiod": 10,
"name": "PS3_Mode_3",
"rp_dead_band": 0.1,
"axis": [
{
"scale": -1.0,
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/PS4_Mode_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"inputdevice": {
"updateperiod": 10,
"name": "PS4_Mode_1",
"rp_dead_band": 0.1,
"axis": [
{
"scale": -1.0,
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/PS4_Mode_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"inputdevice": {
"updateperiod": 10,
"name": "PS4_Mode_2",
"rp_dead_band": 0.1,
"axis": [
{
"scale": -1.0,
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/PS4_shoulder_btns_yaw.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"inputdevice": {
"updateperiod": 10,
"name": "PS4_shoulder_btns_yaw",
"rp_dead_band": 0.1,
"axis": [
{
"scale": -1.0,
Expand Down
1 change: 1 addition & 0 deletions src/cfclient/configs/input/xbox360_mode1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"inputdevice": {
"updateperiod": 10,
"name": "xbox360_mode1_linux",
"rp_dead_band": 0.1,
"axis": [
{
"scale": -1.0,
Expand Down
2 changes: 1 addition & 1 deletion src/cfclient/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def _mux_selected(self, checked):
def _get_dev_status(self, device):
msg = "{}".format(device.name)
if device.supports_mapping:
map_name = "N/A"
map_name = "No input mapping"
if device.input_map:
map_name = device.input_map_name
msg += " ({})".format(map_name)
Expand Down
3 changes: 2 additions & 1 deletion src/cfclient/utils/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def get_list_of_configs(self):
data = json.load(json_data)
new_input_device = {}
new_input_settings = {"updateperiod": 10,
"springythrottle": True}
"springythrottle": True,
"rp_dead_band": 0.05}
for s in data["inputconfig"]["inputdevice"]:
if s == "axis":
for a in data["inputconfig"]["inputdevice"]["axis"]:
Expand Down
9 changes: 7 additions & 2 deletions src/cfclient/utils/input/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def __init__(self, do_device_discovery=True):

self.trim_roll = Config().get("trim_roll")
self.trim_pitch = Config().get("trim_pitch")
self._rp_dead_band = 0.1

self._input_map = None

Expand Down Expand Up @@ -298,13 +299,17 @@ def set_raw_input_map(self, input_map):

def set_input_map(self, device_name, input_map_name):
"""Load and set an input device map with the given name"""
dev = self._get_device_from_name(device_name)
settings = ConfigManager().get_settings(input_map_name)

if settings:
self.springy_throttle = settings["springythrottle"]
self._rp_dead_band = settings["rp_dead_band"]
self._input_map = ConfigManager().get_config(input_map_name)
self._get_device_from_name(device_name).input_map = self._input_map
self._get_device_from_name(device_name).input_map_name = input_map_name
dev.input_map = self._input_map
dev.input_map_name = input_map_name
Config().get("device_config_mapping")[device_name] = input_map_name
dev.set_dead_band(self._rp_dead_band)

def start_input(self, device_name, role="Device", config_name=None):
"""
Expand Down
17 changes: 17 additions & 0 deletions src/cfclient/utils/input/inputreaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def __init__(self, dev_name, dev_id, dev_reader):
self.limit_rp = True
self.limit_thrust = True
self.limit_yaw = True
self.db = 0.

def open(self):
# TODO: Reset data?
Expand All @@ -100,6 +101,9 @@ def open(self):
def close(self):
self._reader.close(self.id)

def set_dead_band(self, db):
self.db = db

def read(self, include_raw=False):
[axis, buttons] = self._reader.read(self.id)

Expand Down Expand Up @@ -135,6 +139,9 @@ def read(self, include_raw=False):
pass
i += 1

self.data.roll = InputDevice.deadband(self.data.roll, self.db)
self.data.pitch = InputDevice.deadband(self.data.pitch, self.db)

if self.limit_rp:
[self.data.roll, self.data.pitch] = self._scale_rp(self.data.roll,
self.data.pitch)
Expand All @@ -149,3 +156,13 @@ def read(self, include_raw=False):
return [axis, buttons, self.data]
else:
return self.data

@staticmethod
def deadband(value, threshold):
if abs(value) < threshold:
value = 0
elif value > 0:
value -= threshold
elif value < 0:
value += threshold
return value / (1 - threshold)

0 comments on commit 120c68c

Please sign in to comment.