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
The firmware in BrickPi3 (and earlier BrickPi models) doesn't know about different kinds of motors, so we just treat everything like an NXT motor.
-- dlech in ev3dev/ev3dev#1059
The work-around is to use the LargeMotor class for the medium motor. One potential problem is if the user's program relies on max_speed since that value is different for medium vs large motors.
If the user does try to use the MediumMotor class we will fail to set the driver (see the intro in ev3dev/ev3dev#1059). One option for presenting the user with a more informed error message is to raise an exception if the MediumMotor class is used:
if platform in ('brickpi', 'brickpi3'):
raise Exception("%s is unaware of different motor types, use LargeMotor instead" % platform)
If you try to use the MediumMotor class the brickpi thinks that it is not connected
robot@pi3[ev3dev-lang-python]# ./utils/foo.py
Traceback (most recent call last):
File "./utils/foo.py", line 5, in <module>
mmotor = MediumMotor(OUTPUT_A)
File "/usr/local/lib/python3.5/dist-packages/python_ev3dev2-2.0.0b2.post5-py3.5.egg/ev3dev2/motor.py", line 1058, in __init__
super(MediumMotor, self).__init__(address, name_pattern, name_exact, driver_name=['lego-ev3-m-motor'], **kwargs)
File "/usr/local/lib/python3.5/dist-packages/python_ev3dev2-2.0.0b2.post5-py3.5.egg/ev3dev2/motor.py", line 316, in __init__
super(Motor, self).__init__(self.SYSTEM_CLASS_NAME, name_pattern, name_exact, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/python_ev3dev2-2.0.0b2.post5-py3.5.egg/ev3dev2/__init__.py", line 201, in __init__
chain_exception(DeviceNotFound("%s is not connected." % self), None)
File "/usr/local/lib/python3.5/dist-packages/python_ev3dev2-2.0.0b2.post5-py3.5.egg/ev3dev2/__init__.py", line 38, in chain_exception
raise exception from cause
ev3dev2.DeviceNotFound: MediumMotor(spi0.1:MA) is not connected.
robot@pi3[ev3dev-lang-python]#
With this patch
robot@pi3[ev3dev-lang-python]# git diff
diff --git a/ev3dev2/motor.py b/ev3dev2/motor.py
index da7afbd..3295c46 100644
--- a/ev3dev2/motor.py
+++ b/ev3dev2/motor.py
@@ -1055,6 +1055,9 @@ class MediumMotor(Motor):
def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, name_exact=False, **kwargs):
+ if platform in ('brickpi', 'brickpi3'):
+ raise Exception("%s is unaware of different motor types, use LargeMotor instead" % platform)
+
super(MediumMotor, self).__init__(address, name_pattern, name_exact, driver_name=['lego-ev3-m-motor'], **kwargs)
robot@pi3[ev3dev-lang-python]#
We give a better description of what the issue is
Traceback (most recent call last):
File "./utils/foo.py", line 5, in <module>
mmotor = MediumMotor(OUTPUT_A)
File "/home/robot/ev3dev-lang-python/ev3dev2/motor.py", line 1059, in __init__
raise Exception("%s is unaware of different motor types, use LargeMotor instead" % platform)
Exception: brickpi3 is unaware of different motor types, use LargeMotor instead
robot@pi3[ev3dev-lang-python]#
In the review for #536@WasabiFan had the idea to have MediumMotor use the LargeMotor driver if running on brickpi(3). I tried it and it works...that seems much better than raising an exception here.
One downside though is max_speed, it is always going to be reported as the max_speed of a LargeMotor (1020). We are going to need to make max_speed writeable, today we raise an exception
Traceback (most recent call last):
File "./utils/foo.py", line 7, in <module>
mmotor.max_speed = 1450
AttributeError: can't set attribute
Looking at the max_speed issue some more...there are other attributes that could differ based on motor type and be reported incorrectly if using a brickpi
commands
count_per_rot
count_per_m
PID constants?
max_speed
state
stop_actions
I can't think of a good clean way to handle this...my gut says there aren't enough ev3dev brickpi users out there to justify really hacking up the code to make this work perfectly. We could just declare that we only support large motors 100% correctly when using brickpi, all others should work but with some quirks.
Traceback (most recent call last):
File "./utils/foo.py", line 10, in <module>
port_C.set_device = "lego-ev3-m-motor"
File "/home/robot/ev3dev-lang-python/ev3dev2/port.py", line 140, in set_device
self._set_device = self.set_attr_string(self._set_device, 'set_device', value)
File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 297, in set_attr_string
return self._set_attribute(attribute, name, value)
File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 258, in _set_attribute
self._raise_friendly_access_error(ex, name)
File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 281, in _raise_friendly_access_error
raise driver_error
File "/home/robot/ev3dev-lang-python/ev3dev2/__init__.py", line 255, in _set_attribute
attribute.write(value)
OSError: [Errno 95] Operation not supported
Not 100% clear on if I did exactly what you were asking for.
Yeah, that's it. FWIW, If it actually worked, you would need a delay after set_device but it looks like it isn't implemented in the kernel driver. I kind of though that would be the case.
I don't see any reason why this couldn't be implemented in the ev3dev driver using the existing BrickPi3 firmware (other than lack of time to do the work needed).
Activity
dwalton76 commentedon Oct 31, 2018
Running
Testing with:
If you try to use the MediumMotor class the brickpi thinks that it is not connected
With this patch
We give a better description of what the issue is
dwalton76 commentedon Oct 31, 2018
In the review for #536 @WasabiFan had the idea to have MediumMotor use the LargeMotor driver if running on brickpi(3). I tried it and it works...that seems much better than raising an exception here.
One downside though is max_speed, it is always going to be reported as the max_speed of a LargeMotor (1020). We are going to need to make max_speed writeable, today we raise an exception
dwalton76 commentedon Oct 31, 2018
Looking at the max_speed issue some more...there are other attributes that could differ based on motor type and be reported incorrectly if using a brickpi
I can't think of a good clean way to handle this...my gut says there aren't enough ev3dev brickpi users out there to justify really hacking up the code to make this work perfectly. We could just declare that we only support large motors 100% correctly when using brickpi, all others should work but with some quirks.
dwalton76 commentedon Oct 31, 2018
@dlech any ideas on a better way to handle this?
dlech commentedon Oct 31, 2018
Can you use
set_deviceon the output port to tell it there is a medium motor attached?WasabiFan commentedon Oct 31, 2018
Yeah, what I want to know is whether you can set the driver manually to be the normal medium motor driver.
dwalton76 commentedon Oct 31, 2018
Trying this:
It barfs on
set_deviceNot 100% clear on if I did exactly what you were asking for.
dlech commentedon Oct 31, 2018
Yeah, that's it. FWIW, If it actually worked, you would need a delay after
set_devicebut it looks like it isn't implemented in the kernel driver. I kind of though that would be the case.WasabiFan commentedon Oct 31, 2018
It looks like it isn't possible to use the medium motor driver on BrickPi I'd say it's fine to throw an error in our constructor.
dwalton76 commentedon Oct 31, 2018
If anyone wants to weigh in over at dexter industries on getting them to support this in the future:
https://forum.dexterindustries.com/t/brickpi3-firmware-an-medium-motors/5463/2
dlech commentedon Oct 31, 2018
I don't see any reason why this couldn't be implemented in the ev3dev driver using the existing BrickPi3 firmware (other than lack of time to do the work needed).