INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Writing sets the ramp down setpoint. Reading returns the current value. Units
are in milliseconds and must be positive. When set to a non-zero value, the
motor speed will decrease from 0 to 100% of `max_speed` over the span of this
setpoint. The actual ramp time is the ratio of the difference be... | def ramp_down_sp(self):
"""
Writing sets the ramp down setpoint. Reading returns the current value. Units
are in milliseconds and must be positive. When set to a non-zero value, the
motor speed will decrease from 0 to 100% of `max_speed` over the span of this
setpoint. The actual... |
The proportional constant for the speed regulation PID. | def speed_p(self):
"""
The proportional constant for the speed regulation PID.
"""
self._speed_p, value = self.get_attr_int(self._speed_p, 'speed_pid/Kp')
return value |
The integral constant for the speed regulation PID. | def speed_i(self):
"""
The integral constant for the speed regulation PID.
"""
self._speed_i, value = self.get_attr_int(self._speed_i, 'speed_pid/Ki')
return value |
The derivative constant for the speed regulation PID. | def speed_d(self):
"""
The derivative constant for the speed regulation PID.
"""
self._speed_d, value = self.get_attr_int(self._speed_d, 'speed_pid/Kd')
return value |
Reading returns a list of state flags. Possible flags are
`running`, `ramping`, `holding`, `overloaded` and `stalled`. | def state(self):
"""
Reading returns a list of state flags. Possible flags are
`running`, `ramping`, `holding`, `overloaded` and `stalled`.
"""
self._state, value = self.get_attr_set(self._state, 'state')
return value |
Reading returns the current stop action. Writing sets the stop action.
The value determines the motors behavior when `command` is set to `stop`.
Also, it determines the motors behavior when a run command completes. See
`stop_actions` for a list of possible values. | def stop_action(self):
"""
Reading returns the current stop action. Writing sets the stop action.
The value determines the motors behavior when `command` is set to `stop`.
Also, it determines the motors behavior when a run command completes. See
`stop_actions` for a list of possi... |
Returns a list of stop actions supported by the motor controller.
Possible values are `coast`, `brake` and `hold`. `coast` means that power will
be removed from the motor and it will freely coast to a stop. `brake` means
that power will be removed from the motor and a passive electrical load wil... | def stop_actions(self):
"""
Returns a list of stop actions supported by the motor controller.
Possible values are `coast`, `brake` and `hold`. `coast` means that power will
be removed from the motor and it will freely coast to a stop. `brake` means
that power will be removed from... |
Writing specifies the amount of time the motor will run when using the
`run-timed` command. Reading returns the current value. Units are in
milliseconds. | def time_sp(self):
"""
Writing specifies the amount of time the motor will run when using the
`run-timed` command. Reading returns the current value. Units are in
milliseconds.
"""
self._time_sp, value = self.get_attr_int(self._time_sp, 'time_sp')
return value |
Run the motor until another command is sent. | def run_forever(self, **kwargs):
"""
Run the motor until another command is sent.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_RUN_FOREVER |
Run to an absolute position specified by `position_sp` and then
stop using the action specified in `stop_action`. | def run_to_abs_pos(self, **kwargs):
"""
Run to an absolute position specified by `position_sp` and then
stop using the action specified in `stop_action`.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_RUN_TO_ABS_POS |
Run to a position relative to the current `position` value.
The new position will be current `position` + `position_sp`.
When the new position is reached, the motor will stop using
the action specified by `stop_action`. | def run_to_rel_pos(self, **kwargs):
"""
Run to a position relative to the current `position` value.
The new position will be current `position` + `position_sp`.
When the new position is reached, the motor will stop using
the action specified by `stop_action`.
"""
... |
Run the motor for the amount of time specified in `time_sp`
and then stop the motor using the action specified by `stop_action`. | def run_timed(self, **kwargs):
"""
Run the motor for the amount of time specified in `time_sp`
and then stop the motor using the action specified by `stop_action`.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_RUN_TIMED |
Run the motor at the duty cycle specified by `duty_cycle_sp`.
Unlike other run commands, changing `duty_cycle_sp` while running *will*
take effect immediately. | def run_direct(self, **kwargs):
"""
Run the motor at the duty cycle specified by `duty_cycle_sp`.
Unlike other run commands, changing `duty_cycle_sp` while running *will*
take effect immediately.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
s... |
Reset all of the motor parameter attributes to their default value.
This will also have the effect of stopping the motor. | def reset(self, **kwargs):
"""
Reset all of the motor parameter attributes to their default value.
This will also have the effect of stopping the motor.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_RESET |
Blocks until ``cond(self.state)`` is ``True``. The condition is
checked when there is an I/O event related to the ``state`` attribute.
Exits early when ``timeout`` (in milliseconds) is reached.
Returns ``True`` if the condition is met, and ``False`` if the timeout
is reached. | def wait(self, cond, timeout=None):
"""
Blocks until ``cond(self.state)`` is ``True``. The condition is
checked when there is an I/O event related to the ``state`` attribute.
Exits early when ``timeout`` (in milliseconds) is reached.
Returns ``True`` if the condition is met, an... |
Blocks until ``running`` is not in ``self.state`` or ``stalled`` is in
``self.state``. The condition is checked when there is an I/O event
related to the ``state`` attribute. Exits early when ``timeout``
(in milliseconds) is reached.
Returns ``True`` if the condition is met, and ``Fal... | def wait_until_not_moving(self, timeout=None):
"""
Blocks until ``running`` is not in ``self.state`` or ``stalled`` is in
``self.state``. The condition is checked when there is an I/O event
related to the ``state`` attribute. Exits early when ``timeout``
(in milliseconds) is re... |
Blocks until ``s`` is in ``self.state``. The condition is checked when
there is an I/O event related to the ``state`` attribute. Exits early
when ``timeout`` (in milliseconds) is reached.
Returns ``True`` if the condition is met, and ``False`` if the timeout
is reached.
Examp... | def wait_until(self, s, timeout=None):
"""
Blocks until ``s`` is in ``self.state``. The condition is checked when
there is an I/O event related to the ``state`` attribute. Exits early
when ``timeout`` (in milliseconds) is reached.
Returns ``True`` if the condition is met, and ... |
Rotate the motor at ``speed`` for ``rotations``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | def on_for_rotations(self, speed, rotations, brake=True, block=True):
"""
Rotate the motor at ``speed`` for ``rotations``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units.
"""
speed_sp = self._speed_native_units(spe... |
Rotate the motor at ``speed`` for ``degrees``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | def on_for_degrees(self, speed, degrees, brake=True, block=True):
"""
Rotate the motor at ``speed`` for ``degrees``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units.
"""
speed_sp = self._speed_native_units(speed)
... |
Rotate the motor at ``speed`` to ``position``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | def on_to_position(self, speed, position, brake=True, block=True):
"""
Rotate the motor at ``speed`` to ``position``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units.
"""
speed = self._speed_native_units(speed)
... |
Rotate the motor at ``speed`` for ``seconds``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | def on_for_seconds(self, speed, seconds, brake=True, block=True):
"""
Rotate the motor at ``speed`` for ``seconds``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units.
"""
if seconds < 0:
raise ValueError... |
Rotate the motor at ``speed`` for forever
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units.
Note that `block` is False by default, this is different from the
other `on_for_XYZ` methods. | def on(self, speed, brake=True, block=False):
"""
Rotate the motor at ``speed`` for forever
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units.
Note that `block` is False by default, this is different from the
other ... |
Returns a list of commands supported by the motor
controller. | def commands(self):
"""
Returns a list of commands supported by the motor
controller.
"""
self._commands, value = self.get_attr_set(self._commands, 'commands')
return value |
Returns the name of the motor driver that loaded this device. See the list
of [supported devices] for a list of drivers. | def driver_name(self):
"""
Returns the name of the motor driver that loaded this device. See the list
of [supported devices] for a list of drivers.
"""
self._driver_name, value = self.get_attr_string(self._driver_name, 'driver_name')
return value |
Gets a list of stop actions. Valid values are `coast`
and `brake`. | def stop_actions(self):
"""
Gets a list of stop actions. Valid values are `coast`
and `brake`.
"""
self._stop_actions, value = self.get_attr_set(self._stop_actions, 'stop_actions')
return value |
Used to set the pulse size in milliseconds for the signal that tells the
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. | def max_pulse_sp(self):
"""
Used to set the pulse size in milliseconds for the signal that tells the
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 attrib... |
Used to set the pulse size in milliseconds for the signal that tells the
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
... | def mid_pulse_sp(self):
"""
Used to set the pulse size in milliseconds for the signal that tells the
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 s... |
Used to set the pulse size in milliseconds for the signal that tells the
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. | def min_pulse_sp(self):
"""
Used to set the pulse size in milliseconds for the signal that tells the
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 ... |
Sets the rate_sp at which the servo travels from 0 to 100.0% (half of the full
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... | def rate_sp(self):
"""
Sets the rate_sp at which the servo travels from 0 to 100.0% (half of the full
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... |
Drive servo to the position set in the `position_sp` attribute. | def run(self, **kwargs):
"""
Drive servo to the position set in the `position_sp` attribute.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_RUN |
Remove power from the motor. | def float(self, **kwargs):
"""
Remove power from the motor.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_FLOAT |
Stop motors immediately. Configure motors to brake if ``brake`` is set. | def off(self, motors=None, brake=True):
"""
Stop motors immediately. Configure motors to brake if ``brake`` is set.
"""
motors = motors if motors is not None else self.motors.values()
for motor in motors:
motor._set_brake(brake)
for motor in motors:
... |
Rotate the motors at 'left_speed & right_speed' for 'degrees'. Speeds
can be percentages or any SpeedValue implementation.
If the left speed is not equal to the right speed (i.e., the robot will
turn), the motor on the outside of the turn will rotate for the full
``degrees`` while the m... | def on_for_degrees(self, left_speed, right_speed, degrees, brake=True, block=True):
"""
Rotate the motors at 'left_speed & right_speed' for 'degrees'. Speeds
can be percentages or any SpeedValue implementation.
If the left speed is not equal to the right speed (i.e., the robot will
... |
Rotate the motors at 'left_speed & right_speed' for 'rotations'. Speeds
can be percentages or any SpeedValue implementation.
If the left speed is not equal to the right speed (i.e., the robot will
turn), the motor on the outside of the turn will rotate for the full
``rotations`` while t... | def on_for_rotations(self, left_speed, right_speed, rotations, brake=True, block=True):
"""
Rotate the motors at 'left_speed & right_speed' for 'rotations'. Speeds
can be percentages or any SpeedValue implementation.
If the left speed is not equal to the right speed (i.e., the robot wil... |
Rotate the motors at 'left_speed & right_speed' for 'seconds'. Speeds
can be percentages or any SpeedValue implementation. | def on_for_seconds(self, left_speed, right_speed, seconds, brake=True, block=True):
"""
Rotate the motors at 'left_speed & right_speed' for 'seconds'. Speeds
can be percentages or any SpeedValue implementation.
"""
if seconds < 0:
raise ValueError("seconds is negativ... |
Start rotating the motors according to ``left_speed`` and ``right_speed`` forever.
Speeds can be percentages or any SpeedValue implementation. | def on(self, left_speed, right_speed):
"""
Start rotating the motors according to ``left_speed`` and ``right_speed`` forever.
Speeds can be percentages or any SpeedValue implementation.
"""
(left_speed_native_units, right_speed_native_units) = self._unpack_speeds_to_native_units(... |
Rotate the motors according to the provided ``steering``.
The distance each motor will travel follows the rules of :meth:`MoveTank.on_for_rotations`. | def on_for_rotations(self, steering, speed, rotations, brake=True, block=True):
"""
Rotate the motors according to the provided ``steering``.
The distance each motor will travel follows the rules of :meth:`MoveTank.on_for_rotations`.
"""
(left_speed, right_speed) = self.get_spee... |
Rotate the motors according to the provided ``steering``.
The distance each motor will travel follows the rules of :meth:`MoveTank.on_for_degrees`. | def on_for_degrees(self, steering, speed, degrees, brake=True, block=True):
"""
Rotate the motors according to the provided ``steering``.
The distance each motor will travel follows the rules of :meth:`MoveTank.on_for_degrees`.
"""
(left_speed, right_speed) = self.get_speed_stee... |
Rotate the motors according to the provided ``steering`` for ``seconds``. | def on_for_seconds(self, steering, speed, seconds, brake=True, block=True):
"""
Rotate the motors according to the provided ``steering`` for ``seconds``.
"""
(left_speed, right_speed) = self.get_speed_steering(steering, speed)
MoveTank.on_for_seconds(self, SpeedNativeUnits(left_s... |
Start rotating the motors according to the provided ``steering`` and
``speed`` forever. | def on(self, steering, speed):
"""
Start rotating the motors according to the provided ``steering`` and
``speed`` forever.
"""
(left_speed, right_speed) = self.get_speed_steering(steering, speed)
MoveTank.on(self, SpeedNativeUnits(left_speed), SpeedNativeUnits(right_speed... |
Calculate the speed_sp for each motor in a pair to achieve the specified
steering. Note that calling this function alone will not make the
motors move, it only calculates the speed. A run_* function must be called
afterwards to make the motors move.
steering [-100, 100]:
* -... | def get_speed_steering(self, steering, speed):
"""
Calculate the speed_sp for each motor in a pair to achieve the specified
steering. Note that calling this function alone will not make the
motors move, it only calculates the speed. A run_* function must be called
afterwards to m... |
Drive distance_mm | def on_for_distance(self, speed, distance_mm, brake=True, block=True):
"""
Drive distance_mm
"""
rotations = distance_mm / self.wheel.circumference_mm
log.debug("%s: on_for_rotations distance_mm %s, rotations %s, speed %s" % (self, distance_mm, rotations, speed))
MoveTan... |
Drive in a circle with 'radius' for 'distance' | def _on_arc(self, speed, radius_mm, distance_mm, brake, block, arc_right):
"""
Drive in a circle with 'radius' for 'distance'
"""
if radius_mm < self.min_circle_radius_mm:
raise ValueError("{}: radius_mm {} is less than min_circle_radius_mm {}" .format(
s... |
Drive clockwise in a circle with 'radius_mm' for 'distance_mm' | def on_arc_right(self, speed, radius_mm, distance_mm, brake=True, block=True):
"""
Drive clockwise in a circle with 'radius_mm' for 'distance_mm'
"""
self._on_arc(speed, radius_mm, distance_mm, brake, block, True) |
Drive counter-clockwise in a circle with 'radius_mm' for 'distance_mm' | def on_arc_left(self, speed, radius_mm, distance_mm, brake=True, block=True):
"""
Drive counter-clockwise in a circle with 'radius_mm' for 'distance_mm'
"""
self._on_arc(speed, radius_mm, distance_mm, brake, block, False) |
Rotate in place 'degrees'. Both wheels must turn at the same speed for us
to rotate in place. | def _turn(self, speed, degrees, brake=True, block=True):
"""
Rotate in place 'degrees'. Both wheels must turn at the same speed for us
to rotate in place.
"""
# The distance each wheel needs to travel
distance_mm = (abs(degrees) / 360) * self.circumference_mm
# ... |
Rotate clockwise 'degrees' in place | def turn_right(self, speed, degrees, brake=True, block=True):
"""
Rotate clockwise 'degrees' in place
"""
self._turn(speed, abs(degrees), brake, block) |
Ported from:
http://seattlerobotics.org/encoder/200610/Article3/IMU%20Odometry,%20by%20David%20Anderson.htm
A thread is started that will run until the user calls odometry_stop()
which will set odometry_thread_run to False | def odometry_start(self, theta_degrees_start=90.0,
x_pos_start=0.0, y_pos_start=0.0,
SLEEP_TIME=0.005): # 5ms
"""
Ported from:
http://seattlerobotics.org/encoder/200610/Article3/IMU%20Odometry,%20by%20David%20Anderson.htm
A thread is started that will run until ... |
Rotate in place to `angle_target_degrees` at `speed` | def turn_to_angle(self, speed, angle_target_degrees, brake=True, block=True):
"""
Rotate in place to `angle_target_degrees` at `speed`
"""
assert self.odometry_thread_id, "odometry_start() must be called to track robot coordinates"
# Make both target and current angles positive ... |
Drive to (`x_target_mm`, `y_target_mm`) coordinates at `speed` | def on_to_coordinates(self, speed, x_target_mm, y_target_mm, brake=True, block=True):
"""
Drive to (`x_target_mm`, `y_target_mm`) coordinates at `speed`
"""
assert self.odometry_thread_id, "odometry_start() must be called to track robot coordinates"
# stop moving
self.of... |
Convert x,y joystick coordinates to left/right motor speed percentages
and move the motors.
This will use a classic "arcade drive" algorithm: a full-forward joystick
goes straight forward and likewise for full-backward. Pushing the joystick
all the way to one side will make it turn on t... | def on(self, x, y, radius=100.0):
"""
Convert x,y joystick coordinates to left/right motor speed percentages
and move the motors.
This will use a classic "arcade drive" algorithm: a full-forward joystick
goes straight forward and likewise for full-backward. Pushing the joystick
... |
The following graphic illustrates the **motor power outputs** for the
left and right motors based on where the joystick is pointing, of the
form ``(left power, right power)``::
(1, 1)
. . . . . . .
. ... | def angle_to_speed_percentage(angle):
"""
The following graphic illustrates the **motor power outputs** for the
left and right motors based on where the joystick is pointing, of the
form ``(left power, right power)``::
(1, 1)
... |
Given a datetime.timedelta object, return the delta in milliseconds | def datetime_delta_to_ms(delta):
"""
Given a datetime.timedelta object, return the delta in milliseconds
"""
delta_ms = delta.days * 24 * 60 * 60 * 1000
delta_ms += delta.seconds * 1000
delta_ms += delta.microseconds / 1000
delta_ms = int(delta_ms)
return delta_ms |
Returns the maximum allowable brightness value. | def max_brightness(self):
"""
Returns the maximum allowable brightness value.
"""
self._max_brightness, value = self.get_cached_attr_int(self._max_brightness, 'max_brightness')
return value |
Return True if ``duration_seconds`` have expired since ``start_time`` | def duration_expired(start_time, duration_seconds):
"""
Return True if ``duration_seconds`` have expired since ``start_time``
"""
if duration_seconds is not None:
delta_seconds = datetime_delta_to_seconds(dt.datetime.now() - start_time)
if delta_seconds >= duration_seconds:
... |
Sets the brightness level. Possible values are from 0 to `max_brightness`. | def brightness(self):
"""
Sets the brightness level. Possible values are from 0 to `max_brightness`.
"""
self._brightness, value = self.get_attr_int(self._brightness, 'brightness')
return value |
Returns a list of available triggers. | def triggers(self):
"""
Returns a list of available triggers.
"""
self._triggers, value = self.get_attr_set(self._triggers, 'trigger')
return value |
Sets the LED trigger. A trigger is a kernel based source of LED events.
Triggers can either be simple or complex. A simple trigger isn't
configurable and is designed to slot into existing subsystems with
minimal additional code. Examples are the `ide-disk` and `nand-disk`
triggers.
... | def trigger(self):
"""
Sets the LED trigger. A trigger is a kernel based source of LED events.
Triggers can either be simple or complex. A simple trigger isn't
configurable and is designed to slot into existing subsystems with
minimal additional code. Examples are the `ide-disk` ... |
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `on` time can
be specified via `delay_on` attribute in milliseconds. | def delay_on(self):
"""
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `on` time can
be specified via `delay_on` attribute in milliseconds.
"""
# Workaround for ev3dev/ev3dev#225.
# 'delay_on' and... |
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `off` time can
be specified via `delay_off` attribute in milliseconds. | def delay_off(self):
"""
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `off` time can
be specified via `delay_off` attribute in milliseconds.
"""
# Workaround for ev3dev/ev3dev#225.
# 'delay_on' ... |
Sets brightness of LEDs in the given group to the values specified in
color tuple. When percentage is specified, brightness of each LED is
reduced proportionally.
Example::
my_leds = Leds()
my_leds.set_color('LEFT', 'AMBER')
With a custom color::
m... | def set_color(self, group, color, pct=1):
"""
Sets brightness of LEDs in the given group to the values specified in
color tuple. When percentage is specified, brightness of each LED is
reduced proportionally.
Example::
my_leds = Leds()
my_leds.set_color(... |
Set attributes for each LED in group.
Example::
my_leds = Leds()
my_leds.set_color('LEFT', brightness_pct=0.5, trigger='timer') | def set(self, group, **kwargs):
"""
Set attributes for each LED in group.
Example::
my_leds = Leds()
my_leds.set_color('LEFT', brightness_pct=0.5, trigger='timer')
"""
# If this is a platform without LEDs there is nothing to do
if not self.leds:... |
Turn all LEDs off | def all_off(self):
"""
Turn all LEDs off
"""
# If this is a platform without LEDs there is nothing to do
if not self.leds:
return
for led in self.leds.values():
led.brightness = 0 |
Put all LEDs back to their default color | def reset(self):
"""
Put all LEDs back to their default color
"""
if not self.leds:
return
self.animate_stop()
for group in self.led_groups:
self.set_color(group, LED_DEFAULT_COLOR) |
Cycle the ``group1`` and ``group2`` LEDs between ``color1`` and ``color2``
to give the effect of police lights. Alternate the ``group1`` and ``group2``
LEDs every ``sleeptime`` seconds.
Animate for ``duration`` seconds. If ``duration`` is None animate for forever.
Example:
.... | def animate_police_lights(self, color1, color2, group1='LEFT', group2='RIGHT', sleeptime=0.5, duration=5, block=True):
"""
Cycle the ``group1`` and ``group2`` LEDs between ``color1`` and ``color2``
to give the effect of police lights. Alternate the ``group1`` and ``group2``
LEDs every `... |
Turn all LEDs in ``groups`` off/on to ``color`` every ``sleeptime`` seconds
Animate for ``duration`` seconds. If ``duration`` is None animate for forever.
Example:
.. code-block:: python
from ev3dev2.led import Leds
leds = Leds()
leds.animate_flash('AMBER... | def animate_flash(self, color, groups=('LEFT', 'RIGHT'), sleeptime=0.5, duration=5, block=True):
"""
Turn all LEDs in ``groups`` off/on to ``color`` every ``sleeptime`` seconds
Animate for ``duration`` seconds. If ``duration`` is None animate for forever.
Example:
.. code-blo... |
Cycle ``groups`` LEDs through ``colors``. Do this in a loop where
we display each color for ``sleeptime`` seconds.
Animate for ``duration`` seconds. If ``duration`` is None animate for forever.
Example:
.. code-block:: python
from ev3dev2.led import Leds
leds... | def animate_cycle(self, colors, groups=('LEFT', 'RIGHT'), sleeptime=0.5, duration=5, block=True):
"""
Cycle ``groups`` LEDs through ``colors``. Do this in a loop where
we display each color for ``sleeptime`` seconds.
Animate for ``duration`` seconds. If ``duration`` is None animate for... |
If the request is for a known file type serve the file (or send a 404) and return True | def do_GET(self):
"""
If the request is for a known file type serve the file (or send a 404) and return True
"""
if self.path == "/":
self.path = "/index.html"
# Serve a file (image, css, html, etc)
if '.' in self.path:
extension = self.path.spli... |
Returns True if the requested URL is supported | def do_GET(self):
"""
Returns True if the requested URL is supported
"""
if RobotWebHandler.do_GET(self):
return True
global motor_max_speed
global medium_motor_max_speed
global max_move_xy_seq
global joystick_engaged
if medium_motor... |
Red, green, and blue components of the detected color, as a tuple.
Officially in the range 0-1020 but the values returned will never be
that high. We do not yet know why the values returned are low, but
pointing the color sensor at a well lit sheet of white paper will return
val... | def raw(self):
"""
Red, green, and blue components of the detected color, as a tuple.
Officially in the range 0-1020 but the values returned will never be
that high. We do not yet know why the values returned are low, but
pointing the color sensor at a well lit sheet of ... |
The RGB raw values are on a scale of 0-1020 but you never see a value
anywhere close to 1020. This function is designed to be called when
the sensor is placed over a white object in order to figure out what
are the maximum RGB values the robot can expect to see. We will use
these maxim... | def calibrate_white(self):
"""
The RGB raw values are on a scale of 0-1020 but you never see a value
anywhere close to 1020. This function is designed to be called when
the sensor is placed over a white object in order to figure out what
are the maximum RGB values the robot can ... |
Same as raw() but RGB values are scaled to 0-255 | def rgb(self):
"""
Same as raw() but RGB values are scaled to 0-255
"""
(red, green, blue) = self.raw
return (min(int((red * 255) / self.red_max), 255),
min(int((green * 255) / self.green_max), 255),
min(int((blue * 255) / self.blue_max), 255)) |
Return colors in Lab color space | def lab(self):
"""
Return colors in Lab color space
"""
RGB = [0, 0, 0]
XYZ = [0, 0, 0]
for (num, value) in enumerate(self.rgb):
if value > 0.04045:
value = pow(((value + 0.055) / 1.055), 2.4)
else:
value = value / ... |
HSV: Hue, Saturation, Value
H: position in the spectrum
S: color saturation ("purity")
V: color brightness | def hsv(self):
"""
HSV: Hue, Saturation, Value
H: position in the spectrum
S: color saturation ("purity")
V: color brightness
"""
(r, g, b) = self.rgb
maxc = max(r, g, b)
minc = min(r, g, b)
v = maxc
if minc == maxc:
re... |
HLS: Hue, Luminance, Saturation
H: position in the spectrum
L: color lightness
S: color saturation | def hls(self):
"""
HLS: Hue, Luminance, Saturation
H: position in the spectrum
L: color lightness
S: color saturation
"""
(r, g, b) = self.rgb
maxc = max(r, g, b)
minc = min(r, g, b)
l = (minc+maxc)/2.0
if minc == maxc:
... |
Measurement of the distance detected by the sensor,
in centimeters.
The sensor will continue to take measurements so
they are available for future reads.
Prefer using the equivalent :meth:`UltrasonicSensor.distance_centimeters` property. | def distance_centimeters_continuous(self):
"""
Measurement of the distance detected by the sensor,
in centimeters.
The sensor will continue to take measurements so
they are available for future reads.
Prefer using the equivalent :meth:`UltrasonicSensor.distance_centimet... |
Measurement of the distance detected by the sensor,
in centimeters.
The sensor will take a single measurement then stop
broadcasting.
If you use this property too frequently (e.g. every
100msec), the sensor will sometimes lock up and writing
to the mode attribute will r... | def distance_centimeters_ping(self):
"""
Measurement of the distance detected by the sensor,
in centimeters.
The sensor will take a single measurement then stop
broadcasting.
If you use this property too frequently (e.g. every
100msec), the sensor will sometimes... |
Measurement of the distance detected by the sensor,
in inches.
The sensor will continue to take measurements so
they are available for future reads.
Prefer using the equivalent :meth:`UltrasonicSensor.distance_inches` property. | def distance_inches_continuous(self):
"""
Measurement of the distance detected by the sensor,
in inches.
The sensor will continue to take measurements so
they are available for future reads.
Prefer using the equivalent :meth:`UltrasonicSensor.distance_inches` property.
... |
Measurement of the distance detected by the sensor,
in inches.
The sensor will take a single measurement then stop
broadcasting.
If you use this property too frequently (e.g. every
100msec), the sensor will sometimes lock up and writing
to the mode attribute will return... | def distance_inches_ping(self):
"""
Measurement of the distance detected by the sensor,
in inches.
The sensor will take a single measurement then stop
broadcasting.
If you use this property too frequently (e.g. every
100msec), the sensor will sometimes lock up a... |
Angle (degrees) and Rotational Speed (degrees/second). | def angle_and_rate(self):
"""
Angle (degrees) and Rotational Speed (degrees/second).
"""
self._ensure_mode(self.MODE_GYRO_G_A)
return self.value(0), self.value(1) |
Wait until angle has changed by specified amount.
If ``direction_sensitive`` is True we will wait until angle has changed
by ``delta`` and with the correct sign.
If ``direction_sensitive`` is False (default) we will wait until angle has changed
by ``delta`` in either direction. | def wait_until_angle_changed_by(self, delta, direction_sensitive=False):
"""
Wait until angle has changed by specified amount.
If ``direction_sensitive`` is True we will wait until angle has changed
by ``delta`` and with the correct sign.
If ``direction_sensitive`` is False (de... |
Returns heading (-25, 25) to the beacon on the given channel. | def heading(self, channel=1):
"""
Returns heading (-25, 25) to the beacon on the given channel.
"""
self._ensure_mode(self.MODE_IR_SEEK)
channel = self._normalize_channel(channel)
return self.value(channel * 2) |
Returns distance (0, 100) to the beacon on the given channel.
Returns None when beacon is not found. | def distance(self, channel=1):
"""
Returns distance (0, 100) to the beacon on the given channel.
Returns None when beacon is not found.
"""
self._ensure_mode(self.MODE_IR_SEEK)
channel = self._normalize_channel(channel)
ret_value = self.value((channel * 2) + 1)
... |
Returns list of currently pressed buttons.
Note that the sensor can only identify up to two buttons pressed at once. | def buttons_pressed(self, channel=1):
"""
Returns list of currently pressed buttons.
Note that the sensor can only identify up to two buttons pressed at once.
"""
self._ensure_mode(self.MODE_IR_REMOTE)
channel = self._normalize_channel(channel)
return self._BUTTO... |
Check for currenly pressed buttons. If the new state differs from the
old state, call the appropriate button event handlers.
To use the on_channel1_top_left, etc handlers your program would do something like:
.. code:: python
def top_left_channel_1_action(state):
... | def process(self):
"""
Check for currenly pressed buttons. If the new state differs from the
old state, call the appropriate button event handlers.
To use the on_channel1_top_left, etc handlers your program would do something like:
.. code:: python
def top_... |
A measurement of the measured sound pressure level, as a
percent. Uses a flat weighting. | def sound_pressure(self):
"""
A measurement of the measured sound pressure level, as a
percent. Uses a flat weighting.
"""
self._ensure_mode(self.MODE_DB)
return self.value(0) * self._scale('DB') |
A measurement of the measured sound pressure level, as a
percent. Uses A-weighting, which focuses on levels up to 55 dB. | def sound_pressure_low(self):
"""
A measurement of the measured sound pressure level, as a
percent. Uses A-weighting, which focuses on levels up to 55 dB.
"""
self._ensure_mode(self.MODE_DBA)
return self.value(0) * self._scale('DBA') |
A measurement of the reflected light intensity, as a percentage. | def reflected_light_intensity(self):
"""
A measurement of the reflected light intensity, as a percentage.
"""
self._ensure_mode(self.MODE_REFLECT)
return self.value(0) * self._scale('REFLECT') |
A measurement of the ambient light intensity, as a percentage. | def ambient_light_intensity(self):
"""
A measurement of the ambient light intensity, as a percentage.
"""
self._ensure_mode(self.MODE_AMBIENT)
return self.value(0) * self._scale('AMBIENT') |
The measured current that the battery is supplying (in microamps) | def measured_current(self):
"""
The measured current that the battery is supplying (in microamps)
"""
self._measured_current, value = self.get_attr_int(self._measured_current, 'current_now')
return value |
The measured voltage that the battery is supplying (in microvolts) | def measured_voltage(self):
"""
The measured voltage that the battery is supplying (in microvolts)
"""
self._measured_voltage, value = self.get_attr_int(self._measured_voltage, 'voltage_now')
return value |
Returns list of available font names. | def available():
"""
Returns list of available font names.
"""
font_dir = os.path.dirname(__file__)
names = [os.path.basename(os.path.splitext(f)[0])
for f in glob(os.path.join(font_dir, '*.pil'))]
return sorted(names) |
Loads the font specified by name and returns it as an instance of
`PIL.ImageFont <http://pillow.readthedocs.io/en/latest/reference/ImageFont.html>`_
class. | def load(name):
"""
Loads the font specified by name and returns it as an instance of
`PIL.ImageFont <http://pillow.readthedocs.io/en/latest/reference/ImageFont.html>`_
class.
"""
try:
font_dir = os.path.dirname(__file__)
pil_file = os.path.join(font_dir, '{}.pil'.format(name))
... |
Returns a list of the available modes of the port. | def modes(self):
"""
Returns a list of the available modes of the port.
"""
(self._modes, value) = self.get_cached_attr_set(self._modes, 'modes')
return value |
Reading returns the currently selected mode. Writing sets the mode.
Generally speaking when the mode changes any sensor or motor devices
associated with the port will be removed new ones loaded, however this
this will depend on the individual driver implementing this class. | def mode(self):
"""
Reading returns the currently selected mode. Writing sets the mode.
Generally speaking when the mode changes any sensor or motor devices
associated with the port will be removed new ones loaded, however this
this will depend on the individual driver implementi... |
In most cases, reading status will return the same value as `mode`. In
cases where there is an `auto` mode additional values may be returned,
such as `no-device` or `error`. See individual port driver documentation
for the full list of possible values. | def status(self):
"""
In most cases, reading status will return the same value as `mode`. In
cases where there is an `auto` mode additional values may be returned,
such as `no-device` or `error`. See individual port driver documentation
for the full list of possible values.
... |
This is a generator function that enumerates all sensors that match the
provided arguments.
Parameters:
name_pattern: pattern that device name should match.
For example, 'sensor*'. Default value: '*'.
keyword arguments: used for matching the corresponding device
attribut... | def list_sensors(name_pattern=Sensor.SYSTEM_DEVICE_NAME_CONVENTION, **kwargs):
"""
This is a generator function that enumerates all sensors that match the
provided arguments.
Parameters:
name_pattern: pattern that device name should match.
For example, 'sensor*'. Default value: '*'.... |
Returns value scaling coefficient for the given mode. | def _scale(self, mode):
"""
Returns value scaling coefficient for the given mode.
"""
if mode in self._mode_scale:
scale = self._mode_scale[mode]
else:
scale = 10**(-self.decimals)
self._mode_scale[mode] = scale
return scale |
Returns the number of decimal places for the values in the `value<N>`
attributes of the current mode. | def decimals(self):
"""
Returns the number of decimal places for the values in the `value<N>`
attributes of the current mode.
"""
self._decimals, value = self.get_attr_int(self._decimals, 'decimals')
return value |
Returns the number of `value<N>` attributes that will return a valid value
for the current mode. | def num_values(self):
"""
Returns the number of `value<N>` attributes that will return a valid value
for the current mode.
"""
self._num_values, value = self.get_attr_int(self._num_values, 'num_values')
return value |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.