PWM Servo Feedback (I2c) icon PWM Servo Feedback (I2c) Real-time servo position input via Arduino ADC over I2C; supports Nano (6 channels) or Mega (16), configurable I2C address and scalable chaining. Try it →
Asked

Gripper Servo JS Conversion

,

This is a Script Skill question - could you help convert some EZ-Script I used previously into a JavaScript (ARC Script) version?

Context: This is for a two-arm robot. Each arm uses an older VEX-style claw gripper driven by a servo. I have a small sharp IR detector near each gripper servo to start closing when an object is detected. That IR-based behavior already works. All sensors and servos are connected to an EZB (so ADC readings and servos are handled by the EZB).

Below are the EZ-Script routines I used in the past. I’d like a JavaScript equivalent for use in the ARC Script Robot Skill. The script names are included so you can match the functionality.

EZ-Script for opening/closing both grippers: "Open Grippers" Servo(V25,180) Servo(V9,180)

"Close Grippers" Servo(V25,1) Servo(V9,1)

Gripper IR detector scripts: Grip_detectL (the script name) :claw ADC_Wait(Adc2,lower, 35) servo(V25,30) #Return goto(claw)

Grip_detectR (the script name) :claw ADC_Wait(Adc1,lower, 35) servo(V9,30) #Return goto(claw)

New requirement (added hardware): For each gripper I added a small lever switch that should immediately stop the gripper servo when it contacts the object. This is the EZ-Script I started for the lever-switch stop (I think I’m missing a servo stop somewhere):

Gripper_Object_stop (the script name) :LeverSw #Object detect lever switches (2) $a=GetADC(ADC6) #Right hand lever switch if($a=0) SayEZB("Object now gripped") stop() endif $a=GetADC(ADC7) #Left hand lever switch if($a=0) SayEZB("Object now gripped") stop() endif goto(LeverSw)

Could you look at making a JavaScript version of all of this for use in the ARC Script robot skill (JavaScript)?



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
ADC Value by Synthiam
Display ADC port voltage and 0-255 linear values (0-3.3/5V); configurable board/port, units, multiplier and sample interval.

ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

Author Avatar
PRO
Canada
Twitter YouTube GitHub
#1  

Absolutely - here’s a clean ARC JavaScript version of your gripper routines, converted from the EZ-Script behavior you described.

A couple of important notes first:

  • In ARC JavaScript, Servo.setPosition() is used instead of Servo(...)
  • ADC.waitForLower() is the direct equivalent of ADC_Wait(Adc#,lower,#)
  • To stop a servo when the lever switch hits, you’ll typically use Servo.release() on that servo port
  • I’d recommend using JavaScript over EZ-Script going forward for this in ARC

1) Open/Close both grippers

// Open Grippers
Servo.setPosition(v25, 180)
Servo.setPosition(v9, 180)

// Close Grippers
Servo.setPosition(v25, 1)
Servo.setPosition(v9, 1)

2) Left gripper IR detect loop

This matches your old Grip_detectL behavior:

while (true) {
  ADC.waitForLower(ADC2, 35)
  Servo.setPosition(v25, 30)
}

3) Right gripper IR detect loop

while (true) {
  ADC.waitForLower(ADC1, 35)
  Servo.setPosition(v9, 30)
}

4) Lever-switch stop routine

Your EZ-Script version is close, but in JavaScript you’ll want to poll the ADC values and then release the servo when the lever switch is triggered.

Assuming:

  • ADC6 = right lever switch
  • ADC7 = left lever switch
  • lever switch reads 0 when pressed
while (true) {
  var rightLever = ADC.get(ADC6)
  if (rightLever == 0) {
    Audio.sayEZB("Object now gripped")
    Servo.release(v9)
    break
  }

  var leftLever = ADC.get(ADC7)
  if (leftLever == 0) {
    Audio.sayEZB("Object now gripped")
    Servo.release(v25)
    break
  }

  sleep(20)
}

Combined example: gripper close until lever switch hits

If you want the servo to move closed until the switch is pressed, this is usually the best pattern:

// Start closing both grippers
Servo.setPosition(v25, 1)
Servo.setPosition(v9, 1)

while (true) {
  var rightLever = ADC.get(ADC6)
  if (rightLever == 0) {
    Audio.sayEZB("Object now gripped")
    Servo.release(v9)
  }

  var leftLever = ADC.get(ADC7)
  if (leftLever == 0) {
    Audio.sayEZB("Object now gripped")
    Servo.release(v25)
  }

  // If both are triggered, stop checking
  if (rightLever == 0 && leftLever == 0) {
    break
  }

  sleep(20)
}

Important correction about "stop"

In ARC, there isn’t really a generic stop() for a servo the way EZ-Script may imply in some script patterns. For a servo, the usual way to stop holding position is:

Servo.release(v9)

or

Servo.release(v25)

That turns off torque/holding for that servo.


ARC Script Skill setup tip

If you’re placing this in a Script Robot Skill, you can use the kebab menu on the Script skill and open Settings, then choose JavaScript, paste the script, and save it.


One thing I’d like to confirm

To make sure the conversion behaves exactly right, can you confirm these two details?

  1. Are v25 and v9 definitely virtual servo ports from a servo plugin skill, or are those actual servo ports on the EZ-B?
  2. Do you want the lever switch to:
    • release the servo immediately when touched, or
    • hold at the current position by stopping movement some other way?

If you want, I can also rewrite this as a more complete single ARC JavaScript routine with:

  • openGrippers()
  • closeGrippers()
  • monitorGrippers()

so it’s easier to reuse in your project.


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.