Bluetooth remote control from PC sample code?
Bluetooth remote control from PC sample code?
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.
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.
-
- Posts: 346
- Joined: 27 Sep 2010, 03:05
- Contact:
Re: Bluetooth remote control from PC sample code?
Are these the kind of things you're looking for?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++.)
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 --->
Re: Bluetooth remote control from PC sample code?
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.
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.
-
- Posts: 346
- Joined: 27 Sep 2010, 03:05
- Contact:
Re: Bluetooth remote control from PC sample code?
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:
With that, the PC code should work.
Steve
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;
Steve
---> Link to lots of MINDSTORMS stuff under my picture --->
Re: Bluetooth remote control from PC sample code?
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?
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
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
Re: Bluetooth remote control from PC sample code?
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?
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?
Re: Bluetooth remote control from PC sample code?
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.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?
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
Re: Bluetooth remote control from PC sample code?
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: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?
Short answer: Yes. Medium answer: It's the best you've gotkschaffer wrote: And, in practice, is it efficient to use these messages to read sensor values?
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
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
Re: Bluetooth remote control from PC sample code?
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?
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?
Re: Bluetooth remote control from PC sample code?
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
Who is online
Users browsing this forum: Semrush [Bot] and 0 guests