Asked — Edited

How To Repeat Cycle A Servo Back And Forth X# Of Times

I'd like to be able to make a servo oscillate back and forth for a set number of cycles. For example, I'd like to be able to edit a script and tell it to cycle 100 times. Another time I'd like to be able to go back in and have it cycle 1000 times. Is there an easy way to do this? (NEWBIE here) -Thanks in advance!


ARC Pro

Upgrade to ARC Pro

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

#1  

I would also like to know - I need to have B9s antennae move back and forth.

PRO
Synthiam
#2  

You can make an EZ-Script



# Set the servo speed to be slow and smooth
ServoSpeed(d5, 3)

# Beginning of the loop
:Loop

# Move one way
Servo(d5, 10)

# Pause for 3 seconds
Sleep(3000)

# Move the other way
Servo(d5, 70)

# Repeat
goto(Loop)

United Kingdom
#3  

I am also a NEWBIE here:)

Correct me if I am wrong, but that script is a continuous cycle with no exit Wouldn't you need to have a IF-THEN-ELSE with an incremented counter for x100 cycles/loops ?

#4  

Agreed -I need to be able to specify a specific # of cycles

#5  

yeah

if(servo, d6 > 50)

ServoSpeed(d5, 3)

:Loop Servo(d5, 10) Sleep(3000) Servo(d5, 70) (enter if command here aswell to "stop it")

goto(Loop)

i think....havent been in the "lab" for a while now.

#6  

Appreciate the feedback but being a total newb I need it spelled out for me -can you post a complete functioning script that would run for 150 cycles (just picking a number to use as an example). Really appreciate the help!

PRO
Synthiam
#7  

Use the c# script or vb script. Here is an example i made for you. It will sweep the servo 5 times on port D5 with the speed set to 3.

I also have it setup to run from a voice command. Or from an EZ-Script command.

Right Click Save As: SweepServoExample.EZB

And here is a copy of the code from the c# script control


using System.IO;
using System.Windows.Forms;
using EZ_B;

namespace VName {

  public class VClass {

    public void Main(EZB ezb0, EZB ezb1, EZB ezb2, EZB ezb3, EZB ezb4) {

      ezb0.Servo.SetServoSpeed(Servo.ServoPortEnum.D5, 3);

      for (int x=0; x < 5; x++) {

        ezb0.Servo.SetServoPosition(Servo.ServoPortEnum.D5, 10);
        
        System.Threading.Thread.Sleep(4000);

        ezb0.Servo.SetServoPosition(Servo.ServoPortEnum.D5, 80);

        System.Threading.Thread.Sleep(4000);
      }
    }
  }
}