This script is a work in progress:

# 4PID + PIR Sensor script

#for inmoov2.0 service

headPort = "COM7"
#leftPort = "COM7"
#rightPort= "COM8"

#select the pin where to start polling ( we can connect a PIR to this pin to see his state HIGH/LOW)
readDigitalPin = 28

i01 = Runtime.createAndStart("i01", "InMoov")
#leftArm = i01.startLeftArm(leftPort)
#leftHand = i01.startLeftHand(leftPort)
#rightArm = i01.startRightArm(rightPort)
#rightHand = i01.startRightHand(rightPort)
 
head = i01.startHead(headPort)
neck = i01.getHeadTracking()
neck.faceDetect()

############################################################
#if needed we can tweak the default settings with these lines
i01.head.eyeY.setMinMax(80,100)
i01.head.eyeY.setRest(78)
i01.head.eyeX.setMinMax(75,100)
i01.head.eyeX.setRest(78)
i01.head.neck.setRest(80)
i01.head.jaw.setMinMax(9,25)
i01.head.mouthControl.setmouth(9,25)
############################################################
 
i01.head.headTracking.xpid.setPID(10.0,5.0,0.1)
i01.head.headTracking.ypid.setPID(15.0,5.0,0.1)
i01.head.eyesTracking.xpid.setPID(15.0,5.0,0.1)
i01.head.eyesTracking.ypid.setPID(20.0,5.0,0.1)
 
eyes = i01.getEyesTracking()
eyes.faceDetect()

sleep(3)

i01.getHead().getArduino().setSampleRate(8000)
i01.getHead().getArduino().digitalDebounceOn(10000)
#start polling data from the digital pin
i01.getHead().getArduino().digitalReadPollingStart(readDigitalPin)
#add python as listener of the arduino service, each time arduino publish the value of the pin
i01.getHead().getArduino().addListener("publishPin", "python", "publishPin")
 
#define a function which is called every time arduino publish the value of the pin
def publishPin():
  pin = msg_i01_getHead_getArduino_publishPin.data[0]
  print pin.pin, pin.value,pin.type,pin.source
  #if an HIGH state is read, PIR is detecting something so start face tracking
  if (pin.value == 1):
   if i01.getHead().getHeadTracking().isIdle():
    i01.getHead().getHeadTracking().faceDetect()
    i01.getHead().getEyesTracking().faceDetect()
    #i01.getHead().getArduino().digitalDebounceOn(10000)
  #if a LOW state is read , stop tracking.. there is no human there !
  elif (pin.value == 0):
   if not i01.getHead().getHeadTracking().isIdle():
    i01.getHead().getHeadTracking().stopTracking()
    i01.getHead().getEyesTracking().stopTracking()
    
#i01.head.mouthControl.mouth.setGoogleURI("http://tts-api.com/tts.mp3?q=")
i01.head.mouthControl.mouth.setGoogleURI("http://tts-api.com/tts.mp3?q=")
ear = runtime.createAndStart("ear","Sphinx")
 
ear.attach(i01.head.mouthControl.mouth)
ear.addCommand("attach head", "i01.head", "attach")
ear.addCommand("disconnect head", "i01.head", "detach")
ear.addCommand("search humans", "i01.head.headTracking", "findFace")
ear.addCommand("stop searching", "i01.head.headTracking", "stopScan")
ear.addCommand("rest", "i01.head", "rest")
 
ear.addCommand("manual", ear.getName(), "lockOutAllGrammarExcept", "voice control")
ear.addCommand("voice control", ear.getName(), "clearLock")
 
ear.addComfirmations("yes", "correct", "yeah", "ya")
ear.addNegations("no", "wrong", "nope", "nah")
 
# all commands MUST be before startListening
ear.startListening()
 

bhouston

10 years 9 months ago

What PIR sensor are you using? I haven't got InMoov 2.0 working yet, will this work with1695?

hairygael

10 years 9 months ago

In reply to by bhouston

Hi Bob,

I use this PIR sensor , it is Borsaci that recomended that one. But for now I haven't been able to use correctly, although I did get some results.

Hopefully with the corrected script by Grog it will work.

GroG

10 years 9 months ago

# 4PID + PIR Sensor script
 
#for inmoov2.0 service
 
headPort = "COM15"
#leftPort = "COM7"
#rightPort= "COM8"
 
#select the pin where to start polling ( we can connect a PIR to this pin to see his state HIGH/LOW)
readDigitalPin = 28
 
i01 = Runtime.createAndStart("i01", "InMoov")
#leftArm = i01.startLeftArm(leftPort)
#leftHand = i01.startLeftHand(leftPort)
#rightArm = i01.startRightArm(rightPort)
#rightHand = i01.startRightHand(rightPort)
 
