locked
Stop Lego NXT drive with Drop handle RRS feed

  • Question

  • Hi! I have a trouble stopping Lego Drive during Drop.

    For example I start motors at Start()

     

    protected override void Start() {
      base.Start();
    
      // wind up
      drive.SetDrivePowerRequest request = new drive.SetDrivePowerRequest(0.6, 0.6);
      Activate(
        Arbiter.Choice(
          _drivePort.SetDrivePower(request),
          delegate(DefaultUpdateResponseType ok) {
            LogInfo(LogGroups.Console, "Drive start success");
          },
          delegate(Fault fault) {
            LogError(LogGroups.Console, "Drive start failed");
          }
        )
      );
    }
    

    When the work is done I want to disable all motors.

     

    [ServiceHandler(ServiceHandlerBehavior.Teardown)]
    public new virtual IEnumerator<ITask> DefaultDropHandler(DsspDefaultDrop dsspDefaultDrop) {
      // stop all motors
      drive.AllStopRequest allStop = new drive.AllStopRequest();
      yield return Arbiter.Choice(
        _drivePort.AllStop(allStop),
        delegate(DefaultUpdateResponseType ok) {
          LogInfo(LogGroups.Console, "Drive stop success");
        },
        delegate(Fault fault) {
          LogError(LogGroups.Console, "Drive stop failed");
        }
      );
    
      // wait a little
      yield return TimeoutPort(TimeSpan.FromSeconds(10)).Receive();
    
      dsspDefaultDrop.ResponsePort.Post(DefaultDropResponseType.Instance);
      yield break;
    }
    

    But when press Ctrl+C I receive failure and the motors continue to work. I think that's because Lego Brick disconnect immediately after pressing Ctrl+C and the stop mesagge remains in drive port. Maybe someone knows how to stop the drive when finish?

    Wednesday, April 13, 2011 6:09 AM

Answers

  • I have also seen similar behavior (robot continues to drive when using ctrl-c to end a dsshost process.
    I am guessing that by the time the drop handler for your service is called the drive service may already have been torn down.

    What is the error you are seeing?

    I would try modifying the drive service so it performs an allStop during it's teardown, or possibly even having the lego brick service itself do that. 

    Note that if you do modify the sample brick or drive service I would first make a backup copy of the src (you can re-install to get back to the original source but that is a hassle) and the service you are modifying is the "(user)" version, so you will need to use that in your manifest and and partners will then also have to be the "(user)" versions.

    Wednesday, March 14, 2012 5:00 PM