We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › how to interface processing with roborealm
Page Index Toggle Pages: 1
how to interface processing with roborealm (Read 4169 times)
how to interface processing with roborealm
Jan 6th, 2010, 8:05am
 
Hi guys, I am new to processing and I want to interface HIM  Grin with roborealm. My goal is to send via serial something from roborealm to processing on the same computer. Someone told me to use a socket to open a virtual port from processing to roborealm.
I have no idea how to do it, someone coul'd help me?!?!?
Re: how to interface processing with roborealm
Reply #1 - Jan 6th, 2010, 10:41am
 
Sounds like you need to use the Serial library...
Re: how to interface processing with roborealm
Reply #2 - Jan 7th, 2010, 10:59am
 
I take a look to the library but i can't understand how to do.
My problem is that roborealm and processing are on the same computer, I have to create a virtual link trought those. I can't use the arduino comport to send directly data from roborealm to arduino because processing use arduino comport to receive data (example, if arduino see something from ultrasonic sensors send via serial "a", in processing if receive "a" say "oh an obstacle")
Re: how to interface processing with roborealm
Reply #3 - Jan 7th, 2010, 12:20pm
 
You're making assumptions about what we know about 'roborealm'.  I based my answer on your desire to "send via serial".  In actual fact assuming this page refers to the 'roborealm' you're on about then you'll probably want the Network library.  I'd guess you then just start a server in Processing on the same port as your roborealm API server and start sending it XML...
Re: how to interface processing with roborealm
Reply #4 - Jan 9th, 2010, 11:02am
 
Uao you open a new world to me. I can't understand how to read the xml file created and modified by roborealm from processing.
My goal is to write with roborealm a xml file and read it with processing, then send commands to arduino with processing. I have to use api or web server to do that? Is this an efficient choose to do what i have to do?
Re: how to interface processing with roborealm
Reply #5 - Jan 10th, 2010, 1:02am
 
I'm not that familiar with the Network library, but in principle, once you've established a network connection, it looks like you'd use the write() method to send a 'request' (see the "Getting the current image dimensions from RoboRealm" example on the page I linked).  That should trigger RoboRealm to send back a message which I assume you'd get with readString().  You can then interpret the XML using XMLElement.

It's probably worth downloading their API example files - it includes Java examples Wink
Re: how to interface processing with roborealm
Reply #6 - Jan 11th, 2010, 2:36pm
 
Hi guys!! I am messing out triyng to read a XML file with processing. How can I do it? I am able to create a XML file with roborealm, but I can't understand how to read it in processing...
Re: how to interface processing with roborealm
Reply #7 - Jan 11th, 2010, 2:52pm
 
like blindfish said Quote:
You can then interpret the XML using XMLElement.
http://processing.org/reference/libraries/xml/XMLElement.html
Re: how to interface processing with roborealm
Reply #8 - Jan 11th, 2010, 6:15pm
 
Ok I tried with xmlelement but i have some problem...

I do this, I know that is crap but i am not a programmer.


I do a simple program in rogorealm to detect the center of movement in front of camera. I take the x variable of this point and i write it on a a .txt file with this settings:
row delimiter: [CR] (what is this??)
column delimiter: comma
text qualifier: double quote

and then i read the file with processing:
Code:
   

lines = loadStrings("cogx2.txt");
println(lines);
index = index + 1;

with 12 framerate.

now i am blocked because I can't take only data without doublequotes and spaces, I think I have to use regular expression to takeout quotes and save only the variable. Anyone has some advise??

i tried something like:
Code:
if (lines > 400) {
leftservo.write(180);
rightservo.write(0);
delay(250);
}

(this would be right turn for 250 milliseconds if something moves on the right side of the camera)
but i can't do this because lines it is not only a variable...

my goal would be to send data to arduino from processing, and then write code that use processing data to react to movement
(rotate servos for example).
Re: how to interface processing with roborealm
Reply #9 - Jan 12th, 2010, 1:18am
 
gioblublu wrote on Jan 11th, 2010, 6:15pm:
<snip />
row delimiter: [CR] (what is this?)
column delimiter: comma
text qualifier: double quote
<snip />

now i am blocked because I can't take only data without doublequotes and spaces, I think I have to use regular expression to takeout quotes and save only the variable. Anyone has some advise?

<snip />


CR - carriage return perhaps
Column delimiter as comma should be fine
It might be useful if you could leave 'text qualifier' empty - since the way you're reading the data it's all coming through as a string anyway.

To clear out spaces use trim().  If you don't have any choice then to clear out the double-quotes you could use substring(), then indexOf() to get the position of the next double quote and substring again; though I suspect there's a more elegant solution...

To split the message into data just use split() on the commas:

Code:
for(int i=o; i< lines.length; i++) {
 String lineContents[] = split(lines[i], ',');
}


You'll then be able to access the values in each line from the 'lineContents' array - e.g. "lineContents[0]" for the first item.  That will give you a string so you're likely to need to convert to a suitable number format before doing anything with them...
Page Index Toggle Pages: 1