[英]Python: setting value of attribute
In this API, it says the following regarding setting a motor's polarity: 在此 API中,它说明了有关设置电动机极性的以下内容:
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: m.polarity ='inverse'不起作用:
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? 我应该怎么做?
Valid values are normal and inverse d . 有效值为正数和反数d 。 (Emphasis mine) (强调我的)
You forgot the d. 你忘记了d。
Also it looks like polarity
is a method for setting the polarity. 而且看起来polarity
是一种设置极性的方法。 You may need to access it like motor.polarity('inversed')
您可能需要像motor.polarity('inversed')
一样访问它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.