Ez430-Chronos Wrist Watch icon Ez430-Chronos Wrist Watch Map TI eZ430-Chronos watch accelerometer X/Y tilt to ARC servos for intuitive, Wii-Remote-style control of servo positions. Try it →
Asked
Ensure Variable State Saver loads first

Ensure Variable State Saver Loads First

Running a JD Humanoid over WiFi to an EZB, and I’m trying to persist a few calibration/tuning variables between ARC sessions using the Variable State Saver skill. I’ve added these globals in the skill’s config with sensible defaults: $headPanOffset, $headTiltOffset, $leftArmOffset, $rightArmOffset, $gaitSpeed. My JavaScript control applies them on startup before I trigger some Auto Position actions:

var pan = 90 + parseInt(GetVar("$headPanOffset") || 0);
var tilt = 90 + parseInt(GetVar("$headTiltOffset") || 0);
Servo(D0, pan);
Servo(D1, tilt);
SetSpeed(D2, GetVar("$gaitSpeed") || 2);

Expected: when I open the project and connect to the JD, it should use the last saved values. Actual: on project load, the values are still at the defaults for a second or two while my scripts and Auto Position frames kick off, then if I manually press Load on Variable State Saver (or call ControlCommand("Variable State Saver", "Load")), everything updates-but by then JD already moved with the wrong offsets/speed.

What I’ve tried:

  • Put ControlCommand("Variable State Saver", "Load") in a dedicated Init script set to run on project start.
  • Moved the same command to the EZB Connection skill’s On Connection script (JD connects reliably).
  • Added small delays (Sleep 500-2000 ms) before reading the variables, which helps sometimes but feels hacky.

Is there a recommended way to guarantee Variable State Saver loads its saved values before any other scripts/skills run, or an autoload option/initialization event I should be using so JD never starts with the defaults?



Related Hardware (view all EZB hardware)
JD Humanoid by EZ-Robot
JD humanoid robot kit - WiFi-enabled, 16 DOF with metal-gear servos; easy, fun, educational, available from the EZ-Robot online store.
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skills (view all robot skills)
Persist and auto-load specified global variables between ARC sessions for consistent, personalized robot behavior and quick state restoration.
EZB Connection by Synthiam
Connects EZ-B I/O controllers to ARC via COM or IP (5 connections). Supports init scripts, battery monitoring, TCP/EZ-Script server and serial/I2C.

ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Yes - the key is to load the Variable State Saver before anything else reads those globals.

For JD, the most reliable pattern is:

  1. Use the EZB Connection skill’s Connection Established script on the same connection index JD uses.
  2. In that script, call ControlCommand("Variable State Saver", "Load") first
  3. Then apply your servo offsets / gait speed
  4. Only after that, start any Auto Position or behavior scripts

That way, the saved values are restored as soon as the EZ-B connects, before your initialization logic runs.


Example startup script

In the EZB Connection skill:

  • click the kebab / hamburger menu
  • open Settings
  • find the Connection Established Script for index 0 if that’s where JD is connected

Use something like:

ControlCommand("Variable State Saver", "Load")
Sleep(100)

var pan = 90 + parseInt(getVar("$headPanOffset", 0))
var tilt = 90 + parseInt(getVar("$headTiltOffset", 0))
var gaitSpeed = parseInt(getVar("$gaitSpeed", 2))

Servo(D0, pan)
Servo(D1, tilt)
Servo.setSpeed(D2, gaitSpeed)

Important notes

1) Load in a project-start script may run too early

If the project starts before the EZ-B connection is ready, some skills may still initialize with defaults. That’s why Connection Established is better than a project-load script for hardware calibration values.

2) ControlCommand("Variable State Saver", "Load") is the right command

That’s the correct way to restore the saved state from script.

3) Your script has one ARC JavaScript detail

You used:

SetSpeed(D2, GetVar("$gaitSpeed") || 2);

In ARC JavaScript, use the servo command form instead:

Servo.setSpeed(D2, parseInt(getVar("$gaitSpeed", 2)))

Also, getVar() is preferred over GetVar().


Best practice for JD

If those offsets are used by multiple skills, you can also:

  • keep them in Variable State Saver
  • load them in Connection Established
  • then have all other scripts read from the already-loaded values

That avoids timing issues and keeps startup deterministic.


If you still see a race condition

If another skill is acting before the connection script finishes, the next step is to:

  • disable that skill’s auto-start behavior until after variables load, or
  • use a dedicated "startup" script that loads variables first, then calls the rest of the behaviors in order

For more on the skill itself:


One question

Are your Auto Position actions being triggered by:

  • the Connection Established script, or
  • another skill’s on load / startup behavior?

If you tell me which skill starts them, I can suggest the cleanest ordering so JD never moves on defaults.

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.