Exchanging Messages Between Robots Via PC(GUI) : Ideas

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Exchanging Messages Between Robots Via PC(GUI) : Ideas

Postby win1for » Wed Jul 14, 2010 8:03 am

Hi Guys,

I have two robots and a GUI application running on a PC. The GUI is connected to the two robots. This means that the two robots can't directly exchange messages between them(because leJOS doesn't allow that).

Now i have to forward the messages via the GUI whenever one robot wants to talk to the other.

What i am now looking for is the best way to construct such messages so that the GUI can differentiate which messages belongs to it and which messages must be forwarded to other robots.

I am looking for ideas or the best way of how to construct such messages and also to be able to read them in the GUI so that it can send the right messages to the right robots and keep the messages that are for it to itself.


Thanks for your help.
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby tlaukkan » Wed Jul 14, 2010 9:52 am

Hi

It looks to me that you can connect form NXT to NXT as well with bluetooth:

http://lejos.sourceforge.net/nxt/nxj/tu ... ations.htm

You just need separate listener threads for different connections.

I would then use DataInputStream and DataOutputStream to transmit messages. First byte tells which message is in question and after that then custom stream reader implementation can read appropriate primitives from the stream.

Would be nice to see how your GUI looks. Post a screenshot :)

-tommi
tlaukkan
New User
 
Posts: 11
Joined: Wed Jul 14, 2010 5:45 am

Postby win1for » Wed Jul 14, 2010 10:01 am

Thanks for your reply but it is not possible to connect the GUI to the two robots and at the same time connect the robots to each other directly. Read the post below . Click the link below:

[url]
viewtopic.php?t=2249
[/url]


How do you construct the message whereby the first byte will tell the message in question? Can you please give me an example. I am very beginner in robot programming. So kindly give me a little example.

Thanks
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby tlaukkan » Wed Jul 14, 2010 10:54 am

Hi

You are correct, it seems that NXT is limited to only inbound connection. What if you initiate the connections from NXT to PC. Then you can use the one inbound connection to NXT to NXT connectivity?

I can try to show shortly how you can implement message transmission. I am in process of writing this kind of simple message transmission for my own needs and the source will be released as open source. I will post links to the source repository once I get something useful together.

I would implement the message transmission in this manner:

1) establishing connection
2) get the input data stream and output data stream
3) construct listener thread for reading messages from input stream (MessageReader)
4) construct object for writing messages to output stream (MessageWriter)

In message reader you can do the following (not tested code):

while(connected) {

byte messageType=inputStream.readByte();
if(messageType==MessageTypes.MessageA) {
MessageA messageA=new MessageA();
messageA.x=inputStream.readInteger();
messages.add(messageA);
} else if(...
...
}

}

In the message writer you can write the messages (not tested code):

public void writeMessage(MessageA messageA) {
outputStream.writeByte(MessageTypes.MessageA);
outputStream.writeInteger(messageA.x);
outputStream.flush();
}

-tommi
tlaukkan
New User
 
Posts: 11
Joined: Wed Jul 14, 2010 5:45 am

Postby win1for » Wed Jul 14, 2010 11:25 am

Thank you soo much for the example.

One last question. Don't be angry at me for this question please. I am a beginner that is why.

What kind of data type can i give to the writeByte() method? I have never used a byte data type before, that is why am asking.

If you like you can update your last post and include the byte data type for me.


Thanks soo much.
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby gloomyandy » Wed Jul 14, 2010 11:33 am

Just to clarify....

The hardware of the NXT limits Bluetooth to 1 inbound connection and 3 outbound connections. However the outbound connection can only connect to the first spp endpoint on the target device. This essentially means that you can not have two NXTs open connections to a PC at the same time (but you can have a PC open connections to multiple NXTs). In theory you could have PC connects to NXT A, NXT A connects to NXT B and NXT B connects to PC, but writing the code for a PC to accept a Bluetooth connection from the NXT is tricky and you will not be able to use the leJOS PC side classes. Also (again due to hardware issues) an NXT with more than one open Bluetooth connection is much slower than when only a single connection is in use (because the hardware has to be switched between the two connections)... Hence my recommendation to use the PC to pass messages between the two NXTs...

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

Postby tlaukkan » Wed Jul 14, 2010 11:42 am

Hi

Thank you Andy for the bluetooth information. Using PC as a hub sounds like a reliable messaging architecture especially if you need the PC connection to keep your robot running.

For message types I would use just byte primitives:

class MessageTypes {
public static byte MessageA=1;
public static byte MessageB=2;
.
.
.
}

-tommi
tlaukkan
New User
 
Posts: 11
Joined: Wed Jul 14, 2010 5:45 am

Postby win1for » Tue Aug 03, 2010 2:03 pm

Hi Guys,

Thank you all for your amazing replies. I still have one major question to ask concerning the actual messages been sent. In my case after i have sent the message type, i must send the actual message. Sometimes i have to sent an int after the message type, sometimes or in a different place in the program i have to send two int values after each other or sometime three int values after each other.

My question is how do i write the Message class so that it can accommodate different number of values that i have to send. Do i have to create for instance a Message class each for two integers, three integers etc..

Is there a way of creating one Message class that can accommodate sending different number of values.

Thanks.
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby Alshain » Wed Aug 04, 2010 7:46 pm

Why not send a number that indicates how many numbers to send at first? Then you can use it for any number of values.
Alshain
New User
 
Posts: 14
Joined: Sat Jan 02, 2010 1:48 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff