New Service For Robot

Hello GroG,
 
All good ?
 
It's done, Eclipse is well installed, and all is ok, i can compile MRL without problem.
can you explain me the next step to create my own service please.
 
And i've also an other question . I'm trying to make to activate the leds of my robot mouth move while it's speaking.
I thinked, the method " isSpeaking" of the service "speak" will give me a bolean . but i see in the javadoc that.
It need a bolean . Can you explain how it work ?
 
I've tried someting like " while mouth.isSpeaking() -> talk() " Where "talk()" is the fonction that make the leds sequence "
But of course " Python ERROR ; isSpeaking need 1 arg, give 0 "
 
Ah ! and a last question : I begin to have some test files in phyton for my sweety, can i put them in the git repository for
python exemples ( Pyrobotlab ) And if yes, how to do that .
 
That all, thx for your help
Have a nice day
beetlejuice

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
GroG's picture

Hello Beetlejuice ! Yes I'm

Hello Beetlejuice !

Yes I'm very well thank you.

The next step is just copy & paste the _TemplateService.java service.  Rename it to something you want.

So now this service would control all the other services you want.
And that would depend on what hardware you have.

If I remember correctly - you have 2 Arduinos ?
6 UltrasonicSensors
OpenCV for the webcam .. etc..

You would add these as members of your new class..

For the mouth & speech - you might want to check out MouthControl - this sends out servo motor commands depending on speech.  

isSpeaking and saying are both "publishing" methods - they are called by the service , not your program - they represent changing events of the Speech service.

you would "map or bind" with them from your service to do what you wanted.

For example :

You see this line in MouthControl ?
mouth.addListener(getName(), "saying");

it's it binds the mouth's "saying" with its own - so that every time mouth has a "saying event" - the method in MouthControl named 'saying" gets called

Inside MouthControl you see it's "saying" method - which breaks apart the words and moves the servo - its starts like this ..
 

public synchronized void saying(String text) {
log.info("move moving to :" + text);
 
 
Hope this helps !
beetlejuice's picture

Thank you, i'll try all that

Thank you, i'll try all that !

beetlejuice's picture

Hello !   I need help, I'm

Hello !

 

I need help, I'm trying to understand how to do the "Sweety's service", I run  MRL from eclipse, ans run python (installed from right clic and 'install' in the runtime tab.

But how to install sweety's service ? if i try to run it with 

sweety = runtime.createAndStart("sweety", "Sweety")

I get this ERROR :

51708 [python] INFO  class org.myrobotlab.service.Python  - exec sweety = runtime.createAndStart("sweety", "Sweety")
51740 [Thread-6] INFO  class org.myrobotlab.service.Runtime  - Runtime.createService sweety
51756 [Thread-6] ERROR class org.myrobotlab.service.Runtime  - error unknown service org.myrobotlab.service.Sweety 
51756 [Thread-6] ERROR class org.myrobotlab.service.Runtime  - org.myrobotlab.service.Sweety is not installed - please install it
 
GroG's picture

its not defined in the an xml

its not defined in the an xml file called serviceData.xml - that's why its complaining about not being installed..

My bet is that it is being created and started .. just not displayed as a tab.

You could confirm this by having some logging in the constructor or serviceStart() which say something like 

log.info("IT WORKY !!!") 

and searching for it in the logs.. or set a breakpoint :)

beetlejuice's picture

The "sweety" tab is well

The "sweety" tab is well displayed, nothing run ( arduino , opencv ) i need to understand By reading the sources of other services .

To try i've just added runtime.start("arduino", "Arduino") under runtime.start("GUI", "GUIService")

But it's not only my service that need to be installed, a lot of them like Arduino or python need to be installed.

Easy for them, just right clic and install ...

 

And another question ; Why ultrasonicSensors's service is in the runtime time of this version from source and not in the buids version like 1.0.84 ? Of course, it work if start from python, but there is no icon in the runtime tab .

have a nice day !

GroG's picture

in the future you should use

in the future you should use :

Runtime.start("arduino","Arduino")

The difference is this is calling a static method, runtime with a small "r" is a convienence handle which Python provides.  Even in python you can (and should) call Runtime.start("sweety","Sweety") with a capital "R"

Yes .. use the source Luke

UltrasonicSensor uses the source's version - because you are running from sources .. the build process makes binaries with the build version - different stuff.

There's no Icon because the serviceData.xml does not have your service in it.

Rock On !

beetlejuice's picture

