Skip to content

Fixing problem with TachoCount - #680

Closed
jabrena wants to merge 2 commits into
masterfrom
#670
Closed

jabrena wants to merge 2 commits into
masterfrom
#670

Conversation

@jabrena

@jabrena jabrena commented Sep 3, 2019 •

Copy link
Copy Markdown
Member

Fixed and tested on an EV3 Brick with a motor.
The solution is fine for me.

@jabrena
jabrena requested a review from JakubVanek September 3, 2019 19:23
@jabrena jabrena self-assigned this Sep 3, 2019

@JakubVanek JakubVanek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I can not see the diff for BaseRegulatedMotor - the whole file shows as deleted and recreated. This could be due to different line endings. However this makes the review quite hard to make, so I cannot yet approve (and it breaks git history/blame).

Jakub

Comment thread build.gradle Resolved
@JakubVanek

Copy link
Copy Markdown
Contributor

Example of the broken diff:
broken

@jabrena

jabrena commented Sep 3, 2019

Copy link
Copy Markdown
Member Author

You are right, I will upload again the change, meanwhile, I will refactor the example.

@JakubVanek

Copy link
Copy Markdown
Contributor

I have fixed the diff, refactored the code and changed the version to 2.6.1-SNAPSHOT.

However I think I found an issue with this polarity approach. Will calling backward() or forward() affect the behaviour of the rotate() function? If yes, then this solution is not working fully (because the existing code has never worked fully). I think that calling forward() or backward() on leJOS has no lasting effects on the state. See this code:

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 FwdBwdRotateTest {
    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);
    }
}

Behaviour that I would expect on leJOS:

  1. Motor starts rotating in direction A and then stops.
  2. Motor rotates 360 degrees in the direction A and then stops.
  3. Motor starts rotating in direction B (opposite to A) and then stops.
  4. Motor rotates 360 degrees in the direction A and then stops.

Behaviour that I suspect would happen on ev3dev-lang-java:

  1. Motor starts rotating in direction A and then stops.
  2. Motor rotates 360 degrees in the direction A and then stops.
  3. Motor starts rotating in direction B (opposite to A) and then stops.
  4. Motor rotates 360 degrees in the direction B and then stops.

I think this will happen because kernel will take the motor as inversed, and as such it will also invert the run-to-rel-pos argument position_sp.

@JakubVanek

Copy link
Copy Markdown
Contributor

I have also found this:
https://www.ev3dev.org/docs/tutorials/tacho-motors/#run-forever

… now the motor is running. Let’s make the motor turn in the opposite direction, but a little slower. Using a negative value changes the direction…

$ echo -300 > $MC/speed_sp
$ echo run-forever > $MC/command

@JakubVanek
JakubVanek self-requested a review September 4, 2019 19:58

@JakubVanek JakubVanek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is necessary to check if the current solution works when combining forward() with rotate().

@JakubVanek

Copy link
Copy Markdown
Contributor

rotateTo() could also be problematic.

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 FwdBwdRotateToTest {
    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);

        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);
    }
}

Behaviour that I would expect on leJOS:

  1. Motor rotates in direction A for a second and then stops.
  2. Motor rotates to the position origin+360°.
  3. Motor rotates in direction B (opposite to A) brieflt and then stops.
  4. Motor rotates back to the position origin+360° + it should go into direciton A.

@jabrena

jabrena commented Sep 5, 2019

Copy link
Copy Markdown
Member Author

Good analysis Jakub, I will test with the examples today

@JakubVanek

Copy link
Copy Markdown
Contributor

Test 1 (FwdBwdRotateTest) failed. Motor has rotated in the B direction, so usage of forward() / backward() changes the behavior of rotate(), which it shouldn't. Forward/backward should not invert the motor, they should only start its rotation in that direction once.

@JakubVanek

Copy link
Copy Markdown
Contributor

Test 2 (FwdBwdRotateToTest) failed. Motor has moved in the B direction, so it probably aimed at origin-360°. This means that forward()/backward() affect the behavior of rotateTo(), which they shouldn't.

Updated source code:

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 FwdBwdRotateToTest {
    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");
        motor.forward();
        Delay.msDelay(1000);
        motor.stop();
        Delay.msDelay(500);

        LOGGER.info("Calling rotateTo(360)");
        motor.rotateTo(360, false);
        Delay.msDelay(500);
        motor.stop();
        Delay.msDelay(500);

        LOGGER.info("Move motor backward for 0,5 second");
        motor.backward();
        Delay.msDelay(500);
        motor.stop();
        Delay.msDelay(500);

        LOGGER.info("Calling rotateTo(360) - motor should move forward a little bit");
        motor.rotateTo(360, false);
        Delay.msDelay(500);
        motor.stop();
    }
}

@JakubVanek

Copy link
Copy Markdown
Contributor

Alternative solution: #689

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants