Repository navigation
Closed
Description
Have installed ev3dev on debian stretch on my EV3 Brick and tried the sample program
example.robotics.ev3.actuator.motor.BasicMotorOperationExample from yesterday's template-project-gradle:
package example.robotics.ev3.actuator.motor;
import ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor;
import lejos.hardware.port.MotorPort;
import lejos.utility.Delay;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class BasicMotorOperationExample {
public static final EV3LargeRegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.B);
public static Logger LOGGER = LoggerFactory.getLogger(BasicMotorOperationExample.class);
public static int DELAY = 2000; //2 Seconds
public static void main(String[] args) {
mA.brake();
LOGGER.info("Starting motor on B");
mA.setSpeed(500);
LOGGER.info("Forward");
mA.forward();
LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed());
Delay.msDelay(DELAY);
LOGGER.info("Stop");
mA.stop();
LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed());
Delay.msDelay(DELAY);
LOGGER.info("Backward");
mA.backward();
LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed());
Delay.msDelay(2000);
LOGGER.info("Stop");
mA.stop();
LOGGER.info("Large Motor is moving: {}, at speed {}", mA.isMoving(), mA.getSpeed());
Delay.msDelay(DELAY);
LOGGER.info("Forward");
mA.forward();
Delay.msDelay(2000);
mA.stop();
LOGGER.info("Stop");
}
}On the ssh console I get this:
> Task :remoteRun
java -server -jar /home/robot/EV3dev_Examples-all-0.3.0.jar
ev3dev#27|2018-11-07 11:51:05 [main] DEBUG ev3dev.hardware.EV3DevDistros - Debian Stretch detected
ev3dev#27|2018-11-07 11:51:06 [main] DEBUG ev3dev.hardware.EV3DevDistros - Debian Stretch detected
ev3dev#27|2018-11-07 11:51:06 [main] DEBUG ev3dev.hardware.EV3DevFileSystem - Root Path: /sys/class
ev3dev#27|2018-11-07 11:51:07 [main] INFO e.a.lego.motors.BaseRegulatedMotor - Configuring motor connected on Port: B
ev3dev#27|2018-11-07 11:51:07 [main] DEBUG e.a.lego.motors.BaseRegulatedMotor - Detecting motor on port: ev3-ports:outB
ev3dev#27|2018-11-07 11:51:07 [main] DEBUG ev3dev.hardware.EV3DevDevice - Detected device on path: /sys/class/lego-port/port5/address, ev3-ports:outB
ev3dev#27|2018-11-07 11:51:07 [main] DEBUG e.a.lego.motors.BaseRegulatedMotor - Setting port in mode: tacho-motor
ev3dev#27|2018-11-07 11:51:08 [main] DEBUG ev3dev.hardware.EV3DevDevice - Detected device on path: /sys/class/tacho-motor/motor9/address, ev3-ports:outB
ev3dev#27|2018-11-07 11:51:09 [main] ERROR ev3dev.utils.Sysfs - File: '/sys/class/tacho-motor/motor9/command' without write permissions.
ev3dev#27|Exception in thread "main" java.lang.ExceptionInInitializerError
ev3dev#27|Caused by: java.lang.RuntimeException: Operation not executed: /sys/class/tacho-motor/motor9/command with value reset
ev3dev#27| at ev3dev.hardware.EV3DevDevice.setStringAttribute(EV3DevDevice.java:118)
ev3dev#27| at ev3dev.actuators.lego.motors.BaseRegulatedMotor.<init>(BaseRegulatedMotor.java:94)
ev3dev#27| at ev3dev.actuators.lego.motors.EV3LargeRegulatedMotor.<init>(EV3LargeRegulatedMotor.java:26)
ev3dev#27| at example.robotics.ev3.actuator.motor.BasicMotorOperationExample.<clinit>(BasicMotorOperationExample.java:16)
Java Runtime:
openjdk version "10" 2018-03-20
OpenJDK Runtime Environment (build 10+46-ev3)
OpenJDK Client VM (build 10+46-ev3, mixed mode, sharing)
Main libraries:
- ev3dev-lang-java-2.4.7-SNAPSHOT.jar
- lejos-commons-0.7.1.jar
However, it works on Oracle Java 8
java version "1.8.0"
Java(TM) SE Embedded Runtime Environment (build 1.8.0-b132, headless)
Java HotSpot(TM) Embedded Client VM (build 25.0-b70, mixed mode)
Activity
robl0377 commentedon Nov 7, 2018
After a reboot of the EV3 Brick I tried it again and it worked with both JDK 8 and JDK 10 just fine!
robl0377 commentedon Nov 8, 2018
Got a similar error today when running the ev3dev.actuators.lego.motors.UnregulatedMotorDemo on the same EV3 brick with OpenJDK 10:
On the ssh console I get this:
You can run it several times on OpenJDK 10, it always gives this error.
However then running on the Oracle JDK 8 it works fine.
After the Oracle JDK 8 run I tried it with OpenJDK 10 again: same error.
Rebooted the EV3..
Running on OpenJDK 10 again: same error:
So it seems reasonable reproducible on OpenJDK 10.
Just for reference: Here is the output of the successful run on OracleJDK 8:
JakubVanek commentedon Nov 8, 2018
Hi,
I did some research about this, but I'm not sure what might be causing this. Could you try running this in SSH? If the
/sys/class/dc-motor/motor0directory doesn't exist, please try another one for this and the next test.That will check that file for writability hopefully by using
access()system call equivalent (see below) and then print the permissions of the file. Then, could you please try running this:If this fails, the problem is really with permissions.
I'm a bit puzzled that this happens only on JDK10 and not JDK8. This is a part of
Sysfs.writeStringfunction:I have looked into the publicly available sources of JDK8 and JDK10 and both do these things to check for writable access:
java.io.File.canWrite()is called.java.io.UnixFileSystem.checkAccess()is called.Java_java_io_UnixFileSystem_checkAccess()is called.access(path, W_OK)system call is invoked on the file.I looked into ev3dev's duty_cycle_sp store for dc-motor and I don't think that causes the write to fail (disclaimer: this is the first time I read the code which handles sysfs, I might be wrong). However, on my desktop Ubuntu, normal users cannot write into sysfs by default. However, I have read that ev3dev uses udev rules to combat this problem. I don't know what is the difference between JVM versions then though.
Could you please try running this while JDK8 and then JDK10 are running:
ps -u -p `pidof java`This should display the user who is running the Java process.
Also, please send us your kernel version:
@dlech what do you think about this problem?
Regards,
Jakub Vanek
dlech commentedon Nov 8, 2018
FWIW, the permission come from here: https://github.com/ev3dev/lego-linux-drivers/blob/ev3dev-stretch/motors/dc_motor_class.c#L572
I think in ev3dev-lang-python, they had to make sure that each attribute was opened with the same permissions. If a file is read-only, it has to be opened for reading only, if it is write only, it has to be opened for writing only, and if it is read/write, it has to be opened for both reading and writing.
JakubVanek commentedon Nov 8, 2018
Hi,
thanks for your response - yup, I looked there now and I see ev3dev-lang-python uses
stat()and keeps the file descriptors open if the user needs to reaccess them:However I think the operation would fail here as well, if
access()reports whether the file can be opened for writing even when only the group bit matches. The attribute fd here would be opened only for reading and then the write on file opened as read-only would probably fail.Regards
jabrena commentedon Nov 8, 2018
Hi @robl0377,
I have tested many times the motors and I didn't find that issue.
In my case, I am testing now with latest build from OpenJDK12 and Debian Stretch. If you like, can you upgrade, I would like to help you and test in team.
Juan Antonio
robl0377 commentedon Nov 8, 2018
jabrena commentedon Nov 8, 2018
I think that the problem is not related with the JVM.
In the past, sometimes, I had the same problem and this is the reason that I added the following delay with 0.5 seconds:
Maybe I could increase a bit more that delay. The reason to have the delay, is because in some way EV3Dev, change internally the folder of the motor and it is necessary to wait a bit. Maybe in the future, we could create some kind of more sophisticated system with CompletableFuture... but at the moment, this is the current solution. Normally, when appear this kind of problem disconnecting the motor and connecting again, the problem is solved. You could have the same problem with the gyro.
But trust me that the problem is not the JVM.
If you add in the example a new delay before the method setPower a new delay, the probability of this scenario should not exist.
Another question I have is: Are you using RCX Unregulated Motor?
This object is designed for Motors without any encoder like the RCX Unregulated motor:
If you are not using this device:
http://bricker.info/parts/5292/
or
Maybe, the result is not predictable.
If you used any EV3 Motor, you should use the example:
UnregulatedMotorDemo2.java
This example use the unregulated features from a normal motor with EV3Dev.
Tomorrow more and welcome to the project.
Juan Antonio
jabrena commentedon Nov 8, 2018
We have in the backlog the creation of a TestingLab to execute from a Jenkins all tests.
#479
Using this way, we could detect the kind of problem that you describe.
In my manual tests, (Maybe in 3 years, thousands) I mitigated this case with the delay but some times, it is possible that exist this problem.
Reviewing the case, I make the question again: What kind of motor are you using to test the feature about UnregulatedMotors.
jabrena commentedon Nov 8, 2018
I think that it will be not necessary to reinstall any JVM.
I suspect that you are using a EV3 Large/Medium Motor, but I need your confirmation.
I like the interest in the project. You will enjoy so much (I hope :))
Cheers
Juan Antonio
25 remaining items
robl0377 commentedon Nov 10, 2018
So I have copied the library's BaseRegulatedMotor class into the test package and changed the delay to 500ms. The LargeMotorDemo program uses the modified class:
jabrena commentedon Nov 10, 2018
Nooo, @robl0377 I didn't explain clear.
I said that if with latest snapshot you observe that you experiment a stable feeling now. After some execution, I mean. If the problem continue, you could deploy the jar from the source project, not from the example project adding the example, the jar will be the same.
robl0377 commentedon Nov 10, 2018
Hmm.. So I don't need to play with some internal delays in the BaseRegulatedMotor class, which could depend on environmental conditions (temperature, voltage, age of the motor..)?
jabrena commentedon Nov 10, 2018
@robl0377 No,
I only need that your run 5 times the same example with the snapshot 2.4.9-SNAPSHOT directly. If the execution is right, I will merge the new delay.
I decrease my EV3Brick with Stretch to the original speed:
And the code has similar times:
With EV3 Overclocked:
With normal speed:
In this release, we added a new required library compile("net.java.dev.jna:jna:4.5.2") to interact with the new LCD Driver, but reviewing the times, this fact doesn't affect the global performance. It is a pity that you are experimented this case. At the moment, the unique solution is to increase a bit the delay but I need to check with you that the new delay mitigate the case in your case.
JakubVanek commentedon Nov 10, 2018
@jabrena I propose this solution:
jabrena commentedon Nov 10, 2018
Hi @JakubVanek,
We are not going to introduce any retry mechanism in that class.
Put this comment in this issue: #555
jabrena commentedon Nov 10, 2018
We only need the tests from @robl0377 with the new delay.
Merge branch 'develop' into #554
jabrena commentedon Nov 10, 2018
Hi @robl0377,
we are waiting for you tests.
We have created a new Snapshot with sources for the library
ev3dev-lang-javaandlejos-commons:https://jitpack.io/#ev3dev-lang-java/ev3dev-lang-java/2.4.12-SNAPSHOT
this Snapshot don't change the delay value, it has the same value than snapshot 2.4.9-SNAPSHOT:
We need to confirm that success tests to close that issue for this release.
Juan Antonio
robl0377 commentedon Nov 10, 2018
To answer your question: I certainly had it running with the original 2.4.9-SNAPSHOT more than 5 times, although I did not test with different temperatures or voltages. Also my motors are a little used.
BTW: I got the book "Beginning Robotics Programming in Java with LEGO Mindstorms" by Wei Lu / Apress 2016. It gives an introduction to robotics programming with classical LeJOS. So I'm now working with the LeJOS again and enjoy the ease of work with the LeJOS Eclipse plugin and the LCD and Buttons :-)
jabrena commentedon Nov 10, 2018
Thanks for the tests @robl0377
We will merge the change tomorrow and we will release.
Note: You are invited to this project when you want to use multiple Bricks, new objects from the JVM 8+, the experience of a complete Linux Distro & an USB support ;)
Cheers
Juan Antonio
Increase delay in BaseRegulatedMotor constructor (#554)