This project has moved and is read-only. For the latest updates, please go here.

DirectCommand Combinations Give Unexpected Results

Mar 10, 2015 at 10:17 PM
Edited Mar 10, 2015 at 10:20 PM
I have been trying to figure out a way to send the desired commands to my EV3 Brick. As I previously posted at:
SendCommandAsync() gave me a System.ArgumentNullException if I used BatchCommands, so I figured I would try DirectCommands (my robot will have several hundred steps, so I would have needed to send multiple batches anyway). But while experimenting with DirectCommands, I had some strange results. I created a handler for a Button as follows:
Private Async Sub btnTest1_Click(sender As Object, e As RoutedEventArgs) Handles btnTest1.Click
    Await Me.MyBrick.DirectCommand.SetMotorPolarity(OutputPort.All, Polarity.Forward)
    Await Me.MyBrick.DirectCommand.StepMotorAtSpeedAsync(OutputPort.A, 25, 360, True)
    Await Me.MyBrick.DirectCommand.SetMotorPolarity(OutputPort.A, Polarity.Opposite)
    Await Me.MyBrick.DirectCommand.StepMotorAtSpeedAsync(OutputPort.A, 25, 360, True)
    Await Me.MyBrick.DirectCommand.StepMotorAtSpeedAsync(OutputPort.B, 25, 360, True)
End Sub
I ran this code multiple times, with different commands commented out each time. Many combinations gave strange results. Some combinations caused a motor to continuously spin instead of stopping after x steps, and one combination actually caused motor C to spin (and you will notice that OutputPort.C is nowhere in the code, other than being part of OutputPort.All). My main questions are:
1: How do I avoid the System.ArgumentNullException when using BatchCommands?
2: Why am I getting these strange results with different combinations of DirectCommands?
3: When should I send the next command (how can I tell when the previous command(s) have finished executing)?
Any help would be appreciated. Thanks.
Mar 11, 2015 at 6:02 PM
As I posted in the other thread, see here for more info on how to wait for the previous command to finish before sending/executing the next: