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
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.
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.
@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.
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.
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:
iftype(motor1) isstr:
motor1=LargeMotor(motor1)
assertisinstance(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.
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.
Activity
ddemidov commentedon Mar 15, 2017
Something like Tank class in helper.py?
ddemidov commentedon Mar 15, 2017
Hmm, that class is not what I thought it was. I thought @dwalton76 had something like this implemented.
WasabiFan commentedon Mar 15, 2017
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.
dwalton76 commentedon Mar 15, 2017
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 :)
dwalton76 commentedon Mar 15, 2017
@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.
ddemidov commentedon Mar 15, 2017
So what would be the interface?
What else?
WasabiFan commentedon Mar 15, 2017
The ones I see are:
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.ensonic commentedon Mar 16, 2017
+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.
WasabiFan commentedon Mar 16, 2017
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
MotorPairwith just port names. The caller could do this:Internally, we'd do this:
This would also mean that we should have a documented way of accessing the internal motor objects.
dwalton76 commentedon Sep 1, 2017
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:
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.dwalton76 commentedon Sep 2, 2017
Turns out I had a bad motor, this is actually working quite nicely. Will post a PR.
dwalton76 commentedon Sep 7, 2017
Fixed