Repository navigation
Fixing problem with TachoCount, second attempt - #689
Merged
Merged
Conversation
This was referenced Sep 25, 2019
Contributor
Author
|
Both tests in #680 have passed. The original issue is also fixed: package example;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.robotics.RegulatedMotor;
import lejos.utility.Delay;
import lombok.extern.slf4j.Slf4j;
@Slf4j
class Test {
public static void main(String[] args) {
LOGGER.info("Initializing motor class");
RegulatedMotor motor = new EV3LargeRegulatedMotor(MotorPort.A);
LOGGER.info("Set motor speed");
motor.hold();
motor.setSpeed(360);
LOGGER.info("Move motor forward for 1 second");
LOGGER.info(Integer.toString(motor.getTachoCount()));
motor.forward();
Delay.msDelay(1000);
motor.stop();
LOGGER.info(Integer.toString(motor.getTachoCount()));
Delay.msDelay(500);
LOGGER.info("Calling rotateTo(360)");
LOGGER.info(Integer.toString(motor.getTachoCount()));
motor.rotateTo(360, false);
LOGGER.info(Integer.toString(motor.getTachoCount()));
Delay.msDelay(500);
motor.stop();
Delay.msDelay(500);
LOGGER.info("Move motor backward for 0,5 second");
LOGGER.info(Integer.toString(motor.getTachoCount()));
motor.backward();
Delay.msDelay(500);
motor.stop();
LOGGER.info(Integer.toString(motor.getTachoCount()));
Delay.msDelay(500);
LOGGER.info("Calling rotateTo(360) - motor should move forward a little bit");
LOGGER.info(Integer.toString(motor.getTachoCount()));
motor.rotateTo(360, false);
LOGGER.info(Integer.toString(motor.getTachoCount()));
Delay.msDelay(500);
motor.stop();
}
} |
JakubVanek
marked this pull request as ready for review
September 25, 2019 21:07
Contributor
Author
|
Also fixes issue #663 (by adding the speed set to |
Contributor
Author
|
Test 1 of 4: verify #663 fix: package test;
import ev3dev.actuators.lego.motors.EV3MediumRegulatedMotor;
import lejos.hardware.port.MotorPort;
public class Test663 {
public static void main(String[] args) throws Exception {
EV3MediumRegulatedMotor m = new EV3MediumRegulatedMotor(MotorPort.C);
m.resetTachoCount();
int dstAngle = 90;
for (int i = 0; i < 10; i++) {
m.rotateTo(dstAngle);
dstAngle = -dstAngle;
Thread.sleep(1000);
}
}
}Result: motor was rotating back and forth => SUCCESS |
Contributor
Author
|
Test 2 of 4: verify #670 fix: package test;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.robotics.RegulatedMotor;
import lejos.utility.Delay;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@Slf4j
public class Test670 {
public static void main(String[] args) throws Exception {
LOGGER.info("MotorEncoderTest");
RegulatedMotor motor = new EV3LargeRegulatedMotor(MotorPort.A);
motor.resetTachoCount();
motor.coast();
ExecutorService executor = Executors.newFixedThreadPool(2);
class MotorReader implements Runnable {
private RegulatedMotor motor;
public MotorReader(RegulatedMotor motor) {
this.motor = motor;
}
public void run() {
for (int x = 1; x < 50; x++) {
LOGGER.info("{} {}", x, motor.getTachoCount());
Delay.msDelay(200);
}
}
}
class MotorWriter implements Runnable {
private RegulatedMotor motor;
public MotorWriter(RegulatedMotor motor) {
this.motor = motor;
}
public void run() {
LOGGER.info("FORWARD");
motor.forward();
Delay.msDelay(2000);
LOGGER.info("BACKWARD");
motor.backward();
Delay.msDelay(2000);
LOGGER.info("FORWARD");
motor.forward();
Delay.msDelay(2000);
LOGGER.info("BACKWARD");
motor.backward();
Delay.msDelay(2000);
}
}
executor.execute(new MotorReader(motor));
executor.execute(new MotorWriter(motor));
executor.awaitTermination(10, TimeUnit.SECONDS);
executor.shutdown();
motor.stop();
LOGGER.info("End");
System.exit(0);
}
}Result: numbers were following a sort of a "triangle wave" => SUCCESS |
Contributor
Author
|
Test 3 of 4: check package test;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.robotics.RegulatedMotor;
import lejos.utility.Delay;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TestRotate {
public static void main(String[] args) {
LOGGER.info("Initializing motor class");
RegulatedMotor motor = new EV3LargeRegulatedMotor(MotorPort.A);
LOGGER.info("Set motor speed");
motor.setSpeed(360);
LOGGER.info("Move motor forward for 1 second");
motor.forward();
Delay.msDelay(1000);
LOGGER.info("Stop the motor and wait 0,5 seconds");
motor.stop();
Delay.msDelay(500);
LOGGER.info("Calling rotate(360) - should move forward, i.e. in the same direction as the last move");
motor.rotate(360, false);
LOGGER.info("Move motor backward for 1 second");
motor.backward();
Delay.msDelay(1000);
LOGGER.info("Stop the motor and wait 0,5 seconds");
motor.stop();
Delay.msDelay(500);
LOGGER.info("Calling rotate(360) - should move forward, i.e. in the oppposite direction to the last move");
motor.rotate(360, false);
}
}Result: the last move was forward too => SUCCESS |
Contributor
Author
|
Test 4 of 4: check package test;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.robotics.RegulatedMotor;
import lejos.utility.Delay;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TestRotateTo {
public static void main(String[] args) {
LOGGER.info("Initializing motor class");
RegulatedMotor motor = new EV3LargeRegulatedMotor(MotorPort.A);
LOGGER.info("Set motor speed");
motor.setSpeed(360);
LOGGER.info("Move motor forward for 1 second");
motor.forward();
Delay.msDelay(1000);
LOGGER.info("Stop the motor and wait 0,5 seconds");
motor.stop();
Delay.msDelay(500);
LOGGER.info("Calling rotateTo(360)");
motor.rotateTo(360, false);
Delay.msDelay(500);
LOGGER.info("Move motor backward for 0,1 second");
motor.backward();
Delay.msDelay(100);
LOGGER.info("Stop the motor and wait 0,5 seconds");
motor.stop();
Delay.msDelay(500);
LOGGER.info("Calling rotateTo(360) - motor should move forward a little bit");
motor.rotateTo(360, false);
}
}Result: the last move was forward too => SUCCESS |
Member
|
Reviewed changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #670
Fixes #663
Supersedes #666
Not yet tested