EZB Connections icon EZB Connections — Add and manage up to 255 EZ-B I/O controller connections in ARC, select COM/IP ports or device addresses to connect or remove devices. Try it →
Asked
1 Participant
Smooth XInput triggers to servo

Smooth Xinput Triggers To Servo

I’m driving a little 2wheel rover with an EZ-B IoTiny over WiFi. Left and right continuous rotation servos are on D0/D1 using the Continuous Rotation Movement Panel, and a micro tilt servo is on D2 for a camera. I added the Joystick (XInput) skill with an Xbox controller (Bluetooth to Windows), hit Refresh, and enabled "Joystick #1 controls movement panel" so the left stick gives variable speed. That part works great.

What I’m trying to do is use the analog triggers for the tilt: RT tilts up proportionally, LT tilts down, with a bit of deadzone and smoothing so tiny touches don’t move it. If I map the triggers directly to a servo in the Joystick (XInput) UI, the tilt is jumpy and I also notice occasional jitters in the drive when I feather the triggers. I’d rather read the raw trigger values in a script, apply a curve/deadzone, then write to D2.

I can’t figure out what variables the Joystick (XInput) exposes. I tried watching a bunch in Variable Watcher and a small JavaScript, but they all stay at 0:

// ARC JavaScript
var rt = getVar("$xinput_rt");
var lt = getVar("$xinput_lt");
// map and write to D2 after smoothing (rt- lt)

I also tried reducing servo speed with ServoSpeed(D2, 2) and adding a simple moving average in JavaScript, but without the correct trigger variables I’m stuck. Is there a recommended way in ARC to access the Joystick (XInput) RT/LT analog values in a script so I can add a deadzone/curve for the D2 tilt without affecting the Movement Panel control?



Related Hardware (view all EZB hardware)
EZ-B Iotiny by EZ-Robot
EZ-B IoTiny works with Synthiam ARCx to control servos, camera, voice, scripts, and IoT from any browser.
Wi-Fi
Servos 8
Camera
Audio
UART None (transmit-only serial on digital ports)
I2C
ADC 2
Digital 8

Related Robot Skills (view all robot skills)
Script by Synthiam
Multi-language ARC Script: build, run and debug Blockly, JavaScript, EZ-Script or Python with Intellisense, run/save/load and Roboscratch support
XInput joystick skill for ARC: maps Xbox controllers to movement, servos, triggers, vibration, variables; supports analog inputs and scripts.

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Yes - there’s a better way in ARC than trying to guess the trigger variable names.

Use the Joystick (XInput) skill’s Variables tab to explicitly assign the trigger values to known global variables, then read those in a Script skill and drive D2 from there.

That’s the proven ARC pattern because:

  • the joystick skill controls the hardware input
  • the script skill handles filtering/smoothing
  • your Movement Panel can keep using the left stick independently

Why your current variables stay 0

$xinput_rt and $xinput_lt are not default ARC variables unless you create them in the Joystick skill settings.

In Joystick (XInput) > Settings > Variables, enable Set EZ-Script Variables and assign the triggers to names you choose, for example:

  • $JoystickLT
  • $JoystickRT

Then those values will become available globally for scripts.

What to do in ARC

1) Configure the Joystick skill

Open the kebab menu on the Joystick (XInput) skill:

  • click the three-line / hamburger menu on the skill
  • go to Settings
  • open the Variables tab
  • enable Set EZ-Script Variables
  • assign:
    • Left Trigger $JoystickLT
    • Right Trigger $JoystickRT

Even if you’re scripting in JavaScript, these are still accessible with getVar().

2) Add a Script skill for tilt smoothing

Have a separate Script skill manage only the tilt servo on D2.
That way you do not interfere with the Movement Panel control.

JavaScript example

Here’s a simple deadzone + smoothing example for D2:

// Smoothed tilt control from XInput triggers
// Assumes Joystick (XInput) Variables tab sets:
// Left Trigger  -> $JoystickLT
// Right Trigger -> $JoystickRT

var target = 90;
var current = 90;
var deadzone = 8;     // ignore tiny trigger movement
var curve = 1.6;      // higher = softer around center
var alpha = 0.18;     // smoothing factor 0..1

function applyDeadzone(v, dz) {
  if (v < dz) return 0;
  return v;
}

function shape(v, maxVal) {
  var n = v / maxVal;         // 0..1
  return Math.pow(n, curve) * maxVal;
}

while (true) {
  var lt = parseFloat(getVar("$JoystickLT", 0));
  var rt = parseFloat(getVar("$JoystickRT", 0));

  lt = applyDeadzone(lt, deadzone);
  rt = applyDeadzone(rt, deadzone);

  // triggers are typically 0..255
  var up = shape(rt, 255);
  var down = shape(lt, 255);

  // center around 90, adjust range as needed
  target = 90 + (up - down) * 0.35;

  // clamp safe servo range
  if (target < 45) target = 45;
  if (target > 135) target = 135;

  current = current + ((target - current) * alpha);

  Servo.setPosition(d2, current);

  sleep(30);
}

Notes

  • Use Servo.setPosition(d2, current) - d2 is a constant, so don’t put it in quotes.
  • ServoSpeed(D2, 2) is not the right pattern here. For a normal positional tilt servo, smoothing in script is the correct method.
  • If you want even better behavior, you can make the triggers relative instead of absolute:
    • RT nudges up
    • LT nudges down
    • script remembers the last tilt position

That often feels more natural for a camera tilt.

If you want the cleanest setup

The best practice is:

  • Joystick (XInput) = input source only
  • Movement Panel = drive base only
  • Script skill = camera tilt filtering and servo logic

That keeps the systems separated and prevents trigger noise from affecting drive control.

A question so I can tailor the script

What do you want the tilt to do overall?

  • center at neutral based on trigger difference
  • or incrementally move while a trigger is held, like a manual pan/tilt control?

If you want, I can give you a polished JavaScript version for either behavior, including a smoother exponential filter and servo limits for your camera mount.

You may also find the built-in ARC AI Assistant handy for rewriting the script right inside ARC:
https://synthiam.com/Products/AI-Assistant

I am a customer support AI and still learning. Please verify important answers in our support documentation. For advanced AI features, use the AI Script Agent built into ARC.