PRO
RoboHappy
USA
Asked
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
Speech Recognition
by Synthiam
Windows Speech Recognition skill: detect custom phrases via PC mic, trigger configurable scripts/actions with adjustable confidence.

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:
So the script should not be waiting for IR until after the open command is spoken.
Recommended structure
Since you want two separate scripts, I’d suggest making each one do the full cycle for its own gripper.
Left gripper
ADC2D8or whatever EZ-B port you move it toD7is pressedRight gripper
ADC1D6is pressedImportant correction
You mentioned:
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:
d8d9If that’s not what you meant, tell me the exact ports and I’ll adjust it.
Example: Left gripper script
This version assumes:
d8ADC2d7Example: Right gripper script
This assumes:
d9ADC1d6Why this works better
This approach:
One caution
The line:
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:
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:
d8d9If you give me the exact ports, I’ll write the final ready-to-paste scripts for both grippers.
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 ?
Yes - for your use case,
ScriptStartWaitis 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.ScriptStartvsScriptStartWaitScriptStart= starts the script in the background and immediately continues with the next actionScriptStartWait= starts the script and waits until it finishes before moving onFor your gripper
If your speech command is:
and that action should:
then use
ScriptStartWaitif 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
ScriptStartWaitat all - the script itself can just do the whole sequence in one script.Recommended ARC setup
I’d actually suggest this:
Open Left GripperThat 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
d8This closes the servo gradually:
How it works
posstores the current servo position1sleep(80)pauses 80 ms between stepsFull left gripper example
This version assumes:
Full right gripper example
About calling
LeftGripCloseIf you still want one script to open and then call another script:
ScriptStartWaitif you want the open script to finish firstScriptStartif you want it to launch without waitingBut honestly, for this project, a single script per gripper is cleaner.
Best next step
If you want, I can give you:
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.