Runtime.start("arduino","Ardu

Runtime.start("arduino","Arduino")

I did it, i made this mistake just when i writed this line in the previus post . When i run from source is normal that i must install almost all the service ? just few of them are already installed .

Here is Sweety.java :

package org.myrobotlab.service;

import org.myrobotlab.framework.Service;
import org.myrobotlab.logging.Level;
import org.myrobotlab.logging.LoggerFactory;
import org.myrobotlab.logging.Logging;
import org.myrobotlab.logging.LoggingFactory;
import org.slf4j.Logger;

public class Sweety extends Service {

	private static final long serialVersionUID = 1L;

	public final static Logger log = LoggerFactory.getLogger(Sweety.class);

	public Sweety(String n) {
		super(n);
	}

	@Override
	public String getDescription() {
		return "Service for the robot Sweety";
	}

 static void main(String[] args) {
		LoggingFactory.getInstance().configure();
		LoggingFactory.getInstance().setLevel(Level.INFO);

		try {

			Sweety sweety = (Sweety)Runtime.start("sweety", "Sweety");
			sweety.test();
			
			/*Runtime.start("gui", "GUIService");;*/
						
			Arduino arduino = (Arduino)Runtime.start("arduino", "Arduino");

		} catch (Exception e) {
			Logging.logException(e);
		}
	}

}
beetlejuice's picture

Previous post updated with

Previous post updated with the last java code tested ans still doesn't want to work 

beetlejuice's picture

Here is the python script

Here is the python script that i would to put in a service ( for now ) :

 

# this is the script for sweety

# libraries
from java.lang import String
from org.myrobotlab.service import Speech
from org.myrobotlab.service import Sphinx
from org.myrobotlab.service import Runtime
from time import sleep
from org.myrobotlab.service import Arduino
from org.myrobotlab.service import Servo

#################
# Hardware setup
#################

# Arduino's pins
rightMotorBackwardPin = 2
rightMotorForwardPin = 3
leftMotorForwardPin = 4
leftMotorBackwardPin = 5

backUltrasonicTrig = 22
backUltrasonicEcho = 23
back_leftUltrasonicTrig = 24
back_leftUltrasonicEcho = 25
back_rightUltrasonicTrig = 26
back_rightUltrasonicEcho = 27
front_leftUltrasonicTrig = 28
front_leftUltrasonicEcho = 29
frontUltrasonicTrig = 30
frontUltrasonicEcho = 31
front_rightUltrasonicTrig = 32
front_rightUltrasonicEcho = 33

SHIFT = 47
LATCH = 48
DATA = 49

# Arduino setup and start
comPort = "COM8"
arduino = Runtime.createAndStart("arduino","Arduino")
arduino.setBoard("atmega2560") # atmega168 | mega2560 | etc

# create ear and mouth
ear = Runtime.createAndStart("ear","Sphinx")
mouth = Runtime.createAndStart("mouth","Speech")
mouth.setLanguage("fr") # choose the langage
mouth.setBackendType("GOOGLE") # can be replaced by "FREETTS"
mouth.setGenderFemale() # setGenderMale or setGenderFemale


 
# Connect the arduino
arduino.connect(comPort,57600,8,1,0)
sleep(2) # give it two second for the serial device to get ready

# set pinMode
arduino.pinMode(SHIFT, Arduino.OUTPUT)
arduino.pinMode(LATCH, Arduino.OUTPUT)
arduino.pinMode(DATA, Arduino.OUTPUT)

# Creating and starting servos services

leftForearm = runtime.createAndStart("leftForearm","Servo")
rightForearm = runtime.createAndStart("rightForearm","Servo")
rightShoulder = runtime.createAndStart("rightShoulder","Servo")
leftShoulder = runtime.createAndStart("leftShoulder","Servo")
rightArm = runtime.createAndStart("rightArm","Servo")
neck = runtime.createAndStart("neck","Servo")
leftEye = runtime.createAndStart("leftEye","Servo")
leftArm = runtime.createAndStart("leftArm","Servo")
rightEye = runtime.createAndStart("rightEye","Servo")
rightHand = runtime.createAndStart("rightHand","Servo")
rightWrist = runtime.createAndStart("rightWrist","Servo")
leftHand = runtime.createAndStart("leftHand","Servo")
leftWrist = runtime.createAndStart("lefttWrist","Servo")

# attach servos
rightForearm.attach(arduino.getName(),34)
leftForearm.attach(arduino.getName(),35)
rightShoulder.attach(arduino.getName(),36)
leftShoulder.attach(arduino.getName(),37)
rightArm.attach(arduino.getName(),38)
leftArm.attach(arduino.getName(),41)
neck.attach(arduino.getName(),39)
leftEye.attach(arduino.getName(),40)
rightEye.attach(arduino.getName(),42)
rightHand.attach(arduino.getName(),46)
rightWrist.attach(arduino.getName(),44)
leftHand.attach(arduino.getName(),43)
leftWrist.attach(arduino.getName(),45)

# Servos min and max
leftForearm.setMinMax(85,140)
rightForearm.setMinMax(5,67)
rightShoulder.setMinMax(0,155)
leftShoulder.setMinMax(0,145)
rightArm.setMinMax(25,130)
neck.setMinMax(55,105)
leftEye.setMinMax(25,125)
leftArm.setMinMax(45,117)
rightEye.setMinMax(80,180)
rightHand.setMinMax(10,75)
rightWrist.setMinMax(0,180)
leftHand.setMinMax(80,150)
leftWrist.setMinMax(0,180)

# Servos start position
def startPosition() :
	leftForearm.moveTo(136)
	rightForearm.moveTo(5)
	rightShoulder.moveTo(4)
	leftShoulder.moveTo(145)
	rightArm.moveTo(30)
	leftArm.moveTo(108)
	neck.moveTo(75)
	leftEye.moveTo(75)
	rightEye.moveTo(127)
	rightHand.moveTo(10)
	rightWrist.moveTo(116)
	leftHand.moveTo(150)
	leftWrist.moveTo(85)

# update the gui with configuration changes
arduino.publishState()
leftForearm.publishState()
rightForearm.publishState()
rightShoulder.publishState()
leftShoulder.publishState()
rightArm.publishState()
neck.publishState()
leftEye.publishState()
leftArm.publishState()
rightEye.publishState()
rightHand.publishState()
rightWrist.publishState()
leftHand.publishState()
leftWrist.publishState()

# Create shiftOut fonction
def shiftOut(value):
	arduino.digitalWrite(LATCH, arduino.LOW)		# Stop the copy
	for byte in value:
		if byte == 1 :
			arduino.digitalWrite(DATA,arduino.HIGH)  
		else :
			arduino.digitalWrite(DATA,arduino.LOW)
		arduino.digitalWrite(SHIFT, arduino.HIGH) 
		arduino.digitalWrite(SHIFT, arduino.LOW)
	arduino.digitalWrite(LATCH, arduino.HIGH)	# copy 

# Mouth LEDs fonctions

def smile():
	shiftOut([1,1,0,1,1,1,0,0]) #	send data
def notHappy():	
	shiftOut([0,0,1,1,1,1,1,0]) #	send data
def speechLess():
	shiftOut([1,0,1,1,1,1,0,0]) # send data
def talk():
	shiftOut([0,0,0,0,0,0,0,0]) #	send data
	sleep(0.05)
	shiftOut([0,0,0,0,0,1,0,0]) #	send data
	sleep(0.05)
	shiftOut([0,0,0,1,1,1,0,0]) #	send data
	sleep(0.05)
	shiftOut([0,0,0,0,0,1,0,0]) #	send data
	sleep(0.05)



#################
# listen and talk
#################

# start listening for the words we are interested in
ear.startListening("bonjour | statut | depart")
 
# set up a message route from the ear --to--> python method "heard"
ear.addListener("recognized", python.name, "heard", String().getClass());
 
# this method is invoked when something is 
# recognized by the ear and print the word recognized

def heard():
      data = msg_ear_recognized.data[0]
      print "heard ", data
      if (data == "bonjour"):
		print data
		hello()
      elif (data == "depart"):
      	print  data
      	startPosition()
    # ... etc
 


def hello():
         	mouth.speak("bonjour")
		rightShoulder.moveTo(155)
		sleep(0.8)
		rightArm.moveTo(45)
		i = 0
		for i in range(1,5):
			rightForearm.moveTo(30)
			sleep(0.2)
			rightForearm.moveTo(5)
			sleep(0.2)
			i+=1
		sleep(0.5)
		rightArm.moveTo(30)	
		rightShoulder.moveTo(4)


# prevent infinite loop - this will suppress the
# recognition when speaking - default behavior
# when attaching an ear to a mouth :)
#ear.attach("mouth")


# starting
startPosition()
hello()
"""if (mouth.isSpeaking()):
	talk()"""
smile()
beetlejuice's picture

Hi, i need again your help

Hi, i need again your help ...

I've an error  [Thread-7] ERROR class org.myrobotlab.logging.Logging  - ------ two time in the python's log when i run the sweety service .

can you help me ? i've just added the function myShiftout, and a line for add a servo that was missing, but the error was already here before i commit these change .

I send you a noworky and i update the sweety.java file on github.

Thx