locked
Controlling NXT using C# RRS feed

  • Question

  •  

    Calling professionals!

    Is there any site or blogs that could provide tutorial or examples on creating a simple program controlling NXT using C#2005?


    Thanks In Advance!

    Tuesday, July 15, 2008 5:00 AM

Answers

All replies

  • Correct me if I am wrong but doesn't MSRS Robotics Tutorial #6 control a Lego NXT?

    Tuesday, July 15, 2008 12:29 PM
  • Hey thanks Bryan,

     

    however, the tutorial isn't clear on the instructions. It provides more explanations on what is implemented and why is it so. Issues regarding where to paste the codes like editing the serial ports had caused me to stuck at the moment.

     

    Step 1: Create an Onboard Remote Communication Interface

    Your robot requires code that supports remote communication interface with the state of the robot's sensors and motors. This code must run on the robot itself. If your robot already supports a communication interface, you can skip this step.

    If your robot does not include a communication interface, you need to create this code using the development tools available for your robot. This code should monitor the sensors for changes and send a message back through its remote communications interface with the PC accordingly. It should also handle incoming motor requests properly. This code should run in a tight loop.

    Should i say this step is redundant? I'm not sure what this whole chunk of information is trying to say. Doesn't an Lego NXT includes and supports a communication interface?
     

    Step 2: Create a Hardware Interface

    Now focus on the code that runs on the PC. That code must communicate with the remote interface of your robot. Some of our services perform the hardware interface in a helper service or C++/CLI library. This tutorial assumes that this is not the case for your robot and the hardware interface occurs in the same service as your "brick" service (called MyBrickService). A brick service can be thought of as the Microsoft Robotics Studio abstraction of your robot. Its state should contain the latest motor and sensor information for your robot.

    The LEGO NXT uses a Bluetooth interface. When the Bluetooth connection is made, it appears as another serial port to the PC. Snippets of code involved in reading and writing to the serial port appear below. The two most important parts of this step are to make sure your permissions are set properly, and handle incoming messages from the serial port in the proper location.

    Set up the serial port.

    Focus on codes? I couldn't find any My Brick Service in the entire list from the tutorial itself. Setting up the serial port is also a big question mark..
     
    SerialPort serialPort = new System.IO.Ports.SerialPort();

    void Open(int comPort, int baudRate)
    {
        serialPort = new SerialPort("COM" + comPort.ToString(), baudRate);
        serialPort.Encoding = Encoding.Default;
        serialPort.Parity = Parity.None;
        serialPort.DataBits = 8;
        serialPort.StopBits = StopBits.One;
        serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
        serialPort.Open();
    }

    //Send data that your robot understands
    void SendData(byte[] buffer)
    {
        ...
        serialPort.Write(buffer, 0, buffer.Length);
    }
    Where do i insert these codes to? The instructions are very very unclear.=(
    Tuesday, July 15, 2008 1:48 PM
  • You are right, and Robotics Studio can control more services (real or simulated) with C#.

     

    The only thing to keep in mind is that Robotics studio runs on a PC and sends commands to the Lego NXT directly. So there is no C# program running on the Lego NXT.

     

    Erik

     

    Update:

    There is already a "Brick" for connecting to the Lego NXT hardware, so no need to write this!

    Tuesday, July 15, 2008 1:49 PM
  •  

    Yeah.. thanks for the many advices!

     

    however, my issue of controlling using C# either a PC or not is not the main focus.

     

    I'm currently running VS 2005 C# on a Laptop with Bluetooth.

     

    I just need help or guidance on controlling or sending a program to NXT and make it move..

     

    Anyone care to lend a helping hand?? =)

    Tuesday, July 15, 2008 2:04 PM
  •  

    - First, make sure the Lego software works over bluetooth to connect to the NXT

     

    - Make sure the NXT has the newest firmware (1.05 I guess, it will take a few minutes to update, so keep waiting)

     

    - Edit MSRS\\samples\Config\LEGO.NXT.Brick.Config.xml and enter the right COM port

     

    - Start from the DSS Command prompt:

    Code Snippet

    dsshost /p:50000 /m:samples\config\lego.nxt.brick.manifest.xml

     

     

     

     

    That is the right order to get everything started. Make sure you do this in this order. You will see a browser window pop up with the connection details.

     

    Erik

    Tuesday, July 15, 2008 2:13 PM
  • yeah, i've done the already. It should be the same one as VPL. i'm currently stucked after bluetooth stage. How C# sends program to NXT

     

    Tuesday, July 15, 2008 3:37 PM
  • Not sure which step you are in, so I assume you

    1) have the Lego working with the Lego software

    2) updated with the NXT to 1.05

    3) changed the .config file

    4) start the manifest

     

    When MSRS starts, a "Brick" service is created. This service communicates DIRECTLY with the NXT, so when you create a C# program, that program sends commands to the Brick service (still on the PC).

     

    The Brick service will then transmit the command via bluetooth to the NXT, as a direct command. So no C# is ever send to the NXT.

     

    Erik

    Tuesday, July 15, 2008 7:29 PM
  •  

    Thanks Erik,

     

    i'm not too sure which stage i'm in as well..

     

    1) have the Lego working with the Lego software

     

    What do you mean by working with the software? MSRS?

     

    2) updated with the NXT to 1.05

     

    My NXT version is 1.01.. How to upgrade to 1.05?

     

    3) changed the .config file

     

    May i know where and how to change the config file? i'm like totally noob LOL

     

    4) start the manifest

     

    Start the manifest using VPL? which programme?

    Wednesday, July 16, 2008 5:19 AM
  • There is a LOT of information in the Robotics Studio Documentation, installed on your machine.

     

    For step 2, read the Lego manuals, and check out this:

    http://msdn.microsoft.com/en-us/library/bb483027.aspx

     

    And then start the VPL tutorials from here:

    http://msdn.microsoft.com/en-us/library/bb870550.aspx

     

    For step 3, if you use Robotics Studio 1.5, a browser will open and allow you to set the COM port

     

    Step 4 is starting a program (e.g. DSSHOST, look above in this conversation, or a VPL program)

     

    Erik

    Wednesday, July 16, 2008 7:20 AM
  •  

    For Step 2, My lecturer said there isn't any MINDSTORM cd available. So i guess its not possible for me to update my filmware. Is it a must anyway?

     

    I've already started VPL ages ago, i'm implementing C# or any other languages like C++ or VB now.

     

    The nxt is able to communicate with my laptop with bluetooth. I've run VPL Tutorial 4 test on the NXT. Its working fine.

     

    Step 4, So do i start a DSSNODE? Any clearer instructions or should i open COMMAND PROMPT from MSRS? VPL meaning to just open a empty VPL?

     

     

    Thanks!

    Wednesday, July 16, 2008 8:31 AM
  • My Lecturer advised me on working on this site:

     

    http://channel9.msdn.com/playground/Sandbox/256505-C-Robotics-Tutorial-4-for-Microsoft-Robotics-Studio-15/

     

    I've downloaded the files and i opened the html document teaching me the implements of services used in the tutorial.

     

    After a whole day of reading and trying to understand, i build the tutorial and it was a success.

     

    However, after its been built, what do i do next?

    i've tried running the debugger, it prompts me:

     

    "Executable For Debug Session"

    Please specify the name of the executable file to be used for the debug session.

    Executable file name: ???

    URL where the project can be accessed (ATL Server Only):

     

    Anyone to help?
    Wednesday, July 16, 2008 8:37 AM
  • Read everything in the Robotics Studio Documentation!

     

    There is a Robotics Tutorial 1 (C#)

    http://msdn.microsoft.com/en-us/library/bb483050.aspx

     

    This will show everything.


    Erik

    Wednesday, July 16, 2008 8:45 AM
  •  

    Oh no man... i was stucked there! =( any quotes from there? more specific instructions as i can't understand those stated in the page...

     

    As in less general terms =)

    Wednesday, July 16, 2008 8:49 AM
  • in the windows explorer, go to MSRS\samples\RoboticsTutorials\Tutorial1\CSharp directory

     

    open RoboticsTutorial1.SLN with Visual Studio

     

    Compile and Run (press F5), that one should work, with all the code form tutorial 1 already included! Compare this code to your code from robotics tutorial 1.

     

    Wednesday, July 16, 2008 9:29 AM
  •  

    oh my god.. my tutorials don't have .sln files!

     

    meaning  i don't have solutions!

     

    anyone can help?

     

    how to generate solution files?

    Monday, July 21, 2008 11:28 AM
  • My only problem with you post is that you stated .. Calling professionals!

    I AM NOT ONE by any means! AND THEN SOME! Self taught and probably wrong everywhere there is code. But it works fer' me.

     

    I have some 'so called C# code' using the Mindsqualls Library for the NXT.

     

    I posted in Google Open Source... I HOPE I got the correct link..

    http://code.google.com/p/nxtmindsquallscollectionofcode/ 

     

    Old man here and I get lost very easy! Go to downloads tab. Two ZIP files.. You said 2005.. Get the 2008.. Gee.. it's free~

     

    Most of the code was made on Express 2005 but changed to 2008 when I posted the code so I am not sure the templates will work on 2005. Or even the code. I would think so?

     

    Have fun!

     

    Sunday, July 27, 2008 9:04 AM
  •  Erik Oppedijk wrote:

    in the windows explorer, go to MSRS\samples\RoboticsTutorials\Tutorial1\CSharp directory

     

    open RoboticsTutorial1.SLN with Visual Studio

     

    Compile and Run (press F5), that one should work, with all the code form tutorial 1 already included! Compare this code to your code from robotics tutorial 1.

     



    Is there anything mentioned about what to do on the browser which is opened along with the dsshost?
     
    Friday, August 15, 2008 1:35 AM
  • Are you asking about the web page for configuring the LEGO NXT V2 services?

     

    Please open a new thread with your question. This one has become a little confusing.

     

    Trevor

     

     

    Friday, August 15, 2008 3:21 AM