loading
 
API returns SAMPLE_LINE_POINTS before module is run, not after as expected
Carl W Ott from United States  [11 posts]
7 year
I use the XML API to control a .robo file with several function tabs.

But it appears that when I request the value of SAMPLE_LINE_POINTS, the API returns the value BEFORE the Sample_Line module is run, not AFTER as is expected.

As the attached photo shows, the relevant .robo function has this sequence:
<...lots of stuff...>
Sample_Line
Watch_Variables

To make sure it was not a timing issue (e.g. API calls catching the value at the wrong point in the processing pipeline), I ran RoboRealm for a bit, then stopped it, placed a call to the API requesting the value of SAMPLE_LINE_POINTS, and then captured the attached photo "API returns unmodified SAMPLE-LINE-POINTS.jpg"

At this point in time, you'll see that Variable_Watch shows a current value for Sample_Line_Points which includes 5 separate line segments separated by the "-1, -1" marker:
(25, 72, 35, 64 ... 105, 88, 95, 84, -1, -1)

However, instead of returning the processed 5 line segments as expected, the API returns a single line:
(84, 95, 85, 80 ... 89, 90, 104, 95)

To confirm the API was returning the value BEFORE the Sample_Line module, I then let RoboRealm run again for a few moments (note that the stimulus was static/unchanged), long enough to disable the Sample_Line module, then stopped RoboRealm, asked the API to return the value of SAMPLE_LINE_POINTS, and captured the attached photo "API matches Variable_Watch when Sample-Line disabled.jpg"

At this point, you'll see that Variable_Watch displays the same value as returned by the API:
(84, 95, 85, 80 ... 89, 90, 104, 95)

Any advice - how can I obtain the output of Sample_Line from the API?  Could it be that I am doing or expecting something wrong - or does RoboRealm need a patch?

I'm currently running RoboRealm personal version v2.80.35.

Thanks,
Carl

  
Carl W Ott from United States  [11 posts] 7 year
FWIW - after posting the issue above, I've found a work-around, but it appears that this work-around may reveal another bug/issue...

To develop the work-around, I looked further & noticed that the Watch module on the 'main' function tab was unexpectedly showing the SAMPLE_LINE_POINTS value before the Sample_Line module which I use to segment lines.  This Sample_Line module is invoked within a function tab called 'BonW_Lines_in_FOV' which is currently manually invoked while I develop the image processing algorithm, and will eventually be invoked automatically from 'main' when new input data is detected.  Yet the Watch module in the 'BonW_Lines_in_FOV' function tab was showing the SAMPLE_LINE_POINTS value AFTER the Sample_Line module, as desired and expected.

So, I created a JScript Program module which would clearly 'capture' SAMPLE_LINE_POINTS at the point in the processing pipeline where it clearly had the desired value, and write that to a new variable under my direct control that I named 'Segmented_Line_Array'.  As the attached screenshot shows, this DID allow me to capture and export the desired data points with one exception - that the "-1, -1" Object Delimiters defined in http://www.roborealm.com/help/Sample_Line.php were unexpectedly replaced in the process with "255, 255" delimiters...

So, is there a recommended way (or RoboRealm patch) which could preserve the specified Object Delimiters?  Although the "255, 255" delimiter works for now, it's easy to imagine that failing in the future if the canvas size had to be made larger than 255 x 255...

Thanks,
Carl






 
Steven Gentner from United States  [1446 posts] 7 year
Carl,

Thanks for the post. Let me try to clarify a couple points.

1. First the easiest, there was a problem in the JScript GetArrayVariable where it was converting integer numbers into unsigned characters which is why you were getting 255 instead of -1. This has been fixed in the latest version. If you'd prefer not to upgrade, you can also just switch that to a VBScript module which has similar syntax but does not have the -1 to 255 conversion issue even in the version you have (we verified that).

Latest version 2.80.45 has this fix.

2. In terms of the API, the API reads and writes will only happen inbetween the pipeline cycles. In other words, when you write something via the API the system will save that value but only expose it to the modules once the pipeline restarts. This is to avoid a value from suddenly changing in the middle of the pipeline which some modules may not like nor expect. The same goes for reads, a copy of the entire variable table is saved and only updated after the pipeline is complete. Again, this is to avoid a sudden change of a value as it is being read via the API (you can imagine an array such as yours being updated midway through a read which would not be very good!).

So, in order to ensure that you are getting a new value one would use

rr.SetVariable "XX", YY
rr.WaitImage() - ensure that the value becomes visible to modules
rr.WaitImage() - ensure that the module has had a chance to run and set new variables
rr.GetVariable("ZZ")

which would ensure that the new value of XX is "seen" by a module and reacted on. Or one could also use

rr.SetVariable "XX", YY
rr.WaitVariableChange("ZZ", 1000)
rr.GetVariable("ZZ")

which would do the same thing.

3. In your case, I think what might be happening is that other Sample_Line modules in use are overwriting that variable that you expect to read. Since the vars to the API only get updated at the end of the pipeline you will always see the wrong value. Thus using your JScript should create a copy that will preserve the value from being overwritten. Note, using the Set_Variable module should also be able to make a copy if you'd prefer not to use a programming module.

Note that tabs can be expected even if not called when they have the "always run" flag set. See the tab properties on the far right and click on the '=' looking like icon to see those settings.

Let me know if any of the above helps ...

STeven.
Carl W Ott from United States  [11 posts] 7 year
Hi STeven,

thanks for the rapid and very helpful reply.  I was wondering about trying the VB module or one of the others to save the value at a known point in time, but then I saw your response.  I tried suggestion 1, and vuola, downloading the current 2.80.45 cleared up the JavaScript typecast issue - that part is now working exactly as expected - thanks.

I've been wondering about items 2 and 3 for some time, realizing that sooner or later I'd have to get more precise about synchronzing events between RoboRealm and my external code.  Your comments help quite a lot.  It makes complete sense that the API 'uses snapshots' and serves to decouple and synchronize external events with internal RoboRealm pipeline processing. But it will be a few days before I can dig into either of those approaches you mention & verify understanding...  

Meanwhile, after a quick review of my .robo code, I can say that:

- only the 'Main' tab runs all the time.  It's purpose is to 'listen for commands' via the API, and then call one of the several function tabs accordingly.  It does NOT have a Sample_Line module.

- there is a tab called 'Load_Course' that is only run when prompted via a call to the API, and it's purpose is to load in a static image of a somewhat complex line following course.  It does NOT have a Sample_Line module.

- there is a tab called 'Simulate_New_Robot_View' which is only run when prompted via a call to the API, and it's purpose is to return a new sub-image extracted from the overall line following course, based on rotation and translation deltas supplied via the API.  It does NOT have a Sample_Line module.

- each of the other function tabs have sample code where I am experimenting with different image manipulation approaches using different RoboRealm modules.  They are each executed only when called.  At this point in time, they are only 'called manually', when I manually select a function tab in the RoboRealm 'IDE'.  Although 3 of them do have exactly one copy of the Sample_Line module, I was only having one of those selected and active when I submitted this issue above. So I don't see how another instance of Sample_Line could be overwriting the desired instance; to my understanding, only the one desired instance of Sample_Line should be executing in this case - the other instances of Sample_Line in unselected function tabs should never be called.

- Based on my understanding of the RoboRealm processing pipeline, from reading documentation and observing behavior, it seems that as described in these pages,
--- http://www.roborealm.com/help/Getting%20Started.php
--- http://www.roborealm.com/help/Call.php

I can have
--- the 'Main' function tab looping indefinitely, so long as there is a source image change (or something e.g. Keyboard read event) to force pipeline evaluation
--- a separate function tab 'foo' selected and actively processing and updating the display in the RoboRealm IDE, even as the Main tab 'accepts commands' from the API and calls a different function tab 'bar'.  It is within the function tab 'foo' that I need to capture SAMPLE_LINE_POINTS for export via the API...

FWIW, I've been doing this in context of a hobby robot competition and a learning exercise for computer vision, node.js and express.  Since there is no native node.js API for RoboRealm, this exercise has also provided the additional opportunity to learn a little about sockets / XML.  Anyhow, the responses you gave for items 2 and 3 above should help harden and tighten up the node.js interface I'm writing - and reduce guesswork in synchronizing timing & events.  It's pretty sloppy right now, but maybe at some point this node.js interface could be worth sharing...

I intend to dabble with suggestions 2 and 3, and keep you posted...

Thanks!

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index