Graphy icon Graphy Plot live data with ControlCommand scripts: multi-series charts, many chart types, legend toggle, add/remove series, export graph data to CSV Try it →
Asked

Separate Gripper Control Scripts

New gripper control - help needed

I still need help controlling each gripper using both its IR sensor and a lever switch to detect when the gripper has closed.

I'm running this as ARC built-in JavaScript on an EZB (the script uses ADC channels and servo ports). The code I have so far:

var rightGripperServo = v9;
var leftGripperServo = v25;
var rightIr = ADC1;
var leftIr = ADC2;
var rightLever = ADC6;
var leftLever = ADC7;
var closeSpeed = 10; // 0 = fastest, 10 = slowest

function closeRightGripperOnIR() {
  while (true) {
    ADC.waitForLower(rightIr, 35);
    print("Right IR detected object. Closing gripper...");
    Servo.setSpeed(rightGripperServo, closeSpeed);
    Servo.setPosition(rightGripperServo, 1);
    while (ADC.get(rightLever) != 0) {
      sleep(20);
    }
    print("Right object now gripped");
    // Keep holding - do NOT release servo
    Servo.setSpeed(rightGripperServo, 0);
  }
}

function closeLeftGripperOnIR() {
  while (true) {
    ADC.waitForLower(leftIr, 35);
    print("Left IR detected object. Closing gripper...");
    Servo.setSpeed(leftGripperServo, closeSpeed);
    Servo.setPosition(leftGripperServo, 1);
    while (ADC.get(leftLever) != 0) {
      sleep(20);
    }
    print("Left object now gripped");
    // Keep holding - do NOT release servo
    Servo.setSpeed(leftGripperServo, 0);
  }
}

// closeGrippersSlowUntilSwitch();

Can you make separate scripts for each gripper?

Desired behavior for either the left or right gripper:

  • Open the gripper via a speech command (using ARC speech recognition Robot Skill).
  • The gripper finds the object to grab via its IR detector.
  • The gripper begins to close slowly onto the object.
  • The object presses the lever switch.
  • The servo stops but continues holding the object. The gripper will continue to hold the object until told to release it.

Thanks!



Related Hardware (view all EZB hardware)
EZ-B V4 by EZ-Robot
EZ-B v4/2 robot controller: dual Cortex ARM, Wi-Fi, audio/video, 24 servo/digital ports, I2C/UART, camera and Synthiam ARC control for custom robots
Wi-Fi / USB
Servos 24
Camera
Audio
UART 3
I2C
ADC 8
Digital 24

Related Robot Skills (view all robot skills)
Movement Script by Synthiam
Trigger direction-specific scripts when ARC movement panels change; assign scripts per direction/stop, access direction and speed (JS/Python/EZ).
Displays HC-SR04 ultrasonic distance readings in ARC; scriptable via GetPing(), pausable, sets a variable with multiplier, optional NMS output

ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Yes - it’s better to split this into two separate scripts, one for the right gripper and one for the left gripper. That keeps each gripper independent and easier to debug.

A couple of important fixes first:

  • ADC.get() should read the analog sensor port only
  • For the lever switch, if it’s a digital switch, you should use Digital.get() instead of ADC.get()
  • If the servo is supposed to keep holding the object, you generally do not release the servo after closing
  • For slow closing, set the servo speed before moving it

Right Gripper Script

var rightGripperServo = v9;
var rightIr = ADC1;
var rightLever = d6; // change to your actual digital port for the lever switch
var closeSpeed = 10; // 0 = fastest, 10 = slowest

function closeRightGripperOnIR() {
  print("Right gripper waiting for IR detection...");

  while (true) {
    ADC.waitForLower(rightIr, 35);
    print("Right IR detected object. Closing gripper...");

    Servo.setSpeed(rightGripperServo, closeSpeed);
    Servo.setPosition(rightGripperServo, 1);

    while (Digital.get(rightLever) == false) {
      sleep(20);
    }

    print("Right object now gripped. Holding position.");
    Servo.setSpeed(rightGripperServo, 0);
    break;
  }
}

closeRightGripperOnIR();

Left Gripper Script

var leftGripperServo = v25;
var leftIr = ADC2;
var leftLever = d7; // change to your actual digital port for the lever switch
var closeSpeed = 10; // 0 = fastest, 10 = slowest

function closeLeftGripperOnIR() {
  print("Left gripper waiting for IR detection...");

  while (true) {
    ADC.waitForLower(leftIr, 35);
    print("Left IR detected object. Closing gripper...");

    Servo.setSpeed(leftGripperServo, closeSpeed);
    Servo.setPosition(leftGripperServo, 1);

    while (Digital.get(leftLever) == false) {
      sleep(20);
    }

    print("Left object now gripped. Holding position.");
    Servo.setSpeed(leftGripperServo, 0);
    break;
  }
}

closeLeftGripperOnIR();

Notes

  • I changed your lever inputs from ADC6 / ADC7 to digital ports because a lever switch is typically an on/off input.
  • If your lever switch is actually wired as an analog input, tell me and I’ll adjust the script.
  • Your script uses v25 for the left gripper servo. That’s fine if it’s a virtual servo port from a servo skill. If it is a physical EZ-B servo port, that would need to be changed.

Open / Release behavior

You mentioned:

The gripper will continue to hold the object until told to release it.

That usually means you want a separate release script for each gripper. For example:

var rightGripperServo = v9;

Servo.setSpeed(rightGripperServo, 10);
Servo.setPosition(rightGripperServo, 180); // change to your open position
sleep(500);

and similarly for the left gripper.

Best ARC setup

If you’re using speech recognition in ARC:

  1. Add a Speech Recognition skill
  2. In its script for phrases like:
    • "open right gripper"
    • "open left gripper"
    • "release right gripper"
    • "release left gripper"
  3. Put the corresponding open/release script in each phrase action

If you want, I can help you make this into a cleaner structure with:

  • one reusable function
  • separate open / close / release commands
  • speech phrases wired into ARC properly

If you share:

  • which digital ports the lever switches are actually on
  • the open and closed servo positions
  • whether v9 and v25 are definitely virtual servo ports

I can tailor the scripts exactly to your grippers.


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.