Behavior programming

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Behavior programming

Postby Stone » Tue Apr 10, 2012 5:36 pm

Hi,
I'm trying to make a bot which travels from point A to B, and avoid obstacles on his way.
I did some research and came to the conclusion that behavior programming is the way to go.
So, the bot always moves forward unless it detects an object which his bumper (touch sensor) or ultrasonic sensor.
But the head has always to turn left - right - left - ... so it can see an object during the program. And when it detects something,
the tachoCount can see at what angle the object is so it can calculate the evasion.
And here's my question: How can I let the head turn left - right - ... continuously during the program execution, and let my program
execute the rest without writing in any block of code something like "rotate(720), rotate(-720)".

Here are two picture's of my bot so you can better imagine how it would work.

Image

Image

Thanks for reading! I hope anyone will answer my question.
Stone
Novice
 
Posts: 27
Joined: Tue Apr 10, 2012 4:29 pm
Location: Belgium

Re: Behavior programming

Postby gloomyandy » Tue Apr 10, 2012 5:47 pm

The easy way to do this is simply to use a separate thread for the scanning.... Simply create the scanning thread before you start the behaviour code...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4113
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Behavior programming

Postby Stone » Tue Apr 10, 2012 5:56 pm

Thank you for responding Andy.
Could you explain me how I can make a second thread, and execute them at the same time?
I knew it could because you could it in NXT-G, but I can't code it in java/ Lejos,
I'm quite new with java (first year industrial engineer) and haven't yet the experience with this.
(I'm already well known with object oriented programming.)

Gratz, Stone

Btw, I'm just new here and and I apologize in advance for the poor english. (Belgium :) )
Stone
Novice
 
Posts: 27
Joined: Tue Apr 10, 2012 4:29 pm
Location: Belgium

Re: Behavior programming

Postby gloomyandy » Tue Apr 10, 2012 6:05 pm

Hi,
Threading in leJOS is just standard Java threads, so you really need to understand how Java does this kind of thing... Take a look at these tutorials for a general background...
http://docs.oracle.com/javase/tutorial/ ... index.html
http://www.javabeginner.com/learn-java/ ... s-tutorial
Then maybe try writing a simple program with a couple of threads to get a feel for how it all works...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4113
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Behavior programming

Postby Stone » Wed Apr 11, 2012 10:06 am

Thanks
Stone
Novice
 
Posts: 27
Joined: Tue Apr 10, 2012 4:29 pm
Location: Belgium


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 4 guests

more stuff