Skip to content

Motor synchronization #315

Closed
Closed

Description

@WasabiFan

There's discussion that has been happening in ev3dev/ev3dev#454 and ev3dev/ev3dev#853 around synchronization of motors, mainly for wheeled robots. While kernel support for "proper" synchronization is not going to be arriving for a while, I think it's reasonable to implement this as best as possible in this library and adapt to the kernel model later.

I'm thinking that a MotorPair class which operates on given motor objects and/or port names would be reasonable as a Python implementation. It would be nice to provide functions for steering, potentially similar to the EV3-G functions.

Thoughts?

Activity

  1. ddemidov commented on Mar 15, 2017

    @ddemidov
    Member

    Something like Tank class in helper.py?

  2. ddemidov commented on Mar 15, 2017

    @ddemidov
    Member

    Hmm, that class is not what I thought it was. I thought @dwalton76 had something like this implemented.

  3. WasabiFan commented on Mar 15, 2017

    @WasabiFan
    MemberAuthor

    In particular, one of the features of this class is that it would be as efficient as it can be for a library written in Python. That primarily means we'd set all the motor properties together and then send the commands sequentially to start them at the same time, which makes a surprisingly large difference in my brief testing.

  4. dwalton76 commented on Mar 15, 2017

    @dwalton76
    Collaborator

    I can't think of any builds I've done where I needed a pair of motors to start at the exact same time...I don't think it was me :)

  5. dwalton76 commented on Mar 15, 2017

    @dwalton76
    Collaborator

    @ddemidov maybe you are thinking of TankWebHandler in https://github.com/rhempel/ev3dev-lang-python/blob/develop/ev3dev/webserver.py , specifically around line 500 where it is starting two motors but with different speeds in order to turn the tank? This was the tank that uses a web interface with a little "joystick" dot that you move around inside a larger circle to control the speed/direction of the tank.

  6. ddemidov commented on Mar 15, 2017

    @ddemidov
    Member

    So what would be the interface?

    class MotorPair(object):
      def __init__(self, m1, m2):
        ...
      def drive(self, power, direction):
        ...

    What else?

  7. WasabiFan commented on Mar 15, 2017

    @WasabiFan
    MemberAuthor

    The ones I see are:

    • The ability to control them in "tank" mode (individual powers for the two motors) as opposed to the current "steering" mode
    • Options for both power and speed control
    • A method to stop both motors
    • An interface to set arbitrary properties on both motors

    Additionally, it would be interesting to see if we could implement it such that the interface was interchangeable with a normal motor, allowing you to pair MotorPairs (e.g., if you have four motors for each corner of a 'bot). That would be a stretch goal though.

  8. ensonic commented on Mar 16, 2017

    @ensonic
    Contributor

    +1 for this. In openroberta I first set all attributes and then start the motors like this:
    https://github.com/OpenRoberta/robertalab-ev3dev/blob/develop/roberta/ev3.py#L374
    which is a pita.

  9. WasabiFan commented on Mar 16, 2017

    @WasabiFan
    MemberAuthor

    One other thought: In case it wasn't clear from my earlier comments, I'd like to make sure that you can optionally initialize a MotorPair with just port names. The caller could do this:

    drive = ev3.MotorPair('outA', 'outD')

    Internally, we'd do this:

    if type(motor1) is str:
        motor1 = LargeMotor(motor1)
    assert isinstance(motor1, BaseMotor), "A motor object or string must be provided"

    This would also mean that we should have a documented way of accessing the internal motor objects.

  10. self-assigned this
    on Sep 1, 2017
  11. dwalton76 commented on Sep 1, 2017

    @dwalton76
    Collaborator

    I've started working on this but named the class MotorSet, you can have as many motors as you want (all wheel drive 4-wheeled vehicles, etc). My first stab is here:
    https://github.com/dwalton76/ev3dev-lang-python/blob/MotorPair/ev3dev/helper.py#L150

    The user can make any sort of motor pair they want but I created LargeMotorPair and MediumMotorPair child classes since those are the two that will be most common. The user would do:

    tank = LargeMotorPair(OUTPUT_A, OUTPUT_C)
    tank.reset()
    tank.run_to_rel_pos(speed_sp=100, position_sp=360)
    tank.wait_until_not_moving()
    

    This isn't working yet though, when I call tank.run_to_rel_pos(speed_sp=100, position_sp=360) the first motor correctly rotates at speed 100 for 360 degrees while the second motor rotates much faster and only stops once the first motor gets to 360. I need to narrow down if this is a python issue or not...my gut says no.

  12. dwalton76 commented on Sep 2, 2017

    @dwalton76
    Collaborator

    Turns out I had a bad motor, this is actually working quite nicely. Will post a PR.

  13. dwalton76 commented on Sep 7, 2017

    @dwalton76
    Collaborator

    Fixed

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