Asked
— Edited

Not having any luck with this script! The head isn't turning as it should. The Camera Control indicates that it is recording, however, I can't find the recording where it says it should be. Any help appreciated. Thanks
#start head in this position
servo(D1,110)
servospeed(D1,0)
sleep(500)
#start video recording
ControlCommand("Camera", CameraRecordStart)
sleep(50)
#head should move to the left in increments of 10 degrees
ServoUP(D1,10)
servospeed(D1,2)
sleep(5000)
$x=Getservo(D1)
sleep(500)
#when the head gets to 150 degrees it should move to the right
if($x > 150)
servoDown(D1,10)
servospeed(D1,2)
sleep(5000)
#when the head gets to 50 degrees it should go back to starting position
elseif($x < 50)
servo(D1,110)
endif
#stop video recording
ControlCommand("Camera", CameraRecordStop)
Stop()
Not your script. There is an open bug report
https://synthiam.com/Community/Questions/7245
Video recording has been broken for a while.
Alan
Ok, thanks. That explains that problem. Any idea why the servo down and servo up isn't working?
Your script doesn't have any loops around the IF which checks the position of the servo, it moves the servo UP 10 degrees and checks for it's position but doesn't move the servo again unless it's at > 150 or < 50.
Since it starts at 110 and moves up by 10, so to 120, it doesn't match either > 150 or < 50 so will only move to 110 then up by 10 degrees before the script stops.
Add a repeat or loop in around where it's checking and moving the servo up/down by increments.
Thanks Rich. That made sense. I've got it working now, here's what I came up with;
Hopefully, the video recording bug will be fixed soon. (hint, hint, wink, wink, DJ ) I'm planning to use this as part of a security system for my house. For now I'll have it take snapshots.
If it works that's great, however in the interests of giving more information for a wider audience and covering the many methods, I would have written it like this;
Neither way is wrong nor is either better, just a different solution to the same problem
Note: My code wasn't written in ARC and is unchecked therefore there may be some slight syntax errors.
That's a cool thing about ARC - there are different ways to write a script to achieve the same thing. Here's another way using Auto Positions and Control Commands;
When the video recording is up and running I'll replace the "Camera Snapshot" with the "Camera Record" CC.
I was looking at the code used in scripts, and not just this one. All the ones I have seen tend to do things the same way. But this code brings up one of the things I have seen often. That is, using sleep delays as the way of giving the servo time to do it's movement. This just seems too imprecise to me. Maybe I'm just being picky (I am a long time programmer (Modula2, ADA, Delphi) and tend to see things in a highly structured and precise way. Anyhow, I'm referring to this section:
As I see it, the statement sleep(500) is there to give the servo time to move to the new position and keep the system from checking the servo position hundreds (thousands?) of times needlessly. Thing is, how long it takes to get there is entirely predicated on the ServoSpeed set. Unless calculated, the sleep time would be a guess or fudge factor at best. Also the servo is going to be commanded to move another 10 degrees from it's current position regardless of whether the servo has made it to the last place it was commanded to go at that moment.
Instead, I was wondering if it might be better to do something like this:
Darn code brackets! Takes out all my lovely formatting.
Here the sleep statement is there only to prevent needless checking of the servo position. In this case limiting it to 10 times a second. There is also the issue of getting out of the loop in case of failure, as well as, favoring RepeatWhile over RepeatUntil but those are other topics. No sense in clouding the issue with that here.
Please let me know of any flaws in my thinking, thanks.
BTW, To whom it may concern ... there is a mistake in the Script manual concerning the RepeatWhile statement definition. The example shows a RepeatUntil statement instead of RepeatWhile. Also both commands show EndRepeat in both instead of EndRepeatUntil and EndRepeatWhile. EndRepeat may be valid for either, but the definition says to use EndRepeatUntil or EndRepeatWhile. Consistency may be the hobgoblin of little minds, but in programming it's a virtue.
(yeah I know, the quote is Foolish Consistency, just go with me here)
On my phone so going to be brief and only touch on one thing. The sleep is not for waiting for the servo but to help reduce the demand on resources.
Also, the servo position is not read from the servo but from the software. Repeating until a variable or command which reads the servo position meets the specified position is redundant since, as far as ARC (and any other software) is concerned, it's already at that position the instance you send the Servo() command.