MRL Java -- Call Backs To --> Python !

In Python we get to call Java Service methods directly (Yay!) ...

But the going the other way, when a Java service wan'ts to call a Python method - the method was always a bit convoluted.

First there was only the "input()" method..
and all Java could only call this one method on a Python script :(

def input():

Then this was enhanced so that at least the method name could be something besides "input", but the parameters were a challenge to get with convoluted array structure.  E.g.

def heard():
    data = msg_i01_ear_recognized.data[0]
 

BUT NOW !...  boys and girls, ladies & gentlemen .. We have real function names with REAL Parameters.
So , the previous example will now be 

def heard(words):
    print words
 

YAY ! - bigger better stronger faster .. (and now with parameters!) :)


Comment viewing options

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

This is Awsome Grog! In my

This is Awsome Grog!

In my starting days I always had doubts how a java service called python but slowly learned seeing the examples. This answers many of my questions and now the function calls are more easier... Yipee!!!

Will I have to make changes in my old script? or will that work fine?

Regarding the documentation of services, Is there a page which describes a list of functions which python can call and use for that service? It would be much easier to read that and use the functions available instead of checking out example codes when you use a service for the first time.

If any such page dosent exist then I guess you could initiate it and we all could add in our examples and list of fuctions whcih we use in a given service, slowly this would give us an exhaustive documentation of every service.

P.S. I am sorry if such a thing already existed for each service of MRL ( I guess I didnt search proerly then) cheeky

GroG's picture

Glad you asked . Here is a

Glad you asked .

Here is a description of more than one way to get the information.

Any method can potentially be a callback .. hmm..  I should document how this can be done.

bhouston's picture

I changed the; def heard():  

I changed the;

def heard():

      data = msg_i01_ear_recognized.data[0]

     ( i commented it )

to;

def heard(words);

      print words

and then all of my commands after "if (data == "command"):

Now it prints the word (i can see that in the python tab) but it doesn't recognize it.

What am I missing or is there something wrong with the program?

GroG's picture

Doesn't recognize it? -

Doesn't recognize it? - Speech must have recognized it .. otherwise it wouldn't have printed ?

Hmmm .. little confused by that statement - give a description of how you "expect it to work" - then send a noWorky !

bhouston's picture

I sent you a no worky, on

I sent you a no worky,

on line 246 I have all of my def heard scripts, so when I say for example, "want to play a game" it should say "sure I like games" and when I say "rock paper scissors" it should say "ready " and them do the script.

I have tried it the way I've always had it prior to 1.0.36 and then the way you describe in this post, neither way works. The No Worky I sent you was before I made any changes.

 

bhouston's picture

This is working now. I put in

This is working now. I put in the following;

def heard(data);

       if (data == "command"):

All good now.

GroG's picture

WooHooo ! Worky ! Your

WooHooo ! Worky !
Your Python-Fu has much improved !