Asked

Help With EZ-Script Coding

I'm working on a project with my EZ-B v4, and I need some assistance with coding the GetDigital command. My aim is to use pin D22 as an input pin to receive a high/low digital signal from an R/C receiver. The receiver uses a PWM-to-digital output device on one of its channels. This setup will allow me to switch my robot's drive wheels between ARC (automatic mode) and R/C control (manual mode).

The script below is intended to monitor the state of pin D22 and provide verbal feedback. When in Automatic Mode, ARC will control the wheels and all sensors. In manual Mode, a standard radio control transmitter will handle the wheel operations. I need this functionality implemented in both EZ-Script and JavaScript.

Here's my current EZ-Script code:

$X = GetDigital(D22)
if ($X = 0)
  $X = "PASS"
  EzbSay("in  manual Mode")
elseif ($X = 1)
  $X = "FAIL"
  EzbSay("in Automatic Mode")
endif

Could you review it and help me ensure that it performs correctly? Additionally, guidance on translating this into JavaScript for the ARC environment would be greatly appreciated. Thank you!


Related Hardware EZ-B v4
Related Controls Script Read Digital

ARC Pro

Upgrade to ARC Pro

Unleash your robot's full potential with the cutting-edge features and intuitive programming offered by Synthiam ARC Pro.

PRO
Canada
#1  

Thanks - this is a good use case. I reviewed your EZ-Script and I’ll provide corrected, robust versions for both EZ-Script (no longer recommended) and JavaScript (for the Script skill). I’ll also include notes about debounce, change-detection (so ARC doesn’t keep repeating speech), and integration tips for switching drive control.

*Note: I do not know EZScript very well and there may be several errors in my code. However, the JavaScript or Python that I provide will always be reliable.

Useful links

Key points before the code

  • Digital.get(d22) in JavaScript returns true/false for the port state. Use the constant d22 without quotes.
  • In EZScript use GetDigital(D22) to read the port (your original usage is almost right, but you need to avoid reassigning and use change-detection to avoid repeated speech).
  • Add a short sleep and only speak when the state changes to avoid constant audio spam and to debounce the signal.
  • If the RC output is actually a PWM pulse (from receiver channel), make sure the PWM-to-digital device outputs a steady HIGH/LOW (latching) and not short pulses; otherwise you’ll need a pulse-to-duty or pulse-reader solution.
  • Use setVar("$DriveMode", "Manual") or "Automatic" if other scripts need to know the current mode.

Corrected EZScript (suitable for the Script skill)

' initialize last state
$Last = -1

:Loop
$X = GetDigital(D22)   ' returns 0 or 1

If ($X = 1)
  If ($Last <> 1)     ' only announce on change
    EzbSay("Manual mode")
    $Last = 1
    ' Optionally set a global variable other scripts can read:
    SetGlobal("$DriveMode", "Manual")
  EndIf
Else
  If ($Last <> 0)     ' only announce on change
    EzbSay("Automatic mode")
    $Last = 0
    SetGlobal("$DriveMode", "Automatic")
  EndIf
EndIf

Sleep(200)   ' 200 ms debounce/poll interval
Goto(Loop)

Notes for EZScript:

  • Use Sleep(ms) to control polling rate.
  • Use SetGlobal (or SetVar depending on your EZScript flavor); if SetGlobal isn't available, use SetVariable; if unsure, you can keep the EzbSay only.
  • If your receiver output is inverted you may need to swap the branches.

JavaScript version (recommended when using Script skill)

  • This example uses change-detection (speaks only when state changes), sets a global variable, and uses print() for logging per ARC guidance.
// JavaScript for the Script skill
var lastState = null;

while (true) {
  var state = Digital.get(d22); // returns true when HIGH

  if (state !== lastState) {
    if (state) {
      print("D22 HIGH -  manual mode");
      Audio.sayEZB("Manual mode");
      setVar("$DriveMode", "Manual");
      // Optionally, disable autonomous movement here:
      // Movement.stop();
      // controlCommand("Movement Panel", "Stop"); // example; adjust skill name if different
    } else {
      print("D22 LOW - Automatic mode");
      Audio.sayEZB("Automatic mode");
      setVar("$DriveMode", "Automatic");
      // Optionally, re-enable autonomous behavior here
      // controlCommand("SomeNavigatorSkill", "Start") 
    }
    lastState = state;
  }

  sleep(200); // 200 ms debounce/poll interval
}

Integration tips

  • Debounce & change detection: the code above avoids repeated announcements and transient pulses by speaking only on changes and using a 200 ms delay. Adjust the delay for your environment.
  • Avoid spamming speech: if you want a single short sound/LED change instead of speech, replace Audio.sayEZB(...) with a beep or other indicator.
  • Switching control of motors: decide what should happen when manual mode engages (e.g., stop ARC Movement skill or release wheel servos). You can call Movement.stop() or use ControlCommand for specific movement or navigation skills. I can give exact ControlCommand examples if you tell me which Movement/drive skill you're using (Movement Panel, Differential Drive, a custom robot skill, etc.).
  • Read Digital skill: If you prefer a GUI skill for monitoring, use the Read Digital skill and link it to scripts via global variables or the Script skill reading Digital.get(d22). Read Digital is nice for debugging in the ARC UI.

A couple of questions to fine-tune the solution

  1. Does the RC receiver/pwm-to-digital device output a steady HIGH/LOW (latched) corresponding to manual vs auto, or does it output short pulses (servo PWM)?
  2. Which Movement/drive skill are you using in ARC (Movement Panel, Differential Drive skill, a custom robot skill)? Do you want ARC to stop wheel outputs automatically when manual mode is detected, or only to set a flag so your other scripts/human operator take control?

If you post the exact hardware behavior for the RC output and the Movement skill name, I’ll give the exact ControlCommand calls and an updated script that will safely switch wheel control for you.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#2  

@Athena To answer your questions above:

  1. Yes, RC Receiver/pwm-to-digital output is provides a steady high output when activated.

  2. This is an old program , using the servo Movement Panel (differential drive) and controls two old parallax HB-25 motor controllers. yes-would like the ARC to stock wheel output when manual mode is selected.