Skip to content

correct way to specify driver for LargeMotor? #227

Closed

Description

@dwalton76

In core.py we have

class LargeMotor(Motor):

    """  
    EV3 large servo motor
    """

    SYSTEM_CLASS_NAME = Motor.SYSTEM_CLASS_NAME
    SYSTEM_DEVICE_NAME_CONVENTION = '*'

    def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, name_exact=False, **kwargs):

        super(LargeMotor, self).__init__(address, name_pattern, name_exact, driver_name=['lego-ev3-l-motor'], **kwargs)

driver_name set to 'lego-ev3-l-motor' and driver_name is not accepted by LargeMotor.init. How does one overwrite the driver_name? You cannot pass it via kwargs, if you do python barfs because we've passed driver_name twice to Motor.init. I need to set it to 'lego-nxt-motor' for my BrickPi.

For now I am doing

diff --git a/ev3dev/brickpi.py b/ev3dev/brickpi.py
index 1df0483..cea56f2 100644
--- a/ev3dev/brickpi.py
+++ b/ev3dev/brickpi.py
@@ -93,3 +93,16 @@ class Leds(object):


 # ~autogen
+
+
+class LargeMotor(Motor):
+    """
+    EV3 large servo motor
+    """
+
+    SYSTEM_CLASS_NAME = Motor.SYSTEM_CLASS_NAME
+    SYSTEM_DEVICE_NAME_CONVENTION = '*'
+
+    def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, name_exact=False, **kwargs):
+
+        super(LargeMotor, self).__init__(address, name_pattern, name_exact, driver_name=['lego-nxt-motor'], **kwargs)

but it feels like there has to be a better way that I am missing.