head = i01.startHead(headPort)
neck = i01.startHeadTracking(headPort)
eyes = i01.startEyesTracking(headPort)
mouth = i01.startMouth()
mouthControl = i01.startMouthControl(headPort)
 
############################################################
#if needed we can tweak the default settings with these lines
i01.head.eyeY.setMinMax(80,100)
i01.head.eyeY.setRest(78)
i01.head.eyeX.setMinMax(75,100)
i01.head.eyeX.setRest(78)
i01.head.neck.setRest(80)
i01.head.jaw.setMinMax(9,25)
i01.mouthControl.setmouth(9,25)
############################################################
 
i01.headTracking.xpid.setPID(10.0,5.0,0.1)
i01.headTracking.ypid.setPID(15.0,5.0,0.1)
i01.eyesTracking.xpid.setPID(15.0,5.0,0.1)
i01.eyesTracking.ypid.setPID(20.0,5.0,0.1)
 
neck.faceDetect()
eyes.faceDetect()
 
sleep(3)
 
headArduino = i01.head.arduino
 
headArduino.setSampleRate(8000)
headArduino.digitalDebounceOn(10000)
#start polling data from the digital pin
headArduino.digitalReadPollingStart(readDigitalPin)
#add python as listener of the arduino service, each time arduino publish the value of the pin
headArduino.addListener("publishPin", "python", "publishPin")
 
#define a function which is called every time arduino publish the value of the pin
def publishPin():
  pin = msg_i01_getHead_getArduino_publishPin.data[0]
  print pin.pin, pin.value,pin.type,pin.source
  #if an HIGH state is read, PIR is detecting something so start face tracking
  if (pin.value == 1):
   if i01.headTracking.isIdle():
    i01.headTracking.faceDetect()
    i01.headTracking.faceDetect()
    #i01.getHead().getArduino().digitalDebounceOn(10000)
  #if a LOW state is read , stop tracking.. there is no human there !
  elif (pin.value == 0):
   if not i01.headTracking.isIdle():
    i01.headTracking.stopTracking()
    i01.headTracking.stopTracking()
    
#i01.head.mouthControl.mouth.setGoogleURI("http://tts-api.com/tts.mp3?q=")
i01.mouth.setGoogleURI("http://tts-api.com/tts.mp3?q=")
#ear = runtime.createAndStart("ear","Sphinx")
ear = i01.startEar()
 
ear.attach(i01.mouthControl.mouth)
ear.addCommand("attach head", "i01.head", "attach")
ear.addCommand("disconnect head", "i01.head", "detach")
ear.addCommand("search humans", "i01.head.headTracking", "findFace")
ear.addCommand("stop searching", "i01.head.headTracking", "stopScan")
ear.addCommand("rest", "i01.head", "rest")
 
ear.addCommand("manual", ear.getName(), "lockOutAllGrammarExcept", "voice control")
ear.addCommand("voice control", ear.getName(), "clearLock")
 
ear.addComfirmations("yes", "correct", "yeah", "ya")
ear.addNegations("no", "wrong", "nope", "nah")
 
# all commands MUST be before startListening
ear.startListening()
 

GroG

10 years 9 months ago

Here's a short script - where you can see what's happening - 

headPort = "COM15"
readDigitalPin = 28
i01 = Runtime.createAndStart("i01", "InMoov")
head = i01.startHead(headPort)
headArduino = i01.head.arduino
headArduino.setSampleRate(8000)
headArduino.digitalDebounceOn(10000)
#start polling data from the digital pin
headArduino.digitalReadPollingStart(readDigitalPin)
#add python as listener of the arduino service, each time arduino publish the value of the pin
headArduino.addListener("publishPin", "python", "publishPin")
 
def publishPin():
  #pin = msg_i01_getHead_getArduino_publishPin.data[0]
  pin = msg_i01_left_publishPin.data[0]
  print pin.pin, pin.value,pin.type,pin.source
 
 
This starts the head - gets the head's arduino and sets up polling on pin 28.
 
On the python tab - you should see the value of pin 28 and other information come in -
The numbers in order mean - the pin number = 28, its value = 1, its type = 1 (which is digital) & its source is i0.left = name of the Arduino it came from.
 
On the oscope you'll see a very slowly moving trace
 
Since I don't have a PIR I won't get any variation - unless I stick a wire into pin 28.  

The recent version of MRLComm.ino has the capability of sending a value to the debounce delay. Debouncing is ignoring signal change until a certain time after the initial trigger.  In the example the debouce delay was set to 10,000 ms or 10 seconds.  The sample rate is the fractional rate at which the pin is read. Currently the lower the value, the higher the rate :P