Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked
Resolved Resolved by DJ Sures!

Centering On Vertical Servos

I'm working on Blockly. Every time I finish running the program, I have to go back to the workspace and center the vertical servos. I want to run my program without having to go back and manually center it. 
The idea is after "else" the vertical servos would reset to 50( I have min and max at 1,100.) However, the Vertical Servos remains at 90. After that point the code doesn't work any more until I center it again. I'm not sure what 90 means. (Is it degrees?)
Here is the code( this is my trial and error work. the d3, 90, 1 was me exploring the multi servos) :

if (Audio.waitForSpeech(2, "Hello")) {

Servo.SetPosition(d3, 90, 0);


} else if (Audio.waitForSpeech(2, "Goodbye")) {

Servo.SetSpeed(d3, 0, 0);


} else {

Servo.SetPosition(d3, 90, 1);

}


Related Hardware EZ-Robot EZ-B IoTiny
PRO
Synthiam
#1   — Edited
Servo positions are somewhat arbitrary - for PWM hobby style servos using the default servo resolution of ARC, the number is "kind of" degrees. It's because not all servos are calibrated the same. Learn how a servo works here: https://synthiam.com/Support/Advanced-Fundamentals/servo-motor

As for your question, the answer is easier by moving the servos into the position before prompting for the wait for speech command. However, the code you have posted won't work. There is too much wrong with your code example to correct so I will demonstrate a completed example for you :). If you're using Blockly then do something like this...

User-inserted image


Follow along with each block in order to see what the code is doing. That's what is great about Blockly when learning to program:D

It will generate this javascript code

Code:

Servo.SetPosition(d0, 90, 0);

Audio.sayWait("What would you like me to do?");

response = (Audio.waitForSpeech(10, "Rotate Left", "Rotate Right"));

if (response == "rotate left") {

Audio.say("Rotating left");

Servo.SetPosition(d0, 180, 0);


} else if (response == "rotate right") {

Audio.say("Rotating Right");

Servo.SetPosition(d0, 1, 0);


} else {

Audio.say("I did not hear you");


}
#2  
Interesting. In EZ Script I'd have to end that with an EndIf. Not needed in Javascript?
PRO
Synthiam
#3  
JavaScript uses { and } to open and close chunks of code for if and repeats and stuff. 

JavaScript is soooo much easier and faster:)
#4  
Thanks DJ. I'm starting to study JavaScript now. I'll be getting into it deeper over the next few weeks.
#5  
Thanks DJ Sures, your comment was super helpful.:)