Execute Parallel Functions

In this example, when calling rockOn(), the servos move to the stated positions and then, inmoov says "Rock on".
How do I have inmoov say "rock on" while the servos are moving to position? IS there a way to execute Parallel?
def rockOn():       
       talk ("rock on")
GroG's picture

Hello tdp378 and

Hello tdp378 and Welcome,

talk("rock on") must be part of your script - and within this method which is not shown, I'm guessing their is something like..

what you could possibly do is :

def rockOn():       
       mouth.speak("rock on");
       sleep(0.5) # a delay 'might' be necessary depending on the latency of the audio playing a cached file
tdp378's picture

The thing I am trying to

The thing I am trying to figure out is having the voice speak while movements are taking place. Currently, it says rock on before the servo moves. I want it to say rock on during the servo moves. If that makes sense. It executes in steps I guess.

Step 1. Say rock on
Step 2. Move servos

I am trying to get it to combine step 1 and 2 to execute simultaneously. This is not a good example because the speaking text is very short. What if I wanted inmoov to speak a paragraph. Basically I would not be able to have him move while he is talking correct?

GroG's picture

Incorrect ,  my sample should

Incorrect , 

my sample should be valid.

MyRobotLab - is massively multi-threaded.

It's just usually people want to block the execution thread until speaking is done.

InMoov primarily uses speakBlocking("some text - like Let's Rock") - this stops execution until the speech is finished.

But the Speech synthesis  regular 'speak' command will not block - meaning you can do anything else you want with that same thread - like move servos, motors etc .. 'simultaneously'

tdp378's picture

I see the error of my ways!

I see the error of my ways! Thank you!

The mouth control service does not seem to work recently that's why I just put the talk method in my script. Now I see that that method has to complete before the movement is made. Is there any reason why the mouth control service would be erring out?

GroG's picture

We Can Help !!! Send a No

We Can Help !!!

Send a No Worky !!

tdp378's picture

Sent no worky

I started the keyboard service and assigned keys to a couple of methods. The methods work and the speeh says the words but the mouth does not move

below is my entire script

from time import sleep
import threading
from org.myrobotlab.service import Arduino
from org.myrobotlab.service import Runtime
from org.myrobotlab.service import Servo
leftPort = "COM15"
# create the services
keyboard = Runtime.start("keyboard", "Keyboard")
i01 = Runtime.createAndStart("i01", "InMoov")
#webgui = Runtime.start("webgui","WebGui")
# set voice
#voices = acapelaSpeech.getVoices()
#for voice in voices:
 #   acapelaSpeech.setVoice("Will")
sleep(1) # give it a second for the serial device to get ready
# tweaking default settings of Neck
# tweaking default settings Mouth
# tweaking default settings of left hand
ear = i01.ear
ear.addCommand("open hand","python","openLeftHand")
ear.addListener("recognized", "python", "heard")
def heard(phrase):
      #talk ("you said " + phrase)
      print "heard ", phrase
#Keyboard Commands
def onKey(key):
    if(key == 'O'): # Open Hand
        i01.mouth.speak ("hand open")
    elif(key == 'C'): # close hand
      i01.mouth.speak ("hand closed")
# Reusable Movements
def openLeftHand():
def closeLeftHand():
GroG's picture

Hi Tdp, I looked at your sent

Hi Tdp,

I looked at your sent  noWorky - I don't see your Arduinos responding - check for zombies 

-  http://myrobotlab.org/content/helpful-myrobotlab-tips-and-tricks-0#zombie

If no zombies, then did you go through a more simple tutorial yet - of how you need to load MRLComm.ino through the Arduino IDE ?


tdp378's picture

Ok, I think i have the

Ok, I think i have the communication problem fixed. I send another no worky However, the jaw still will not move while speaking. Everything else appears to be working properly. The hand moves correctly and the voice speaks the correct phrase. I can move all sliders and the servos respond in tune. 

I am at a loss. Am I missing something in my code for the mouth control service? If I put the below method in my script and invoke talk("yada yada yada")  the mouth moves correctly but not with the mouthControl service.

def talk (sent): 
  ison = False
  a = sent.split()
  for word in a:
    if word[len(word)-2:] == "es" : # removing es at the end of the word
      testword = word[:-2] +'xx' # adding x's to help keep the timing
    elif word[len(word)-1:] == "e" : # removing the silant e at the end of the word
      testword = word[:-1] +'x'
      testword = word
    for x in range(0, len(testword)):
      if testword[x] in ('a', 'e', 'i', 'o', 'u', 'y' ) and ison == False :
        #arduino.digitalWrite(13, Arduino.HIGH)
        mouth.moveTo(80) # move the servo to the open spot
        ison = True
        mouth.moveTo(15) # close the servo 
      elif testword[x] in ('.') :
        #arduino.digitalWrite(13, Arduino.LOW)
        ison = False
      else: #sleep(0.5)  sleep half a second
        #arduino.digitalWrite(13, Arduino.LOW)
        ison = False
        sleep(0.06) # sleep half a second
    #arduino.digitalWrite(13, Arduino.LOW)
# end of talk function