This project has moved. For the latest updates, please go here.

step precision

Jan 31, 2014 at 7:11 PM

First of all nice API!

At the moment I'm trying to create a winrt application. One of the functions I want to create is to turn to a certain angle. I'm facing a problem with the step precision with the following code.
        private async void TurnToAngle(double angle)
            // reset all values on brick
            await _brick.DirectCommand.ClearAllDevices();
            // with 2360 steps the ev3 makes a 360 spin, calculate how many steps are 
            // required for the requested angle
            uint steps = (uint)(Math.Round((double)(2360 / 360)) * (int)Math.Round(Math.Abs(angle)));
            // set debug values
            _stepsRequired = steps;

            // turn to angle
            if (angle <= 0)
                await _brick.DirectCommand.StepMotorAtPowerAsync(OutputPort.B, 100, steps, false);
                await _brick.DirectCommand.StepMotorAtPowerAsync(OutputPort.C, -100, steps, false);
            else if (angle <= 90)
                await _brick.DirectCommand.StepMotorAtPowerAsync(OutputPort.B, -100, steps, false);
                await _brick.DirectCommand.StepMotorAtPowerAsync(OutputPort.C, 100, steps, false);
If I execute the code above and monitor the values of the motors with the following code:
        void BrickChanged(object sender, BrickChangedEventArgs e)
            var stepsBExecuted = e.Ports[InputPort.B].SIValue;
            var stepsCExecuted = e.Ports[InputPort.C].SIValue;

            System.Diagnostics.Debug.WriteLine(string.Format("{0} {1} {2}", e.Ports[InputPort.B].RawValue, e.Ports[InputPort.B].RawValue, _stepsRequired));
I get constantly logs like these:
60 60 420
184 184 420
320 320 420
456 456 420
541 541 420
580 580 420
585 585 420

With the above example the motors need to step 420 rotations, but they execute 585. For every angle I try to execute, the motors are stepping more then requested. Is this normal behavior? If so anything can be done about it? If not normal behavior is there something i'm doing wrong?

I hope somebody can help me out!

Feb 2, 2014 at 9:50 AM
Nevermind the stupid question, found the answer myself, you have to set the brake parameter to true in the StepMotorAtPowerAsync function
Feb 8, 2014 at 8:14 PM
Hi Pieter,

Saw this post with logic to make turns.

I tried it and it's turning way too much...
wonder if the " 2360 steps the ev3 makes a 360 spin"
is based on your robot configuration / design.

I don't know the difference between TurnMotorAtPower ( never stops ? ) vs TurnMotorAtPowerForTime vs StepMotorAtPower
for making turns.

I've been stuck on this for a while.
I'm using the WPF sample ( windows 7 )

Thanks, LA Guy
Feb 8, 2014 at 10:13 PM

The 2360 steps to make a 360 degree spin is based on the Tracker robot configuration. I found this step value by trial and error. I guess the step value will be different for every robot configuration.

To make a controlled turn I think it's best to use StepMotorAtPower

Feb 12, 2014 at 10:12 PM
Edited Feb 12, 2014 at 10:13 PM
Hi Pieter,

Thanks for your help ! :)

I have this code trying to make a 90 degree left turn.
Trouble is that the robot turns almost a 360 turn ( about 300 ) no matter what
value I put for steps: 1 - 2000
           // ??? Left ( port B ) wheel turns longer and slower backwards

           _brick.BatchCommand.StepMotorAtPower(OutputPort.B, -PowerValue1, steps, true);

           _brick.BatchCommand.StepMotorAtPower(OutputPort.C, PowerValue1, steps, true);

           await _brick.BatchCommand.SendCommandAsync();
Does the 2nd parameter : Power - affect the amount of the turn ?
( don't think it should ), I change that from 10 - 50 and it doesn't do anything but controll the speed of the turn ( as expected ).

It would be great, if I can come up with a function to turn the robot like the "Steering" control in the Lego IDE
where you specify the turn degree angle.

This left / right turn programming issue is holding up my project to program a Maze Solver.

Thanks Again, LA Guy
Feb 18, 2014 at 6:41 PM
Finally had some time to test. Not seeing that behavior here. I set the steps value and changed the power values and saw the motors turn the same amount, just at different
Feb 19, 2014 at 3:11 AM

Thanks for testing.
I see that others are making turns with no problem.

But, I'm still stuck with this odd behavior.
I will try again in a few days.
Work stuff comes first.

I wish you can add some functions to the API to mimic the Move Steering Block ( which has angle / degrees of turn )
which was so easy to use in Lego IDE.

Thanks, LA Guy
Feb 19, 2014 at 6:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Feb 20, 2014 at 4:12 PM

Thanks for making a new feature request.

If other people are interested in this to "make turns" easier then please go to
Issues tab and UP VOTE the "Move Steering Api" item.

Meanwhile, I'm gonna see if I can borrow another Lego Robot and try making turns with that one.

Thanks, LA Guy
Feb 21, 2014 at 7:11 AM

@LA_Guy, I also don't have the behavior you describe, I can make my robot turn to the angle I want with every speed/power.

And from what I've done until now, I think it will be really hard to make a general function to turn a robot to a specified angle. I think this will be hard because the configuration (build) of every robot is different
Feb 22, 2014 at 6:05 AM
Edited Feb 22, 2014 at 6:06 AM
@pieterdv @peekb
Hi Guys,

Turns are working now.

"With egg all over my face", I finally found that I had a coding error where the steps ( number of steps ) wasn't being set in the code above the turn functions.
After setting the steps to 241 and motor speed to 30 , the robot is turning fine for 90 degree turn.

I will post the code when I clean it up and get left and right turns going.

Not sure why I didn't just put the debugger on to find this bug.

Thanks, LA Guy