It's official! You can talk to lego robots with Cold Fusion!!! Many many thanks to Jeremy Allaire and Jody Zhang for tips, many thanks to the LeJOS team for writing the Mindstorms JVM. Most of all, thanks to the guy who wrote the RCXDirect package, Tim Rinkens! You can read more about Tim Rinkens' wonderful java package here: http://rcxtools.sourceforge.net/rcxdirect/e_index.html
I think the high point of the day was when I sent my browser to http://localhost:8500/webrover/test.cfm , and my robot suddenly smacked into the wall on other side of the room. It scared the heck out of my cat! *sniff* The little webrover is all grown up and running around :)
For anyone interested in how I finally hacked the code to send a command from a Cold Fusion webpage to a Java object to my Lego robot, keep reading...
There are two ways to communicate with the lego via I-R. The first way is to write your own protocol and use the java.io package in the lejos operating system. The second way is to use a pre-written toolkit called "RCXDirect". I'm going with rcxdirect because it's perfect for remote control. However, RCXDirect requires a binary executable written in C, called "rcxsend.exe", as well as cygwin.dll. Under ordinary circumstances, you just put a copy of the rcxsend.exe into any java application that requires rcxdirect. When I rebooted everything and ran my code in a .cfm page, the code would try to contact the IR tower but nothing happened. It wasn't until I got into DOS, ran the cfstart.bat to force all system messages onto the screen, that I saw the following message:
Program "C:\CFUSIO~1\runtime\servers\default\rcxsend.exe" not found!
RCXDirectConnect: motor packet: failed
05/17 12:55:10 user FileServlet: init
So, I put a copy of rcxsend.exe and cygwin.dll into that directory. The motors start revving up now, but I wondered about the purpose of this default folder. I downloaded from sourceforge the source code which creates the infra-red connection, and figured out how the original programmer found the path to rcxsend.exe:
private static String sendPATH = System.getProperty("user.dir") +
((new File("rcxdirect")).isDirectory() ?
(File.separator + "rcxdirect"):"");
According to the java API docs, "user.dir" is a System property which returns a string path to user's current working directory. But why is "runtime/servers/default" the current working directory? I opened up the cfstart.bat file, and saw these commands:
setlocal
cd ..\runtime\servers\default
..\..\bin\jrun -start default
endlocal
I can think of three easy ways to run executable files from cold fusion: 1) Put all executables in a common directory and add the directory to your PATH environment variable (in Windows). 2) Modify the batch file to start from a custom directory, such as "runtime\servers\samuel_stuff" 3) If you're using java, just modify the path instead of relying on System static properties. I think option #2 is probably safer, since you won't have to make any changes to the environment variables or the actual code.
Conclusion: The debugging feature works really well in CFMX, but if you want to see more descriptive system messages about your Java code, you should run the batch file from command line rather than double-clicking on the batch file. Anyways, I hope I can claim dibs on being the first person to hook up a mobile robot to Cold Fusion :)
I will upload code and instructions soon. For now, must finish working on the book.
***Sam does a funky victory dance with his robot***
Posted by samuel at May 17, 2002 06:44 PMreally cool stuff sam.
pictures! we need pictures!
Posted by: Mike Chambers at May 18, 2002 01:59 AMyou are insane...really.... howd u ever think of controling a lego robot from a website?
now u gotta put a webcam on the robot so u can really navigate the beast from the website...
judging by what uve done...i think ull have the webcam part done pretty soon....
great stuff man....
im thinking..how hard would it be to write a small java socket server to run on a host on a random port. You talk to this server and it talks to the lego? that way any flash movie can do this as well. i wouldnt mind helping..i just wrote a decentralized socket server for flash in java and find this really interesting....
lemme know..
again great stuff man
nik
Posted by: nik at May 18, 2002 09:57 PMHey Mike, got to finish the book first :) Ironically, I had to choose between buying the Mindstorms kit or buying a digital camera for my summer budget. I'll post some pictures next week with another person's digital camera, hopefully with a working Flash interface by Friday!
Nik, a wireless camera is all part of the plan! I've already decided on an X10 package I want to buy soon. As far as socket server goes, it's possible to simply write a java server and control the robot directly that way. However, it would be difficult to put the video stream and robot controls in the same interface. I'm going to use some technology that hasn't been announced by Macromedia yet, combined with ColdFusion/JRun.
Hopefully, they'll announce that stuff so I can showcase the live control. Otherwise, I'll just post the regular Java and Cold Fusion code and wait until later to do the video stuff.
Posted by: Sam at May 18, 2002 10:09 PMhey again Sam,
I'd love to see how you did all your coldfusion to rcx stuff.
Our bot is not that impressive, and the reason why i had access to lots of mindstorms stuff is that friends of mine did a lego robotics workshop where we could use a lot of lego packages.
Since they still have those we're thinking of starting some lego robots hobby club (That should be nice :) ).
I can't show any pictures right now, but if they are online i let you know.
I'm very interessted in the fact of controlling the robot through the net, so i will definitly have a look at lejos and java for the controlling. I hope i can fix something up using ASP or PHP instead of Coldfusion ( I don't have access to a Coldfusion server). Please let me know when or where i can have a peek at your code. If could help you in any way, just let me know.
My friend is going to the dorkbot nyc meeting on june 5th, they hope to be showing some bots there. So if you're in the area just drop in to have a look. http://dorkbot.org/
cya, heXman
Posted by: heXman at May 19, 2002 01:47 PMcant wait to see it finished :-)
difficult eh? now i feel like doing the server just cause u said its difficult :-)
hmm... making a video streaming server would be interesting...
nik
Posted by: Nik at May 19, 2002 11:15 PMThat is an inspiring idea. Maybe you should put a webcam on the thing and drop it into a fishtank ;-)
Posted by: Daniel Wabyick at May 20, 2002 09:09 PMhey cool
I did it with flash and javascript, check the link!
regards
Henrik
Posted by: Henrik at May 31, 2002 10:10 PMand here it is :-)
http://www.zapoo.dk/webbi/rovset1.htm
Posted by: Henrik at May 31, 2002 10:11 PMhi samuel van, well i read ur article on net, well i am doing a project related to robotics and i was thinking that if u can help me with ur ideas,i amthinking to use a webcam and a digital camera to guide my robot its a mobile robot,the problem is if ican download the pictures from the preset software programe of the digital camera to my application software in c,and is it possible to download the pictures from the webcam to my application programme in C or will sherlock32 will help me communicating with my webcam or digital camera.My problem basically is that i need some serious help regarding this and i hope u can help me with that..pls contact me
chao!!!
Hi, I just wanted so say thank you guys ! i really like your site and i hope you'll continue to improving it.
Posted by: viagra at January 25, 2004 12:04 AM