Dual-Axis Compass icon Dual-Axis Compass Dual-axis I2C magnetic sensor for EZ-B robots enabling magnetic direction sensing; requires short 2-3 in wiring. Third-party hardware. 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)
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
Windows Speech Recognition skill: detect custom phrases via PC mic, trigger configurable scripts/actions with adjustable confidence.

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
#9  

Yes - a couple key points there.

1) PCA9685 and servo speed

No, the PCA9685 robot skill does not provide true servo speed control. It outputs standard PWM pulses, so the servo moves at whatever speed its internal mechanics and load allow.

If you need slower motion, the usual ARC approach is to move in small steps with a delay in between. That works on the PCA9685, SSC-32, and normal EZ-B servo ports.

2) Your sensors should only be active after the open command

That makes sense. The clean behavior is:

  • Speech command opens the gripper
  • Then the script starts watching the IR sensor
  • Once IR detects the object, it closes slowly
  • While closing, it waits for the lever switch
  • When lever is pressed, it stops closing and holds
  • It does not keep running forever unless you want it to

So the script should not be waiting for IR until after the open command is spoken.


Since you want two separate scripts, I’d suggest making each one do the full cycle for its own gripper.

Left gripper

  • Open on speech command
  • Watch ADC2
  • Close using D8 or whatever EZ-B port you move it to
  • Stop when lever switch on D7 is pressed

Right gripper

  • Open on speech command
  • Watch ADC1
  • Close using its servo port
  • Stop when lever switch on D6 is pressed

Important correction

You mentioned:

D8 = Left, D8 = right

I assume one of those was a typo. If both grippers are being moved to the EZ-B v4, they need different ports.

For example:

  • Left gripper servo = d8
  • Right gripper servo = d9

If that’s not what you meant, tell me the exact ports and I’ll adjust it.


Example: Left gripper script

This version assumes:

  • Left servo = d8
  • Left IR = ADC2
  • Left lever = d7
  • Lever is normally closed and goes LOW when pressed
print("Opening left gripper...");

Servo.setPosition(d8, 180);
sleep(600);

print("Waiting for object on left IR sensor...");

while (ADC.get(ADC2) >= 35) {
  sleep(20);
}

print("Object detected. Closing left gripper slowly...");

while (Digital.get(d7) == true) {
  Servo.setPosition(d8, Servo.getPosition(d8) - 1);
  sleep(80);
}

print("Left lever switch pressed. Holding object.");

Example: Right gripper script

This assumes:

  • Right servo = d9
  • Right IR = ADC1
  • Right lever = d6
  • Lever is normally closed and goes LOW when pressed
print("Opening right gripper...");

Servo.setPosition(d9, 180);
sleep(600);

print("Waiting for object on right IR sensor...");

while (ADC.get(ADC1) >= 35) {
  sleep(20);
}

print("Object detected. Closing right gripper slowly...");

while (Digital.get(d6) == true) {
  Servo.setPosition(d9, Servo.getPosition(d9) - 1);
  sleep(80);
}

print("Right lever switch pressed. Holding object.");

Why this works better

This approach:

  • opens first from speech
  • only then begins looking for the object
  • closes gradually without servo speed support
  • stops as soon as the lever switch is hit
  • leaves the servo holding position

One caution

The line:

Servo.setPosition(d8, Servo.getPosition(d8) - 1);

works best if the servo is already at the open position and moving toward closed. If the servo direction is reversed on your mechanism, the increment may need to go the other way.


Suggested ARC setup

Use your Speech Recognition skill to trigger one script for:

  • "open left gripper"
  • "open right gripper"

Then the script itself can continue into the IR / lever sequence.

If you want separate "release" commands, that can be a different script that just re-opens the servo.


Quick question

Can you confirm the final EZ-B servo ports you want for testing?

For example:

  • Left = d8
  • Right = d9

If you give me the exact ports, I’ll write the final ready-to-paste scripts for both grippers.

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.
#10  

Yes, My EZB servo would be; Left =d8, Right=d9

