Class ServoMotor
The servo motor class provides a uniform interface for using hobby type servo motors.
Declaration
source linkDocumentation
Methods
▶ def __init__(self, address=None, name_pattern=SYSTEM_DEVICE_NAME_CONVENTION, ...) overrideinherited doc Spin through the Linux sysfs class for the device type and find a device that matches the provided name pattern and attributes (if any).
def __init__(
self,
address=None,
name_pattern=SYSTEM_DEVICE_NAME_CONVENTION,
name_exact=False,
**kwargs,
)
This method overrides ev3dev2.Device.__init__.
- Parameters:
- class_name: class name of the device, a subdirectory of /sys/class.
For example, 'tacho-motor'.
- name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
- name_exact: when True, assume that the name_pattern provided is the
exact device name and use it directly.
- keyword arguments: used for matching the corresponding device
attributes. For example, address='outA', or driver_name=['lego-ev3-us', 'lego-nxt-us']. When argument value is a list, then a match against any entry of the list is enough.
Example:
d = ev3dev.Device('tacho-motor', address='outA')
s = ev3dev.Device('lego-sensor', driver_name=['lego-ev3-us', 'lego-nxt-us'])If there was no valid connected device, an error is thrown.
▷ def address(self) @property Returns the name of the port that this motor is connected to.
@property
def address(self)
▷ def command(self) @property Sets the command for the servo. Valid values are ``run`` and ``float``. Setting to ``run`` will cause the servo to be driven to the position_sp set in the ``position_sp`` attribute. Setting to ``float`` will remove power from the motor.
@property
def command(self)
▷ def command(self, value) @command.setter @command.setter
def command(
self,
value,
)
▷ def driver_name(self) @property Returns the name of the motor driver that loaded this device. See the list of [supported devices] for a list of drivers.
@property
def driver_name(self)
▷ def float(self, **kwargs) Remove power from the motor.
▶ def max_pulse_sp(self) @property Used to set the pulse size in milliseconds for the signal that tells the
@property
def max_pulse_sp(self)
servo to drive to the maximum (clockwise) position_sp. Default value is 2400. Valid values are 2300 to 2700. You must write to the position_sp attribute for changes to this attribute to take effect.
@max_pulse_sp.setter
def max_pulse_sp(
self,
value,
)
▶ def mid_pulse_sp(self) @property Used to set the pulse size in milliseconds for the signal that tells the
@property
def mid_pulse_sp(self)
servo to drive to the mid position_sp. Default value is 1500. Valid values are 1300 to 1700. For example, on a 180 degree servo, this would be 90 degrees. On continuous rotation servo, this is the 'neutral' position_sp where the motor does not turn. You must write to the position_sp attribute for changes to this attribute to take effect.
@mid_pulse_sp.setter
def mid_pulse_sp(
self,
value,
)
▶ def min_pulse_sp(self) @property Used to set the pulse size in milliseconds for the signal that tells the
@property
def min_pulse_sp(self)
servo to drive to the miniumum (counter-clockwise) position_sp. Default value is 600. Valid values are 300 to 700. You must write to the position_sp attribute for changes to this attribute to take effect.
@min_pulse_sp.setter
def min_pulse_sp(
self,
value,
)
▶ def polarity(self) @property Sets the polarity of the servo. Valid values are ``normal`` and ``inversed``.
@property
def polarity(self)
Setting the value to inversed will cause the position_sp value to be inversed. i.e -100 will correspond to max_pulse_sp, and 100 will correspond to min_pulse_sp.
▷ def polarity(self, value) @polarity.setter @polarity.setter
def polarity(
self,
value,
)
▶ def position_sp(self) @property Reading returns the current position_sp of the servo. Writing instructs the
@property
def position_sp(self)
servo to move to the specified position_sp. Units are percent. Valid values are -100 to 100 (-100% to 100%) where -100 corresponds to min_pulse_sp, 0 corresponds to mid_pulse_sp and 100 corresponds to max_pulse_sp.
@position_sp.setter
def position_sp(
self,
value,
)
▶ def rate_sp(self) @property Sets the rate_sp at which the servo travels from 0 to 100.0% (half of the full
@property
def rate_sp(self)
range of the servo). Units are in milliseconds. Example: Setting the rate_sp to 1000 means that it will take a 180 degree servo 2 second to move from 0 to 180 degrees. Note: Some servo controllers may not support this in which case reading and writing will fail with -EOPNOTSUPP. In continuous rotation servos, this value will affect the rate_sp at which the speed ramps up or down.
▷ def rate_sp(self, value) @rate_sp.setter @rate_sp.setter
def rate_sp(
self,
value,
)
▷ def run(self, **kwargs) Drive servo to the position set in the ``position_sp`` attribute.
▷ def state(self) @property Returns a list of flags indicating the state of the servo. Possible values are: * ``running``: Indicates that the motor is powered.