You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Doubt about Unregulated motors implementation #649
I am exploring how devices are handled in ev3dev and in this library and I noticed that unregulated motors should be handled differently. Currently, the port mode is switched to dc-motor. IMHO this is wrong: it is still an EV3 motor. By switching the port to the dumb mode you lose the ability to query the encoder position. Manual power-setting can be achieved with standard tacho-motor by running command run-direct and writing the power to duty_cycle_sp.
Hmm, it seems that it is more complicated. This is the way I see it:
Original leJOS UnregulatedMotor can read out tacho values and is intended for direct PWM control. For example: I once wanted to create a "reading head" for a color sensor and wanted to control it directly [link]. I used UnregulatedMotor to do this.
ev3dev-lang-java changes meaning of these APIs. UnregulatedMotor is instead intended for non-tacho motors and unregulated motor control is achieved through BaseRegulatedMotor. However, it also changes a meaning of this function, which is newly used for the switch: suspendRegulation(). The original behavior is even stated in the documentation for the new function:
* Removes this motors from the motors regulation system. After this call
* the motors will be in float mode and will have stopped. Note calling any
* of the high level move operations (forward, rotate etc.), will
* automatically enable regulation.
* @return true iff regulation has been suspended.
*/
Looking into leJOS sources, suspendRegulation() is equal to calling flt().
However, in this library, no automatic reenabling is done, rather the motor switches to what effectively is the behavior of UnregulatedMotor on leJOS.
The problem I see with it is that UnregulatedMotor cannot read the tacho sensor, because the kernel doesn't try to read it, because it makes no assumptions about what is on the port, because it was configured to see the port as a dc-motor.
Then there is RCXMotor in leJOS. This is the equivalent of a dc-motor - the sysfs kernel device is even getting named like that: ev3-ports:outA:rcx-motor. Indeed, RCX motor has no way of reporting tacho values back, so this way it would be consistent.
TL;DR: the current UnregulatedMotor should be RCXMotor and instead the BaseRegulatedMotor logic behind suspendRegulation/regulationFlag should be in UnregulatedMotor. suspendRegulation should essentially call flt().
no, my doubt is about the API. The UnregulatedMotor is not supposed to be for DC Motors. RCXMotor is. In particular, leJOS UnregulatedMotor can read tacho count, while UnregulatedMotor in this library cannot.
There is also another reason why I'd like fix the API to be like on leJOS: because then UnregulatedMotors will not need to wait for a switch to dc-motor mode - they will be handled by the tacho-motor mode (+ see note below). RCXMotors will however still have the problem and this can be avoided only by udev, retry mechanism or a delay. RCXMotors will simply need to be flagged as problematic.
suspendRegulation() in leJOS was intended to be like flt(). It was not related to UnregulatedMotor switching.
I think that reading the port mode before writing it is the way to go. It should not be changed if it is in auto or tacho-motor mode, only when it is in a different mode. If the mode attribute is not readable, there is also a status attribute which should be.
the permission denied issue will disappear for BaseRegulatedMotor descendants and the fixed UnregulatedMotor.
Activity
JakubVanek commentedon Feb 23, 2019
Hmm, it seems that it is more complicated. This is the way I see it:
Original leJOS UnregulatedMotor can read out tacho values and is intended for direct PWM control. For example: I once wanted to create a "reading head" for a color sensor and wanted to control it directly [link]. I used UnregulatedMotor to do this.
ev3dev-lang-java changes meaning of these APIs. UnregulatedMotor is instead intended for non-tacho motors and unregulated motor control is achieved through BaseRegulatedMotor. However, it also changes a meaning of this function, which is newly used for the switch:
suspendRegulation(). The original behavior is even stated in the documentation for the new function:ev3dev-lang-java/src/main/java/ev3dev/actuators/lego/motors/BaseRegulatedMotor.java
Lines 100 to 106 in 9d02a05
Looking into leJOS sources,
suspendRegulation()is equal to callingflt().However, in this library, no automatic reenabling is done, rather the motor switches to what effectively is the behavior of UnregulatedMotor on leJOS.
JakubVanek commentedon Feb 23, 2019
The problem I see with it is that UnregulatedMotor cannot read the tacho sensor, because the kernel doesn't try to read it, because it makes no assumptions about what is on the port, because it was configured to see the port as a
dc-motor.JakubVanek commentedon Feb 23, 2019
Then there is RCXMotor in leJOS. This is the equivalent of a
dc-motor- the sysfs kernel device is even getting named like that:ev3-ports:outA:rcx-motor. Indeed, RCX motor has no way of reporting tacho values back, so this way it would be consistent.JakubVanek commentedon Feb 23, 2019
TL;DR: the current UnregulatedMotor should be RCXMotor and instead the BaseRegulatedMotor logic behind
suspendRegulation/regulationFlagshould be in UnregulatedMotor.suspendRegulationshould essentially callflt().jabrena commentedon Feb 25, 2019
Hi @JakubVanek,
The support is running fine for DC Motors, you have many examples in examples Repo. I don´t know the nature of this issue.
If you have a doubt about the behaviour, post an example in the issue to review.
Did you tests a DC Motor with your Brick?
Juan Antonio
[-]Unregulated motors are implemented incorrectly[/-][+]Doubt about Unregulated motors implementation[/+]JakubVanek commentedon Feb 26, 2019
Hi @jabrena,
no, my doubt is about the API. The UnregulatedMotor is not supposed to be for DC Motors. RCXMotor is. In particular, leJOS UnregulatedMotor can read tacho count, while UnregulatedMotor in this library cannot.
Regards,
Jakub Vanek
JakubVanek commentedon Feb 26, 2019
There is also another reason why I'd like fix the API to be like on leJOS: because then UnregulatedMotors will not need to wait for a switch to
dc-motormode - they will be handled by thetacho-motormode (+ see note below). RCXMotors will however still have the problem and this can be avoided only by udev, retry mechanism or a delay. RCXMotors will simply need to be flagged as problematic.suspendRegulation()in leJOS was intended to be likeflt(). It was not related to UnregulatedMotor switching.Note: If and after #651 (comment) is implemented:
the permission denied issue will disappear for BaseRegulatedMotor descendants and the fixed UnregulatedMotor.
jabrena commentedon Feb 26, 2019
Please, lets me consider if it is a bug or not.
jabrena commentedon Sep 1, 2019
Current implementation is working fine for RCXMotor and EV3Motor as Unregulated motors.