Vehicle Forward method

HomeForumsMonoBrick EV3 FirmwareVehicle Forward method

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #4903
    Author Image
    lemuus
    Participant

    Hi,

    I was playing a little bit with MonoBrick, and I noticed that when I use this method:

    void MonoBrickFirmware.Movement.Vehicle.Forward ( sbyte speed )

    The motors start running, but the method never returns, so you end up blocked in that call.
    Is that the expected behavior? I would have thought that the idea of the method was to left the motors running at the given speed and return, to do for example, something like this:

    
    var sensor = new EV3IRSensor(SensorPort.In4);
    Vehicle vehicle = new Vehicle (MotorPort.OutB, MotorPort.OutC);
    vehicle.ReverseLeft = false;
    vehicle.ReverseRight = false;
    vehicle.Forward (50);
    while (true) 
    {
      if (sensor.ReadDistance () < 40) 
      {
        vehicle.Brake ();
        vehicle.Off ();
        break;
      }
    }
    

    Thanks 🙂
    Daniel.

    #4904
    Author Image
    Anders Søborg
    Keymaster

    Hi there

    Yes I can see your problem. I already committed a fix. Until this will be official released simply start your call in a new thread like this.

    
    new Thread(delegate() {
     vehicle.Forward (50);			
    }).Start();
    

    However please note that other functions also block for a reason. They return a waithandle so you can wait for the movement to finish. You can see an example of this here.

    Thanks for pointing this out!

    /Anders

    #4906
    Author Image
    lemuus
    Participant

    Hi,

    I tried that solution, but now I get blocked on the vehicle.Brake() method.
    I also tried to stop the thread with the Forward method, before calling the vehicle.Brake() method, but then I get a System.InvalidOperationException on the thread with the vehicle.Forward call.

    Thank you,
    Daniel.

    #4907
    Author Image
    Anders Søborg
    Keymaster

    Hi there

    I will have a look at it tomorrow and upload a new version as soon as I have a fix. In the meantime use the motor sync class which is the class that the vehicle class is based on – or you could just wait a day or two…

    /Anders

    #4909
    Author Image
    Anders Søborg
    Keymaster

    Hi there

    I have attached a new firmware dll with a fix. If you are using the Xamarin add-in simply replace the dll with the one attached. I will create a official release for this dll tomorrow.

    /Anders

    • This reply was modified 10 years, 1 month ago by Author ImageAnders Søborg. Reason: Attached file not accepted
    Attachments:
    You must be logged in to view attached files.
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Posted in

Make a donation