wood burning stoves 2.0*
The moose likes Java in General and the fly likes java robotics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java robotics" Watch "java robotics" New topic
Author

java robotics

michael spiker
Greenhorn

Joined: Sep 11, 2006
Posts: 5
I,m not sure if this is the correct forum, but here goes, I have a robot that uses a full pc using java. I want to scan the parallel port for input (bumpswitch) all the time, but I don't want it to interfere with rest of the program unless triggered. I tried a loop ...that was tragic. any help would be appreciated
ps sorry for the long post.
Tim Manchester
Ranch Hand

Joined: Nov 03, 2004
Posts: 62
Well there's more than one way to skin a cat (as I often think just after my cat pees on something), but here's what I'd do:

I'd create the main class where most of the application runs (let's call it MainClass just to be creative) and another class derived from the thread class to listen to the parallel port and report back to MainClass when it hears something. We'll call it ParallelListener just because I'm funny that way.

ParallelListener would look something like this:


The way you'd create a ParallelListener in your MainClass is straightforward:


Note that in the ParallelListener class, after getting some signal from the parallel port and decoding it's meaning, I'd call methods on the MainClass to take whatever action necessary to handle it (but that's just me).

Also, note that you shut down the ParallelListener thread by calling it's stopRunning() method like this:


*** Added the following to post ***
Note that programming robots can be tricky buisness, especially if you have to worry about real-time concern like collisions, time sensitive processes, etc (I used to program industrial robots awhile back). Polling for I/O needs to be done in it's own thread and that thread needs to share CPU time with everybody else or "Bad Things(tm)" will happen. Play with the timeing of the sleep command to get a balance between sharing the cpu and responsiveness to commands from the parallel port.

Java, while my favorite language is not the most effective choice for this sort of thing. May I ask why you chose it for programming a robot?
*** End of additional posting ***

I hope that helps.

Regards,

Tim Manchester

[ September 11, 2006: Message edited by: Tim Manchester ]
[ September 12, 2006: Message edited by: Tim Manchester ]
michael spiker
Greenhorn

Joined: Sep 11, 2006
Posts: 5
Thank you for the reply I'm going to work with this and see what more I can learn. I do not do robotics for any other reason, than my son and I get a lot of satisfaction from building something from scratch and having it work as intended. I am a metal fabricator by trade so I don't like to buy any more than I have to, and I want to teach my son that overcoming the challenges you face in the building is a lot more rewarding than just buying it off the shelf. As for my reason for using java, I find java intriguing to use and if it presents challenges then I can also learn something along the way as I try to overcome them. I have also given thought to using linux at a later date, and java will in some ways make the switch easier (I think). thanks again
Tim Manchester
Ranch Hand

Joined: Nov 03, 2004
Posts: 62
Rat's I've reread my post and I see a cut-and-paste error. Please pull the sleep() call out of the enclosing "if (iNdx >1)" and delete the if. It doesn't belong there. Sorry.

Regards,

Tim
 
wood burning stoves
 
subject: java robotics
 
Similar Threads
SCJD Candidates Motivation
i want java quetion
how to get sum for dynamic checkboxes
text field validations
java books