Activity

  1. WasabiFan commented on Oct 6, 2016

    @WasabiFan
    Member

    Looks like that's just an error; the driver name for the LargeMotor should allow for both NXT and EV3 motors. The intent is that this is not changeable from the user's perspective, but nonetheless the default is wrong in this case. We should just be able to update this line in the spec as well as any other instances of this that may have popped up (I can't think of any right now) and re-run autogen.

  2. dwalton76 commented on Oct 6, 2016

    @dwalton76
    CollaboratorAuthor

    I think the default setting is ok, the problem is that the LargeMotor init cannot be passed the driver_name. I've never dug into the autogen side of ev3dev-lang-python though, are the init params also somewhere in the spec?

  3. WasabiFan commented on Oct 6, 2016

    @WasabiFan
    Member

    See this line. That line includes a comment which begins one of the auto-generated blocks, and there is an accompanying one after the LargeMotor class which ends the block. So, that whole thing is generated by a template.

    The goal here is that it's easy to make changes to common code (despite the developer's bets efforts to minimize that code) and update everything together. It also significantly decreases the risk of mistakes causing odd behavior that is hard to track down: everything is deliberate and procedural.

    If you have cloned this repo with all its submodules, you should just be able to edit the ev3dev-lang/spec.json file and then run ev3dev-lang/autogen.js from the root of the Python repo. It should update everything for you. You can use the git diff to see what was changed but keep in mind that any changes you've made to those special blocks in your local copy will be reset. IIRC, you don't need to pass it any parameters, however you will need Node.js installed.

    If you make a change and like it, check out the develop branch in the ev3dev-lang submodule and then commit your changes on that branch and open a PR for them.

  4. WasabiFan commented on Oct 6, 2016

    @WasabiFan
    Member

    Actually, I'm a bit confused... for me, the LargeMotor class already works with NXT motors. I don't have time to look into it now though.

  5. dwalton76 commented on Oct 6, 2016

    @dwalton76
    CollaboratorAuthor

    Thanks for the pointers...I'll futz around with it. I have the same basic problem when using PiStorms though because the driver that is loaded is

    robot@raspberrypi2[LegoDigitalClock]# cat /sys/class/tacho-motor/motor0/driver_name 
    lego-nxt-motor
    robot@raspberrypi2[LegoDigitalClock]#
    

    but we are looking for lego-ev3-l-motor so it thinks the motor isn't connected

  6. self-assigned this
    on Oct 6, 2016
  7. WasabiFan commented on Oct 6, 2016

    @WasabiFan
    Member

    Oh, wait... I know why I am not hitting this problem. It's because my NXT motor is being detected as an EV3 motor (lego-ev3-l-motor). @dlech is that expected?

  8. ddemidov commented on Oct 6, 2016

    @ddemidov
    Member

    NXT motor has separate class both in specification and in the language bindings. So it should work with

    m = ev3.NxtMotor();
  9. ddemidov commented on Oct 6, 2016

    @ddemidov
    Member

    The motor was not listed in documentation. c1c80ad fixes this: http://python-ev3dev.readthedocs.io/en/latest/motors.html#nxt-servo-motor

  10. ddemidov commented on Oct 6, 2016

    @ddemidov
    Member

    @WasabiFan,

    for me, the LargeMotor class already works with NXT motors

    Could be your version of the library is older than #216

  11. WasabiFan commented on Oct 6, 2016

    @WasabiFan
    Member

    NXT motor has separate class both in specification and in the language bindings.

    Ah, that makes sense. I completely forgot that we had a separate class! Although honestly, I'm not sure why we have it separate: It would make more sense if they were both controlled by the basic motor class.

    Could be your version of the library is older than #216

    Nope, I'm seeing this with direct sysfs attribute access from the shell.

  12. dwalton76 commented on Oct 6, 2016

    @dwalton76
    CollaboratorAuthor

    Ah thank you @ddemidov I had not noticed there was a different motor class for NXT motors...that is the solution I was looking for.

    I'm fine if we close this ticket

  13. dwalton76 commented on Oct 6, 2016

    @dwalton76
    CollaboratorAuthor

    On a somewhat related note, have any of you used a brickpi? I built a lego digitial clock that I've had on my desk at work for 2+ years (plugged in the entire time) and it burned up two of the motors :(

  14. WasabiFan commented on Oct 6, 2016

    @WasabiFan
    Member

    I think I am going to open an issue to discuss if we actually want to keep that extra class. Right now though, this issue can be closed I think.

    @dwalton76 No, I've never used a BrickPi or any of the other extension boards... Just the EV3. Although I do have some RasPis and a BeagleBone Black.

  15. ddemidov commented on Oct 6, 2016

    @ddemidov
    Member

    LargeMotor, MediumMotor, and NxtMotor are all just inherit from Motor and do not add any extra functionality besides providing the correct driver names to the constructor. If one needs a universal class, one can just use Motor with appropriate address or driver name directly.

  16. WasabiFan commented on Oct 6, 2016

    @WasabiFan
    Member

    Isn't the NXT motor the same as an EV3 large motor in every aspect but hole placement/shape (and possibly build quality)? i.e. There is no difference in tacho measurements or any other driver capabilities. For that reason, it seems to me that it would make more sense for a LargeMotor to also work with NXT motors -- that way you can easily differentiate between "large" and "medium" motors while still having your code function with NXT motors.

  17. ddemidov commented on Oct 6, 2016

    @ddemidov
    Member

    If that is the case, then it does make sense to merge large and nxt motor classes.

  18. ddemidov commented on Oct 6, 2016

    @ddemidov
    Member

    Both EV3 and NXT motors are now covered by the LargeMotor class.

  19. dlech commented on Oct 6, 2016

    @dlech
    Member

    http://philohome.com/motors/motorcomp.htm

    The differences are slight, but there are some differences. EV3 motor has slightly more torque and goes slightly faster.

    I'm not saying you shouldn't merge the classes, just pointing out the differences.

  20. dwalton76 commented on Oct 6, 2016

    @dwalton76
    CollaboratorAuthor

    @WasabiFan stick to EV3 :) I've been experimenting with pistorms, brickpi and EVB but none of them are as reliable and easy to use as the EV3 brick is.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions