Skip to content

Instantly share code, notes, and snippets.

@WhiteMagic
Created April 9, 2019 12:39
Show Gist options
  • Save WhiteMagic/029f7dc0acbe287983675de85babf709 to your computer and use it in GitHub Desktop.
Save WhiteMagic/029f7dc0acbe287983675de85babf709 to your computer and use it in GitHub Desktop.
Allows control of a two engine throttle which shifts overall throttle value based on rudder input.
import gremlin
from gremlin.user_plugin import *
# User configurable variables
mode = ModeVariable(
"Mode",
"The mode to use for this mapping"
)
rudder_axis = PhysicalInputVariable(
"Rudder Axis",
"Axis which controls rudder input",
[gremlin.common.InputType.JoystickAxis]
)
throttle_axis = PhysicalInputVariable(
"Throttle Axis",
"Axis which controls throttle input",
[gremlin.common.InputType.JoystickAxis]
)
virtual_left = VirtualInputVariable(
"Left throttle",
"vJoy axis mapped to the left throttle",
[gremlin.common.InputType.JoystickAxis]
)
virtual_right = VirtualInputVariable(
"Right throttle",
"vJoy axis mapped to the right throttle",
[gremlin.common.InputType.JoystickAxis]
)
invert_rudder = BoolVariable(
"Invert rudder",
"Whether or not the rudder directions should be inverted",
False
)
invert_throttle = BoolVariable(
"Invert throttle",
"Whether or not to invert the throttle direction",
False
)
# Device decorators
rudder_dec = rudder_axis.create_decorator(mode.value)
throttle_dec = throttle_axis.create_decorator(mode.value)
# Storage variables
total_throttle = 0.0
rudder_input = 0.0
def update_throttles(vjoy):
left_throttle = max(-1.0, min(1.0, total_throttle + rudder_input))
right_throttle = max(-1.0, min(1.0, total_throttle - rudder_input))
if invert_rudder.value:
left_throttle, right_throttle = right_throttle, left_throttle
left_device = vjoy[virtual_left.value["device_id"]]
left_device.axis(virtual_left.value["input_id"]).value = left_throttle
right_device = vjoy[virtual_right.value["device_id"]]
right_device.axis(virtual_right.value["input_id"]).value = right_throttle
@rudder_dec.axis(rudder_axis.input_id)
def rudder(event, vjoy):
global rudder_input
rudder_input = event.value
update_throttles(vjoy)
@throttle_dec.axis(throttle_axis.input_id)
def throttle(event, vjoy):
global total_throttle
total_throttle = event.value
if invert_throttle.value:
total_throttle *= -1
update_throttles(vjoy)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment