Bluetooth remote control from PC sample code?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
kschaffer
Posts: 11
Joined: 21 Dec 2010, 15:40

Bluetooth remote control from PC sample code?

Post by kschaffer »

Hi, I'm using the BricxCC environment. I've been searching for several hours looking for an example of remote-controlling the NXT from C++ code on the PC. Ideally the NXT side uses NXC in the BricxCC environment, and the PC side written in C or C++ (currently I'm using MS Visual Studio Express C++.)



I've found several phone-to-NXT (!) examples of control, but want to do this from the PC (AI, turnaround time, etc. I've written Bricx programs that store a log file on the brick, which I then download and analyze later, but I really need live interaction.)

I would prefer, at this time, to not put an alternative OS on the brick.

Ideally, the example:

- On NXT, uses something written in NXC in BricxCC.
- On PC, any C or C++ code will do -- I'm just using MS Visual Studio Express (C++)
- Uses Bluetooth, though I could switch back to USB hardwire if that's the only example available.




ETA: I will also be passing back sensor data, but that should not be hard to add on since it's all messages.
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Bluetooth remote control from PC sample code?

Post by hassenplug »

kschaffer wrote:Hi, I'm using the BricxCC environment. I've been searching for several hours looking for an example of remote-controlling the NXT from C++ code on the PC. Ideally the NXT side uses NXC in the BricxCC environment, and the PC side written in C or C++ (currently I'm using MS Visual Studio Express C++.)
Are these the kind of things you're looking for?

http://code.entersources.com/f/Communic ... 172_0.aspx

http://www.codeproject.com/KB/cs/nxtBluetooth.aspx

Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
kschaffer
Posts: 11
Joined: 21 Dec 2010, 15:40

Re: Bluetooth remote control from PC sample code?

Post by kschaffer »

Sort of -- however those:

1. Use the graphical NXT-G stuff to provide the brick-side part
2. Relies on a .Net SerialPort object for the serial port, PC-side. Their code does not compile as it cannot find any of that stuff, even though I am using MS Visual Studio Express.

It is, of course, all the overhead with opening the serial port *on both sides* that is the big sticker here. Once I can chat both ways, I can handle the rest.
hassenplug
Posts: 346
Joined: 27 Sep 2010, 03:05
Contact:

Re: Bluetooth remote control from PC sample code?

Post by hassenplug »

For the communication to work, it shouldn't matter to one end (the PC) what type of software is running on the other end (NXT).

So, you should be able to run any NXT software with the PC code listed. (the fact that you may not yet know what to do on the NXT is a different matter).

The serial port object is in the system.io.ports class. Make sure you code has this at the beginning:

Code: Select all

using System.IO.Ports;
With that, the PC code should work.

Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: Bluetooth remote control from PC sample code?

Post by linusa »

Check this: https://sourceforge.net/apps/phpbb/mind ... ?f=3&t=181

Also, google "Mindsqualls" and "NXT++" and "libnxt" and "aNXT". Some remote control packages. You don't necessarily need "client code written in NXC or NXT-G".

What do you want to do?
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
kschaffer
Posts: 11
Joined: 21 Dec 2010, 15:40

Re: Bluetooth remote control from PC sample code?

Post by kschaffer »

Ok I have that working, I think anyway. Next step is to read the serial port on the NXT using BricxCC.


So do I want to open a serial port (on the NXT) and receive my own messages? Or am I sending (from the PC, over the serial port) the Bluetooth-encoded messages (e.g. PLAYTONE, SETOUTPUTSTATE, etc.)? What's over there on the NXT listening and processing these?


And, in practice, is it efficient to use these messages to read sensor values?
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: Bluetooth remote control from PC sample code?

Post by aswin0 »

kschaffer wrote: So do I want to open a serial port (on the NXT) and receive my own messages? Or am I sending (from the PC, over the serial port) the Bluetooth-encoded messages (e.g. PLAYTONE, SETOUTPUTSTATE, etc.)?


What's over there on the NXT listening and processing these?


And, in practice, is it efficient to use these messages to read sensor values?
You can choose either of these methods. What you call Bluetooth encoded messages is called Direct commands. They are processed by the firmware without a user program in between. The other way uses just messages, a subset of Direct commands actually. But then it is up to your program to read and process these messages. The first method gives more programming on the pc and latency problems (NXT-G: 13 msg/s, robotc 250 msg/s, others:?). The second method gives more programming on the NXT, less latency problems. But it requires you to think about the right platform for the different parts of your program.

I tend to go for messages. I keep sensory processing and motor processing on the NXT as well as basic behavior. Will, memory, intelligence I implement on pc. Not al my robots have the latter ;-)

Info on direct messages can by found on the Lego extreme website under Bluetooth.
My blog: nxttime.wordpress.com
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: Bluetooth remote control from PC sample code?

Post by linusa »

kschaffer wrote:So do I want to open a serial port (on the NXT) and receive my own messages? Or am I sending (from the PC, over the serial port) the Bluetooth-encoded messages (e.g. PLAYTONE, SETOUTPUTSTATE, etc.)? What's over there on the NXT listening and processing these?
Yes, you are sending those messages (or direct commands, was was correctly stated above). You can implement all of this on your own, or you can look at other implementations and modify their ideas, or just use their code directly. Look for the keywords I posted above, they all do it this way. If you aren't limited to C++, there are many more packages.
kschaffer wrote: And, in practice, is it efficient to use these messages to read sensor values?
Short answer: Yes. Medium answer: It's the best you've got :-)
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
kschaffer
Posts: 11
Joined: 21 Dec 2010, 15:40

Re: Bluetooth remote control from PC sample code?

Post by kschaffer »

Ok, since I already have sensor-gathering and analysis built to run on the NXT, I think I would like to just pipe it to the PC rather than use the PC to request the data.

So...on the NXT, using a BricxCC-generated program, let's say I have a string to send (flattened-var of struct, but that's beside the point).


string myData = mysteryFunctionToSendItToTheSerialPortOnThePC(myData);


What are the actual line(s) I want to replace "mysteryFunctionToSendItToTheSerialPortOnThePC" with?
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: Bluetooth remote control from PC sample code?

Post by aswin0 »

I do not use BrickCC or NXC myself so I wouldn't know. But check the NXC manual for "Comm module functions".
My blog: nxttime.wordpress.com
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests