script as a template

Guys just posted my main script for DeathInvoke to follow, ofcourse can be hellpfull for other people, the easiest way is to start top to bottom adding stuff and see if everything works

 

from java.lang import String
import threading
import random
import codecs
import io
import itertools
import time
import os
import urllib2
import textwrap
import socket
import shutil
import json
from datetime import datetime

##############################################################
## This is the Zorba script                                 ##
## this script is to run on MRL 1700+                       ##
##############################################################

# All bot specific configuration goes here.
leftPort = "/dev/ttyACM1"
rightPort = "/dev/ttyACM0"
headPort = leftPort

## these are the configurations for the chatbot and gestures
gesturesPath = "/home/pedro/Dropbox/pastaPessoal/3Dprinter/inmoov/scripts/zorba/gestures"
aimlBotName = "zorba"
aimlUserName = "Pedro"
botVoice = "WillBadGuy"

## toggle to only load program ab  and skip the inmoov services
startInMoov = True
randomGesture = True

if randomGesture:
    randomEyeLid = True
    randomHip = True

#######################################################################
## helper function help debug the recognized text from webkit/sphinx
#######################################################################
def heard(data):
  print "Speech Recognition Data:"+str(data)
 
 
######################################################################
#                                                                    #
# MAIN ENTRY POINT  - Start and wire together all the services.      #
#                                                                    #
######################################################################  
# Start the webgui service without starting the browser
webgui = Runtime.create("WebGui","WebGui")
webgui.autoStartBrowser(False)
webgui.startService()
# Then start the browsers and show the WebkitSpeechRecognition service named i01.ear
webgui.startBrowser("http://localhost:8888/#/service/i01.ear")  
 
#######################################################################
## Create ProgramAB chat bot ( This is the inmoov "brain" )
#######################################################################
zorba = Runtime.createAndStart("zorba", "ProgramAB")
zorba.startSession(aimlUserName, aimlBotName)

#######################################################################
## Html filter to clean the output from programab.  (just in case)
#######################################################################
htmlfilter = Runtime.createAndStart("htmlfilter", "HtmlFilter")
 
 
#######################################################################
## mouth service, speech synthesis
#######################################################################
mouth = Runtime.createAndStart("i01.mouth", "AcapelaSpeech")
mouth.setVoice(botVoice)

#######################################################################
## the "ear" of the inmoov
#######################################################################
ear = Runtime.createAndStart("i01.ear", "WebkitSpeechRecognition")
ear.addListener("publishText", python.name, "heard");
ear.addMouth(mouth)

#######################################################################
## MRL Routing webkitspeechrecognition/ear -> program ab -> htmlfilter -> mouth
#######################################################################
ear.addTextListener(zorba)
zorba.addTextListener(htmlfilter)
htmlfilter.addTextListener(mouth)

###starting the INMOOV
i01 = Runtime.create("i01", "InMoov")

###############right hand####################
rightHand = Runtime.create("i01.rightHand","InMoovHand")
#tweeking default settings for right hand
rightHand.thumb.setMinMax(0,180)
rightHand.index.setMinMax(0,180)
rightHand.majeure.setMinMax(0,180)
rightHand.ringFinger.setMinMax(0,180)
rightHand.pinky.setMinMax(0,180)
rightHand.wrist.setMinMax(0,180)

rightHand.thumb.map(0,180,20,155)
rightHand.index.map(0,180,30,130)
rightHand.majeure.map(0,180,38,150)
rightHand.ringFinger.map(0,180,30,175)
rightHand.pinky.map(0,180,30,150)
rightHand.wrist.map(0,180,40,135)

rightHand.thumb.setVelocity(0)
rightHand.index.setVelocity(0)
rightHand.majeure.setVelocity(0)
rightHand.ringFinger.setVelocity(0)
rightHand.pinky.setVelocity(0)
rightHand.wrist.setVelocity(0)

####################RIGHT ARM###############
###i01.startRightArm(rightPort)
rightArm = Runtime.create("i01.rightArm", "InMoovArm")
##### tweak default RightArm
rightArm.bicep.setMinMax(0,60)
rightArm.rotate.setMinMax(46,130)
rightArm.shoulder.setMinMax(0,155)
rightArm.omoplate.setMinMax(8,85)

rightArm.bicep.map(0,180,0,60)
rightArm.rotate.map(0,180,46,130)
rightArm.shoulder.map(0,180,0,155)
rightArm.omoplate.map(0,180,8,85)

rightArm.bicep.setVelocity(0)
rightArm.rotate.setVelocity(0)
rightArm.shoulder.setVelocity(0)
rightArm.omoplate.setVelocity(0)

i01 = Runtime.start("i01","InMoov")
i01.setMute(False)

right = Runtime.start("i01.right", "Arduino")
right.connect("/dev/ttyACM0")
###########STARTING SIDE NECK CONTROL########

#rollneck = Runtime.start("rollneck","Servo")

#rollneck.attach(right,12)
#rollneck.setRest(61)
#rollneck.moveTo(61)
#rollneck.detach()

###########STARTING EYELID########

eyelid = Runtime.start("eyelid","Servo")

eyelid.attach(right,13)
eyelid.setMinMax(53,85)
eyelid.map(0,180,53,85)
eyelid.setRest(85)
eyelid.moveTo(180)
eyelid.detach()

################STARTING THE HEAD##############
head = Runtime.create("i01.head", "InMoovHead")
####weaking defaults settings of head
head.jaw.setMinMax(35,75)
head.jaw.map(0,180,35,75)
head.jaw.setRest(35)
head.jaw.setVelocity(0)
####tweaking default settings of eyes
head.eyeY.setMinMax(68,144)
head.eyeY.map(0,180,68,144)
head.eyeY.setRest(58)
head.eyeY.setVelocity(0)
head.eyeX.setMinMax(48,131)
head.eyeX.map(0,180,48,131)
head.eyeX.setRest(90)
head.eyeX.setVelocity(0)
####tweaking default settings of neck
head.neck.setMinMax(40,142)
head.neck.map(0,180,40,142)
head.neck.setRest(70)
head.neck.setVelocity(0)
head.rothead.setMinMax(21,151)
head.rothead.map(0,180,21,151)
head.rothead.setRest(88)
head.rothead.setVelocity(0)

################STARTING THE STOMACH##############
torso = Runtime.create("i01.torso", "InMoovTorso")
# tweaking default torso settings
torso.topStom.setMinMax(80,97)
torso.topStom.map(0,180,80,97)
torso.topStom.setRest(90)
torso.topStom.setVelocity(0)
#torso.midStom.setMaxVelocity(13)
#torso.midStom.setMinMax(0,180)
#torso.midStom.map(0,180,50,130)
#torso.lowStom.setMaxVelocity(13)
#torso.lowStom.setMinMax(0,180)
#torso.lowStom.map(0,180,60,120)

#torso.midStom.setRest(90)
#torso.lowStom.setRest(90)
##################
#######################################################################
## setting OpenCv service
##################################################################
#opencv=Runtime.start("opencv","OpenCV")
#i01.opencv.setCameraIndex(1)

if startInMoov:
   ##i01.startAll(leftPort, rightPort)
   ##i01.startMouth()
   i01.startMouthControl(leftPort)
   i01.mouthControl.setmouth(0,180)
   
 
 
##################
   ##i01.startEar()
   i01.startRightArm(rightPort)
   i01.rightArm.detach()
   i01.startRightHand(rightPort)
   i01.rightHand.detach()
   i01.startHead(leftPort)
   ##i01.startLeftArm(leftPort)
   ##i01.startLeftHand(leftPort)
   i01.startTorso(leftPort)
   i01.torso.detach()
   #################
   i01.opencv.setCameraIndex(1)
   ###################
   i01.startEyesTracking(leftPort,22,24)
   i01.startHeadTracking(leftPort)
   ############################################################
   #to tweak the default PID values
   i01.eyesTracking.pid.setPID("eyeX",12.0,1.0,0.1)
   i01.eyesTracking.pid.setPID("eyeY",12.0,1.0,0.1)
   i01.headTracking.pid.setPID("rothead",5.0,1.0,0.1)
   i01.headTracking.pid.setPID("neck",5.0,1.0,0.1)
   i01.head.detach()
##################
   ##i01.startPIR("COM20",30)
   
else:
   i01.mouth = mouth
   

#####################

######################################################################
# Helper functions and various gesture definitions
######################################################################
i01.loadGestures(gesturesPath)
ear.startListening()

#########################################################################
#### Launch the web gui and create the webkit speech recognition gui
#### This service works in Google Chrome only with the WebGui
####################################################################
###webgui = Runtime.createAndStart("webgui","WebGui")

#### starting services
#########################################################################
###leftneckServo.detach()
###rightneckServo.detach()
###i01.startHead(leftPort)
###i01.detach()