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.
 
 
[[home/GroG/dna.py]]
 
References

beetlejuice

9 years 11 months ago

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 !