Home→Forums→MonoBrick EV3 Firmware→Vehicle Forward method
- This topic has 4 replies, 2 voices, and was last updated 11 years ago by
Anders Søborg.
-
AuthorPosts
-
October 19, 2014 at 06:58 #4903

lemuusParticipantHi,
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.October 19, 2014 at 08:47 #4904
Anders SøborgKeymasterHi 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
October 19, 2014 at 20:53 #4906
lemuusParticipantHi,
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.October 19, 2014 at 22:14 #4907
Anders SøborgKeymasterHi 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
-
This reply was modified 11 years ago by
Anders Søborg.
October 20, 2014 at 19:59 #4909
Anders SøborgKeymasterHi 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 11 years ago by
Anders Søborg. Reason: Attached file not accepted
Attachments:
You must be logged in to view attached files. -
This reply was modified 11 years ago by
-
AuthorPosts
You must be logged in to reply to this topic.

Follow