0

In this API, it says the following regarding setting a motor's polarity:

polarity

Sets the polarity of the motor. With normal polarity, a positive duty cycle will cause the motor to rotate clockwise. With inversed polarity, a positive duty cycle will cause the motor to rotate counter-clockwise. Valid values are normal and inversed.

import ev3dev.ev3 as ev3
import numpy as numpy
m = ev3.LargeMotor('outA')
time = numpy.random.normal(loc=5.0, scale=1.0, size=None)
time = time * 1000
speed = 180 / ( time / 1000 )
m.run_timed(time_sp=time, speed_sp=speed)
m.polarity = 'inverse'
time = numpy.random.normal(loc=5.0, scale=1.0, size=None)
time = time * 1000
speed = 180 / ( time / 1000 )
m.run_timed(time_sp=5000, speed_sp=100)

m.polarity = 'inverse' doesn't work:

robot@ev3dev:~$ python gaussian_motor.py 
Traceback (most recent call last):
  File "gaussian_motor.py", line 8, in <module>
    m.polarity = 'inverse'
  File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 388, in polarity
    self.set_attr_string('polarity', value)
  File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 216, in set_attr_string
    self._set_attribute(attribute, "{0}".format(value))
  File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 204, in _set_attribute
    self._attribute_cache.write(abspath(self._path + '/' + attribute), value)
  File "/usr/lib/python2.7/dist-packages/ev3dev/core.py", line 91, in write
    f.write(value.encode())
IOError: [Errno 22] Invalid argument

How am I supposed to do this?

1 Answer 1

1

Valid values are normal and inversed. (Emphasis mine)

You forgot the d.

Also it looks like polarity is a method for setting the polarity. You may need to access it like motor.polarity('inversed')

Sign up to request clarification or add additional context in comments.

2 Comments

No, that documentation would have listed it as polarity(...) if it was a method.
@chepner you're right. I was confused because a lot of them use words usually associated with functions, like return

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.