6

I have problem with regulation of the motor when I control EV3 with Bluetooth. Here is the code:

RemoteEV3 ev3 = new RemoteEV3("10.0.1.1");
    ev3.setDefault();
    RMIRegulatedMotor leftMotor = ev3.createRegulatedMotor("A", 'L');
    RMIRegulatedMotor rightMotor = ev3.createRegulatedMotor("B", 'L');
    EV3ColorSensor color_sensor = new EV3ColorSensor(SensorPort.S2);
    int color_id = color_sensor.getColorID();
    while(color_id!=7){
        leftMotor.setSpeed(300);
        rightMotor.setSpeed(300);
        leftMotor.setAcceleration(1000);
        rightMotor.setAcceleration(1000);
        leftMotor.backward();
        rightMotor.backward();
        Delay.msDelay(500);
        leftMotor.stop(true);
        rightMotor.stop(true);
        color_id = color_sensor.getColorID();
    }
    System.out.println("Establishing connection. Please wait ...");
    if(leftMotor!=null) leftMotor.close();
    if(rightMotor!=null) rightMotor.close();
    if(color_sensor!=null) color_sensor.close();

The problem is that the EV3's motor not continuously moving. It is stop a bit and then continue moving, it is kinda lagging or problems with regulation of RMIRegulatedMotor. However, if I change from RMIRegulatedMotor to RegulatedMotor and compile it directly with the brick not Bluetoothm, there is no problem at all.

4
  • Looking at your code, you're telling the motors to go at a speed of 300, then pause execution for 500ms, then you're telling the motors to stop, before continuing around again. Due to delays in communication you'll probably find that this will cause a stuttery motion that you might not notice when running it on the device. Nov 4, 2014 at 9:40
  • Perhaps if you moved the calls to stop out of the while loop, then the motors would keep running until the colour id was 7. Nov 4, 2014 at 9:41
  • I am so stupid with this function. Thank for your suggestion. Nov 4, 2014 at 14:41
  • Pair programming for the win - often it just needs another pair of eyes ;) Nov 4, 2014 at 15:39

1 Answer 1

1

Looking at your code, you're saying:

  1. Set the motors to a speed of 300, acceleration of 1000
  2. Run the motors backwards
  3. Pause execution of your program for 500ms
  4. Stop the motors
  5. If you're not seeing colour id 7, go to 1.

Assuming that this was exactly the same code you had on the Brick, I'd guess the delays introduced by the communication will cause a stuttery motion that you might not notice when running it on the device.

If you pulled the following lines out of your while loop things would probably be smoother:

leftMotor.stop(true);
rightMotor.stop(true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.