locked
Lego NXT Motor Degrees RRS feed

  • Question

  • Is there any way to control my LEGO NXT using exact degrees? 

    What I have been attempting is using a data block to a NXT block with a SetMotorRotation. In the Data block i Include the degrees as an Int. In the Data Connections I set the TargetPower as .4 then set RampUp as false. StopAfterDegrees as Value. StopAfterRotations as 0. StopState as MotorStopState.Brake. The result is sporadic at best. Often it pauses for a while then shoots in a direction and doesn't stop at the degrees I specified.

    Also...Using VPL is it possible to create a very long step by step program? For example...Move motor 1 then move motor 2 then move motor 3 then move motor 2 then move motor 3...and so on and so forth...

    Also...How is everyone programming with code? I haven't seen any files that were generated by VPL that could be opened with Visual Studio. 

    Monday, June 18, 2012 2:09 AM

Answers

  • The answer is yes and no. 

    It is not a native/built-in feature of the sample Lego motor service, but the Lego NXT motors have excellent encoders with 360 tick resolution and the service does provice the means to monitor the tick updates coming from the motor and so in theory you could move a specific number of degrees (ticks).

    I would be a more advanced project to create such a service, but not impossible.  If you do, please do share with the community.

    Also note that there is a "RotateDegrees" feature of the GenericDifferentialDrive service that uses setting for the wheel diameter and distance between wheels to enact the turns.  It does use the encoders to do this. You might find that helpful by itself, or use the sample code as a starting point for creating your service.

    The code for the drive is in samples\common\drive

    The line to look at for how the rotate is performed is 450.

    • Proposed as answer by Gershon Parent Tuesday, July 3, 2012 4:41 PM
    • Marked as answer by Stryker7 Friday, July 6, 2012 2:49 AM
    Tuesday, July 3, 2012 4:41 PM

All replies

  • Sorry, I don't have any LEGO hardware so I can't help on the degree problem.  

    As far as a step-by-step program; as you have probably noticed, VPL is different than other visual languages because it is message based and asynchronous.  This has the interesting effect of making some simple things harder, but the benefit of making some very complicated things much easier.  There is a great tutorial in VPL for a step-by-step program which should help you understand this new way of programming.  In VPL, click on Help, then select "Hands on Labs", the tutorial "Drive in a square" should help.  

    If you would like to see some C# code generated by VPL, place an Activity block in your diagram area and double click to open it.  Place your VPL code inside this activity block.  You can place it in the default area, or add additional actions within that block.  When you are done, select "Build" --> "Compile as a service" and you will create a new service which you can see after you refresh your services (View --> Reload Services).  This also generates C# code which you can open and modify.  

    Monday, June 18, 2012 9:09 PM
    Moderator
  • You said that you wanted a template for a step-by-step for a traditionally synchronous technique expressed as a dataflow template.  If the "Drive in a square" tutorial doesn't answer your questions, I would suggest that you buy the WROX book on Microsoft Robotics Studio

    http://www.amazon.com/Professional-Microsoft-Robotics-Developer-Programmer/dp/0470141077/ref=sr_1_2?ie=UTF8&qid=1340895069&sr=8-2&keywords=microsoft+robotics+developer+studio+4

    And read the appropriate chapters -- a couple of times.  I did, and still refer to it to completely understand the environment.  This is NOT a simple programming toolset, but if you are willing to expend the effort, it is well worth it. 

    Thursday, June 28, 2012 2:52 PM
    Moderator
  • Thanks for your answers they've been very helpful but I'm really interested in knowing whether I can control the NXT using exact degrees.
    Sunday, July 1, 2012 5:08 AM
  • The answer is yes and no. 

    It is not a native/built-in feature of the sample Lego motor service, but the Lego NXT motors have excellent encoders with 360 tick resolution and the service does provice the means to monitor the tick updates coming from the motor and so in theory you could move a specific number of degrees (ticks).

    I would be a more advanced project to create such a service, but not impossible.  If you do, please do share with the community.

    Also note that there is a "RotateDegrees" feature of the GenericDifferentialDrive service that uses setting for the wheel diameter and distance between wheels to enact the turns.  It does use the encoders to do this. You might find that helpful by itself, or use the sample code as a starting point for creating your service.

    The code for the drive is in samples\common\drive

    The line to look at for how the rotate is performed is 450.

    • Proposed as answer by Gershon Parent Tuesday, July 3, 2012 4:41 PM
    • Marked as answer by Stryker7 Friday, July 6, 2012 2:49 AM
    Tuesday, July 3, 2012 4:41 PM
  • That good comments, here I can contribute them with the instructive one to form lso services of the NXT http://social.technet.microsoft.com/wiki/contents/articles/12955.microsoft-robotics-developer-studio-tutorial-en-espanol.aspx
    • Proposed as answer by Antonio Najarro Wednesday, October 31, 2012 2:39 AM
    Sunday, August 12, 2012 8:21 PM
  • Waiting to continue reaching I place another link to be able to form the sensor of lay sound, wait could serve them

    http://social.technet.microsoft.com/wiki/contents/articles/12990.test-sound-sensor-en-mrds-es-es.aspx

    @ltheux

    • Proposed as answer by Antonio Najarro Wednesday, October 31, 2012 2:39 AM
    Tuesday, October 30, 2012 10:06 PM
  • hi Stryker,i meet this problem,have you solve this problem ?please help me  
    Tuesday, November 25, 2014 2:51 AM