View unanswered posts | View active topics It is currently Thu Apr 24, 2014 2:53 pm






Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
High Level Bluetooth and RS485 functions? 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post High Level Bluetooth and RS485 functions?
hi,
how are the High Level RobotC Bluetooth and RS485 commands working?
The help is awfully bad!
Here are the corresponding NBC/NXC commands:

Quote:
http://bricxcc.sourceforge.net/nbc/doc/NBC_Guide.pdf

3.12. NBC/NXC Comm Module
The NBC/NXC comm module encompasses support for all forms of Bluetooth, USB, and HiSpeed
communication.

Code:
Module Constants      Value
CommModuleName      "Comm.mod"
CommModuleID         0x00050001
Table 57. Comm Module Constants

You can use the Bluetooth communication methods to send information to other devices
connected to the NXT brick. The NXT firmware also implements a message queuing or mailbox
system which you can access using these methods.

Communication via Bluetooth uses a master/slave connection system. One device must be
designated as the master device before you run a program using Bluetooth. If the NXT is the
master device then you can configure up to three slave devices using connection 1, 2, and 3 on
the NXT brick. If your NXT is a slave device then connection 0 on the brick must be reserved for
the master device.
Programs running on the master NXT brick can send packets of data to any connected slave
devices using the BluetoothWrite method. Slave devices write response packets to the message
queuing system where they wait for the master device to poll for the response.
Using the direct command protocol, a master device can send messages to slave NXT bricks in
the form of text strings addressed to a particular mailbox. Each mailbox on the slave NXT brick
is a circular message queue holding up to five messages. Each message can be up to 58 bytes
long.
To send messages from a master NXT brick to a slave brick, use BluetoothWrite on the master
brick to send a MessageWrite direct command packet to the slave. Then, you can use
ReceiveMessage on the slave brick to read the message. The slave NXT brick must be running a
program when an incoming message packet is received. Otherwise, the slave NXT brick ignores
the message and the message is dropped.

3.12.1. High-level functions

SendRemoteBool (connection, queue, bvalue, out result) Function
This method sends a boolean value to the device on the specified connection. The message
containing the boolean value will be written to the specified queue on the remote brick.
SendRemoteBool (1, queue, false, result)

SendRemoteNumber (connection, queue, value, out result) Function
This method sends a numeric value to the device on the specified connection. The message
containing the numeric value will be written to the specified queue on the remote brick.
SendRemoteNumber (1, queue, 123, result)

SendRemoteString(connection, queue, strval, out result) Function
This method sends a string value to the device on the specified connection. The message
containing the string value will be written to the specified queue on the remote brick.
SendRemoteString (1, queue, 'hello world', result)

SendResponseBool(queue, bvalue, out result) Function
This method sends a boolean value as a response to a received message. The message
containing the boolean value will be written to the specified queue (+10) on the slave brick
so that it can be retrieved by the master brick via automatic polling.
SendResponseBool (queue, false, result)

SendResponseNumber (queue, value, out result) Function
This method sends a numeric value as a response to a received message. The message
containing the numeric value will be written to the specified queue (+10) on the slave brick
so that it can be retrieved by the master brick via automatic polling.
SendResponseNumber (queue, 123, result)

SendResponseString (queue, strval, out result) Function
This method sends a string value as a response to a received message. The message
containing the string value will be written to the specified queue (+10) on the slave brick so
that it can be retrieved by the master brick via automatic polling.
SendResponseString (queue, 'hello world', result)

ReceiveRemoteBool (queue, remove, out bvalue, out result) Function
This method is used on a master brick to receive a boolean value from a slave device
communicating via a specific mailbox or message queue. Optionally remove the last read
message from the message queue depending on the value of the boolean remove parameter.
ReceiveRemoteBool (queue, true, bvalue, result)

ReceiveRemoteNumber(queue, remove, out value, out result) Function
This method is used on a master brick to receive a numeric value from a slave device
communicating via a specific mailbox or message queue. Optionally remove the last read
message from the message queue depending on the value of the boolean remove parameter.
ReceiveRemoteBool (queue, true, value, result)

ReceiveRemoteString (queue, remove, out strval, out result) Function
This method is used on a master brick to receive a string value from a slave device
communicating via a specific mailbox or message queue. Optionally remove the last read
message from the message queue depending on the value of the boolean remove parameter.
ReceiveRemoteString (queue, true, strval, result)

ReceiveRemoteMessageEx(queue, remove, out strval, out val, out bval, out result) Function
This method is used on a master brick to receive a string, boolean, or numeric value from a
slave device communicating via a specific mailbox or message queue. Optionally remove the
last read message from the message queue depending on the value of the boolean remove
parameter.
ReceiveRemoteMessageEx (queue, true, strval, val, bval, result)

SendMessage (queue, msg, out result) Function
This method writes the message buffer contents to the specified mailbox or message queue.
The maximum message length is 58 bytes.
SendMessage (mbox, data, result)
NBC Programmer's Guide

ReceiveMessage (queue, remove, out buffer, out result) Function
This method retrieves a message from the specified queue and writes it to the buffer
provided. Optionally removes the last read message from the message queue depending on
the value of the boolean remove parameter.
RecieveMessage (mbox, true, buffer, result)

BluetoothStatus(connection, out result) Function
This method returns the status of the specified Bluetooth connection. Avoid calling
BluetoothWrite or any other API function that writes data over a Bluetooth connection while
BluetoothStatus returns STAT_COMM_PENDING.
BluetoothStatus (1, result)

BluetoothWrite (connection, buffer, out result) Function
This method tells the NXT firmware to write the data in the buffer to the device on the
specified Bluetooth connection. Use BluetoothStatus to determine when this write request is
completed.
BluetoothWrite (1, data, result)

RemoteMessageRead (connection, queue, out result) Function
This method sends a MessageRead direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteMessageRead(1, 5, result)

RemoteMessageWrite (connection, queue, msg, out result) Function
This method sends a MessageWrite direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteMessageWrite (1, 5, 'test', result)

RemoteStartProgram (connection, filename, out result) Function
This method sends a StartProgram direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteStartProgram (1, 'myprog.rxe', result)

RemoteStopProgram (connection, out result) Function
This method sends a StopProgram direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteStopProgram(1, result)

RemotePlaySoundFile (connection, filename, bLoop, out result) Function
This method sends a PlaySoundFile direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemotePlaySoundFile(1, 'click.rso', false, result)


RemotePlayTone (connection, frequency, duration, out result) Function
This method sends a PlayTone direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemotePlayTone (1, 440, 1000, result)

RemoteStopSound (connection, out result) Function
This method sends a StopSound direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteStopSound (1, result)

RemoteKeepAlive (connection, out result) Function
This method sends a KeepAlive direct command to the device on the specified connection.
Use BluetoothStatus to determine when this write request is completed.
RemoteKeepAlive (1, result)

RemoteResetScaledValue (connection, port, out result) Function
This method sends a ResetScaledValue direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteResetScaledValue (1, IN_1, result)

RemoteResetMotorPosition (connection, port, bRelative, out result)Function
This method sends a ResetMotorPosition direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteResetMotorPosition (1, OUT_A, true, result)

RemoteSetInputMode (connection, port, type, mode, out result) Function
This method sends a SetInputMode direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteSetInputMode (1, IN_1, IN_TYPE_LOWSPEED, IN_MODE_RAW, result)

RemoteSetOutputState(connection, port, speed, mode, regmode, turnpct, runstate, tacholimit, out result) Function
This method sends a SetOutputState direct command to the device on the specified
connection. Use BluetoothStatus to determine when this write request is completed.
RemoteSetOutputState (1, OUT_A, 75, OUT_MODE_MOTORON,OUT_REGMODE_IDLE, 0, OUT_RUNSTATE_RUNNING, 0, result)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Thu Nov 06, 2008 5:01 am, edited 4 times in total.



Wed Nov 05, 2008 1:14 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: High Level Bluetooth and RS485 functions?
And why are you posting NXC commands in the RobotC forum? No offense, but you are going to get people confused. I'm tempted to delete this so people don't think these commands work in RobotC. I would not assume these commands work similarly to any of the RobotC commands.

Sorry for the gloom and doom, I'm just concerned.

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Nov 05, 2008 11:48 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: High Level Bluetooth and RS485 functions?
I think I wrote clearly enough that the quoted commands are NBC/NXC.

And the reason is, as I wrote:
I didn't find any RobotC overview on this subject, and
I'm looking for the RobotC commands corresponding to these NBC/NXC commands!

I guess actually most people know NXC much longer than RobotC. Coming from NXT-G to a first script language, NXC is supposed to be mostly the first step, and so these commands are mostly already well-known (to be exact, the excerpt above is from the NBC manual). But for those who didn't know that there are different C-based languages I highlighted "NBC/NXC" by a red color in my post above. Now I think there won't be any confusion any more.

I plainly thought:
Because NXC/NBC is a simple freeware and both RobotC and NXC are C-based,
for any function of the C-based freeware there should exist a kind of counterpart in the commercial product RobotC.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Nov 06, 2008 4:09 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: High Level Bluetooth and RS485 functions?
Hi Ford,

I think the red makes it much more clear, thank you. B-)

Looking at the NXC commands, there don't appear to be to many eqivilent commands to RobotC. NXC looks like they have functions to do some basic bluetooth master slave stuff while the RobotC commands give lower level bluetooth control, and you would have to write your own functions to do the master slave work.

Have you taken a look at the help files section: Bluetooth on the NXT?

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Nov 06, 2008 1:54 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: High Level Bluetooth and RS485 functions?
yes, I did, but I didn't find anything about BT network commands for 3 or 4 nxts , and I didn't find the requested information on any SendResponse... and/or SendRemote... commands.

As you may have noticed, I need those commands very urgently for building up a multiplexer network (by BT, or maybe also by RS485 - but BT seems to be easier because it's full duplex)!

Or can YOU give me a sample code for POLLING a sensor or CONTROLLING a motor at a 2nd or 3rd nxt by remote control commands?

I don't want any nxt to send all sensor values every 100msecs, that will lead to BT pollution - I want to poll the values by the master just in case he needs them
- OR -
the values need to be sent automatically by a BT slave to the BT master in case of values are somewhat critical, so that motors have to react to this (stop, turn,...).

The same is due to motor control.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Nov 06, 2008 2:06 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: High Level Bluetooth and RS485 functions?
Sadly I have only one NXT, I haven't been able to play around with any bluetooth examples.

I poked around and here is what I may try since RobotC is full duplex:

* Set up 3 bluetooth contacts on the master nxt, one contact for each slave nxt
* In the code, have the master connect to one slave nxt using btConnect(nPort, sFriendlyName)
* When you need to pole a different slave NXT, use btDisconnect(nPort) to disconnect that connection then reconnect to a different slave NXT on the contact list. Don't know how quickly it can do this, but I think it may be a start in the right direction.

Thats what I may try first, and then experiment and expand from there.

Also, I just noticed this sample program in the bluetooth folder: HS 485 LowLevel. have you taken a look at this file? Its in version 1.46.

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Nov 06, 2008 2:24 pm
Profile WWW
Rookie

Joined: Sat Oct 25, 2008 3:47 pm
Posts: 38
Post Re: High Level Bluetooth and RS485 functions?
Isn't the latest version available for NXT 1.45?
viewtopic.php?f=8&t=798


Thu Nov 06, 2008 3:09 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: High Level Bluetooth and RS485 functions?
There is a 1.46, it had some fixes for FTC users.

viewtopic.php?f=33&t=826

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Nov 06, 2008 3:16 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: High Level Bluetooth and RS485 functions?
HS 485 ? this is supposed to be the RS485 Highspeed communication, not BT!

And "switching" from 1 slave to another: how can I send a motor command to 1 nxt, and must not risk missing 1 message that has been sent by another one at this moment ? That really can't be the right way!
The BT master may be connected to 3 different slaves at the same time, and thus it has to be!

But you haven't answered to my real question:

Even if I had connected the master to only 1 of my slave nxts: how can I poll the slave's sensor values if I want, receive the slave's sensor values if they need to, and control the slave's motors?

If possible, show me a command like
SendRemoteNumber(...) to send a speific code to a slave (e.g. code=1001 for sensor value of S1)
and the linked command
ReceiveRemoteNumber(...) to receive the related sensor value
this answer is sent by the slave "automatically" as an answer, if he received the specific code, using the slave command
SendResponseNumber(...)?

But much easier it could be done if there existed commands like
int GetRemoteSensorValue(nxtID, port) or GetRemoteSensorValue(nxtID, port, &value)
and
SetRemoteMotor(nxtID, port, speed)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Nov 06, 2008 3:24 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: High Level Bluetooth and RS485 functions?
Quote:
how can I send a motor command to 1 nxt, and must not risk missing 1 message that has been sent by another one at this moment ? That really can't be the right way!


Yes this cannot be allowed to happen, that is why one NXT has to be a Master. The slave NXT's cannot use any bluetooth communication unless it it told to do so by the master. The master has to only communicate with one Slave at a time, or else messages will be lost and you no longer have a master slave setup. What you want is a peer to peer type of communication, and I don't believe the NXT bluetooth is capable of that.

Here is my vision of what this could look like:

* MASTER NXT connects to SLAVE A
* MASTER NXT tells SLAVE A to reply back its Sensor Values (Slave A should be poling its sensors when master is not communicating with it, will save time)
* SLAVE A replies its Sensor Values back to MASTER NXT
* MASTER NXT receives message and can then disconnect from SLAVE A to connect to a different slave

This is basically how the I2C communication with custom sensors works, the sensor only replies back when it is told to do so. I see this as doing the same thing, with the only differences is the wires are replaced with radio messages and the communication is between NXT's.

As for examples of how a bluetooth message should be sent or received, I would look into the sample programs and see what syntax they used.

Did this help? Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Nov 06, 2008 4:09 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: High Level Bluetooth and RS485 functions?
ok, I see your point of view,
but I don't understand anything written in the examples,
and I dont need and don't want 3 pages of code for just one command,

I need 1 single command for remote sensor polling,
and 1 command for remote motor control.


so now: where are the High Level BT commands like in NXC/NBC :?:

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Thu Nov 06, 2008 6:12 pm, edited 3 times in total.



Thu Nov 06, 2008 4:39 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: High Level Bluetooth and RS485 functions?
I found something you may be interested in poking through, there is a txt file in RobotC that has little descriptions of all the functions, these decriptions pop up when you scroll over the functions in the left hand side of RobotC. You can open the text file and look through the list and copy/paste the text if you need them translated.

C:\Program Files\Robotics Academy\ROBOTC for Mindstorms\Includes\BuiltInVariables.txt

As for the high level bluetooth commands, nobody has made any yet. I see this being another great community project too B-)

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Nov 06, 2008 4:51 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: High Level Bluetooth and RS485 functions?
(see my related threads: the community was not able to do this, and I guess: even will not be in future!)

But as I wrote some post above:
Because RobotC is a comercial product, one can expext that it has the same abilities and functionalities like a freeware product!

In NXC/NBC this has already been done by the developers.

So for RobotC, this has to be done by the developers, too!

(and I'm really terrified that it hasn't already been done by now!)

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Nov 06, 2008 4:52 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: High Level Bluetooth and RS485 functions?
Everything is there in RobotC to make these kind of libraries and drivers, I see the developers jobs at to make sure that the compiler, IED, and the low level library is working properly. Those are every users essential tools. But sometimes, the programmer has to make his own tools for his end application, and this Master Slave bluetooth I think is one of these examples. I would love to build a working driver for everyone, I just don't have a second NXT lol ;-).

I also agree with your point that this should be considered as a feature added, but it will come when it comes. Developers can only do so much at once ;-). My biggest reason I think the users should do it is RobotC is meant for teaching robotics and technology, and what a better way to learn it is to be confronted with a big problem, design and think your way through it and create something that is usefully for everyone in the end. This is a awesome opportunity for somebody out there to learn it for themselves, not have it done for them.

.... Man I wish I had a second NXT right now, I want to play with the bluetooth commands lol.

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Thu Nov 06, 2008 5:16 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: High Level Bluetooth and RS485 functions?
There's a big, big virtual market place in Germany, a grand invention, and I wonder why you don't have this in the U.S.?

Maybe new technologies need some time to come over the big ocean that devides us, but some day, when Americans accepted learning from Europeans, you may find this in the grand world wide web.

It will be called ebay (try to find this maybe by another big European virtual searching engine invention, called google), I recently purchased here 1 nxt brick for 56 EUROS (approx. 70 US Dollars).

In 10 years, when you'll be able to use google and ebay, too, it maybe will be even a little cheaper!

But consider: Maybe nobody will ever remember RobotC at that time if you'll wait so long to implement freeware functions to your commercial product...!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Nov 06, 2008 5:39 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 21 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.