Services - Remix

Some services in MyRobotLab are composites of other services.  This allows for more structure, complexity and higher functionality.  Tracking, InMoov, Plantoid are a few examples of services which contain other services.

The Tracking service is used to track faces or points in a video stream.
It contains OpenCV, 2 X Servo, and 2 X PID Services.  The OpenCV service provides a video stream. The PID services provide quick calculations from a targeted point in the video stream to move 2 (pan & tilt) servos.  Here are some examples of it in action.

Now, what if we wanted to run 2 tracking systems simultaneously, and these two systems share the same Arduino?  We don't have access directly to the internals of the Tracking service, but we do have ability to change Service names.  And this is all we need.

First, lets look at what the internals of a Tracking service named tracker1 would look like. 

This single line of Python will dump all the details of the contents of a Tracking service.

print(Runtime.buildDNA("tracker1", "Tracking"))

tracker1.xpid=[tracker1.xpid] PID - pan PID
tracker1.ypid=[tracker1.ypid] PID - tilt PID
tracker1.arduino=[tracker1.arduino] Arduino - shared Arduino instance
tracker1.y=[tracker1.y] Servo - tilt servo
tracker1.opencv=[tracker1.opencv] OpenCV - shared OpenCV instance
tracker1.x=[tracker1.x] Servo - pan servo
 
The Arduino will be called tracker1.arduino without any modification.  But we are going to share it with a second Tracking service, so we will reserve a name.
 
Now, lets change the name to sharedArduino with the following Python.
Runtime.reserveRootAs("tracker1.arduino","sharedArduino")
The plan is to make another tracking service named "tracker2".  We will change tracker2's  Arduino to be named sharedArduino too.
Runtime.reserveRootAs("tracker2.arduino","sharedArduino")
Lets see what we have done to the global defintion now:
print(Runtime.getDNA())
The output shows, if a tracking service named tracking1 is created it will have a Arduino service named sharedArduino, same as the tracker2's Arduino.
 
tracker1.arduino=[sharedArduino] null - null
tracker2.arduino=[sharedArduino] null - null
 
Here is the result and all of the code.
 
 

#file : home/GroG/dna.py edit raw
########################################################
# DNA - (Description of Neighboring Automata) 
# Some services are composites of other services. If written
# correctly these composites "bind" to other services using
# names. The following example shows how to share the same
# Arduino service between 2 different Tracking services.
#
# more info : http://myrobotlab.org/content/sample-inmoov-head-dna

from org.myrobotlab.service import Tracking

# print out the dna of a service
# you can get all of the names and types of services
# which a composite needs

# this command will show what the DNA would look like
# if you were going to start a Tracking service named tracker1
dna = Runtime.buildDNA("tracker1", "Tracking")
print (dna)


# this substitutes a name for a different name
Runtime.reserveRootAs("tracker1.arduino","sharedArduino")
Runtime.reserveRootAs("tracker2.arduino","sharedArduino")

# print our changes to the global registery
print(Runtime.getDNA())

# since you know the name of the service which will be shared you
# may create it first and apply additional configuration changes
# or other changes
sharedArduino = Runtime.create("sharedArduino","Arduino")
sharedArduino.connect("COM4")

# now start the 2 Tracking services
tracker1 = Runtime.start("tracker1","Tracking")
tracker2 = Runtime.start("tracker2","Tracking")
 
References

Comment viewing options

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

Hello ! Thx for this ! Now

Hello !

Thx for this ! Now i've only one arduino's tab for : "arduino", "tracking1.arduino" and "tracking2.arduino"

Theres is a lot of things hidden in MRL lol !