Passing data in from an outside application

I would like to know if there is a way to call an external application and have that application pass back a variable that can be used in myrobotlab.  I have a lot of functions that I would like to be able to use that are developed outside of myrobotlab.  Is there a tcp server or any way for me to get the results of these functions passed back into myrobotlab?

GroG's picture

Hello and Welcom d.cochran

Hello and Welcom d.cochran !

Yes .. there are many ways.  So many ways, that it would be better if you gave a concrete example of what you are trying to do.

High level services which allow connectivity into & out of myrobotlab:

WebGUI - The new GUI for MRL

This one you can use the REST api - to send data into any service or method in myrobotlab

RemoteAdapter - allows connectivity to multiple instances of MyRobotLab. Allows peer to peer service sharing

Allows multiple instances of myrobotlab or any other application which can send MRL messages over TCP or UDP

XMPP - client xmpp service - will allow a duplex communication without the need of port-forwarding

A nifty service which allows connectionless messages to be sent over XMPP - nice protocol to jump through NATs and Firewalls

The more details in your questions, the more detail we can provide in our answers.

d.cochran's picture

Thank you GroG

I half way figured out my answer by playing around with some Python to do this but was looking for a tcp server to that already existed.  

 

I have an application that does a lot of things that are robot related which is written in c#. To see what it currently does, visit cochranrobotics.com and go to the ez-AI link.  The gist of the application is that a user can launch a piece of the app by calling the exe and passing a switch.  This app will perform a task and return a value to a tcp port to be used by myrobotlab.  For example, I am adding adding a distance measure tool now.  It is for either stereo camera or mono camera.  The math functions to calculate distance are done in a class in c# and the distance to the recognized object is passed back to the tcp server for use.  The goal is to make this robot software independent.

The tcp port communication could also be used when passing information between robot platforms.  For example, if I liked using a different platform for controlling servos and reading sensors, I could call my robot lab for certain features that I like better in it, and still tie to my preferred platform for servo control and other things.  I am exploring to see what myrobotlab offers but want to make sure that I don't put myself in a box that limits me.  My preferred programming language is C# but I like some of the things that are available through this platform.  I also like finding something that works and don't like to recode other things that are working very well.

 

By offering a tcp communication method, I won't need to recode much of EZ-AI to work with myrobotlab.  The only issue I have currently with the Python I wrote is that it can't handle really large amounts of text.  I will explore the other solutions that you mentioned tomorrow,  Thank you for the suggestions of where to look.

GroG's picture

Sure ... here to get you

Sure ... here to get you started with a simple "cause & effect"

1. download myrobotlab.jar
2. press -> runtime -> system -> install all (you may get an error - don't worry about it - growing pains :)
restart.
This downloads all the dependencies for all the services.. you only have to do it once...

Next start mrl again - and put this in the Python window

webgui = Runtime.start("webgui","WebGUI")

At this point you can send url's from any application which can access any method within MRL.
To get lists of methods you can press the REST link

Will look like this (depending on what services are running)

the buttons create URLs - and the URLs can be used from any application to send data and execut requests and get data back from the services

For example with 2 URLs I can create a Speech service named "speech"

http://127.0.0.1:7777/services/runtime/start/speech/Speech

and make it say something

http://127.0.0.1:7777/services/speech/speak/hello%20i%20will%20say%20something

everything is accessable this way.

d.cochran's picture

Thank you again

This looks like it will work great.  Thanks so much.  I have a couple of other development efforts with this project and will include the hooks to MyRobotLab after this release is complete.

Have a great day!

d.cochran's picture

GroG, another hopefully simple question

I have been playing with this some and the speach works great, but I do have another question for you more about myrobotlab more than anything...

The project that I have is dependent on the programmer of the robot application doing things with the data I pass back.  Is there a way to simply set a variable with the information that I pass back, and allow the robot programmer to decide what they want to do with that information?  

Here is an example.  One of my functions gets the walking directions to a destination from Google Maps API.  It stores this route in a database table, then calculates the bearing that the robot should take to hit the end of the first leg.  This is passed back to the robot app for the robot to do whatever it needs to do to head in that direction.  While this is happening, my application is querying the GPS to adjust the heading (passing it back to the robot app) and know when the robot has reached that point, before loading up the next leg of the route and passing back the new direction that the robot should head in.  I dont want to tie the user down by saying that this has to go to a specific part of the MyRobotLab application, but allow them to do what they need/want to do with this information.  They could speak the information that is being returned or use it to do something else.  

I am sorry for what seems to me to be a simple question, but I am so new to MyRobotLab and have someone who wants me to put hooks into MRL from my project.

Would this or how would this be able to be caught in MRL and used? http://127.0.0.1:7777/services/runtime/receive/This%20is%20a%20test

Thanks for the help.  I do really appreciate it.

GroG's picture

I'm afraid I didn't follow

I'm afraid I didn't follow the example.  But I can generalize communication to and from MRL and maybe that will help decide if what you want done is possible.

There are primarily 2 types of messaging.  Synchronous and Asynchronous.  

Synchronous - someone asks for something and waits for a response - the response data comes back and everyone is happy - examples of this would be a http GET request & response.

Asynchronous - Listeners & Event handling, or subscribe / publish system are Asynchronous.  This is when you subscribe or listen for an event .. and the data arrives when the event is triggered.  (This is how most of life is :)

MRL support both types.

http is designed primarily for Synchronous communication.
websockets can support both Asynchronous 

WebGUI has websockets support.

Sorry, I'm probably to far in the implementation details to be useful for you.. 

I did not understand your senario - PICTURES HELP !!  1000+ Words = 1 picture

below is a simple synchronous call from ez robot to mrl and mrl returns the data

 

d.cochran's picture

Global type variable

GroG, Thank you for continuing to help me on this.  The only way that I know to get my idea across is to list all of the things currently in EZ-AI.  This is in no way ment to be an advertisment, just trying to give you a clear picture of what I am trying to do.

I agree that this would definately be asynchronous communication.  The way that this is programmed in another platform is that the user launches the EZ-AI application and includes the switch indicating which part of EZ-AI they want to get data from.  These are listed below.  Sometimes, this is just text that is ment to be spoken.  Sometimes this is data that is used by the robot to do something. 

EZ-AI uses a database backend.  The user can call a usp using EZ-AI that determines its next action.  EZ-AI will return this action name back to the other platform which is used by that platform to do something.  For example, it might remind you to take your meds, or pay your mortgage.  It might play a song or get the news weather, sports or say a nursery rhyme based on the recognized user and the age of the user.  EZ-AI flags that item that was performed in the database as being complete so that it isnt repeated until a specific (user definable by the database) number of minutes has passed.

The user could call the application using the /CBO switch which would go into cookbook mode.  This allows the user to choose recipes and print them or have the robot speek these to them.  

As you can see below, there are many things that can be done and the list is growing.  I see how I would pass back a specific piece of data to a specific part of MRL without any issue.  I would like to pass back information and have the programmer determine what to do with that data based on what they told EZ-AI to do.  The data could be the traffic report, the direction the robot should head in, or maybe a reminder that it is their wifes birthday.  I am looking for a way to set a global variable that could be used by the robot programmer to do something.  

I dont know how to get this to happen in your platform.  In the current platform there is a wait for change function that watches a variable and waits for that variable to change before using the data in that variable.  I set that variable to a value, and the robot programmer knows what they have asked to be returned.  When that variable changes, they use the value to do whatever they need to do with it.

Again, thank you for your patience.  I have included the text below to help you understand the types of functions that are performed by EZ-AI.

"EZ-AI is a utility that can allow your robot to do many things. It can be used to allow multiple robots to work seamlessly together from different computers or different locations.  It also gives your robot a non-volatile memory and allows users to have completely different experiences with your robot based on their age or other factors. You can use all of some of these features.



Here is a list of its current abilities

Usage:



EZ-AI requires that you start it using switches. This is easy to do and allows EZ-AI to quickly open only the section of the program that you want or need to use. 



Interface

/I open the EZ-AI interface. This is where you will input data to make EZ-AI your own.



Pop3 email 

/P use the email checker process which tells you how many new emails you have since it last checked.

The EZ-AI configuration file has EmailServer, UserName, Password, and LastTimeEmailChecked values that will need to be configured to use this feature.



Database

/D uses the database to store or retrieve data from it. There are a lot of features of EZ-AI that use this to store and retrieve information. For example, this allows you to setup reminders for yourself or other users, and allows the robot to know if today is a special day such as a birthday or anniversary for you. There are too many things to mention here that are possible with this feature. This allows your robot to have a non-volatile memory which lets your robot remember what it has done and not repeat those things. It also is a way that the robots can communicate with each other and see if another robot has already completed a task, so that it doesn't attempt to do the same task. 





RSSFeeds

/R use to get an RSS feed, parse it and return the results back. This allows the data that is coming back in the RSS feeds to be cleaned before they are returned.  EZ-AI has a table that allows the user to put in phonetically correct pronunciations of words. There is a screen that allows the user to enter this data in the EZ-AI interface.



Chatbot

/C use the chatbot

The chatbot runs local to your install. This allows EZ-AI to know what questions the user can ask by reading the AIML data from the Program-O (chatbot) database. This helps drastically in the speech recognition of what the user says. 



Web Information Search

/W use the Wikipedia query. Just speak the question and Wikipedia will be searched for information on the topic EZ-AI understood you speak. Saying Goodbye will close the wikipedia search.



UPC Code Search

/U use the UPC code search.

The EZ-AI configuration file has a UPCServer value which needs to be changed to your APIKeyCodefromEANData.com. Saying Goodbye will close the UPC code search. RoboRealm is used to scan the barcode. You will need a camera that is pretty high definition to make this part work.



Bible Verses

/B Gets verses of the bible for you upon request

This has 3 modes.

/B normal will use the normal interface

/B daily will get the daily verse from the Bible.

/B random will get a random verse from the Bible.

After saying the Book Chapter and Verses you would say read verses to pass the variable back.

After getting the verses, you can say Print Verses to print out the verses that you just retrieved.

If you make a mistake or EZ-AI misunderstands what you requested, you can say Make Correction and the form will be cleared and you can start over.

Saying Goodbye will close the Bible search.



Map Directions

/M gives you driving directions from Google Maps. There is an extensive list of cities that are populated in the cities table in the database.

EZ-AI configuration file has a DefaultContenant value which is used to limit the cities to a specific continent. 

There is a database table in the EZ-AI /I interface that allows you to put in common addresses. By saying Address and then the name you assign, this address will be used. For example Address Mom will put in the address that you have assigned to Mom in the database.

EZ-AI configuration file has a HomeAddress value which allows you to say home to populate the field with this value.

EZ-AI configuration file has a GoogleMapsAPIKeycode which needs to be modified with your own Google developer APIKeyCode

Saying Goodbye will close the Directions search.

Saying Get Directions will send to the robot software. After the directions are retrieved, saying Print Directions will print these directions to your default printer.

If you make a mistake or EZ-AI misunderstands what you requested, you can say Make Correction and the form will be cleared and you can start over.

If you have a GPS, the Current Location feature is enabled which allows you to say Current Location instead of an address.



Outdoor

/O Normal will use a GPS that is attached to your computer (designed for robots with onboard computers) to find your current location and display it on a map downloaded from google maps. It will query the GPS every second and update the robot software and its internal map every 10 seconds by default. This interval is user adjustable through the EZ-AI.exe.config file. EZ-AI will scan com ports 1 to 5 to try to find an attached GPS. It will track where you are and update a map. It also passes this information back.

/O Navigation will put this map into navigation mode.

It will first get your current location and pass it back to you. It will then show where you currently are, and where your destination point is for this leg of the route. It will also return back to the robot software the direction that your robot needs to head to achieve this point. When you are within .00001 of the destination in lat and lng, the leg will be marked as achieved and the next leg will start. your map will change to go to the next leg of your robots trip.



Navigation Directions

Called by using /NAV switch.

Navigation module that allows a user to get directions and then navigate to the location based on google API walking directions. The form works like the Map Directions module but stores the returned information in a table in EZ-AI. This is used with the Outdoor Navigation mode to allow your robot to travel to a destination using GPS.



Skype

/S launches skype. Their API isn't worth messing with but this can be used for telepresence. i am using VSee as it is free and works great. Skype works also. If you setup VSee on your computers, you can set the robot to autoanswer if a specific user calls it. This is how I am using it currently.



Emergency

/E switch will post a message on Facebook. This is for emergencies. It uses the Emergency table that can be updated from EZ-AI /I

My vision of this is that the user of the robot would say something like "Robot, I need help" and the robot would respond with, "Do you want me to post a message on facebook asking people to assist you?" If the user says "Yes" then EZ-AI.exe /E would launch and wait for the user to ask what type of an emergency it is. For example, the user would say something like "It is a medical emergency" which would post on facebook the text from the database called Medical Emergency. This text can be anything you want it to be. It could say, Please send an ambulance to 111 Blue Bonnet Road or something like that. After the message is posted, the user can be told that the message was posted to social media sites by saying the variable returned to the robot software. If you have a GPS, the closest street address to your location will be posted with your message.



Cookbook 

/CBO uses BigOven.Com to search for recipes.

saying "Search Recipes" will pull back the 70 most popular recipes.

saying "More Recipes" will load the next 70 most popular recipes.

saying "Previous Recipes" will move back to the previous list of recipes.

saying "Choose" and then the name of the recipe will retrieve that recipe and the ingredients for that recipe.

Saying "Print Recipe" will print the recipe that you have displayed"

saying "Goodbye" will close the module.

The number of recipes returned is now a user definable variable in the EZ-AI.exe.Config file."

d.cochran's picture

a bit more information

https://www.youtube.com/watch?v=ODrbxVD9BdE

This might give you a bit better of an idea of some of the things the database is used for.

GroG's picture

Interesting.  Thanks for the

Interesting.  Thanks for the information.  

I don't know much about EZ-software, so I appreciate your explanations. 

This is the limited things I know about EZ (please correct me if I'm wrong) :

  • EZ is primarily closed source
  • its written in C# 
  • it only runs on Windows (perhaps on Linux with mono - but drivers would be a pain)
  • There is a thing called EZ Builder which will spawn a process with command line parameters - and perhaps stream back the spawned processes' output stream ?
  • You have created a "plug in" - EZ-AI which is spawned by EZ Builder (the commercial closed source program) - and it does a variety of cool things. 
  • You have given me a list of all the very cool things EZ-AI does which you wrote - it is a Finite State Machine of sorts and is driven by time & context of the person it recognizes.  It serves back a set of interesting custom events which are all stored in you database.

Is this close?  It will help me to provide better answers for you if I understand whay systems you are coming from. 

PS please change your avatar - you are not a scared gopher ;)

d.cochran's picture

About EZ-Builder and EZ-AI

  • EZ is primarily closed source
    EZ-Builder is a closed system in that the source code for the application is not available to be modified.  There is an SDK that exposes all of the classes that are used and you can use this SDK to build whatever you want to build outside of the EZ-Builder application.  It is closed in that the controller is not open source.  Modifications can be made to the controller to allow you to do what you would like to the controller.  It is closed in that it only works with their controller.  They took the Apple route.
  • its written in C# - True
  • it only runs on Windows (perhaps on Linux with mono - but drivers would be a pain) - True, however MS has announced that it will "soon" have .NET for Linux systems.
  • There is a thing called EZ Builder which will spawn a process with command line parameters - and perhaps stream back the spawned processes' output stream ? - EZ-Builder is the EZ-Robot application used to control robots on their platform.  It can spawn processes and wait for this process to return data.
  • You have created a "plug in" - EZ-AI which is spawned by EZ Builder (the commercial closed source program) - and it does a variety of cool things. - EZ-AI is the "plug-in" of sorts that I wrote.  I wrote this so that it could be used with EZ-Builder or any other application that I can pass data back into.  
  • You have given me a list of all the very cool things EZ-AI does which you wrote - it is a Finite State Machine of sorts and is driven by time & context of the person it recognizes.  It serves back a set of interesting custom events which are all stored in you database. - At this point, very close.  There are some web based actions that use API's that are not stored in a database, but could be.  

 I am building this to be a true AI and will be adding Neural Network logic to allow it to do a lot more.  The list of things that it does currently is growing.  For example, I am working on a module that will measure distance to an object using sterovision and monovision.  The sterovision part is pretty easy.  We will be doing multiple monovision calculations and either calculate based on all of these, or allow the user to pick which of these they want to rely on.  

There are some other things that are in development like relating data to each other and autonomous research to interests that the user(s) have asked about.  This research would be linked together to provide information about a topic that the user didnt ask for.  For example, the robot might know that the user is interested in Sci-Fi movies and the robot could ask the user if they knew that a new star wars movie was coming out.

EZ-Builder was just the first platform that I interfaced with.  I wrote my application so that parts of it could be placed on a different machine than the robot.  I wrote it so that multiple robots could share information from a server if that is the configuration the user wants to go with.  I have a couple of users running it in this fashon.  I really dont care which robot platform the user uses, or if it is a website that is using the information and not using a robot platform.  It is isolated from the robot application.

The robot application calls EZ-AI using a switch and then EZ-AI does what the user asked it to do and returns that data.  EZ-AI has some screens that are used outside of the robot to gather information for some of the features it has.  For example, software controlling the robot would run C:\ez-ai\ez-ai.exe /C to launch the chatbot.  The chatbot would then launch outside of the robot platform.  The user would ask a question or make a statement.  The resulting text is returned (currently to EZ-Builder via a TCP connection) which sets a variable.  The robot software sits has a process running that is checking for that variable to change because it knows that the user started the chatbot.  When this variable changes, it speeks the text.

EZ-Builder doesnt have anything built into it to know what I am doing with EZ-AI.  I have noting in my program to know what EZ-Builder is doing.  EZ-Builder knows how to launch a script that is programmed by the robot programmer to "Kick off Chatbot".  When this script is called, it launches the EZ-AI using the /C switch.  EZ-AI launches and sees the /C switch and knows to load the chatbot interface.  This uses JSON to communicate with the chatbot.  When the user asks a question, EZ-AI passes this to the Chatbot software.  The Chatbot software returns the responce to EZ-AI.  EZ-AI passes that responce back to EZ-Builder via TCP port setting a variable in EZ-Builder.  The script that is in EZ-Builder is monitoring for a change to this variable and when this variable changes, it does whatever he wants to do with this data.

The only tie that EZ-AI has to EZ-Builder is that EZ-Builder has a command it in that allows a variable to be set from a TCP connection.  I could allow the user to specify a configuration item that tells which platform a robot is running on.  I could even have one robot on EZ-Builder and another on MRL through information in the database.  This would allow me to handle the communication back to that robot in the correct way.

As you can see, whe programming this application, I did everything that I could to prevent being tied to a single robot platform short of writing it in a language that was platform independent.  I started this project a couple of months ago and already knew about  MS plans to allow .NET to be run on Linux, so I didnt worry about that much.

I hope this helps.  I would like to include the tie to MRL in an upcomming release.  Is there a component that could be developed for MRL to handle return data from EZ-AI?  It is a small system now that does some cool things.  Over the next year I am sure that it will be much more of an actual AI.  

GroG's picture

Thanks for the explanation -

Thanks for the explanation - its become a bit more clear.  From what you described EZ-Builder has a scripting service - what type of scripting does it support ?  Python ? 

Within this script - is that where your socket is waiting for the information coming back from EZ-AI ?

If so, the exact same sort of thing could be done with MRL,  MRL has a Python script service.  Your exact script could be copied over - the more relevant question would be - what services in MRL would you like to interface with (this is where the script would diverge from EZ-Builder) ? 

You probably do not know all the services, nor at what maturity level each is in .. and I don't know the specifics of what your system is lacking and what features you want which MRL currently has.  This could probably be figured out but it will take a little time for you to become familiar with MRL.  To start with, here is a list of a group of services in various levels of development - http://myrobotlab.org/matrix.php .. a sort of "menu"

Do you see this type of script / socket integration sufficient or do you need tighter integration ?  The basic glue of MRL is Python (although other scripting languages are planned).  It glues all the blocks together to provide the desired system. The basic block of MRL is the "Service", services are written in Java.  If you need tighter integration (which at this time I don't see why you would) - you can create a MRL Service.

 

d.cochran's picture

Scripts

The scripting language in EZ-Builder is definately not standard.  It is geared to their platform and is similar to basic.

Could I do this?

Write a python script that uses a variable that could be used to determine the correct action that should be taken based on what was requested by the user?  The script would then wait for a variable to be set in it from the returned value from EZ-AI.  Would this script be able to then call other services in MRL and pass in the variable such as speech?  The issue I ran into was that I didnt find anything in the python service from http://127.0.0.1:7777/services that would allow me to set a variable.  It may be because my script doesnt have a variable (global or otherwise) in it yet.  I dont know.

Yes, the script is what is waiting for the variable to change.  The variable is set outside of the script but it could be set in the script.

This is how I envision it working but just am not familiar with MRL.  I definately agree that I need to spend time in MRL to understand how it works.

As far as why I am doing this...

There is someone who has asked me to tie my AI into MRL so that they can use what I have written with MRL.  I want to give users of EZ-AI options as to what platform they use EZ-AI with so MRL seemed like a good fit.  

d.cochran's picture

About MRL

Please tell me if i am off base here or not.

There are services.  These services are used by Python.  The robot is programmed in Python to use these services.  Python can call these services and pass information to these services.

The programmer would write their code in python in MRL and use the services as they need.

If this is correct, I think the above solution would work.  I just need to figure out how to pass the information back into a variable in Python.  

GroG's picture

Yes all correct.  Python

Yes all correct.  Python itself is one of these services, meaning another Scripting service could be created to provide the same functionality but with a different language - e.g. JavaScript, Scala ... whatever..

My guess as to the shortest path from A to B would be :

Post a link to your EZ-Builder Basic Script.
Basically is would just be a port of this to standard Python - we could help you there..

You have written an AI system - but what would help others is if you posted the API or details of the JSON that is reaturned.

 

d.cochran's picture

Thanks again and the fog is lifting :)

There is no API or JSON from the AI system to the application software.  What is returned is cleaned up strings.  The JSON conversion from the other API's that I use such as google, BigOven and others is parsed to return a string.  The information that is returned from the database is a string.  

I use many scripts in EZ-Builder depending on the reques of the user but I am inculding one example.

This is a script that checks to see if today is a holiday

Portion of BrainFunctions script 

#This uses the database to determine the next action that should happen for this user

ControlCommand("Script Manager", ScriptStart, "GetUserActivityFromDB")
Sleep(2000)

#Based on the results from the above script, things happen.  For example, the next action could be to check #to see if today is a special day for this user.
IF($UserActivity = "Check Dates")
  $RobotAnswer = ""
  ControlCommand("Script Manager", ScriptStart, "GetPersonalHolidayFromDB")
  WaitForChange($RobotAnswer)
  IF(LENGTH($SQLReturn) > 0)
    SayEZBWait("Today is your " + $RobotAnswer + ".") 
  ENDIF
ENDIF
 
GetUserActivityFromDB Script
$SqlCommand = "EXEC usp_GetNextActivity'"+$UserName+"', '" + ToString($SongsEnabled) + "'" 
ControlCommand("Script Manager", ScriptStart, "EZ-AI DB Call")
$UserActivity = $RobotAnswer
 
CheckDates Script
$SqlCommand = "EXEC usp_CheckTodayForPersonalHoliday '"+$UserName+"'"
ControlCommand("Script Manager", ScriptStart, "EZ-AI DB Call")
 
EZ-AI DB CALL Script
FileWrite("C:\EZ-AI\WorkQueue\Query.txt",$SqlCommand)
FileWrite("C:\EZ-AI\WorkQueue\Robot.txt",$RobotName)
$QueryParams = "/D In"
EXEC("C:\EZ-AI\EZ-AI.exe", $QueryParams)
Sleep(3000)
$QueryParams = ""
 
This starts EZ-AI and has it make a database call to EXEC usp_CheckTodayForPersonalHoliday '"+$UserName+"'"
 
EZ-AI returns this into a string variable called $RobotAnswer.  As you can see from the script, I say the returned value.  ControlCommand() is what I see as your services.
 
The goal of EZ-AI is to simplify the steps needed by the user to be able to get to the data.  It is written to be used by the non-programmer.  Because of this, it handles the conversion from json, xml or HTML from other API's in the EZ-AI application and returns to the robot software in the form of a cleaned string.  Sometimes these can be very long, such as the traffic RSS feed in London England.  A lot of what I have done above is done to keep things as simple as possible.  Most of the users of this application dont program much.  Most see what is listed above as programming.  Because of this, I try to do as much as possible in EZ-AI and retrun data that is usable by the user without requiring them to handle much parsing if any.  
 
I think that once I got this ported, I would be good getting the rest of it ported.  Really, I dont want to build an entire solution for someone, but give them an example of how they would use the data that is passed back from EZ-AI in MRL.
 
 

 

GroG's picture

Can I see the details

Can I see the details of ControlCommand method ?  Or is this an EZ-Build system call ?

d.cochran's picture

sorry, that is an EZ-Builder command

I wish I could.  Unfortunately it is an EZ-Builder command.

 

Basically, I am using it as a function call in my scripts.

GroG's picture

That's fine .. I was just

That's fine .. I was just trying to find out where your example script ended and where the EZ-SDK was called.
I assume ControlCommand is documented somewhere - can you provide a link or detail ?

I think you already mentioned this - but it would seem optimal that this command is simply ported in Python to do the equivalent as it does in EZ-Builder.  But to suggest something I would need to know on a "Black Box" level what ControlCommand does and what it returns.  

d.cochran's picture

About EZ-SDK and things

CommandControl() just calls another command in EZ-Builder.  Because you dont have a structured language per se, you can use it to call or start another component.

When I program, I like to make a function or class do one thing.  I carried this logic over to EZ-Builder when I wrote these scripts.  I have color coded the scripts below to help understand the flow.  The yellow calls the yellow section below and so on.

You can see that the last color (sorry color blind) on this calls the EZ-AI application.  It uses a TCP port to return the information back to the $RobotAnswer variable.  As you can see in this flow, the EZ-AI application is started 2 times.  The first is to get the current user activity from the database, and the second is to check to see if the date is a holiday for that user.  Each time, the same $RobotAnswer variable is updated from the EZ-AI application.  

One more thing that I should mention...  EZ-AI opens the connection to the TCP server in EZ-Builder, writes to it, and then closes that connection.  It does this every time that data is passed back to EZ-Builder from EZ-AI.  It doesnt leave the TCP port connected.

These scripts are in EZ-Builder.

Portion of BrainFunctions script 

#This uses the database to determine the next action that should happen for this user

ControlCommand("Script Manager", ScriptStart, "GetUserActivityFromDB")
Sleep(2000)

#Based on the results from the above script, things happen.  For example, the next action could be to check #to see if today is a special day for this user.
IF($UserActivity = "Check Dates")
  $RobotAnswer = ""
  ControlCommand("Script Manager", ScriptStart, "GetPersonalHolidayFromDB")
  WaitForChange($RobotAnswer)
  IF(LENGTH($RobotAnswer) > 0)
    SayEZBWait("Today is your " + $RobotAnswer + ".") 
  ENDIF
ENDIF
 
GetUserActivityFromDB Script
$SqlCommand = "EXEC usp_GetNextActivity'"+$UserName+"', '" + ToString($SongsEnabled) + "'" 
ControlCommand("Script Manager", ScriptStart, "EZ-AI DB Call")
$UserActivity = $RobotAnswer
 
GetPersonalHolidayFromDB Script
$SqlCommand = "EXEC usp_CheckTodayForPersonalHoliday '"+$UserName+"'"
ControlCommand("Script Manager", ScriptStart, "EZ-AI DB Call")
 
EZ-AI DB CALL Script
FileWrite("C:\EZ-AI\WorkQueue\Query.txt",$SqlCommand)
FileWrite("C:\EZ-AI\WorkQueue\Robot.txt",$RobotName)
$QueryParams = "/D In"
EXEC("C:\EZ-AI\EZ-AI.exe", $QueryParams)
Sleep(3000)
$QueryParams = ""
 
In C# I would replace the ControlCommand statements with something like ezaiDBCall($SqlCommand) to call that function.  In EZ-Builder, there are no functions and each script acts as its own.
 
To walk through this example, 
BrainFunctions script starts
it calls GetUserActivityFromDB
GetUserActivityFromDB sets a variable to be used later
GetUserActivityFromDB calls EZ-AI DB Call
EZ-AI DB Call writes a text file using the parameters set by the GetUserActivityFromDB
EZ-AI DB Call writes a text file with the $RobotName variable -- Depricated and not needed.
EZ-AI DB Call sets a parameter that is used to complete what is needed to call EZ-AI
EZ-AI DB Call launches EZ-AI passing in the just set parameter as the switch and another variable used for in or out of EZ-Builder
(EZ-AI runs the usp that was requested and sends the result back to the $RobotAnswer variable in EZ-Builder)
EZ-AI DB Call waits 3 seconds
EZ-AI DB Call sets the parameter it used to call EZ-AI back to blank
This will return me back to the calling script which kicks me back to GetUserActivityFromDB Script
The variable $UserActivity is set to the $RobotAnswer variable
I am then returned back to the calling script which is BrainFunctions
BrainFunctions checks to see if the $RobotAnswer variable is set to Check Dates
If it is, it sets the $RobotAnswer back to blank and
calls the GetPersonalHolidyFromDB Script.
This sets the command that will be run by EZ-AI  and calls the EZ-AI DB Call script
EZ-AI DB Call writes a text file using the parameters set by the GetUserActivityFromDB
EZ-AI DB Call writes a text file with the $RobotName variable -- Depricated and not needed.
EZ-AI DB Call sets a parameter that is used to complete what is needed to call EZ-AI
EZ-AI DB Call launches EZ-AI passing in the just set parameter as the switch and another variable used for in or out of EZ-Builder
(EZ-AI runs the usp that was requested and sends the result back to the $RobotAnswer variable in EZ-Builder)
EZ-AI DB Call waits 3 seconds
EZ-AI DB Call sets the parameter it used to call EZ-AI back to blank
I am returned back to the calling script which is GetPersonalHolidayFromDB Script but I am at the end of that script so
I am returned back to the calling script which is BrainFunctions Script
BrainFunctions script has been sitting and waiting for the $RobotAnswer variable to change and it has so
It checks to see if the length is > 0 characters.
If it is, it speaks the text "Today is your " + $RobotAnswer + "." 
 
Thre brain functions script continues on doing other things, but with this, I could figure out the rest I believe.
GroG, I want to thank you again for helping me with this.  You have been very patient and it is appreciated.
One more thing, the EZ-SDK is called from withing EZ-AI to interface back to EZ-Builder.  It contains the object that opens the TCP port connection that is used to pass the information back to EZ-Builder.
 
 

 

d.cochran's picture

EZ-SDK with Python

http://www.ez-robot.com/Community/Forum/posts.aspx?threadId=3275

In doing more digging, I found this thread.  It is a project that someone has that uses the EZ-SDK from Python.  It might provide some help by providing information on something you are familiar with with something I am familiar with.

There is also a version for Mono.  It can be found here http://www.ez-robot.com/EZ-Builder/mono

 

wvantoorn's picture

Not that im making a

Not that im making a commercial for MRL, but after what ive seen over on EZ, and after what i know MRL can do, even with program AB (chatbot, Alice, aiml) and knowing that mrl can control everything with a chip in it, it would look much more easy if you would use mrl as the main, since it has all the services you need, everyday new stuff is beeing build, created and thought of.

But again, i dont have any interest in MRL, other then making it the best robot independent platform in the world! Did you know that even asimo stole from MRL? but we allow him, hes asimo and hes cute!

But all jokes aside, if python could be the main programming style, i think for your users it could be the way to go, python is one of the cleanest and easy to learn language there is!

 

GroG's picture

I'm glad your head of public

I'm glad your head of public relations wvantoorn ;)

You are really very good at diplomacy..  

But what I think d.cochran is doing is, he has made a very cool "plug-in" to EZ-Robot and wants to allow his application ... which I think really is not necessarily part of EZ-Robot available for MRL users..

He mentioned that he wished to make is application .. currently named "EZ-AI" platform agnostic.

Please correct me if I am wrong.

wvantoorn's picture

Ah, then i misread! But

Ah, then i misread!

But anyway,d.cochran, welcome to the family!

Love your dog!

 

d.cochran's picture

I understand what you are saying

I see some benefits to using MRL over EZ-Robot.  I see some benefits to using EZ-Robot over MRL.  Both have their strong points.  The thing to remember is that this AI is being developed for the non-programmer to use.  The main benefit of EZ-Robot is that it allows people who dont know how to program to do some cool things.  The benefit to MRL is that if you can do some programming, it allows you to build some amazing things.  

EZ-AI is ment to allow users of either robot platform to be able to add some things to their robots that allow it to be much more than what is available in either without some programming.  For example, some "in the works development efforts" are calculating distances to objects using either one or multiple cameras, associating information to other information, probability calculations based on past things, centralized knowledge base, smart use of outdoor navigation mode allowing the user to say things like "Find the closest Starbucks" and have the robot plot a course if the Starbucks is within a certain distance and if not, see if there are any other coffee houses in that distance and a lot more.

If you think about all of these scenarios, they are useful to any platform of robot and the programming should therefore be independent of any platform of robot.  There would need to be hooks into these platforms, but other than that, the request is made and the data is returned.

EZ-AI has its own local chatbot which allows the questions that are in that chatbot to be loaded into the dictation library, allowing the robot to know the possible questions, and thus improve the speech recognition with even the weakest of speech engines (microsoft).  There are plans to go to DNS but the $5,000 price tag has put that on hold for a bit.

This project is under 2 months old, and that time has been spent adding capabilities instead of working on an API.  I will probably have one of my developers start working on an API shortly but, I just found 15 new things that I want to add so, I am not sure what will come first. 

I have a question out to the developer who worked on the Python SDK.  He has been gone for about a year so I dont know that he will see it.  In any event, I plan on looking into if it supports the features that I am using in the windows version of the SDK.  It should, and if so, I might rewrite a version that works with Python.  From my reading of his posts it looks like it has to be run in IronPython due to its dependency on .NET.  It is something that I look to explore.

Because MRL is made up of more of the programmer base, I plan on supplying a sample that is much more limited than I provided to the EZ-Robot community.  Most there are not programmers so more had to be done to build that userbase.

Thank you for your thoughts.  I do understand where you are coming from and appreciate it.

d.cochran's picture

Try my hand at some python

I am attempting to try my hand at some python and am having an issue.  This is the code and the output from the java window.  The python window is empty.  There is some highlighted script that I cant seem to figure out how to make work.  
 
I am using the execMethod from the python service through the webgui.  The results from the tabs in myrobotlab are below.  I am running gui 1.0.107.
 
Any help you could give would be great.  I am just trying to figure out how to get the data back in and usable.  I started down the path of a global variable but that is really up to the person doing the scripting for their robot. 
 
[Code]
from time import sleep
from org.myrobotlab.service import Speech
from org.myrobotlab.service import Runtime
import sys, string, os, subprocess
 
speech = Runtime.create("speech","Speech")
speech.startService()
speech.speak("hello brave new world")
 
webgui = Runtime.start("webgui","WebGUI")
 
os.chdir( 'c:\\EZ-AI\\' )
subprocess.Popen('C:\\EZ-AI\\EZ-AI.exe /C')
 
class MyClass:
@staticmethod
def setRobotAnswer( value ):
robotanswer = value 
speech.speak( robotanswer )
[/Code]
 
Everything works down to the function and the setRobotAnswer function.
 
Output from the java tab
185060423 [python] INFO  class org.myrobotlab.fileLib.FileIO  - looking for /resource/Python/pythonConsole.py
185060423 [python] INFO  class org.myrobotlab.service.Python  - exec import sys
from javax.swing import JFrame
from javax.swing import JPanel
from javax.swing import JLabel
from javax.swing import JTextArea
from javax.swing import JScrollPane
from javax.swing import JTabbedPane
from javax.swing import WindowConstants
from java.awt import BorderLayout
from java.lang import Boolean
 
# myService is a local variable
# created to point to this Python
# service
 
class Console:
 
  def __init__(self):
    self.stdout = None
    self.stderr = None
    
  def write(self,string):
    myService.invoke("publishStdOut", string)
    
  def attach(self):
    if (self.stdout == None):    
      self.stdout = sys.stdout
      self.stderr = sys.stderr
      sys.stdout = self
      sys.stderr = self
   
  def detach(self):
    if (self.stdout != None):
      sys.stdout = self.stdout
      sys.stderr = self.stderr
      self.stdout = None
      self.stderr = None
    
console = Console()
console.attach()
185060423 [python] INFO  class org.myrobotlab.service.Runtime  - Runtime.createService python
185060423 [python] INFO  class org.myrobotlab.service.Runtime  - Runtime.createService python
185062264 [python] INFO  class org.myrobotlab.fileLib.FileIO  - looking for /resource/Python/pythonConsole.py
185062264 [python] INFO  class org.myrobotlab.service.Python  - exec import sys
from javax.swing import JFrame
from javax.swing import JPanel
from javax.swing import JLabel
from javax.swing import JTextArea
from javax.swing import JScrollPane
from javax.swing import JTabbedPane
from javax.swing import WindowConstants
from java.awt import BorderLayout
from java.lang import Boolean
 
# myService is a local variable
# created to point to this Python
# service
 
class Console:
 
  def __init__(self):
    self.stdout = None
    self.stderr = None
    
  def write(self,string):
    myService.invoke("publishStdOut", string)
    
  def attach(self):
    if (self.stdout == None):    
      self.stdout = sys.stdout
      self.stderr = sys.stderr
      sys.stdout = self
      sys.stderr = self
   
  def detach(self):
    if (self.stdout != None):
      sys.stdout = self.stdout
      sys.stderr = self.stderr
      self.stdout = None
      self.stderr = None
    
console = Console()
console.attach()
185062264 [python] INFO  class org.myrobotlab.service.Runtime  - Runtime.createService python
185062264 [python] INFO  class org.myrobotlab.service.Runtime  - Runtime.createService python
185063559 [python] INFO  class org.myrobotlab.service.Python  - exec from time import sleep
from org.myrobotlab.service import Speech
from org.myrobotlab.service import Runtime
import sys, string, os, subprocess
 
speech = Runtime.create("speech","Speech")
speech.startService()
speech.speak("hello brave new world")
 
webgui = Runtime.start("webgui","WebGUI")
 
os.chdir( 'c:\\EZ-AI\\' )
subprocess.Popen('C:\\EZ-AI\\EZ-AI.exe /C')
 
class MyClass:
@staticmethod
def setRobotAnswer( value ):
robotanswer = value 
speech.speak( robotanswer )
 
 
185063559 [Thread-236] INFO  class org.myrobotlab.service.Runtime  - Runtime.createService speech
185063559 [Thread-236] INFO  class org.myrobotlab.service.Runtime  - Runtime.createService webgui
185063559 [speech] INFO  org.myrobotlab.service.Speech  - audioFile\google\en_gb\audrey\hello brave new world.mp3 is found 
185063559 [speech] INFO  org.myrobotlab.service.Speech  - isSpeaking true
185063559 [speech] INFO  org.myrobotlab.service.AudioFile  - started
185065588 [speech] INFO  org.myrobotlab.service.AudioFile  - stopped
185065588 [speech] INFO  org.myrobotlab.service.AudioFile  - stoppedFile audioFile/google/en_gb/audrey/hello brave new world.mp3
185066197 [speech] INFO  org.myrobotlab.service.Speech  - isSpeaking false
185080193 [WebSocketWorker-38] INFO  org.myrobotlab.webgui.WSServer  - onRawOpen /127.0.0.1:58410
185080198 [WebSocketWorker-38] INFO  org.myrobotlab.webgui.WSServer  - GET /services/python/execMethod/MyClass.setRobotAnswer('This%20is%20fun') HTTP/1.1
Host: 127.0.0.1:7777
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
 
output from the java tab when I run http://127.0.0.1:7777/services/python/execMethod/MyClass.setRobotAnswer('This%20is%20fun')
 
185080198 [WebSocketWorker-38] INFO  org.myrobotlab.webgui.WSServer  - GET [/services/python/execMethod/MyClass.setRobotAnswer('This%20is%20fun')]
185080198 [WebSocketWorker-38] INFO  org.myrobotlab.webgui.TypeConverter  - method with same ordinal of params found execMethod.1 - building new converter
185080198 [WebSocketWorker-38] INFO  org.myrobotlab.webgui.TypeConverter  - attempting conversion into String from inbound data MyClass.setRobotAnswer('This is fun')
185080198 [WebSocketWorker-38] INFO  org.myrobotlab.webgui.TypeConverter  - successfully converted all types
185080198 [WebSocketWorker-38] INFO  org.myrobotlab.webgui.WSServer  - sending 136 bytes
 
 
python tab is empty the entire time.
 
I am lost 
 
Thanks
David
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
wvantoorn's picture

Hi david, i dont know if Grog

Hi david, i dont know if Grog already fixed newest mrl release, but 107 is faulty.

didnt update mine for some days, but i used 1.0.99 and it works well. Ive used it for my inmoov robot and no problem running the python and so on.

so maybe you could download the earlier release, try it and it should be worky. Also in the help tab in the right corner when in runtime, you can sent a noworky to grog, so he can evaluate the errors. 

I hope this helps.

d.cochran's picture

Thank you wvantoorn

Thanks so much.  I will try an earlier version.  Also, thanks for testing this and verifying it works.  

GroG's picture

What wvantoorn said is true..

What wvantoorn said is true.. MRL currently is going through some growing pains .

If you have problems - send a noWorky ...

This link describes how.

myrobotlab.org/content/helpful-myrobotlab-tips-and-tricks-0#noWorky

It sends a log file to the group

d.cochran's picture

GroG, I completely understand

I would rather see growing pains than a project that has died anyday.  Good work on MRL.  

Feel free to drop into cochranrobotics.com.  I have started a forum for EZ-AI.  Register and you will have access to the forums.  You will see what all is planned and what the discussions (very few right now) are for what people are looking for in an AI.  I think you guys would be valuable members of this forum.

wvantoorn's picture

D.cochran, ive seen your

D.cochran, ive seen your Wall-E and i fell in love! Makes me want one real bad, was my favorite movie about robots! Have to search for one!

d.cochran's picture

Thank you

It was a fun project.  It ended up getting me involved in teaching robotics to 4th and 5th grade students.  I donate my time to a local school.  This program is extending to 6th grade next year because the parents have demanded that the program expand.  All good and my boss is very understanding and appreciative of the time I spend with these students.  I ended up using Wall-E in the class and he hasn't faired so well.  After more robots were purchased by the school, he was put on a shelf and I haven't really messed with him much because I started work on my AI project.

Thanks for the kind words!

David

d.cochran's picture

NoWorky sent

Dupe post

GroG's picture

Update...

Ok, I see a noWorky from you ..

Its with 1.0.107 ..  so our version with "growing pains" ...
Anyway - I see a very large binary dump .. which my first guess is python loading (or  attempting to load) dlls ?

Not sure, because  I don't really see your script you executed.. usually its printed before execution..

Very "strange"

d.cochran's picture

Binary dump

I wonder if that is from the subprocess.  In the Chatbot (which is the example) I load all of the AIML from the chatbot into the dictation library.  

Let me try it with a module that doesnt load a lot of data.  Give me a few minutes and I will send you another noworkie and see if it provides any other information for you.

d.cochran's picture

Noworky sent

I ran it with the outdoor map module.  It loads far less data.  It loads a map from google maps and the lat long from the GPS.  Hopefully it will provide more insight.

GroG's picture

This one I still get the

This one I still get the binary blob - may not be related to your script .. not sure..

I also see your script which was executed...

It looks like you change the directory and start your EZ-AI .. does it start?

Then you define a class but don't use it?

What were you expecting it to do?

d.cochran's picture

About the script

My exe starts without any issues.  

This part of the script is where I am having an issue

class MyClass:
@staticmethod
def setRobotAnswer( value ):
robotanswer = value 
speech.speak( robotanswer )
 
I then try to launch this section of the script by using the WebGUI under the Python service  I use execMethod and pass in MyClass.setRobotAnswer('This is fun').  It launches a browers window to http://127.0.0.1:7777/services/python/execMethod/MyClass.setRobotAnswer('This%20is%20fun')
 
This is what is returned in the java window but the speech.speak(robotanswer) from MyClass.setRobotAnswer doesnt fire.
 
322648337 [WebSocketWorker-40] INFO  org.myrobotlab.webgui.WSServer  - GET [/services/python/execMethod/MyClass.setRobotAnswer('This%20is%20fun')]
322648338 [WebSocketWorker-40] INFO  org.myrobotlab.webgui.TypeConverter  - method with same ordinal of params found execMethod.1 - building new converter
322648338 [WebSocketWorker-40] INFO  org.myrobotlab.webgui.TypeConverter  - attempting conversion into String from inbound data MyClass.setRobotAnswer('This is fun')
322648338 [WebSocketWorker-40] INFO  org.myrobotlab.webgui.TypeConverter  - successfully converted all types
322648338 [WebSocketWorker-40] INFO  org.myrobotlab.webgui.WSServer  - sending 136 bytes
 
Thanks
David
 

 

GroG's picture

Ok ..  I think I know what

Ok ..  I think I know what you want, and you got close..  but no one has needed to send parameters into methods from the webgui to a free-form script in Python (yet) :)

I added that ability - but you'll need to wait for the next release to get it ...

I assume you've found out how to execute arbitrary methods in Python (albiet without parameters) - This little demo did both..

d.cochran's picture

Thanks GroG

I will wait for the new version.  I wont implement into my app for a bit, so I have time.  I have one of my programmers refactoring a lot of what I put together quickly in order to get a working product.  It is taking him a bit of time but we will add this when the refactoring is complete.  Thanks so much for the example also.  

Have a great day!

d.cochran's picture

GroG, is this in the 113 release

Hey GroG, checking back in with you to see if this was added and is in the 113 release.  Let me know.  

Thank you

David

GroG's picture

Yep... it's there Just

Yep...

it's there

Just tested it ...  be aware that the method is called with binary data - so you need to convert it to the type you want e.g. str() if you want to use it as a string...


#file : home/GroG/RestToPython.py edit raw
webgui = Runtime.start("webgui","WebGUI")

def callBack(binaryData):
  data = str(binaryData)
  print("callBack was called with data=", data)
  if (data == 'Hello'):
    print('Yay!')