locked
How to determine when my lego NXT robot has stopped? RRS feed

  • Question

  • I would like to know when my lego robot has stopped moving.  For example I have code that calls drive distance.  I would like to know when the robot has finished driving that distance.

    I also have a related problem.  If have code to tell my robot to drive to coordinates (12, 7).  If I put an obstacle on its way to that coordinate it stops.  I would like to know the distance it travelled when it was stopped.


    I am doing this using C#.  I noticed a Drive State method in the Update class and thought this might work but could not get the notifications from the drive to fire.

    I also noticed a DriveEncodersUpdate in VPL with a number of methods that looked promising but I have been unable to access those in C#

    Any help on how to do this will be great.






    GradStudent
    Friday, January 25, 2008 11:36 PM

Answers

  • Unfortunately, DriveDistance and RotateDegrees are implementation-specific. I have requested clarification on several different "options" for these operations. One of these is when the response gets posted back to the caller. Some robots send the response when DriveDistance has finished, for example the Simulated Differential Drive that shipped with V1.5. However some send it as soon as the robot starts moving, like my implementation of the Simulated Diff Drive. This is not something that can be specified in a generic contract so there is no "official" way to do it.

     

    And then there are many robot implementations that simply do not support DriveDistance or RotateDegrees. It seems that if the robot does not have wheel encoders, then people do not bother with these services. However, I have implemented them using timers on the robot services that I have been writing. They are nowhere near accurate, but at least you can call an operation without getting a "Not Implemented" exception.

     

    Back to the original question. If the drive service is implemented properly, then you should be able to subscribe to it. Whenever the power changes on the motors you should get a message. This means that when the robot stops you should see a notification. However, once again, some authors have not followed this rule religiously.

     

    And lastly, the DriveState is supposed to reflect what the robot is doing but it seems that many implementations never set this particular state property.

     

    What you have highlighted is an area where everyone needs to pull together and make sure that their services conform. However, first we need agreement on how the services should behave!

     

    Trevor

     

    Thursday, February 7, 2008 8:48 AM

All replies

  • I had the same problem with the P3DX (actually the SimulatedDifferentialDrive, so I think both of us are using the same service - at least the same generic contract).

     

    In order to know when the robot has stopped I listen to the DriveUpdate notifications from the DifferentialDrive and check the wheels state (wheels velocity). I am doing now preliminary testing, so far it seems that the drive always sends an update message when the wheels are stopped after the DriveDistance operation is completed.

     

    Code Snippet

    using pxdrive = Microsoft.Robotics.Services.Drive.Proxy;

    [...]

     

    void DriveUpdateNotification(pxdrive.Update update)

    {

    pxdrive.DriveDifferentialTwoWheelState s = update.Body;

     

    int leftVel = VelocityFromWheel(s.LeftWheel);

    int rightVel = VelocityFromWheel(s.RightWheel);

    [...]

    }

     

    private int VelocityFromWheel(Microsoft.Robotics.Services.Motor.Proxy.WheeledMotorState wheel)

    {

    if (wheel == null)

    {

    return 0;

    }

    return (int)(1000 * wheel.WheelSpeed); // meters to millimeters

    }

     

     

    Maybe some of the methods you mention are not implemented in the concrete service you are using. Like RotateDegrees in the SimulatedDifferentialDrive...

     

    Wednesday, February 6, 2008 5:58 PM
  • Unfortunately, DriveDistance and RotateDegrees are implementation-specific. I have requested clarification on several different "options" for these operations. One of these is when the response gets posted back to the caller. Some robots send the response when DriveDistance has finished, for example the Simulated Differential Drive that shipped with V1.5. However some send it as soon as the robot starts moving, like my implementation of the Simulated Diff Drive. This is not something that can be specified in a generic contract so there is no "official" way to do it.

     

    And then there are many robot implementations that simply do not support DriveDistance or RotateDegrees. It seems that if the robot does not have wheel encoders, then people do not bother with these services. However, I have implemented them using timers on the robot services that I have been writing. They are nowhere near accurate, but at least you can call an operation without getting a "Not Implemented" exception.

     

    Back to the original question. If the drive service is implemented properly, then you should be able to subscribe to it. Whenever the power changes on the motors you should get a message. This means that when the robot stops you should see a notification. However, once again, some authors have not followed this rule religiously.

     

    And lastly, the DriveState is supposed to reflect what the robot is doing but it seems that many implementations never set this particular state property.

     

    What you have highlighted is an area where everyone needs to pull together and make sure that their services conform. However, first we need agreement on how the services should behave!

     

    Trevor

     

    Thursday, February 7, 2008 8:48 AM