# Abnormal behaviour with 'run in parallel' with motorD

**URL:** https://forum.makecode.com/t/abnormal-behaviour-with-run-in-parallel-with-motord/727
**Category:** EV3
**Created:** [November 2, 2019, 7:24am UTC](https://forum.makecode.com/t/abnormal-behaviour-with-run-in-parallel-with-motord/727 "2019-11-02T07:24:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wahk](https://avatars.discourse-cdn.com/v4/letter/w/a8b319/32.png) [@wahk](https://forum.makecode.com/u/wahk)
#### Post date: [November 2, 2019, 7:24am UTC](https://forum.makecode.com/t/abnormal-behaviour-with-run-in-parallel-with-motord/727/1 "2019-11-02T07:24:36Z")

</div>

I am trying out MakeCode EV3 and I found an abnormal behaviour when I tried to run motorD and motorB at the same time. In the example code, I expected both motors to complete one revolution simultaneously before the program exit. The simulator does exactly that but the robot does not turn the motors as expected. The motors did not seem to turn at all.

```auto
control.runInParallel(function () {
    motors.mediumD.run(50, 1, MoveUnit.Rotations)
})
motors.largeB.run(50, 1, MoveUnit.Rotations)
brick.exitProgram()

```

However, if I replace motorD with motorA, the robot behaves as expected and both motors will complete one revolution simultaneously before the program exit.

```auto
control.runInParallel(function () {
    motors.mediumA.run(50, 1, MoveUnit.Rotations)
})
motors.largeB.run(50, 1, MoveUnit.Rotations)
brick.exitProgram()

```

Did I miss something here?

---

<div class="post-metadata">

### Author: ![peli](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/peli/32/12_2.png) [@peli](https://forum.makecode.com/u/peli)
#### Post date: [November 4, 2019, 10:00pm UTC](https://forum.makecode.com/t/abnormal-behaviour-with-run-in-parallel-with-motord/727/2 "2019-11-04T22:00:26Z")

</div>

Could you describe briefly the hardware configuration to reproduce this? Medium motor on A/D and large on B?

(Looks like we need a better way to run in parallel and merge threads).

---

<div class="post-metadata">

### Author: ![Jeff](https://avatars.discourse-cdn.com/v4/letter/j/e19b73/32.png) [@Jeff](https://forum.makecode.com/u/Jeff)
#### Post date: [November 4, 2019, 10:51pm UTC](https://forum.makecode.com/t/abnormal-behaviour-with-run-in-parallel-with-motord/727/3 "2019-11-04T22:51:32Z")

</div>

I tried messing with runInParallel a while back and found the scheduler was less then ideal to say the least. The brick is a single core AFAK so at the end of the day you are only really going to do 1 thing at a time. I had some success by doing something like this:

```auto
control.runInParallel(function () {
while(motors.mediumA.Angle() < 360) /// or whatever you want for rotations
{
    motors.mediumA.run(50);
    pause(1);
}
motors.mediumA.stop();
})

```

without a pause both motors fail to run correctly. It seems like there is an issue with proper time slices for each thread. For what I’ve seen, right now it is better to keep everything in the same thread and maybe start a motor without rotation value and start the other motor then monitor each motors rotations in the same loop.

---

<div class="post-metadata">

### Author: ![wahk](https://avatars.discourse-cdn.com/v4/letter/w/a8b319/32.png) [@wahk](https://forum.makecode.com/u/wahk)
#### Post date: [November 4, 2019, 10:53pm UTC](https://forum.makecode.com/t/abnormal-behaviour-with-run-in-parallel-with-motord/727/4 "2019-11-04T22:53:27Z")

</div>

Medium motor on A and D.  
Large motor on B and C.  
Color Sensors on 3 and 4.

I was trying to duplicate programs (for FLL City Shaper) that were made with EV3 mindstorm. I find MakeCode to be very good. My robot performs similarly with both Mindstorm and MakeCode except for the problem report above.
