_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q228600 | Motor.max_speed | train | def max_speed(self):
"""
Returns the maximum value that is accepted by the `speed_sp` attribute. This
may be slightly different than the maximum speed that a particular motor can
reach - it's the maximum theoretical speed.
"""
(self._max_speed, value) = self.get_cached_at... | python | {
"resource": ""
} |
q228601 | Motor.ramp_up_sp | train | def ramp_up_sp(self):
"""
Writing sets the ramp up 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 increase from 0 to 100% of `max_speed` over the span of this
setpoint. The actual ram... | python | {
"resource": ""
} |
q228602 | Motor.ramp_down_sp | train | 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... | python | {
"resource": ""
} |
q228603 | Motor.speed_p | train | 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 | python | {
"resource": ""
} |
q228604 | Motor.speed_i | train | 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 | python | {
"resource": ""
} |
q228605 | Motor.speed_d | train | 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 | python | {
"resource": ""
} |
q228606 | Motor.state | train | 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 | python | {
"resource": ""
} |
q228607 | Motor.stop_action | train | 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... | python | {
"resource": ""
} |
q228608 | Motor.stop_actions | train | 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... | python | {
"resource": ""
} |
q228609 | Motor.time_sp | train | 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 | python | {
"resource": ""
} |
q228610 | Motor.run_forever | train | 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 | python | {
"resource": ""
} |
q228611 | Motor.run_to_abs_pos | train | 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 | python | {
"resource": ""
} |
q228612 | Motor.run_to_rel_pos | train | 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`.
"""
... | python | {
"resource": ""
} |
q228613 | Motor.run_timed | train | 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 | python | {
"resource": ""
} |
q228614 | Motor.stop | train | def stop(self, **kwargs):
"""
Stop any of the run commands before they are complete using the
action specified by `stop_action`.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_STOP | python | {
"resource": ""
} |
q228615 | Motor.reset | train | 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 | python | {
"resource": ""
} |
q228616 | Motor.on_for_rotations | train | 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... | python | {
"resource": ""
} |
q228617 | Motor.on_for_degrees | train | 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)
... | python | {
"resource": ""
} |
q228618 | Motor.on_to_position | train | 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)
... | python | {
"resource": ""
} |
q228619 | Motor.on_for_seconds | train | 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... | python | {
"resource": ""
} |
q228620 | Motor.on | train | 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 ... | python | {
"resource": ""
} |
q228621 | DcMotor.commands | train | 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 | python | {
"resource": ""
} |
q228622 | DcMotor.stop_actions | train | 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 | python | {
"resource": ""
} |
q228623 | ServoMotor.mid_pulse_sp | train | 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... | python | {
"resource": ""
} |
q228624 | ServoMotor.run | train | 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 | python | {
"resource": ""
} |
q228625 | ServoMotor.float | train | def float(self, **kwargs):
"""
Remove power from the motor.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_FLOAT | python | {
"resource": ""
} |
q228626 | MotorSet.off | train | 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:
... | python | {
"resource": ""
} |
q228627 | MoveTank.on_for_degrees | train | 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
... | python | {
"resource": ""
} |
q228628 | MoveTank.on_for_rotations | train | 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... | python | {
"resource": ""
} |
q228629 | MoveTank.on_for_seconds | train | 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... | python | {
"resource": ""
} |
q228630 | MoveTank.on | train | 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(... | python | {
"resource": ""
} |
q228631 | MoveSteering.on_for_seconds | train | 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... | python | {
"resource": ""
} |
q228632 | MoveSteering.on | train | 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... | python | {
"resource": ""
} |
q228633 | MoveDifferential._on_arc | train | 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... | python | {
"resource": ""
} |
q228634 | MoveDifferential.on_arc_right | train | 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) | python | {
"resource": ""
} |
q228635 | MoveDifferential.on_arc_left | train | 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) | python | {
"resource": ""
} |
q228636 | MoveDifferential._turn | train | 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
# ... | python | {
"resource": ""
} |
q228637 | MoveDifferential.turn_right | train | def turn_right(self, speed, degrees, brake=True, block=True):
"""
Rotate clockwise 'degrees' in place
"""
self._turn(speed, abs(degrees), brake, block) | python | {
"resource": ""
} |
q228638 | MoveDifferential.turn_to_angle | train | 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 ... | python | {
"resource": ""
} |
q228639 | datetime_delta_to_ms | train | 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 | python | {
"resource": ""
} |
q228640 | duration_expired | train | 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:
... | python | {
"resource": ""
} |
q228641 | Led.max_brightness | train | 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 | python | {
"resource": ""
} |
q228642 | Led.brightness | train | 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 | python | {
"resource": ""
} |
q228643 | Led.triggers | train | def triggers(self):
"""
Returns a list of available triggers.
"""
self._triggers, value = self.get_attr_set(self._triggers, 'trigger')
return value | python | {
"resource": ""
} |
q228644 | Led.trigger | train | 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` ... | python | {
"resource": ""
} |
q228645 | Led.delay_on | train | 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... | python | {
"resource": ""
} |
q228646 | Led.delay_off | train | 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' ... | python | {
"resource": ""
} |
q228647 | Leds.set_color | train | 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(... | python | {
"resource": ""
} |
q228648 | Leds.set | train | 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:... | python | {
"resource": ""
} |
q228649 | Leds.all_off | train | 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 | python | {
"resource": ""
} |
q228650 | Leds.reset | train | 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) | python | {
"resource": ""
} |
q228651 | Leds.animate_police_lights | train | 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 `... | python | {
"resource": ""
} |
q228652 | Leds.animate_cycle | train | 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... | python | {
"resource": ""
} |
q228653 | Leds.animate_rainbow | train | def animate_rainbow(self, group1='LEFT', group2='RIGHT', increment_by=0.1, sleeptime=0.1, duration=5, block=True):
"""
Gradually fade from one color to the next
Animate for ``duration`` seconds. If ``duration`` is None animate for forever.
Example:
.. code-block:: python
... | python | {
"resource": ""
} |
q228654 | ColorSensor.raw | train | 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 ... | python | {
"resource": ""
} |
q228655 | ColorSensor.lab | train | 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 / ... | python | {
"resource": ""
} |
q228656 | GyroSensor.wait_until_angle_changed_by | train | 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... | python | {
"resource": ""
} |
q228657 | InfraredSensor.buttons_pressed | train | 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... | python | {
"resource": ""
} |
q228658 | SoundSensor.sound_pressure | train | 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') | python | {
"resource": ""
} |
q228659 | SoundSensor.sound_pressure_low | train | 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') | python | {
"resource": ""
} |
q228660 | LightSensor.reflected_light_intensity | train | 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') | python | {
"resource": ""
} |
q228661 | LightSensor.ambient_light_intensity | train | 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') | python | {
"resource": ""
} |
q228662 | available | train | 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) | python | {
"resource": ""
} |
q228663 | LegoPort.modes | train | 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 | python | {
"resource": ""
} |
q228664 | LegoPort.mode | train | 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... | python | {
"resource": ""
} |
q228665 | LegoPort.status | train | 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.
... | python | {
"resource": ""
} |
q228666 | list_sensors | train | 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: '*'.... | python | {
"resource": ""
} |
q228667 | Sensor._scale | train | 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 | python | {
"resource": ""
} |
q228668 | Sensor.units | train | def units(self):
"""
Returns the units of the measured value for the current mode. May return
empty string
"""
self._units, value = self.get_attr_string(self._units, 'units')
return value | python | {
"resource": ""
} |
q228669 | Sensor.value | train | def value(self, n=0):
"""
Returns the value or values measured by the sensor. Check num_values to
see how many values there are. Values with N >= num_values will return
an error. The values are fixed point numbers, so check decimals to see
if you need to divide to get the actual ... | python | {
"resource": ""
} |
q228670 | FbMem._open_fbdev | train | def _open_fbdev(fbdev=None):
"""Return the framebuffer file descriptor.
Try to use the FRAMEBUFFER
environment variable if fbdev is not given. Use '/dev/fb0' by
default.
"""
dev = fbdev or os.getenv('FRAMEBUFFER', '/dev/fb0')
fbfid = os.open(dev, os.O_RDWR)
... | python | {
"resource": ""
} |
q228671 | FbMem._get_fix_info | train | def _get_fix_info(fbfid):
"""Return the fix screen info from the framebuffer file descriptor."""
fix_info = FbMem.FixScreenInfo()
fcntl.ioctl(fbfid, FbMem.FBIOGET_FSCREENINFO, fix_info)
return fix_info | python | {
"resource": ""
} |
q228672 | FbMem._get_var_info | train | def _get_var_info(fbfid):
"""Return the var screen info from the framebuffer file descriptor."""
var_info = FbMem.VarScreenInfo()
fcntl.ioctl(fbfid, FbMem.FBIOGET_VSCREENINFO, var_info)
return var_info | python | {
"resource": ""
} |
q228673 | FbMem._map_fb_memory | train | def _map_fb_memory(fbfid, fix_info):
"""Map the framebuffer memory."""
return mmap.mmap(
fbfid,
fix_info.smem_len,
mmap.MAP_SHARED,
mmap.PROT_READ | mmap.PROT_WRITE,
offset=0
) | python | {
"resource": ""
} |
q228674 | Display.update | train | def update(self):
"""
Applies pending changes to the screen.
Nothing will be drawn on the screen until this function is called.
"""
if self.var_info.bits_per_pixel == 1:
b = self._img.tobytes("raw", "1;R")
self.mmap[:len(b)] = b
elif self.var_info... | python | {
"resource": ""
} |
q228675 | _make_scales | train | def _make_scales(notes):
""" Utility function used by Sound class for building the note frequencies table """
res = dict()
for note, freq in notes:
freq = round(freq)
for n in note.split('/'):
res[n] = freq
return res | python | {
"resource": ""
} |
q228676 | Sound.play_tone | train | def play_tone(self, frequency, duration, delay=0.0, volume=100,
play_type=PLAY_WAIT_FOR_COMPLETE):
""" Play a single tone, specified by its frequency, duration, volume and final delay.
:param int frequency: the tone frequency, in Hertz
:param float duration: Tone duration, in ... | python | {
"resource": ""
} |
q228677 | Sound.play_note | train | def play_note(self, note, duration, volume=100, play_type=PLAY_WAIT_FOR_COMPLETE):
""" Plays a note, given by its name as defined in ``_NOTE_FREQUENCIES``.
:param string note: The note symbol with its octave number
:param float duration: Tone duration, in seconds
:param int volume: The ... | python | {
"resource": ""
} |
q228678 | Sound.speak | train | def speak(self, text, espeak_opts='-a 200 -s 130', volume=100, play_type=PLAY_WAIT_FOR_COMPLETE):
""" Speak the given text aloud.
Uses the ``espeak`` external command.
:param string text: The text to speak
:param string espeak_opts: ``espeak`` command options (advanced usage)
:... | python | {
"resource": ""
} |
q228679 | Sound.play_song | train | def play_song(self, song, tempo=120, delay=0.05):
""" Plays a song provided as a list of tuples containing the note name and its
value using music conventional notation instead of numerical values for frequency
and duration.
It supports symbolic notes (e.g. ``A4``, ``D#3``, ``Gb5``) and... | python | {
"resource": ""
} |
q228680 | list_device_names | train | def list_device_names(class_path, name_pattern, **kwargs):
"""
This is a generator function that lists names of all devices matching the
provided parameters.
Parameters:
class_path: class path of the device, a subdirectory of /sys/class.
For example, '/sys/class/tacho-motor'.
... | python | {
"resource": ""
} |
q228681 | list_devices | train | def list_devices(class_name, name_pattern, **kwargs):
"""
This is a generator function that takes same arguments as `Device` class
and enumerates all devices present in the system that match the provided
arguments.
Parameters:
class_name: class name of the device, a subdirectory of /sys/cla... | python | {
"resource": ""
} |
q228682 | Device._get_attribute | train | def _get_attribute(self, attribute, name):
"""Device attribute getter"""
try:
if attribute is None:
attribute = self._attribute_file_open( name )
else:
attribute.seek(0)
return attribute, attribute.read().strip().decode()
except... | python | {
"resource": ""
} |
q228683 | Device._set_attribute | train | def _set_attribute(self, attribute, name, value):
"""Device attribute setter"""
try:
if attribute is None:
attribute = self._attribute_file_open( name )
else:
attribute.seek(0)
if isinstance(value, str):
value = value.e... | python | {
"resource": ""
} |
q228684 | GyroBalancer.shutdown | train | def shutdown(self):
"""Close all file handles and stop all motors."""
self.stop_balance.set() # Stop balance thread
self.motor_left.stop()
self.motor_right.stop()
self.gyro_file.close()
self.touch_file.close()
self.encoder_left_file.close()
self.encoder_r... | python | {
"resource": ""
} |
q228685 | GyroBalancer._fast_read | train | def _fast_read(self, infile):
"""Function for fast reading from sensor files."""
infile.seek(0)
return(int(infile.read().decode().strip())) | python | {
"resource": ""
} |
q228686 | GyroBalancer._fast_write | train | def _fast_write(self, outfile, value):
"""Function for fast writing to motor files."""
outfile.truncate(0)
outfile.write(str(int(value)))
outfile.flush() | python | {
"resource": ""
} |
q228687 | GyroBalancer._set_duty | train | def _set_duty(self, motor_duty_file, duty, friction_offset,
voltage_comp):
"""Function to set the duty cycle of the motors."""
# Compensate for nominal voltage and round the input
duty_int = int(round(duty*voltage_comp))
# Add or subtract offset and clamp the value bet... | python | {
"resource": ""
} |
q228688 | GyroBalancer.balance | train | def balance(self):
"""Run the _balance method as a thread."""
balance_thread = threading.Thread(target=self._balance)
balance_thread.start() | python | {
"resource": ""
} |
q228689 | GyroBalancer._move | train | def _move(self, speed=0, steering=0, seconds=None):
"""Move robot."""
self.drive_queue.put((speed, steering))
if seconds is not None:
time.sleep(seconds)
self.drive_queue.put((0, 0))
self.drive_queue.join() | python | {
"resource": ""
} |
q228690 | GyroBalancer.move_forward | train | def move_forward(self, seconds=None):
"""Move robot forward."""
self._move(speed=SPEED_MAX, steering=0, seconds=seconds) | python | {
"resource": ""
} |
q228691 | GyroBalancer.move_backward | train | def move_backward(self, seconds=None):
"""Move robot backward."""
self._move(speed=-SPEED_MAX, steering=0, seconds=seconds) | python | {
"resource": ""
} |
q228692 | GyroBalancer.rotate_left | train | def rotate_left(self, seconds=None):
"""Rotate robot left."""
self._move(speed=0, steering=STEER_MAX, seconds=seconds) | python | {
"resource": ""
} |
q228693 | GyroBalancer.rotate_right | train | def rotate_right(self, seconds=None):
"""Rotate robot right."""
self._move(speed=0, steering=-STEER_MAX, seconds=seconds) | python | {
"resource": ""
} |
q228694 | ButtonBase.evdev_device | train | def evdev_device(self):
"""
Return our corresponding evdev device object
"""
devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()]
for device in devices:
if device.name == self.evdev_device_name:
return device
raise Exception("%s: ... | python | {
"resource": ""
} |
q228695 | ButtonBase.wait_for_bump | train | def wait_for_bump(self, buttons, timeout_ms=None):
"""
Wait for the button to be pressed down and then released.
Both actions must happen within timeout_ms.
"""
start_time = time.time()
if self.wait_for_pressed(buttons, timeout_ms):
if timeout_ms is not None:... | python | {
"resource": ""
} |
q228696 | ButtonEVIO.buttons_pressed | train | def buttons_pressed(self):
"""
Returns list of names of pressed buttons.
"""
for b in self._buffer_cache:
fcntl.ioctl(self._button_file(b), self.EVIOCGKEY, self._buffer_cache[b])
pressed = []
for k, v in self._buttons.items():
buf = self._buffer_c... | python | {
"resource": ""
} |
q228697 | _orted_process | train | def _orted_process():
"""Waits maximum of 5 minutes for orted process to start"""
for i in range(5 * 60):
procs = [p for p in psutil.process_iter(attrs=['name']) if p.info['name'] == 'orted']
if procs:
return procs
time.sleep(1) | python | {
"resource": ""
} |
q228698 | _parse_custom_mpi_options | train | def _parse_custom_mpi_options(custom_mpi_options):
# type: (str) -> Tuple[argparse.Namespace, List[str]]
"""Parse custom MPI options provided by user. Known options default value will be overridden
and unknown options would be identified separately."""
parser = argparse.ArgumentParser()
parser.add_... | python | {
"resource": ""
} |
q228699 | download_and_install | train | def download_and_install(uri, name=DEFAULT_MODULE_NAME, cache=True):
# type: (str, str, bool) -> None
"""Download, prepare and install a compressed tar file from S3 or local directory as a module.
The SageMaker Python SDK saves the user provided scripts as compressed tar files in S3.
This function down... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.