Please help with servoSequencePoint / servo.sequencePlay

Hi all
Please could someone advise me why the following servo.sequencePlay code only works the once.
The first time the doorSwitch goes HIGH the code works, thereafter the servo.sequencePlay code is ignored .
I have spent some time on the internet but surprisingly i have found very little info.
much appreciated.


#include <VarSpeedServo.h>

//VarSpeedServo Servo1;
VarSpeedServo Servo2;
VarSpeedServo Servo3;

int doorSwitch = 8;

servoSequencePoint door[] = {{140, 3}, {120, 6}, {100, 9}, {80, 12}, {65, 15}, {50, 20}
};
servoSequencePoint gate[] =  {{120, 10}, {75, 10}, {120, 10}, {75, 10}
};

void setup() {

  Serial.begin(9600);

  //Servo1.attach(10);
  Servo2.attach(11);
  Servo3.attach(12);

  pinMode (8, INPUT_PULLUP);

  //Servo1.write (53, 10);
  Servo2.write (164, 10);
  Servo3.write (53, 10);

}
void loop() {

  if (digitalRead (doorSwitch) == HIGH) {
    Servo2.sequencePlay(door, 6, false, 0);
    Servo3.sequencePlay(gate, 4, false, 0);
  }
  if (digitalRead (doorSwitch) == LOW) {
    Servo2.write (164, 10);
    Servo3.write (53, 10);
  }
}

Well done posting formatted code in code tags!
Check the end positions of those 2 different actions. Where does the servos end up? Does the second block, doorSwitch == LOW return the servos to a doorSwitch being HIGH?
Use serial monitor and Serial.print to tell things. Is there a function like Servo.pos that can return the position?
In what state is the doorSwitch when the execution hangs?

thanks for the reply
doorSwitch==LOW returns the servo to the original start position
doorswitch==HIGH carries out a sequence of moves then stops.
the program works fine the first time the doorSwitch==HIGH however if the doorSwitch is change to LOW (original start position) and back to HIGH the servos no longer carry out the sequence of moves (the servos stay in the original start position)
In summery
doorSwitch==HIGH only work the first time, the second time doorSwitch==High nothing happens.
It appears the Servo.sequencePlay code is ignored the second time around.

Okey.
Are both servo1 and servo2 behaving similar, refucing a second sequence?
The best I can say is: dig in the documentation for that sequnce running. Does it need some kind of reset after completion?

Yes both servos are refusing a second sequence.
The problem is I am finding it difficult to find documentation on sequence running, there seems to be a lack on information on the internet.

You may want to save a copy of the library and then add some serial prints to it. Probably best to add some to your own code first so you see what's being executed.

Thanks for you response
I am relatively new to this, so I will need to look into what servo information I can serial print.

You use servo.sequencePlay.... What other functions does that library provide? How did You find the sequence function?
Are there any demands like a special end marker is used in the array?

I have not had much experience with library's if I am honest (other than including them), I am trying to learn the basics first.
This is the only information I could find on the internet.

VarSpeedServo/ServoSequence.ino at master · netlabtoolkit/VarSpeedServo · GitHub

I only have a tiny phone for the moment...
Use Windows filemanager and check what files there are in that servo folder.
You found an example code, and that's okey.
Check the details, compare the example array with Your arrays........

It doesn't matter how many libraries You have used. They are all different.
It's the way to dig and find out that is the common part.

i repeat parts of reply #10 below:

Use Windows filemanager and check what files there are in that servo folder.
You found an example code, and that's okey.
Check the details, compare the example array with Your arrays........

There are files, in the library folder, that can be opened by any simple text editor like Notepad, and be inspected. Try that!

Through trial and error, I have made some progress.
It would appear that the programe does not like Servo.sequencePlay command being used with Servo.write command
I have deleted the following lines from void loop ()

Servo2.write (164, 10);
Servo3.write (53, 10);

and replaced then with additional Servo.sequencePlay lines

Servo2.sequencePlay(doorclose, 1, false, 0);
Servo3.sequencePlay(gateclose, 1, false, 0);

having made necessary changes to void setup()
The programe now works !

This does cause some minor issues as the Sevro.sequencePlay command need to be in a 'loop' so l will need to find away to make the second servo wait for the first servo to finish.
I am not aware for a Servo.sequencePlay command that waits for the servo to finish before commencing so I may need to do this with a timer.

I do not understand why I cannot use Servo.write with Servo.sequencePlay, however the programe works so I am not complaining.

Thankyou for your help

for your information here is my new code


#include <VarSpeedServo.h>

//VarSpeedServo Servo1;
VarSpeedServo Servo2;
VarSpeedServo Servo3;

int doorSwitch = 8;

servoSequencePoint dooropen[] = {{140, 3}, {120, 6}, {100, 9}, {80, 12}, {65, 15}, {50, 20}
};
servoSequencePoint gateopen[] = {{120, 10}, {7510}, {120, 10}, {75, 10}
};
servoSequencePoint doorclose[] = {{164, 10}
};
servoSequencePoint gateclose[] = {{53, 10}
};

void setup() {

Serial.begin(9600);

//Servo1.attach(10);
Servo2.attach(11);
Servo3.attach(12);

pinMode (8, INPUT_PULLUP);

//Servo1.write (53, 10);
Servo2.write (164, 10);
Servo3.write (53, 10);

}
void loop() {

if (digitalRead (doorSwitch) == HIGH) {
Servo2.sequencePlay(dooropen, 6, false, 0);
Servo3.sequencePlay(gateopen, 4, false, 0);
}

if (digitalRead (doorSwitch) == LOW) {
Servo2.sequencePlay(doorclose, 1, false, 0);
Servo3.sequencePlay(gateclose, 1, false, 0);
}
}

Great work! Well done! Who would guess that?

Do both servos fully run their sequences?
Okey, I got that You want one to run its entire sequence and then the other one should run.

Read the suggestions how to find available functions within the library! I have a feeling that there might be a function telling the status, running the sequence or sequence done.

Use Serial monitor and add a test print, Serial.println("Bo the lines executed.");
just after the Servo3 line!
If that message comes up on serial monitor You really know that sequencePlay is none blocking and the execution of servo sequence is still ongoing.

Sorry been out all day
I will try your suggestion.
I am sure I can get this working now.
May I take this opportunity to thankyou for you assistance / suggestions.

No problem with a day off but weeks... then most helpers have to start from the beginning and that's unwanted, no use, extra work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.