Setmultiplemotorscommand

I currently added setmultiplemotors command with no luck. but if I add forward command the robot moves forward. Any thoughts to why one works and one doesn’t

The command is non-blocking. It just sets up the motor speed, but the program moves on. If that command was the last/only in your program, the program finished, stopping all the motors too.
For testing, add wait(10, seconds) to the end of the program. In real setting, you’d either do something useful while the motors are moving on their own, or you’d wait on some condition instead,
like waiting for a bumper hit, distance driven (using resetMotorEncoder()/getMotorEncoder()) or perhaps gyro heading.

As usual, to get better advice, it helps to post the actual program used.

This is what I am trying to do. Move Forward until distance then stop

program.jpg

That suggests you’re using the ultrasonic distance sensor, are you?
It confuses me a bit, since you initially mentioned replacing the “forward” command.
If all you want to do is to blindly move 100mm, then the program would use no distance sensor and rely solely on the motor encoders. It would then read something like:


setMultipleMotors(50, leftMotor, rightMotor, , );
waitUntil(getMotorEncoder(leftMotor) >= 180);
stopMultipleMotors(leftMotor, rightMotor);

Now, why 180? I am assuming a lot: You’re using the usual 200mm travel size tires with no gears, directly attached to the motor. Thus one wheel rotation (360 degrees) would be 200mm travel size and for 100mm travel, you only need 180 degrees. I also assume that you’re using degrees as the motor encoder unit, which is the default.

If you really intended to use the ultrasonic distance sensor and keep running until the robot is 100mm from a wall, I would suggest using the firmware’s built-in Device Info screen to verify what does the distance sensor actually see in your setup, or possibly write a program displaying the current sensor reading while running, such as:


setMultipleMotors(50, leftMotor, rightMotor, , );
displaySensorValues(line1, distanceMM);
repeatUntil(getDistanceValue(distanceMM) < 100) {
    displaySensorValues(line2, distanceMM);
}
stopMultipleMotors(leftMotor, rightMotor);
wait(100, seconds);

That way, you’d capture both the initial sensor reading (in case the loop never executed) and the continuous value while the robot is running.