So, after I would verbally say a command like "Open Left Gripper", the script would open the gripper then call "LeftGripClose", so at this point to call the script, would I use a scriptstart or scriptstartwait?

also, when you mentioned, move in small steps with a delay in between. could you provide a quick how to ?

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#11  

Yes - for your use case, ScriptStartWait is usually the better choice if the "Open Left Gripper" phrase should fully run the open action and then continue into the close-wait logic in the same flow.

ScriptStart vs ScriptStartWait

  • ScriptStart = starts the script in the background and immediately continues with the next action
  • ScriptStartWait = starts the script and waits until it finishes before moving on

For your gripper

If your speech command is:

  • Open Left Gripper

and that action should:

  1. open the gripper
  2. then wait for IR
  3. then close on the object
  4. then hold

then use ScriptStartWait if you’re calling another script from within that chain and you want the next step to wait.

But if the speech recognition phrase directly runs the full gripper script, you may not need ScriptStartWait at all - the script itself can just do the whole sequence in one script.

I’d actually suggest this:

  • Speech phrase: Open Left Gripper
  • Action: run the LeftGripClose script directly
  • Inside that script:
    • open the gripper
    • wait for IR
    • close slowly
    • stop on lever
    • hold

That is simpler than calling one script from another unless you specifically want the open step separated.


Quick example of a "small steps with delay" move

Since SSC-32 and PCA9685 don’t really use ARC’s servo speed the way EZ-B servo ports do, you can simulate slow motion by moving the servo a little at a time.

Example: slow close on d8

This closes the servo gradually:

var pos = 180; // open position

print("Opening gripper...");
Servo.setPosition(d8, pos);
sleep(500);

print("Starting slow close...");
while (Digital.get(d7) == true) {
  pos = pos - 1;
  if (pos < 1) {
    pos = 1;
    break;
  }

  Servo.setPosition(d8, pos);
  sleep(80); // bigger number = slower movement
}

print("Lever pressed. Holding position.");

How it works

  • pos stores the current servo position
  • each loop reduces it by 1
  • sleep(80) pauses 80 ms between steps
  • increasing the sleep value makes movement slower
  • decreasing it makes movement faster

Full left gripper example

This version assumes:

  • Left servo = d8
  • Left IR = ADC2
  • Left lever = d7
  • lever switch is normally closed and goes LOW when pressed
var pos = 180;

print("Opening left gripper...");
Servo.setPosition(d8, 180);
sleep(500);

print("Waiting for object...");
while (ADC.get(ADC2) >= 35) {
  sleep(20);
}

print("Object detected. Closing slowly...");

pos = 180;
while (Digital.get(d7) == true) {
  pos = pos - 1;
  if (pos <= 1) {
    pos = 1;
    Servo.setPosition(d8, pos);
    break;
  }

  Servo.setPosition(d8, pos);
  sleep(80);
}

print("Left gripper closed and holding.");

Full right gripper example

var pos = 180;

print("Opening right gripper...");
Servo.setPosition(d9, 180);
sleep(500);

print("Waiting for object...");
while (ADC.get(ADC1) >= 35) {
  sleep(20);
}

print("Object detected. Closing slowly...");

pos = 180;
while (Digital.get(d6) == true) {
  pos = pos - 1;
  if (pos <= 1) {
    pos = 1;
    Servo.setPosition(d9, pos);
    break;
  }

  Servo.setPosition(d9, pos);
  sleep(80);
}

print("Right gripper closed and holding.");

About calling LeftGripClose

If you still want one script to open and then call another script:

  • use ScriptStartWait if you want the open script to finish first
  • use ScriptStart if you want it to launch without waiting

But honestly, for this project, a single script per gripper is cleaner.


Best next step

If you want, I can give you:

  1. Left gripper full final script
  2. Right gripper full final script
  3. Open-only scripts
  4. Release-only scripts
  5. Speech Recognition phrase mapping

all in a ready-to-paste format for ARC.

Also, questions like this are often easier to refine with the ARC AI Assistant right inside the script editor: https://synthiam.com/Products/AI-Assistant

If you want, I can build the final two scripts now using your exact ports and logic.

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.