repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | SpeedRPS.to_native_units | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired rotations-per-second
"""
assert abs(self.rotations_per_second) <= motor.max_rps,\
"invalid rotations-per-second: {} max RPS is {}, {} was requested".format(
motor, motor.max_rps, self.rotations_per_second)
return self.rotations_per_second/motor.max_rps * motor.max_speed | python | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired rotations-per-second
"""
assert abs(self.rotations_per_second) <= motor.max_rps,\
"invalid rotations-per-second: {} max RPS is {}, {} was requested".format(
motor, motor.max_rps, self.rotations_per_second)
return self.rotations_per_second/motor.max_rps * motor.max_speed | [
"def",
"to_native_units",
"(",
"self",
",",
"motor",
")",
":",
"assert",
"abs",
"(",
"self",
".",
"rotations_per_second",
")",
"<=",
"motor",
".",
"max_rps",
",",
"\"invalid rotations-per-second: {} max RPS is {}, {} was requested\"",
".",
"format",
"(",
"motor",
",... | Return the native speed measurement required to achieve desired rotations-per-second | [
"Return",
"the",
"native",
"speed",
"measurement",
"required",
"to",
"achieve",
"desired",
"rotations",
"-",
"per",
"-",
"second"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L155-L162 | train | 228,100 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | SpeedRPM.to_native_units | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired rotations-per-minute
"""
assert abs(self.rotations_per_minute) <= motor.max_rpm,\
"invalid rotations-per-minute: {} max RPM is {}, {} was requested".format(
motor, motor.max_rpm, self.rotations_per_minute)
return self.rotations_per_minute/motor.max_rpm * motor.max_speed | python | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired rotations-per-minute
"""
assert abs(self.rotations_per_minute) <= motor.max_rpm,\
"invalid rotations-per-minute: {} max RPM is {}, {} was requested".format(
motor, motor.max_rpm, self.rotations_per_minute)
return self.rotations_per_minute/motor.max_rpm * motor.max_speed | [
"def",
"to_native_units",
"(",
"self",
",",
"motor",
")",
":",
"assert",
"abs",
"(",
"self",
".",
"rotations_per_minute",
")",
"<=",
"motor",
".",
"max_rpm",
",",
"\"invalid rotations-per-minute: {} max RPM is {}, {} was requested\"",
".",
"format",
"(",
"motor",
",... | Return the native speed measurement required to achieve desired rotations-per-minute | [
"Return",
"the",
"native",
"speed",
"measurement",
"required",
"to",
"achieve",
"desired",
"rotations",
"-",
"per",
"-",
"minute"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L180-L187 | train | 228,101 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | SpeedDPS.to_native_units | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired degrees-per-second
"""
assert abs(self.degrees_per_second) <= motor.max_dps,\
"invalid degrees-per-second: {} max DPS is {}, {} was requested".format(
motor, motor.max_dps, self.degrees_per_second)
return self.degrees_per_second/motor.max_dps * motor.max_speed | python | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired degrees-per-second
"""
assert abs(self.degrees_per_second) <= motor.max_dps,\
"invalid degrees-per-second: {} max DPS is {}, {} was requested".format(
motor, motor.max_dps, self.degrees_per_second)
return self.degrees_per_second/motor.max_dps * motor.max_speed | [
"def",
"to_native_units",
"(",
"self",
",",
"motor",
")",
":",
"assert",
"abs",
"(",
"self",
".",
"degrees_per_second",
")",
"<=",
"motor",
".",
"max_dps",
",",
"\"invalid degrees-per-second: {} max DPS is {}, {} was requested\"",
".",
"format",
"(",
"motor",
",",
... | Return the native speed measurement required to achieve desired degrees-per-second | [
"Return",
"the",
"native",
"speed",
"measurement",
"required",
"to",
"achieve",
"desired",
"degrees",
"-",
"per",
"-",
"second"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L205-L212 | train | 228,102 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | SpeedDPM.to_native_units | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired degrees-per-minute
"""
assert abs(self.degrees_per_minute) <= motor.max_dpm,\
"invalid degrees-per-minute: {} max DPM is {}, {} was requested".format(
motor, motor.max_dpm, self.degrees_per_minute)
return self.degrees_per_minute/motor.max_dpm * motor.max_speed | python | def to_native_units(self, motor):
"""
Return the native speed measurement required to achieve desired degrees-per-minute
"""
assert abs(self.degrees_per_minute) <= motor.max_dpm,\
"invalid degrees-per-minute: {} max DPM is {}, {} was requested".format(
motor, motor.max_dpm, self.degrees_per_minute)
return self.degrees_per_minute/motor.max_dpm * motor.max_speed | [
"def",
"to_native_units",
"(",
"self",
",",
"motor",
")",
":",
"assert",
"abs",
"(",
"self",
".",
"degrees_per_minute",
")",
"<=",
"motor",
".",
"max_dpm",
",",
"\"invalid degrees-per-minute: {} max DPM is {}, {} was requested\"",
".",
"format",
"(",
"motor",
",",
... | Return the native speed measurement required to achieve desired degrees-per-minute | [
"Return",
"the",
"native",
"speed",
"measurement",
"required",
"to",
"achieve",
"desired",
"degrees",
"-",
"per",
"-",
"minute"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L230-L237 | train | 228,103 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.address | def address(self):
"""
Returns the name of the port that this motor is connected to.
"""
self._address, value = self.get_attr_string(self._address, 'address')
return value | python | def address(self):
"""
Returns the name of the port that this motor is connected to.
"""
self._address, value = self.get_attr_string(self._address, 'address')
return value | [
"def",
"address",
"(",
"self",
")",
":",
"self",
".",
"_address",
",",
"value",
"=",
"self",
".",
"get_attr_string",
"(",
"self",
".",
"_address",
",",
"'address'",
")",
"return",
"value"
] | Returns the name of the port that this motor is connected to. | [
"Returns",
"the",
"name",
"of",
"the",
"port",
"that",
"this",
"motor",
"is",
"connected",
"to",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L403-L408 | train | 228,104 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.commands | def commands(self):
"""
Returns a list of commands that are supported by the motor
controller. Possible values are `run-forever`, `run-to-abs-pos`, `run-to-rel-pos`,
`run-timed`, `run-direct`, `stop` and `reset`. Not all commands may be supported.
- `run-forever` will cause the motor to run until another command is sent.
- `run-to-abs-pos` will run to an absolute position specified by `position_sp`
and then stop using the action specified in `stop_action`.
- `run-to-rel-pos` will 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-timed` will run the motor for the amount of time specified in `time_sp`
and then stop the motor using the action specified by `stop_action`.
- `run-direct` will 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.
- `stop` will stop any of the run commands before they are complete using the
action specified by `stop_action`.
- `reset` will reset all of the motor parameter attributes to their default value.
This will also have the effect of stopping the motor.
"""
(self._commands, value) = self.get_cached_attr_set(self._commands, 'commands')
return value | python | def commands(self):
"""
Returns a list of commands that are supported by the motor
controller. Possible values are `run-forever`, `run-to-abs-pos`, `run-to-rel-pos`,
`run-timed`, `run-direct`, `stop` and `reset`. Not all commands may be supported.
- `run-forever` will cause the motor to run until another command is sent.
- `run-to-abs-pos` will run to an absolute position specified by `position_sp`
and then stop using the action specified in `stop_action`.
- `run-to-rel-pos` will 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-timed` will run the motor for the amount of time specified in `time_sp`
and then stop the motor using the action specified by `stop_action`.
- `run-direct` will 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.
- `stop` will stop any of the run commands before they are complete using the
action specified by `stop_action`.
- `reset` will reset all of the motor parameter attributes to their default value.
This will also have the effect of stopping the motor.
"""
(self._commands, value) = self.get_cached_attr_set(self._commands, 'commands')
return value | [
"def",
"commands",
"(",
"self",
")",
":",
"(",
"self",
".",
"_commands",
",",
"value",
")",
"=",
"self",
".",
"get_cached_attr_set",
"(",
"self",
".",
"_commands",
",",
"'commands'",
")",
"return",
"value"
] | Returns a list of commands that are supported by the motor
controller. Possible values are `run-forever`, `run-to-abs-pos`, `run-to-rel-pos`,
`run-timed`, `run-direct`, `stop` and `reset`. Not all commands may be supported.
- `run-forever` will cause the motor to run until another command is sent.
- `run-to-abs-pos` will run to an absolute position specified by `position_sp`
and then stop using the action specified in `stop_action`.
- `run-to-rel-pos` will 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-timed` will run the motor for the amount of time specified in `time_sp`
and then stop the motor using the action specified by `stop_action`.
- `run-direct` will 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.
- `stop` will stop any of the run commands before they are complete using the
action specified by `stop_action`.
- `reset` will reset all of the motor parameter attributes to their default value.
This will also have the effect of stopping the motor. | [
"Returns",
"a",
"list",
"of",
"commands",
"that",
"are",
"supported",
"by",
"the",
"motor",
"controller",
".",
"Possible",
"values",
"are",
"run",
"-",
"forever",
"run",
"-",
"to",
"-",
"abs",
"-",
"pos",
"run",
"-",
"to",
"-",
"rel",
"-",
"pos",
"ru... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L423-L446 | train | 228,105 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.driver_name | def driver_name(self):
"""
Returns the name of the driver that provides this tacho motor device.
"""
(self._driver_name, value) = self.get_cached_attr_string(self._driver_name, 'driver_name')
return value | python | def driver_name(self):
"""
Returns the name of the driver that provides this tacho motor device.
"""
(self._driver_name, value) = self.get_cached_attr_string(self._driver_name, 'driver_name')
return value | [
"def",
"driver_name",
"(",
"self",
")",
":",
"(",
"self",
".",
"_driver_name",
",",
"value",
")",
"=",
"self",
".",
"get_cached_attr_string",
"(",
"self",
".",
"_driver_name",
",",
"'driver_name'",
")",
"return",
"value"
] | Returns the name of the driver that provides this tacho motor device. | [
"Returns",
"the",
"name",
"of",
"the",
"driver",
"that",
"provides",
"this",
"tacho",
"motor",
"device",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L469-L474 | train | 228,106 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.duty_cycle | def duty_cycle(self):
"""
Returns the current duty cycle of the motor. Units are percent. Values
are -100 to 100.
"""
self._duty_cycle, value = self.get_attr_int(self._duty_cycle, 'duty_cycle')
return value | python | def duty_cycle(self):
"""
Returns the current duty cycle of the motor. Units are percent. Values
are -100 to 100.
"""
self._duty_cycle, value = self.get_attr_int(self._duty_cycle, 'duty_cycle')
return value | [
"def",
"duty_cycle",
"(",
"self",
")",
":",
"self",
".",
"_duty_cycle",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_duty_cycle",
",",
"'duty_cycle'",
")",
"return",
"value"
] | Returns the current duty cycle of the motor. Units are percent. Values
are -100 to 100. | [
"Returns",
"the",
"current",
"duty",
"cycle",
"of",
"the",
"motor",
".",
"Units",
"are",
"percent",
".",
"Values",
"are",
"-",
"100",
"to",
"100",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L477-L483 | train | 228,107 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.duty_cycle_sp | def duty_cycle_sp(self):
"""
Writing sets the duty cycle setpoint. Reading returns the current value.
Units are in percent. Valid values are -100 to 100. A negative value causes
the motor to rotate in reverse.
"""
self._duty_cycle_sp, value = self.get_attr_int(self._duty_cycle_sp, 'duty_cycle_sp')
return value | python | def duty_cycle_sp(self):
"""
Writing sets the duty cycle setpoint. Reading returns the current value.
Units are in percent. Valid values are -100 to 100. A negative value causes
the motor to rotate in reverse.
"""
self._duty_cycle_sp, value = self.get_attr_int(self._duty_cycle_sp, 'duty_cycle_sp')
return value | [
"def",
"duty_cycle_sp",
"(",
"self",
")",
":",
"self",
".",
"_duty_cycle_sp",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_duty_cycle_sp",
",",
"'duty_cycle_sp'",
")",
"return",
"value"
] | Writing sets the duty cycle setpoint. Reading returns the current value.
Units are in percent. Valid values are -100 to 100. A negative value causes
the motor to rotate in reverse. | [
"Writing",
"sets",
"the",
"duty",
"cycle",
"setpoint",
".",
"Reading",
"returns",
"the",
"current",
"value",
".",
"Units",
"are",
"in",
"percent",
".",
"Valid",
"values",
"are",
"-",
"100",
"to",
"100",
".",
"A",
"negative",
"value",
"causes",
"the",
"mo... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L486-L493 | train | 228,108 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.polarity | def polarity(self):
"""
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`.
"""
self._polarity, value = self.get_attr_string(self._polarity, 'polarity')
return value | python | def polarity(self):
"""
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`.
"""
self._polarity, value = self.get_attr_string(self._polarity, 'polarity')
return value | [
"def",
"polarity",
"(",
"self",
")",
":",
"self",
".",
"_polarity",
",",
"value",
"=",
"self",
".",
"get_attr_string",
"(",
"self",
".",
"_polarity",
",",
"'polarity'",
")",
"return",
"value"
] | 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`. | [
"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",... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L510-L518 | train | 228,109 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.position | def position(self):
"""
Returns the current position of the motor in pulses of the rotary
encoder. When the motor rotates clockwise, the position will increase.
Likewise, rotating counter-clockwise causes the position to decrease.
Writing will set the position to that value.
"""
self._position, value = self.get_attr_int(self._position, 'position')
return value | python | def position(self):
"""
Returns the current position of the motor in pulses of the rotary
encoder. When the motor rotates clockwise, the position will increase.
Likewise, rotating counter-clockwise causes the position to decrease.
Writing will set the position to that value.
"""
self._position, value = self.get_attr_int(self._position, 'position')
return value | [
"def",
"position",
"(",
"self",
")",
":",
"self",
".",
"_position",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_position",
",",
"'position'",
")",
"return",
"value"
] | Returns the current position of the motor in pulses of the rotary
encoder. When the motor rotates clockwise, the position will increase.
Likewise, rotating counter-clockwise causes the position to decrease.
Writing will set the position to that value. | [
"Returns",
"the",
"current",
"position",
"of",
"the",
"motor",
"in",
"pulses",
"of",
"the",
"rotary",
"encoder",
".",
"When",
"the",
"motor",
"rotates",
"clockwise",
"the",
"position",
"will",
"increase",
".",
"Likewise",
"rotating",
"counter",
"-",
"clockwise... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L525-L533 | train | 228,110 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.position_p | def position_p(self):
"""
The proportional constant for the position PID.
"""
self._position_p, value = self.get_attr_int(self._position_p, 'hold_pid/Kp')
return value | python | def position_p(self):
"""
The proportional constant for the position PID.
"""
self._position_p, value = self.get_attr_int(self._position_p, 'hold_pid/Kp')
return value | [
"def",
"position_p",
"(",
"self",
")",
":",
"self",
".",
"_position_p",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_position_p",
",",
"'hold_pid/Kp'",
")",
"return",
"value"
] | The proportional constant for the position PID. | [
"The",
"proportional",
"constant",
"for",
"the",
"position",
"PID",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L540-L545 | train | 228,111 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.position_i | def position_i(self):
"""
The integral constant for the position PID.
"""
self._position_i, value = self.get_attr_int(self._position_i, 'hold_pid/Ki')
return value | python | def position_i(self):
"""
The integral constant for the position PID.
"""
self._position_i, value = self.get_attr_int(self._position_i, 'hold_pid/Ki')
return value | [
"def",
"position_i",
"(",
"self",
")",
":",
"self",
".",
"_position_i",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_position_i",
",",
"'hold_pid/Ki'",
")",
"return",
"value"
] | The integral constant for the position PID. | [
"The",
"integral",
"constant",
"for",
"the",
"position",
"PID",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L552-L557 | train | 228,112 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.position_d | def position_d(self):
"""
The derivative constant for the position PID.
"""
self._position_d, value = self.get_attr_int(self._position_d, 'hold_pid/Kd')
return value | python | def position_d(self):
"""
The derivative constant for the position PID.
"""
self._position_d, value = self.get_attr_int(self._position_d, 'hold_pid/Kd')
return value | [
"def",
"position_d",
"(",
"self",
")",
":",
"self",
".",
"_position_d",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_position_d",
",",
"'hold_pid/Kd'",
")",
"return",
"value"
] | The derivative constant for the position PID. | [
"The",
"derivative",
"constant",
"for",
"the",
"position",
"PID",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L564-L569 | train | 228,113 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.max_speed | 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_attr_int(self._max_speed, 'max_speed')
return value | python | 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_attr_int(self._max_speed, 'max_speed')
return value | [
"def",
"max_speed",
"(",
"self",
")",
":",
"(",
"self",
".",
"_max_speed",
",",
"value",
")",
"=",
"self",
".",
"get_cached_attr_int",
"(",
"self",
".",
"_max_speed",
",",
"'max_speed'",
")",
"return",
"value"
] | 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. | [
"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",
... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L591-L598 | train | 228,114 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.ramp_up_sp | 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 ramp time is the ratio of the difference between the
`speed_sp` and the current `speed` and max_speed multiplied by `ramp_up_sp`.
"""
self._ramp_up_sp, value = self.get_attr_int(self._ramp_up_sp, 'ramp_up_sp')
return value | python | 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 ramp time is the ratio of the difference between the
`speed_sp` and the current `speed` and max_speed multiplied by `ramp_up_sp`.
"""
self._ramp_up_sp, value = self.get_attr_int(self._ramp_up_sp, 'ramp_up_sp')
return value | [
"def",
"ramp_up_sp",
"(",
"self",
")",
":",
"self",
".",
"_ramp_up_sp",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_ramp_up_sp",
",",
"'ramp_up_sp'",
")",
"return",
"value"
] | 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 ramp time is the ratio of the difference between the
`speed_sp` and the current `speed` and max_speed multiplied by `ramp_up_sp`. | [
"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",
"moto... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L628-L637 | train | 228,115 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.ramp_down_sp | 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 ramp time is the ratio of the difference between the
`speed_sp` and the current `speed` and max_speed multiplied by `ramp_down_sp`.
"""
self._ramp_down_sp, value = self.get_attr_int(self._ramp_down_sp, 'ramp_down_sp')
return value | python | 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 ramp time is the ratio of the difference between the
`speed_sp` and the current `speed` and max_speed multiplied by `ramp_down_sp`.
"""
self._ramp_down_sp, value = self.get_attr_int(self._ramp_down_sp, 'ramp_down_sp')
return value | [
"def",
"ramp_down_sp",
"(",
"self",
")",
":",
"self",
".",
"_ramp_down_sp",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_ramp_down_sp",
",",
"'ramp_down_sp'",
")",
"return",
"value"
] | 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 between the
`speed_sp` and the current `speed` and max_speed multiplied by `ramp_down_sp`. | [
"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",
"mo... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L644-L653 | train | 228,116 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.speed_p | 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 | 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 | [
"def",
"speed_p",
"(",
"self",
")",
":",
"self",
".",
"_speed_p",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_speed_p",
",",
"'speed_pid/Kp'",
")",
"return",
"value"
] | The proportional constant for the speed regulation PID. | [
"The",
"proportional",
"constant",
"for",
"the",
"speed",
"regulation",
"PID",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L660-L665 | train | 228,117 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.speed_i | 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 | 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 | [
"def",
"speed_i",
"(",
"self",
")",
":",
"self",
".",
"_speed_i",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_speed_i",
",",
"'speed_pid/Ki'",
")",
"return",
"value"
] | The integral constant for the speed regulation PID. | [
"The",
"integral",
"constant",
"for",
"the",
"speed",
"regulation",
"PID",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L672-L677 | train | 228,118 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.speed_d | 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 | 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 | [
"def",
"speed_d",
"(",
"self",
")",
":",
"self",
".",
"_speed_d",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_speed_d",
",",
"'speed_pid/Kd'",
")",
"return",
"value"
] | The derivative constant for the speed regulation PID. | [
"The",
"derivative",
"constant",
"for",
"the",
"speed",
"regulation",
"PID",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L684-L689 | train | 228,119 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.state | 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 | 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 | [
"def",
"state",
"(",
"self",
")",
":",
"self",
".",
"_state",
",",
"value",
"=",
"self",
".",
"get_attr_set",
"(",
"self",
".",
"_state",
",",
"'state'",
")",
"return",
"value"
] | Reading returns a list of state flags. Possible flags are
`running`, `ramping`, `holding`, `overloaded` and `stalled`. | [
"Reading",
"returns",
"a",
"list",
"of",
"state",
"flags",
".",
"Possible",
"flags",
"are",
"running",
"ramping",
"holding",
"overloaded",
"and",
"stalled",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L696-L702 | train | 228,120 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.stop_action | 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 possible values.
"""
self._stop_action, value = self.get_attr_string(self._stop_action, 'stop_action')
return value | python | 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 possible values.
"""
self._stop_action, value = self.get_attr_string(self._stop_action, 'stop_action')
return value | [
"def",
"stop_action",
"(",
"self",
")",
":",
"self",
".",
"_stop_action",
",",
"value",
"=",
"self",
".",
"get_attr_string",
"(",
"self",
".",
"_stop_action",
",",
"'stop_action'",
")",
"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. | [
"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",
... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L705-L713 | train | 228,121 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.stop_actions | 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 the motor and a passive electrical load will
be placed on the motor. This is usually done by shorting the motor terminals
together. This load will absorb the energy from the rotation of the motors and
cause the motor to stop more quickly than coasting. `hold` does not remove
power from the motor. Instead it actively tries to hold the motor at the current
position. If an external force tries to turn the motor, the motor will 'push
back' to maintain its position.
"""
(self._stop_actions, value) = self.get_cached_attr_set(self._stop_actions, 'stop_actions')
return value | python | 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 the motor and a passive electrical load will
be placed on the motor. This is usually done by shorting the motor terminals
together. This load will absorb the energy from the rotation of the motors and
cause the motor to stop more quickly than coasting. `hold` does not remove
power from the motor. Instead it actively tries to hold the motor at the current
position. If an external force tries to turn the motor, the motor will 'push
back' to maintain its position.
"""
(self._stop_actions, value) = self.get_cached_attr_set(self._stop_actions, 'stop_actions')
return value | [
"def",
"stop_actions",
"(",
"self",
")",
":",
"(",
"self",
".",
"_stop_actions",
",",
"value",
")",
"=",
"self",
".",
"get_cached_attr_set",
"(",
"self",
".",
"_stop_actions",
",",
"'stop_actions'",
")",
"return",
"value"
] | 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 will
be placed on the motor. This is usually done by shorting the motor terminals
together. This load will absorb the energy from the rotation of the motors and
cause the motor to stop more quickly than coasting. `hold` does not remove
power from the motor. Instead it actively tries to hold the motor at the current
position. If an external force tries to turn the motor, the motor will 'push
back' to maintain its position. | [
"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",
"a... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L720-L734 | train | 228,122 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.time_sp | 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 | 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 | [
"def",
"time_sp",
"(",
"self",
")",
":",
"self",
".",
"_time_sp",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_time_sp",
",",
"'time_sp'",
")",
"return",
"value"
] | 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. | [
"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",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L737-L744 | train | 228,123 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.run_forever | 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 | 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 | [
"def",
"run_forever",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_RUN_FOREVER"
] | Run the motor until another command is sent. | [
"Run",
"the",
"motor",
"until",
"another",
"command",
"is",
"sent",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L750-L756 | train | 228,124 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.run_to_abs_pos | 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 | 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 | [
"def",
"run_to_abs_pos",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_RUN_TO_ABS_POS"
] | Run to an absolute position specified by `position_sp` and then
stop using the action specified in `stop_action`. | [
"Run",
"to",
"an",
"absolute",
"position",
"specified",
"by",
"position_sp",
"and",
"then",
"stop",
"using",
"the",
"action",
"specified",
"in",
"stop_action",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L758-L765 | train | 228,125 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.run_to_rel_pos | 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`.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_RUN_TO_REL_POS | python | 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`.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_RUN_TO_REL_POS | [
"def",
"run_to_rel_pos",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_RUN_TO_REL_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`. | [
"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",
"... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L767-L776 | train | 228,126 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.run_timed | 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 | 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 | [
"def",
"run_timed",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_RUN_TIMED"
] | Run the motor for the amount of time specified in `time_sp`
and then stop the motor 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",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L778-L785 | train | 228,127 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.stop | 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 | 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 | [
"def",
"stop",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_STOP"
] | Stop any of the run commands before they are complete using the
action specified by `stop_action`. | [
"Stop",
"any",
"of",
"the",
"run",
"commands",
"before",
"they",
"are",
"complete",
"using",
"the",
"action",
"specified",
"by",
"stop_action",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L797-L804 | train | 228,128 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.reset | 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 | 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 | [
"def",
"reset",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_RESET"
] | Reset all of the motor parameter attributes to their default value.
This will also have the effect of stopping the motor. | [
"Reset",
"all",
"of",
"the",
"motor",
"parameter",
"attributes",
"to",
"their",
"default",
"value",
".",
"This",
"will",
"also",
"have",
"the",
"effect",
"of",
"stopping",
"the",
"motor",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L806-L813 | train | 228,129 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.on_for_rotations | 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(speed)
self._set_rel_position_degrees_and_speed_sp(rotations * 360, speed_sp)
self._set_brake(brake)
self.run_to_rel_pos()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | python | 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(speed)
self._set_rel_position_degrees_and_speed_sp(rotations * 360, speed_sp)
self._set_brake(brake)
self.run_to_rel_pos()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | [
"def",
"on_for_rotations",
"(",
"self",
",",
"speed",
",",
"rotations",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"speed_sp",
"=",
"self",
".",
"_speed_native_units",
"(",
"speed",
")",
"self",
".",
"_set_rel_position_degrees_and_speed_sp... | Rotate the motor at ``speed`` for ``rotations``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | [
"Rotate",
"the",
"motor",
"at",
"speed",
"for",
"rotations"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L958-L972 | train | 228,130 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.on_for_degrees | 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)
self._set_rel_position_degrees_and_speed_sp(degrees, speed_sp)
self._set_brake(brake)
self.run_to_rel_pos()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | python | 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)
self._set_rel_position_degrees_and_speed_sp(degrees, speed_sp)
self._set_brake(brake)
self.run_to_rel_pos()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | [
"def",
"on_for_degrees",
"(",
"self",
",",
"speed",
",",
"degrees",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"speed_sp",
"=",
"self",
".",
"_speed_native_units",
"(",
"speed",
")",
"self",
".",
"_set_rel_position_degrees_and_speed_sp",
... | Rotate the motor at ``speed`` for ``degrees``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | [
"Rotate",
"the",
"motor",
"at",
"speed",
"for",
"degrees"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L974-L988 | train | 228,131 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.on_to_position | 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)
self.speed_sp = int(round(speed))
self.position_sp = position
self._set_brake(brake)
self.run_to_abs_pos()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | python | 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)
self.speed_sp = int(round(speed))
self.position_sp = position
self._set_brake(brake)
self.run_to_abs_pos()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | [
"def",
"on_to_position",
"(",
"self",
",",
"speed",
",",
"position",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"speed",
"=",
"self",
".",
"_speed_native_units",
"(",
"speed",
")",
"self",
".",
"speed_sp",
"=",
"int",
"(",
"round",... | Rotate the motor at ``speed`` to ``position``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | [
"Rotate",
"the",
"motor",
"at",
"speed",
"to",
"position"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L990-L1005 | train | 228,132 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.on_for_seconds | 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("seconds is negative ({})".format(seconds))
speed = self._speed_native_units(speed)
self.speed_sp = int(round(speed))
self.time_sp = int(seconds * 1000)
self._set_brake(brake)
self.run_timed()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | python | 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("seconds is negative ({})".format(seconds))
speed = self._speed_native_units(speed)
self.speed_sp = int(round(speed))
self.time_sp = int(seconds * 1000)
self._set_brake(brake)
self.run_timed()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | [
"def",
"on_for_seconds",
"(",
"self",
",",
"speed",
",",
"seconds",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"if",
"seconds",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"seconds is negative ({})\"",
".",
"format",
"(",
"seconds",
... | Rotate the motor at ``speed`` for ``seconds``
``speed`` can be a percentage or a :class:`ev3dev2.motor.SpeedValue`
object, enabling use of other units. | [
"Rotate",
"the",
"motor",
"at",
"speed",
"for",
"seconds"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1007-L1026 | train | 228,133 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | Motor.on | 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 `on_for_XYZ` methods.
"""
speed = self._speed_native_units(speed)
self.speed_sp = int(round(speed))
self._set_brake(brake)
self.run_forever()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | python | 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 `on_for_XYZ` methods.
"""
speed = self._speed_native_units(speed)
self.speed_sp = int(round(speed))
self._set_brake(brake)
self.run_forever()
if block:
self.wait_until('running', timeout=WAIT_RUNNING_TIMEOUT)
self.wait_until_not_moving() | [
"def",
"on",
"(",
"self",
",",
"speed",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"False",
")",
":",
"speed",
"=",
"self",
".",
"_speed_native_units",
"(",
"speed",
")",
"self",
".",
"speed_sp",
"=",
"int",
"(",
"round",
"(",
"speed",
")",
")",... | 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. | [
"Rotate",
"the",
"motor",
"at",
"speed",
"for",
"forever"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1028-L1045 | train | 228,134 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | DcMotor.commands | 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 | 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 | [
"def",
"commands",
"(",
"self",
")",
":",
"self",
".",
"_commands",
",",
"value",
"=",
"self",
".",
"get_attr_set",
"(",
"self",
".",
"_commands",
",",
"'commands'",
")",
"return",
"value"
] | Returns a list of commands supported by the motor
controller. | [
"Returns",
"a",
"list",
"of",
"commands",
"supported",
"by",
"the",
"motor",
"controller",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1215-L1221 | train | 228,135 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | DcMotor.stop_actions | 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 | 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 | [
"def",
"stop_actions",
"(",
"self",
")",
":",
"self",
".",
"_stop_actions",
",",
"value",
"=",
"self",
".",
"get_attr_set",
"(",
"self",
".",
"_stop_actions",
",",
"'stop_actions'",
")",
"return",
"value"
] | Gets a list of stop actions. Valid values are `coast`
and `brake`. | [
"Gets",
"a",
"list",
"of",
"stop",
"actions",
".",
"Valid",
"values",
"are",
"coast",
"and",
"brake",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1317-L1323 | train | 228,136 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | ServoMotor.mid_pulse_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 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.
"""
self._mid_pulse_sp, value = self.get_attr_int(self._mid_pulse_sp, 'mid_pulse_sp')
return value | python | 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 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.
"""
self._mid_pulse_sp, value = self.get_attr_int(self._mid_pulse_sp, 'mid_pulse_sp')
return value | [
"def",
"mid_pulse_sp",
"(",
"self",
")",
":",
"self",
".",
"_mid_pulse_sp",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_mid_pulse_sp",
",",
"'mid_pulse_sp'",
")",
"return",
"value"
] | 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
where the motor does not turn. You must write to the position_sp attribute for
changes to this attribute to take effect. | [
"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",
"t... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1494-L1504 | train | 228,137 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | ServoMotor.run | 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 | 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 | [
"def",
"run",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_RUN"
] | Drive servo to the position set in the `position_sp` attribute. | [
"Drive",
"servo",
"to",
"the",
"position",
"set",
"in",
"the",
"position_sp",
"attribute",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1596-L1602 | train | 228,138 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | ServoMotor.float | def float(self, **kwargs):
"""
Remove power from the motor.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_FLOAT | python | def float(self, **kwargs):
"""
Remove power from the motor.
"""
for key in kwargs:
setattr(self, key, kwargs[key])
self.command = self.COMMAND_FLOAT | [
"def",
"float",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"key",
",",
"kwargs",
"[",
"key",
"]",
")",
"self",
".",
"command",
"=",
"self",
".",
"COMMAND_FLOAT"
] | Remove power from the motor. | [
"Remove",
"power",
"from",
"the",
"motor",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1604-L1610 | train | 228,139 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MotorSet.off | 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:
motor.stop() | python | 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:
motor.stop() | [
"def",
"off",
"(",
"self",
",",
"motors",
"=",
"None",
",",
"brake",
"=",
"True",
")",
":",
"motors",
"=",
"motors",
"if",
"motors",
"is",
"not",
"None",
"else",
"self",
".",
"motors",
".",
"values",
"(",
")",
"for",
"motor",
"in",
"motors",
":",
... | Stop motors immediately. Configure motors to brake if ``brake`` is set. | [
"Stop",
"motors",
"immediately",
".",
"Configure",
"motors",
"to",
"brake",
"if",
"brake",
"is",
"set",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1699-L1709 | train | 228,140 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveTank.on_for_degrees | 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
turn), the motor on the outside of the turn will rotate for the full
``degrees`` while the motor on the inside will have its requested
distance calculated according to the expected turn.
"""
(left_speed_native_units, right_speed_native_units) = self._unpack_speeds_to_native_units(left_speed, right_speed)
# proof of the following distance calculation: consider the circle formed by each wheel's path
# v_l = d_l/t, v_r = d_r/t
# therefore, t = d_l/v_l = d_r/v_r
if degrees == 0 or (left_speed_native_units == 0 and right_speed_native_units == 0):
left_degrees = degrees
right_degrees = degrees
# larger speed by magnitude is the "outer" wheel, and rotates the full "degrees"
elif abs(left_speed_native_units) > abs(right_speed_native_units):
left_degrees = degrees
right_degrees = abs(right_speed_native_units / left_speed_native_units) * degrees
else:
left_degrees = abs(left_speed_native_units / right_speed_native_units) * degrees
right_degrees = degrees
# Set all parameters
self.left_motor._set_rel_position_degrees_and_speed_sp(left_degrees, left_speed_native_units)
self.left_motor._set_brake(brake)
self.right_motor._set_rel_position_degrees_and_speed_sp(right_degrees, right_speed_native_units)
self.right_motor._set_brake(brake)
log.debug("{}: on_for_degrees {}".format(self, degrees))
# These debugs involve disk I/O to pull position and position_sp so only uncomment
# if you need to troubleshoot in more detail.
# log.debug("{}: left_speed {}, left_speed_native_units {}, left_degrees {}, left-position {}->{}".format(
# self, left_speed, left_speed_native_units, left_degrees,
# self.left_motor.position, self.left_motor.position_sp))
# log.debug("{}: right_speed {}, right_speed_native_units {}, right_degrees {}, right-position {}->{}".format(
# self, right_speed, right_speed_native_units, right_degrees,
# self.right_motor.position, self.right_motor.position_sp))
# Start the motors
self.left_motor.run_to_rel_pos()
self.right_motor.run_to_rel_pos()
if block:
self._block() | python | 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
turn), the motor on the outside of the turn will rotate for the full
``degrees`` while the motor on the inside will have its requested
distance calculated according to the expected turn.
"""
(left_speed_native_units, right_speed_native_units) = self._unpack_speeds_to_native_units(left_speed, right_speed)
# proof of the following distance calculation: consider the circle formed by each wheel's path
# v_l = d_l/t, v_r = d_r/t
# therefore, t = d_l/v_l = d_r/v_r
if degrees == 0 or (left_speed_native_units == 0 and right_speed_native_units == 0):
left_degrees = degrees
right_degrees = degrees
# larger speed by magnitude is the "outer" wheel, and rotates the full "degrees"
elif abs(left_speed_native_units) > abs(right_speed_native_units):
left_degrees = degrees
right_degrees = abs(right_speed_native_units / left_speed_native_units) * degrees
else:
left_degrees = abs(left_speed_native_units / right_speed_native_units) * degrees
right_degrees = degrees
# Set all parameters
self.left_motor._set_rel_position_degrees_and_speed_sp(left_degrees, left_speed_native_units)
self.left_motor._set_brake(brake)
self.right_motor._set_rel_position_degrees_and_speed_sp(right_degrees, right_speed_native_units)
self.right_motor._set_brake(brake)
log.debug("{}: on_for_degrees {}".format(self, degrees))
# These debugs involve disk I/O to pull position and position_sp so only uncomment
# if you need to troubleshoot in more detail.
# log.debug("{}: left_speed {}, left_speed_native_units {}, left_degrees {}, left-position {}->{}".format(
# self, left_speed, left_speed_native_units, left_degrees,
# self.left_motor.position, self.left_motor.position_sp))
# log.debug("{}: right_speed {}, right_speed_native_units {}, right_degrees {}, right-position {}->{}".format(
# self, right_speed, right_speed_native_units, right_degrees,
# self.right_motor.position, self.right_motor.position_sp))
# Start the motors
self.left_motor.run_to_rel_pos()
self.right_motor.run_to_rel_pos()
if block:
self._block() | [
"def",
"on_for_degrees",
"(",
"self",
",",
"left_speed",
",",
"right_speed",
",",
"degrees",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"(",
"left_speed_native_units",
",",
"right_speed_native_units",
")",
"=",
"self",
".",
"_unpack_speeds... | 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 motor on the inside will have its requested
distance calculated according to the expected turn. | [
"Rotate",
"the",
"motors",
"at",
"left_speed",
"&",
"right_speed",
"for",
"degrees",
".",
"Speeds",
"can",
"be",
"percentages",
"or",
"any",
"SpeedValue",
"implementation",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1810-L1861 | train | 228,141 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveTank.on_for_rotations | 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 will
turn), the motor on the outside of the turn will rotate for the full
``rotations`` while the motor on the inside will have its requested
distance calculated according to the expected turn.
"""
MoveTank.on_for_degrees(self, left_speed, right_speed, rotations * 360, brake, block) | python | 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 will
turn), the motor on the outside of the turn will rotate for the full
``rotations`` while the motor on the inside will have its requested
distance calculated according to the expected turn.
"""
MoveTank.on_for_degrees(self, left_speed, right_speed, rotations * 360, brake, block) | [
"def",
"on_for_rotations",
"(",
"self",
",",
"left_speed",
",",
"right_speed",
",",
"rotations",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"MoveTank",
".",
"on_for_degrees",
"(",
"self",
",",
"left_speed",
",",
"right_speed",
",",
"ro... | 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 the motor on the inside will have its requested
distance calculated according to the expected turn. | [
"Rotate",
"the",
"motors",
"at",
"left_speed",
"&",
"right_speed",
"for",
"rotations",
".",
"Speeds",
"can",
"be",
"percentages",
"or",
"any",
"SpeedValue",
"implementation",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1863-L1873 | train | 228,142 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveTank.on_for_seconds | 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 negative ({})".format(seconds))
(left_speed_native_units, right_speed_native_units) = self._unpack_speeds_to_native_units(left_speed, right_speed)
# Set all parameters
self.left_motor.speed_sp = int(round(left_speed_native_units))
self.left_motor.time_sp = int(seconds * 1000)
self.left_motor._set_brake(brake)
self.right_motor.speed_sp = int(round(right_speed_native_units))
self.right_motor.time_sp = int(seconds * 1000)
self.right_motor._set_brake(brake)
log.debug("%s: on_for_seconds %ss at left-speed %s, right-speed %s" %
(self, seconds, left_speed, right_speed))
# Start the motors
self.left_motor.run_timed()
self.right_motor.run_timed()
if block:
self._block() | python | 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 negative ({})".format(seconds))
(left_speed_native_units, right_speed_native_units) = self._unpack_speeds_to_native_units(left_speed, right_speed)
# Set all parameters
self.left_motor.speed_sp = int(round(left_speed_native_units))
self.left_motor.time_sp = int(seconds * 1000)
self.left_motor._set_brake(brake)
self.right_motor.speed_sp = int(round(right_speed_native_units))
self.right_motor.time_sp = int(seconds * 1000)
self.right_motor._set_brake(brake)
log.debug("%s: on_for_seconds %ss at left-speed %s, right-speed %s" %
(self, seconds, left_speed, right_speed))
# Start the motors
self.left_motor.run_timed()
self.right_motor.run_timed()
if block:
self._block() | [
"def",
"on_for_seconds",
"(",
"self",
",",
"left_speed",
",",
"right_speed",
",",
"seconds",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"if",
"seconds",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"seconds is negative ({})\"",
".",
"f... | Rotate the motors at 'left_speed & right_speed' for 'seconds'. Speeds
can be percentages or any SpeedValue implementation. | [
"Rotate",
"the",
"motors",
"at",
"left_speed",
"&",
"right_speed",
"for",
"seconds",
".",
"Speeds",
"can",
"be",
"percentages",
"or",
"any",
"SpeedValue",
"implementation",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1875-L1902 | train | 228,143 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveTank.on | 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(left_speed, right_speed)
# Set all parameters
self.left_motor.speed_sp = int(round(left_speed_native_units))
self.right_motor.speed_sp = int(round(right_speed_native_units))
# This debug involves disk I/O to pull speed_sp so only uncomment
# if you need to troubleshoot in more detail.
# log.debug("%s: on at left-speed %s, right-speed %s" %
# (self, self.left_motor.speed_sp, self.right_motor.speed_sp))
# Start the motors
self.left_motor.run_forever()
self.right_motor.run_forever() | python | 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(left_speed, right_speed)
# Set all parameters
self.left_motor.speed_sp = int(round(left_speed_native_units))
self.right_motor.speed_sp = int(round(right_speed_native_units))
# This debug involves disk I/O to pull speed_sp so only uncomment
# if you need to troubleshoot in more detail.
# log.debug("%s: on at left-speed %s, right-speed %s" %
# (self, self.left_motor.speed_sp, self.right_motor.speed_sp))
# Start the motors
self.left_motor.run_forever()
self.right_motor.run_forever() | [
"def",
"on",
"(",
"self",
",",
"left_speed",
",",
"right_speed",
")",
":",
"(",
"left_speed_native_units",
",",
"right_speed_native_units",
")",
"=",
"self",
".",
"_unpack_speeds_to_native_units",
"(",
"left_speed",
",",
"right_speed",
")",
"# Set all parameters",
"... | Start rotating the motors according to ``left_speed`` and ``right_speed`` forever.
Speeds can be percentages or any SpeedValue implementation. | [
"Start",
"rotating",
"the",
"motors",
"according",
"to",
"left_speed",
"and",
"right_speed",
"forever",
".",
"Speeds",
"can",
"be",
"percentages",
"or",
"any",
"SpeedValue",
"implementation",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1904-L1922 | train | 228,144 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveSteering.on_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_speed), SpeedNativeUnits(right_speed), seconds, brake, block) | python | 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_speed), SpeedNativeUnits(right_speed), seconds, brake, block) | [
"def",
"on_for_seconds",
"(",
"self",
",",
"steering",
",",
"speed",
",",
"seconds",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"(",
"left_speed",
",",
"right_speed",
")",
"=",
"self",
".",
"get_speed_steering",
"(",
"steering",
",",... | Rotate the motors according to the provided ``steering`` for ``seconds``. | [
"Rotate",
"the",
"motors",
"according",
"to",
"the",
"provided",
"steering",
"for",
"seconds",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1962-L1967 | train | 228,145 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveSteering.on | 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 | 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)) | [
"def",
"on",
"(",
"self",
",",
"steering",
",",
"speed",
")",
":",
"(",
"left_speed",
",",
"right_speed",
")",
"=",
"self",
".",
"get_speed_steering",
"(",
"steering",
",",
"speed",
")",
"MoveTank",
".",
"on",
"(",
"self",
",",
"SpeedNativeUnits",
"(",
... | Start rotating the motors according to the provided ``steering`` and
``speed`` forever. | [
"Start",
"rotating",
"the",
"motors",
"according",
"to",
"the",
"provided",
"steering",
"and",
"speed",
"forever",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L1969-L1975 | train | 228,146 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveDifferential._on_arc | 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(
self, radius_mm, self.min_circle_radius_mm))
# The circle formed at the halfway point between the two wheels is the
# circle that must have a radius of radius_mm
circle_outer_mm = 2 * math.pi * (radius_mm + (self.wheel_distance_mm / 2))
circle_middle_mm = 2 * math.pi * radius_mm
circle_inner_mm = 2 * math.pi * (radius_mm - (self.wheel_distance_mm / 2))
if arc_right:
# The left wheel is making the larger circle and will move at 'speed'
# The right wheel is making a smaller circle so its speed will be a fraction of the left motor's speed
left_speed = speed
right_speed = float(circle_inner_mm/circle_outer_mm) * left_speed
else:
# The right wheel is making the larger circle and will move at 'speed'
# The left wheel is making a smaller circle so its speed will be a fraction of the right motor's speed
right_speed = speed
left_speed = float(circle_inner_mm/circle_outer_mm) * right_speed
log.debug("%s: arc %s, radius %s, distance %s, left-speed %s, right-speed %s, circle_outer_mm %s, circle_middle_mm %s, circle_inner_mm %s" %
(self, "right" if arc_right else "left",
radius_mm, distance_mm, left_speed, right_speed,
circle_outer_mm, circle_middle_mm, circle_inner_mm
)
)
# We know we want the middle circle to be of length distance_mm so
# calculate the percentage of circle_middle_mm we must travel for the
# middle of the robot to travel distance_mm.
circle_middle_percentage = float(distance_mm / circle_middle_mm)
# Now multiple that percentage by circle_outer_mm to calculate how
# many mm the outer wheel should travel.
circle_outer_final_mm = circle_middle_percentage * circle_outer_mm
outer_wheel_rotations = float(circle_outer_final_mm / self.wheel.circumference_mm)
outer_wheel_degrees = outer_wheel_rotations * 360
log.debug("%s: arc %s, circle_middle_percentage %s, circle_outer_final_mm %s, outer_wheel_rotations %s, outer_wheel_degrees %s" %
(self, "right" if arc_right else "left",
circle_middle_percentage, circle_outer_final_mm,
outer_wheel_rotations, outer_wheel_degrees
)
)
MoveTank.on_for_degrees(self, left_speed, right_speed, outer_wheel_degrees, brake, block) | python | 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(
self, radius_mm, self.min_circle_radius_mm))
# The circle formed at the halfway point between the two wheels is the
# circle that must have a radius of radius_mm
circle_outer_mm = 2 * math.pi * (radius_mm + (self.wheel_distance_mm / 2))
circle_middle_mm = 2 * math.pi * radius_mm
circle_inner_mm = 2 * math.pi * (radius_mm - (self.wheel_distance_mm / 2))
if arc_right:
# The left wheel is making the larger circle and will move at 'speed'
# The right wheel is making a smaller circle so its speed will be a fraction of the left motor's speed
left_speed = speed
right_speed = float(circle_inner_mm/circle_outer_mm) * left_speed
else:
# The right wheel is making the larger circle and will move at 'speed'
# The left wheel is making a smaller circle so its speed will be a fraction of the right motor's speed
right_speed = speed
left_speed = float(circle_inner_mm/circle_outer_mm) * right_speed
log.debug("%s: arc %s, radius %s, distance %s, left-speed %s, right-speed %s, circle_outer_mm %s, circle_middle_mm %s, circle_inner_mm %s" %
(self, "right" if arc_right else "left",
radius_mm, distance_mm, left_speed, right_speed,
circle_outer_mm, circle_middle_mm, circle_inner_mm
)
)
# We know we want the middle circle to be of length distance_mm so
# calculate the percentage of circle_middle_mm we must travel for the
# middle of the robot to travel distance_mm.
circle_middle_percentage = float(distance_mm / circle_middle_mm)
# Now multiple that percentage by circle_outer_mm to calculate how
# many mm the outer wheel should travel.
circle_outer_final_mm = circle_middle_percentage * circle_outer_mm
outer_wheel_rotations = float(circle_outer_final_mm / self.wheel.circumference_mm)
outer_wheel_degrees = outer_wheel_rotations * 360
log.debug("%s: arc %s, circle_middle_percentage %s, circle_outer_final_mm %s, outer_wheel_rotations %s, outer_wheel_degrees %s" %
(self, "right" if arc_right else "left",
circle_middle_percentage, circle_outer_final_mm,
outer_wheel_rotations, outer_wheel_degrees
)
)
MoveTank.on_for_degrees(self, left_speed, right_speed, outer_wheel_degrees, brake, block) | [
"def",
"_on_arc",
"(",
"self",
",",
"speed",
",",
"radius_mm",
",",
"distance_mm",
",",
"brake",
",",
"block",
",",
"arc_right",
")",
":",
"if",
"radius_mm",
"<",
"self",
".",
"min_circle_radius_mm",
":",
"raise",
"ValueError",
"(",
"\"{}: radius_mm {} is less... | Drive in a circle with 'radius' for 'distance' | [
"Drive",
"in",
"a",
"circle",
"with",
"radius",
"for",
"distance"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L2118-L2171 | train | 228,147 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveDifferential.on_arc_right | 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 | 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) | [
"def",
"on_arc_right",
"(",
"self",
",",
"speed",
",",
"radius_mm",
",",
"distance_mm",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"self",
".",
"_on_arc",
"(",
"speed",
",",
"radius_mm",
",",
"distance_mm",
",",
"brake",
",",
"bloc... | Drive clockwise in a circle with 'radius_mm' for 'distance_mm' | [
"Drive",
"clockwise",
"in",
"a",
"circle",
"with",
"radius_mm",
"for",
"distance_mm"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L2173-L2177 | train | 228,148 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveDifferential.on_arc_left | 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 | 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) | [
"def",
"on_arc_left",
"(",
"self",
",",
"speed",
",",
"radius_mm",
",",
"distance_mm",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"self",
".",
"_on_arc",
"(",
"speed",
",",
"radius_mm",
",",
"distance_mm",
",",
"brake",
",",
"block... | Drive counter-clockwise in a circle with 'radius_mm' for 'distance_mm' | [
"Drive",
"counter",
"-",
"clockwise",
"in",
"a",
"circle",
"with",
"radius_mm",
"for",
"distance_mm"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L2179-L2183 | train | 228,149 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveDifferential._turn | 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
# The number of rotations to move distance_mm
rotations = distance_mm/self.wheel.circumference_mm
log.debug("%s: turn() degrees %s, distance_mm %s, rotations %s, degrees %s" %
(self, degrees, distance_mm, rotations, degrees))
# If degrees is positive rotate clockwise
if degrees > 0:
MoveTank.on_for_rotations(self, speed, speed * -1, rotations, brake, block)
# If degrees is negative rotate counter-clockwise
else:
rotations = distance_mm / self.wheel.circumference_mm
MoveTank.on_for_rotations(self, speed * -1, speed, rotations, brake, block) | python | 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
# The number of rotations to move distance_mm
rotations = distance_mm/self.wheel.circumference_mm
log.debug("%s: turn() degrees %s, distance_mm %s, rotations %s, degrees %s" %
(self, degrees, distance_mm, rotations, degrees))
# If degrees is positive rotate clockwise
if degrees > 0:
MoveTank.on_for_rotations(self, speed, speed * -1, rotations, brake, block)
# If degrees is negative rotate counter-clockwise
else:
rotations = distance_mm / self.wheel.circumference_mm
MoveTank.on_for_rotations(self, speed * -1, speed, rotations, brake, block) | [
"def",
"_turn",
"(",
"self",
",",
"speed",
",",
"degrees",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"# The distance each wheel needs to travel",
"distance_mm",
"=",
"(",
"abs",
"(",
"degrees",
")",
"/",
"360",
")",
"*",
"self",
"."... | Rotate in place 'degrees'. Both wheels must turn at the same speed for us
to rotate in place. | [
"Rotate",
"in",
"place",
"degrees",
".",
"Both",
"wheels",
"must",
"turn",
"at",
"the",
"same",
"speed",
"for",
"us",
"to",
"rotate",
"in",
"place",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L2185-L2207 | train | 228,150 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveDifferential.turn_right | def turn_right(self, speed, degrees, brake=True, block=True):
"""
Rotate clockwise 'degrees' in place
"""
self._turn(speed, abs(degrees), brake, block) | python | def turn_right(self, speed, degrees, brake=True, block=True):
"""
Rotate clockwise 'degrees' in place
"""
self._turn(speed, abs(degrees), brake, block) | [
"def",
"turn_right",
"(",
"self",
",",
"speed",
",",
"degrees",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"self",
".",
"_turn",
"(",
"speed",
",",
"abs",
"(",
"degrees",
")",
",",
"brake",
",",
"block",
")"
] | Rotate clockwise 'degrees' in place | [
"Rotate",
"clockwise",
"degrees",
"in",
"place"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L2209-L2213 | train | 228,151 |
ev3dev/ev3dev-lang-python | ev3dev2/motor.py | MoveDifferential.turn_to_angle | 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 numbers between 0 and 360
if angle_target_degrees < 0:
angle_target_degrees += 360
angle_current_degrees = math.degrees(self.theta)
if angle_current_degrees < 0:
angle_current_degrees += 360
# Is it shorter to rotate to the right or left
# to reach angle_target_degrees?
if angle_current_degrees > angle_target_degrees:
turn_right = True
angle_delta = angle_current_degrees - angle_target_degrees
else:
turn_right = False
angle_delta = angle_target_degrees - angle_current_degrees
if angle_delta > 180:
angle_delta = 360 - angle_delta
turn_right = not turn_right
log.debug("%s: turn_to_angle %s, current angle %s, delta %s, turn_right %s" %
(self, angle_target_degrees, angle_current_degrees, angle_delta, turn_right))
self.odometry_coordinates_log()
if turn_right:
self.turn_right(speed, angle_delta, brake, block)
else:
self.turn_left(speed, angle_delta, brake, block)
self.odometry_coordinates_log() | python | 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 numbers between 0 and 360
if angle_target_degrees < 0:
angle_target_degrees += 360
angle_current_degrees = math.degrees(self.theta)
if angle_current_degrees < 0:
angle_current_degrees += 360
# Is it shorter to rotate to the right or left
# to reach angle_target_degrees?
if angle_current_degrees > angle_target_degrees:
turn_right = True
angle_delta = angle_current_degrees - angle_target_degrees
else:
turn_right = False
angle_delta = angle_target_degrees - angle_current_degrees
if angle_delta > 180:
angle_delta = 360 - angle_delta
turn_right = not turn_right
log.debug("%s: turn_to_angle %s, current angle %s, delta %s, turn_right %s" %
(self, angle_target_degrees, angle_current_degrees, angle_delta, turn_right))
self.odometry_coordinates_log()
if turn_right:
self.turn_right(speed, angle_delta, brake, block)
else:
self.turn_left(speed, angle_delta, brake, block)
self.odometry_coordinates_log() | [
"def",
"turn_to_angle",
"(",
"self",
",",
"speed",
",",
"angle_target_degrees",
",",
"brake",
"=",
"True",
",",
"block",
"=",
"True",
")",
":",
"assert",
"self",
".",
"odometry_thread_id",
",",
"\"odometry_start() must be called to track robot coordinates\"",
"# Make ... | Rotate in place to `angle_target_degrees` at `speed` | [
"Rotate",
"in",
"place",
"to",
"angle_target_degrees",
"at",
"speed"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/motor.py#L2310-L2347 | train | 228,152 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | datetime_delta_to_ms | 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 | 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 | [
"def",
"datetime_delta_to_ms",
"(",
"delta",
")",
":",
"delta_ms",
"=",
"delta",
".",
"days",
"*",
"24",
"*",
"60",
"*",
"60",
"*",
"1000",
"delta_ms",
"+=",
"delta",
".",
"seconds",
"*",
"1000",
"delta_ms",
"+=",
"delta",
".",
"microseconds",
"/",
"10... | Given a datetime.timedelta object, return the delta in milliseconds | [
"Given",
"a",
"datetime",
".",
"timedelta",
"object",
"return",
"the",
"delta",
"in",
"milliseconds"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L65-L73 | train | 228,153 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | duration_expired | 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:
return True
return False | python | 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:
return True
return False | [
"def",
"duration_expired",
"(",
"start_time",
",",
"duration_seconds",
")",
":",
"if",
"duration_seconds",
"is",
"not",
"None",
":",
"delta_seconds",
"=",
"datetime_delta_to_seconds",
"(",
"dt",
".",
"datetime",
".",
"now",
"(",
")",
"-",
"start_time",
")",
"i... | Return True if ``duration_seconds`` have expired since ``start_time`` | [
"Return",
"True",
"if",
"duration_seconds",
"have",
"expired",
"since",
"start_time"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L80-L91 | train | 228,154 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Led.max_brightness | 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 | 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 | [
"def",
"max_brightness",
"(",
"self",
")",
":",
"self",
".",
"_max_brightness",
",",
"value",
"=",
"self",
".",
"get_cached_attr_int",
"(",
"self",
".",
"_max_brightness",
",",
"'max_brightness'",
")",
"return",
"value"
] | Returns the maximum allowable brightness value. | [
"Returns",
"the",
"maximum",
"allowable",
"brightness",
"value",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L132-L137 | train | 228,155 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Led.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 | python | 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 | [
"def",
"brightness",
"(",
"self",
")",
":",
"self",
".",
"_brightness",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_brightness",
",",
"'brightness'",
")",
"return",
"value"
] | Sets the brightness level. Possible values are from 0 to `max_brightness`. | [
"Sets",
"the",
"brightness",
"level",
".",
"Possible",
"values",
"are",
"from",
"0",
"to",
"max_brightness",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L140-L145 | train | 228,156 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Led.triggers | def triggers(self):
"""
Returns a list of available triggers.
"""
self._triggers, value = self.get_attr_set(self._triggers, 'trigger')
return value | python | def triggers(self):
"""
Returns a list of available triggers.
"""
self._triggers, value = self.get_attr_set(self._triggers, 'trigger')
return value | [
"def",
"triggers",
"(",
"self",
")",
":",
"self",
".",
"_triggers",
",",
"value",
"=",
"self",
".",
"get_attr_set",
"(",
"self",
".",
"_triggers",
",",
"'trigger'",
")",
"return",
"value"
] | Returns a list of available triggers. | [
"Returns",
"a",
"list",
"of",
"available",
"triggers",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L152-L157 | train | 228,157 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Led.trigger | 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` and `nand-disk`
triggers.
Complex triggers whilst available to all LEDs have LED specific
parameters and work on a per LED basis. The `timer` trigger is an example.
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `on` and `off` time can
be specified via `delay_{on,off}` attributes in milliseconds.
You can change the brightness value of a LED independently of the timer
trigger. However, if you set the brightness value to 0 it will
also disable the `timer` trigger.
"""
self._trigger, value = self.get_attr_from_set(self._trigger, 'trigger')
return value | python | 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` and `nand-disk`
triggers.
Complex triggers whilst available to all LEDs have LED specific
parameters and work on a per LED basis. The `timer` trigger is an example.
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `on` and `off` time can
be specified via `delay_{on,off}` attributes in milliseconds.
You can change the brightness value of a LED independently of the timer
trigger. However, if you set the brightness value to 0 it will
also disable the `timer` trigger.
"""
self._trigger, value = self.get_attr_from_set(self._trigger, 'trigger')
return value | [
"def",
"trigger",
"(",
"self",
")",
":",
"self",
".",
"_trigger",
",",
"value",
"=",
"self",
".",
"get_attr_from_set",
"(",
"self",
".",
"_trigger",
",",
"'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.
Complex triggers whilst available to all LEDs have LED specific
parameters and work on a per LED basis. The `timer` trigger is an example.
The `timer` trigger will periodically change the LED brightness between
0 and the current brightness setting. The `on` and `off` time can
be specified via `delay_{on,off}` attributes in milliseconds.
You can change the brightness value of a LED independently of the timer
trigger. However, if you set the brightness value to 0 it will
also disable the `timer` trigger. | [
"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"... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L160-L178 | train | 228,158 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Led.delay_on | 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 'delay_off' attributes are created when trigger is set
# to 'timer', and destroyed when it is set to anything else.
# This means the file cache may become outdated, and we may have to
# reopen the file.
for retry in (True, False):
try:
self._delay_on, value = self.get_attr_int(self._delay_on, 'delay_on')
return value
except OSError:
if retry:
self._delay_on = None
else:
raise | python | 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 'delay_off' attributes are created when trigger is set
# to 'timer', and destroyed when it is set to anything else.
# This means the file cache may become outdated, and we may have to
# reopen the file.
for retry in (True, False):
try:
self._delay_on, value = self.get_attr_int(self._delay_on, 'delay_on')
return value
except OSError:
if retry:
self._delay_on = None
else:
raise | [
"def",
"delay_on",
"(",
"self",
")",
":",
"# Workaround for ev3dev/ev3dev#225.",
"# 'delay_on' and 'delay_off' attributes are created when trigger is set",
"# to 'timer', and destroyed when it is set to anything else.",
"# This means the file cache may become outdated, and we may have to",
"# re... | 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. | [
"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",
... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L209-L229 | train | 228,159 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Led.delay_off | 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' and 'delay_off' attributes are created when trigger is set
# to 'timer', and destroyed when it is set to anything else.
# This means the file cache may become outdated, and we may have to
# reopen the file.
for retry in (True, False):
try:
self._delay_off, value = self.get_attr_int(self._delay_off, 'delay_off')
return value
except OSError:
if retry:
self._delay_off = None
else:
raise | python | 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' and 'delay_off' attributes are created when trigger is set
# to 'timer', and destroyed when it is set to anything else.
# This means the file cache may become outdated, and we may have to
# reopen the file.
for retry in (True, False):
try:
self._delay_off, value = self.get_attr_int(self._delay_off, 'delay_off')
return value
except OSError:
if retry:
self._delay_off = None
else:
raise | [
"def",
"delay_off",
"(",
"self",
")",
":",
"# Workaround for ev3dev/ev3dev#225.",
"# 'delay_on' and 'delay_off' attributes are created when trigger is set",
"# to 'timer', and destroyed when it is set to anything else.",
"# This means the file cache may become outdated, and we may have to",
"# r... | 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. | [
"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",... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L249-L269 | train | 228,160 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Leds.set_color | 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('LEFT', 'AMBER')
With a custom color::
my_leds = Leds()
my_leds.set_color('LEFT', (0.5, 0.3))
"""
# If this is a platform without LEDs there is nothing to do
if not self.leds:
return
color_tuple = color
if isinstance(color, str):
assert color in self.led_colors, \
"%s is an invalid LED color, valid choices are %s" % \
(color, ', '.join(self.led_colors.keys()))
color_tuple = self.led_colors[color]
assert group in self.led_groups, \
"%s is an invalid LED group, valid choices are %s" % \
(group, ', '.join(self.led_groups.keys()))
for led, value in zip(self.led_groups[group], color_tuple):
led.brightness_pct = value * pct | python | 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('LEFT', 'AMBER')
With a custom color::
my_leds = Leds()
my_leds.set_color('LEFT', (0.5, 0.3))
"""
# If this is a platform without LEDs there is nothing to do
if not self.leds:
return
color_tuple = color
if isinstance(color, str):
assert color in self.led_colors, \
"%s is an invalid LED color, valid choices are %s" % \
(color, ', '.join(self.led_colors.keys()))
color_tuple = self.led_colors[color]
assert group in self.led_groups, \
"%s is an invalid LED group, valid choices are %s" % \
(group, ', '.join(self.led_groups.keys()))
for led, value in zip(self.led_groups[group], color_tuple):
led.brightness_pct = value * pct | [
"def",
"set_color",
"(",
"self",
",",
"group",
",",
"color",
",",
"pct",
"=",
"1",
")",
":",
"# If this is a platform without LEDs there is nothing to do",
"if",
"not",
"self",
".",
"leds",
":",
"return",
"color_tuple",
"=",
"color",
"if",
"isinstance",
"(",
"... | 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::
my_leds = Leds()
my_leds.set_color('LEFT', (0.5, 0.3)) | [
"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",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L321-L353 | train | 228,161 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Leds.set | 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:
return
assert group in self.led_groups, \
"%s is an invalid LED group, valid choices are %s" % \
(group, ', '.join(self.led_groups.keys()))
for led in self.led_groups[group]:
for k in kwargs:
setattr(led, k, kwargs[k]) | python | 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:
return
assert group in self.led_groups, \
"%s is an invalid LED group, valid choices are %s" % \
(group, ', '.join(self.led_groups.keys()))
for led in self.led_groups[group]:
for k in kwargs:
setattr(led, k, kwargs[k]) | [
"def",
"set",
"(",
"self",
",",
"group",
",",
"*",
"*",
"kwargs",
")",
":",
"# If this is a platform without LEDs there is nothing to do",
"if",
"not",
"self",
".",
"leds",
":",
"return",
"assert",
"group",
"in",
"self",
".",
"led_groups",
",",
"\"%s is an inval... | Set attributes for each LED in group.
Example::
my_leds = Leds()
my_leds.set_color('LEFT', brightness_pct=0.5, trigger='timer') | [
"Set",
"attributes",
"for",
"each",
"LED",
"in",
"group",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L355-L375 | train | 228,162 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Leds.all_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 | python | 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 | [
"def",
"all_off",
"(",
"self",
")",
":",
"# 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"... | Turn all LEDs off | [
"Turn",
"all",
"LEDs",
"off"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L377-L387 | train | 228,163 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Leds.reset | 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 | 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) | [
"def",
"reset",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"leds",
":",
"return",
"self",
".",
"animate_stop",
"(",
")",
"for",
"group",
"in",
"self",
".",
"led_groups",
":",
"self",
".",
"set_color",
"(",
"group",
",",
"LED_DEFAULT_COLOR",
")"
] | Put all LEDs back to their default color | [
"Put",
"all",
"LEDs",
"back",
"to",
"their",
"default",
"color"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L389-L400 | train | 228,164 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Leds.animate_police_lights | 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 ``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_police_lights('RED', 'GREEN', sleeptime=0.75, duration=10)
"""
def _animate_police_lights():
self.all_off()
even = True
start_time = dt.datetime.now()
while True:
if even:
self.set_color(group1, color1)
self.set_color(group2, color2)
else:
self.set_color(group1, color2)
self.set_color(group2, color1)
if self.animate_thread_stop or duration_expired(start_time, duration):
break
even = not even
sleep(sleeptime)
self.animate_thread_stop = False
self.animate_thread_id = None
self.animate_stop()
if block:
_animate_police_lights()
else:
self.animate_thread_id = _thread.start_new_thread(_animate_police_lights, ()) | python | 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 ``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_police_lights('RED', 'GREEN', sleeptime=0.75, duration=10)
"""
def _animate_police_lights():
self.all_off()
even = True
start_time = dt.datetime.now()
while True:
if even:
self.set_color(group1, color1)
self.set_color(group2, color2)
else:
self.set_color(group1, color2)
self.set_color(group2, color1)
if self.animate_thread_stop or duration_expired(start_time, duration):
break
even = not even
sleep(sleeptime)
self.animate_thread_stop = False
self.animate_thread_id = None
self.animate_stop()
if block:
_animate_police_lights()
else:
self.animate_thread_id = _thread.start_new_thread(_animate_police_lights, ()) | [
"def",
"animate_police_lights",
"(",
"self",
",",
"color1",
",",
"color2",
",",
"group1",
"=",
"'LEFT'",
",",
"group2",
"=",
"'RIGHT'",
",",
"sleeptime",
"=",
"0.5",
",",
"duration",
"=",
"5",
",",
"block",
"=",
"True",
")",
":",
"def",
"_animate_police_... | 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:
.. code-block:: python
from ev3dev2.led import Leds
leds = Leds()
leds.animate_police_lights('RED', 'GREEN', sleeptime=0.75, duration=10) | [
"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",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L413-L457 | train | 228,165 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Leds.animate_cycle | 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 forever.
Example:
.. code-block:: python
from ev3dev2.led import Leds
leds = Leds()
leds.animate_cyle(('RED', 'GREEN', 'AMBER'))
"""
def _animate_cycle():
index = 0
max_index = len(colors)
start_time = dt.datetime.now()
while True:
for group in groups:
self.set_color(group, colors[index])
index += 1
if index == max_index:
index = 0
if self.animate_thread_stop or duration_expired(start_time, duration):
break
sleep(sleeptime)
self.animate_thread_stop = False
self.animate_thread_id = None
self.animate_stop()
if block:
_animate_cycle()
else:
self.animate_thread_id = _thread.start_new_thread(_animate_cycle, ()) | python | 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 forever.
Example:
.. code-block:: python
from ev3dev2.led import Leds
leds = Leds()
leds.animate_cyle(('RED', 'GREEN', 'AMBER'))
"""
def _animate_cycle():
index = 0
max_index = len(colors)
start_time = dt.datetime.now()
while True:
for group in groups:
self.set_color(group, colors[index])
index += 1
if index == max_index:
index = 0
if self.animate_thread_stop or duration_expired(start_time, duration):
break
sleep(sleeptime)
self.animate_thread_stop = False
self.animate_thread_id = None
self.animate_stop()
if block:
_animate_cycle()
else:
self.animate_thread_id = _thread.start_new_thread(_animate_cycle, ()) | [
"def",
"animate_cycle",
"(",
"self",
",",
"colors",
",",
"groups",
"=",
"(",
"'LEFT'",
",",
"'RIGHT'",
")",
",",
"sleeptime",
"=",
"0.5",
",",
"duration",
"=",
"5",
",",
"block",
"=",
"True",
")",
":",
"def",
"_animate_cycle",
"(",
")",
":",
"index",... | 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 = Leds()
leds.animate_cyle(('RED', 'GREEN', 'AMBER')) | [
"Cycle",
"groups",
"LEDs",
"through",
"colors",
".",
"Do",
"this",
"in",
"a",
"loop",
"where",
"we",
"display",
"each",
"color",
"for",
"sleeptime",
"seconds",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L501-L543 | train | 228,166 |
ev3dev/ev3dev-lang-python | ev3dev2/led.py | Leds.animate_rainbow | 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
from ev3dev2.led import Leds
leds = Leds()
leds.animate_rainbow()
"""
def _animate_rainbow():
# state 0: (LEFT,RIGHT) from (0,0) to (1,0)...RED
# state 1: (LEFT,RIGHT) from (1,0) to (1,1)...AMBER
# state 2: (LEFT,RIGHT) from (1,1) to (0,1)...GREEN
# state 3: (LEFT,RIGHT) from (0,1) to (0,0)...OFF
state = 0
left_value = 0
right_value = 0
MIN_VALUE = 0
MAX_VALUE = 1
self.all_off()
start_time = dt.datetime.now()
while True:
if state == 0:
left_value += increment_by
elif state == 1:
right_value += increment_by
elif state == 2:
left_value -= increment_by
elif state == 3:
right_value -= increment_by
else:
raise Exception("Invalid state {}".format(state))
# Keep left_value and right_value within the MIN/MAX values
left_value = min(left_value, MAX_VALUE)
right_value = min(right_value, MAX_VALUE)
left_value = max(left_value, MIN_VALUE)
right_value = max(right_value, MIN_VALUE)
self.set_color(group1, (left_value, right_value))
self.set_color(group2, (left_value, right_value))
if state == 0 and left_value == MAX_VALUE:
state = 1
elif state == 1 and right_value == MAX_VALUE:
state = 2
elif state == 2 and left_value == MIN_VALUE:
state = 3
elif state == 3 and right_value == MIN_VALUE:
state = 0
if self.animate_thread_stop or duration_expired(start_time, duration):
break
sleep(sleeptime)
self.animate_thread_stop = False
self.animate_thread_id = None
self.animate_stop()
if block:
_animate_rainbow()
else:
self.animate_thread_id = _thread.start_new_thread(_animate_rainbow, ()) | python | 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
from ev3dev2.led import Leds
leds = Leds()
leds.animate_rainbow()
"""
def _animate_rainbow():
# state 0: (LEFT,RIGHT) from (0,0) to (1,0)...RED
# state 1: (LEFT,RIGHT) from (1,0) to (1,1)...AMBER
# state 2: (LEFT,RIGHT) from (1,1) to (0,1)...GREEN
# state 3: (LEFT,RIGHT) from (0,1) to (0,0)...OFF
state = 0
left_value = 0
right_value = 0
MIN_VALUE = 0
MAX_VALUE = 1
self.all_off()
start_time = dt.datetime.now()
while True:
if state == 0:
left_value += increment_by
elif state == 1:
right_value += increment_by
elif state == 2:
left_value -= increment_by
elif state == 3:
right_value -= increment_by
else:
raise Exception("Invalid state {}".format(state))
# Keep left_value and right_value within the MIN/MAX values
left_value = min(left_value, MAX_VALUE)
right_value = min(right_value, MAX_VALUE)
left_value = max(left_value, MIN_VALUE)
right_value = max(right_value, MIN_VALUE)
self.set_color(group1, (left_value, right_value))
self.set_color(group2, (left_value, right_value))
if state == 0 and left_value == MAX_VALUE:
state = 1
elif state == 1 and right_value == MAX_VALUE:
state = 2
elif state == 2 and left_value == MIN_VALUE:
state = 3
elif state == 3 and right_value == MIN_VALUE:
state = 0
if self.animate_thread_stop or duration_expired(start_time, duration):
break
sleep(sleeptime)
self.animate_thread_stop = False
self.animate_thread_id = None
self.animate_stop()
if block:
_animate_rainbow()
else:
self.animate_thread_id = _thread.start_new_thread(_animate_rainbow, ()) | [
"def",
"animate_rainbow",
"(",
"self",
",",
"group1",
"=",
"'LEFT'",
",",
"group2",
"=",
"'RIGHT'",
",",
"increment_by",
"=",
"0.1",
",",
"sleeptime",
"=",
"0.1",
",",
"duration",
"=",
"5",
",",
"block",
"=",
"True",
")",
":",
"def",
"_animate_rainbow",
... | Gradually fade from one color to the next
Animate for ``duration`` seconds. If ``duration`` is None animate for forever.
Example:
.. code-block:: python
from ev3dev2.led import Leds
leds = Leds()
leds.animate_rainbow() | [
"Gradually",
"fade",
"from",
"one",
"color",
"to",
"the",
"next"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/led.py#L545-L617 | train | 228,167 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | ColorSensor.raw | 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 white paper will return
values in the 250-400 range.
If this is an issue, check out the rgb() and calibrate_white() methods.
"""
self._ensure_mode(self.MODE_RGB_RAW)
return self.value(0), self.value(1), self.value(2) | python | 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 white paper will return
values in the 250-400 range.
If this is an issue, check out the rgb() and calibrate_white() methods.
"""
self._ensure_mode(self.MODE_RGB_RAW)
return self.value(0), self.value(1), self.value(2) | [
"def",
"raw",
"(",
"self",
")",
":",
"self",
".",
"_ensure_mode",
"(",
"self",
".",
"MODE_RGB_RAW",
")",
"return",
"self",
".",
"value",
"(",
"0",
")",
",",
"self",
".",
"value",
"(",
"1",
")",
",",
"self",
".",
"value",
"(",
"2",
")"
] | 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
values in the 250-400 range.
If this is an issue, check out the rgb() and calibrate_white() methods. | [
"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",
"n... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L226-L238 | train | 228,168 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | ColorSensor.lab | 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 / 12.92
RGB[num] = value * 100.0
# http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
# sRGB
# 0.4124564 0.3575761 0.1804375
# 0.2126729 0.7151522 0.0721750
# 0.0193339 0.1191920 0.9503041
X = (RGB[0] * 0.4124564) + (RGB[1] * 0.3575761) + (RGB[2] * 0.1804375)
Y = (RGB[0] * 0.2126729) + (RGB[1] * 0.7151522) + (RGB[2] * 0.0721750)
Z = (RGB[0] * 0.0193339) + (RGB[1] * 0.1191920) + (RGB[2] * 0.9503041)
XYZ[0] = X / 95.047 # ref_X = 95.047
XYZ[1] = Y / 100.0 # ref_Y = 100.000
XYZ[2] = Z / 108.883 # ref_Z = 108.883
for (num, value) in enumerate(XYZ):
if value > 0.008856:
value = pow(value, (1.0 / 3.0))
else:
value = (7.787 * value) + (16 / 116.0)
XYZ[num] = value
L = (116.0 * XYZ[1]) - 16
a = 500.0 * (XYZ[0] - XYZ[1])
b = 200.0 * (XYZ[1] - XYZ[2])
L = round(L, 4)
a = round(a, 4)
b = round(b, 4)
return (L, a, b) | python | 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 / 12.92
RGB[num] = value * 100.0
# http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
# sRGB
# 0.4124564 0.3575761 0.1804375
# 0.2126729 0.7151522 0.0721750
# 0.0193339 0.1191920 0.9503041
X = (RGB[0] * 0.4124564) + (RGB[1] * 0.3575761) + (RGB[2] * 0.1804375)
Y = (RGB[0] * 0.2126729) + (RGB[1] * 0.7151522) + (RGB[2] * 0.0721750)
Z = (RGB[0] * 0.0193339) + (RGB[1] * 0.1191920) + (RGB[2] * 0.9503041)
XYZ[0] = X / 95.047 # ref_X = 95.047
XYZ[1] = Y / 100.0 # ref_Y = 100.000
XYZ[2] = Z / 108.883 # ref_Z = 108.883
for (num, value) in enumerate(XYZ):
if value > 0.008856:
value = pow(value, (1.0 / 3.0))
else:
value = (7.787 * value) + (16 / 116.0)
XYZ[num] = value
L = (116.0 * XYZ[1]) - 16
a = 500.0 * (XYZ[0] - XYZ[1])
b = 200.0 * (XYZ[1] - XYZ[2])
L = round(L, 4)
a = round(a, 4)
b = round(b, 4)
return (L, a, b) | [
"def",
"lab",
"(",
"self",
")",
":",
"RGB",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"XYZ",
"=",
"[",
"0",
",",
"0",
",",
"0",
"]",
"for",
"(",
"num",
",",
"value",
")",
"in",
"enumerate",
"(",
"self",
".",
"rgb",
")",
":",
"if",
"value",
... | Return colors in Lab color space | [
"Return",
"colors",
"in",
"Lab",
"color",
"space"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L273-L317 | train | 228,169 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | GyroSensor.wait_until_angle_changed_by | 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 (default) we will wait until angle has changed
by ``delta`` in either direction.
"""
assert self.mode in (self.MODE_GYRO_G_A, self.MODE_GYRO_ANG,
self.MODE_TILT_ANG),\
'Gyro mode should be MODE_GYRO_ANG, MODE_GYRO_G_A or MODE_TILT_ANG'
start_angle = self.value(0)
if direction_sensitive:
if delta > 0:
while (self.value(0) - start_angle) < delta:
time.sleep(0.01)
else:
delta *= -1
while (start_angle - self.value(0)) < delta:
time.sleep(0.01)
else:
while abs(start_angle - self.value(0)) < delta:
time.sleep(0.01) | python | 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 (default) we will wait until angle has changed
by ``delta`` in either direction.
"""
assert self.mode in (self.MODE_GYRO_G_A, self.MODE_GYRO_ANG,
self.MODE_TILT_ANG),\
'Gyro mode should be MODE_GYRO_ANG, MODE_GYRO_G_A or MODE_TILT_ANG'
start_angle = self.value(0)
if direction_sensitive:
if delta > 0:
while (self.value(0) - start_angle) < delta:
time.sleep(0.01)
else:
delta *= -1
while (start_angle - self.value(0)) < delta:
time.sleep(0.01)
else:
while abs(start_angle - self.value(0)) < delta:
time.sleep(0.01) | [
"def",
"wait_until_angle_changed_by",
"(",
"self",
",",
"delta",
",",
"direction_sensitive",
"=",
"False",
")",
":",
"assert",
"self",
".",
"mode",
"in",
"(",
"self",
".",
"MODE_GYRO_G_A",
",",
"self",
".",
"MODE_GYRO_ANG",
",",
"self",
".",
"MODE_TILT_ANG",
... | 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. | [
"Wait",
"until",
"angle",
"has",
"changed",
"by",
"specified",
"amount",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L636-L661 | train | 228,170 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | InfraredSensor.buttons_pressed | 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._BUTTON_VALUES.get(self.value(channel), []) | python | 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._BUTTON_VALUES.get(self.value(channel), []) | [
"def",
"buttons_pressed",
"(",
"self",
",",
"channel",
"=",
"1",
")",
":",
"self",
".",
"_ensure_mode",
"(",
"self",
".",
"MODE_IR_REMOTE",
")",
"channel",
"=",
"self",
".",
"_normalize_channel",
"(",
"channel",
")",
"return",
"self",
".",
"_BUTTON_VALUES",
... | Returns list of currently pressed buttons.
Note that the sensor can only identify up to two buttons pressed at once. | [
"Returns",
"list",
"of",
"currently",
"pressed",
"buttons",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L848-L856 | train | 228,171 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | SoundSensor.sound_pressure | 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 | 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') | [
"def",
"sound_pressure",
"(",
"self",
")",
":",
"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 flat weighting. | [
"A",
"measurement",
"of",
"the",
"measured",
"sound",
"pressure",
"level",
"as",
"a",
"percent",
".",
"Uses",
"a",
"flat",
"weighting",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L935-L941 | train | 228,172 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | SoundSensor.sound_pressure_low | 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 | 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') | [
"def",
"sound_pressure_low",
"(",
"self",
")",
":",
"self",
".",
"_ensure_mode",
"(",
"self",
".",
"MODE_DBA",
")",
"return",
"self",
".",
"value",
"(",
"0",
")",
"*",
"self",
".",
"_scale",
"(",
"'DBA'",
")"
] | A measurement of the measured sound pressure level, as a
percent. Uses A-weighting, which focuses on levels up to 55 dB. | [
"A",
"measurement",
"of",
"the",
"measured",
"sound",
"pressure",
"level",
"as",
"a",
"percent",
".",
"Uses",
"A",
"-",
"weighting",
"which",
"focuses",
"on",
"levels",
"up",
"to",
"55",
"dB",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L944-L950 | train | 228,173 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | LightSensor.reflected_light_intensity | 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 | 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') | [
"def",
"reflected_light_intensity",
"(",
"self",
")",
":",
"self",
".",
"_ensure_mode",
"(",
"self",
".",
"MODE_REFLECT",
")",
"return",
"self",
".",
"value",
"(",
"0",
")",
"*",
"self",
".",
"_scale",
"(",
"'REFLECT'",
")"
] | A measurement of the reflected light intensity, as a percentage. | [
"A",
"measurement",
"of",
"the",
"reflected",
"light",
"intensity",
"as",
"a",
"percentage",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L976-L981 | train | 228,174 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/lego.py | LightSensor.ambient_light_intensity | 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 | 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') | [
"def",
"ambient_light_intensity",
"(",
"self",
")",
":",
"self",
".",
"_ensure_mode",
"(",
"self",
".",
"MODE_AMBIENT",
")",
"return",
"self",
".",
"value",
"(",
"0",
")",
"*",
"self",
".",
"_scale",
"(",
"'AMBIENT'",
")"
] | A measurement of the ambient light intensity, as a percentage. | [
"A",
"measurement",
"of",
"the",
"ambient",
"light",
"intensity",
"as",
"a",
"percentage",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/lego.py#L984-L989 | train | 228,175 |
ev3dev/ev3dev-lang-python | ev3dev2/fonts/__init__.py | available | 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 | 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) | [
"def",
"available",
"(",
")",
":",
"font_dir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
"names",
"=",
"[",
"os",
".",
"path",
".",
"basename",
"(",
"os",
".",
"path",
".",
"splitext",
"(",
"f",
")",
"[",
"0",
"]",
")",
"for... | Returns list of available font names. | [
"Returns",
"list",
"of",
"available",
"font",
"names",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/fonts/__init__.py#L5-L12 | train | 228,176 |
ev3dev/ev3dev-lang-python | ev3dev2/port.py | LegoPort.modes | 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 | 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 | [
"def",
"modes",
"(",
"self",
")",
":",
"(",
"self",
".",
"_modes",
",",
"value",
")",
"=",
"self",
".",
"get_cached_attr_set",
"(",
"self",
".",
"_modes",
",",
"'modes'",
")",
"return",
"value"
] | Returns a list of the available modes of the port. | [
"Returns",
"a",
"list",
"of",
"the",
"available",
"modes",
"of",
"the",
"port",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/port.py#L105-L110 | train | 228,177 |
ev3dev/ev3dev-lang-python | ev3dev2/port.py | LegoPort.mode | 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 implementing this class.
"""
self._mode, value = self.get_attr_string(self._mode, 'mode')
return value | python | 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 implementing this class.
"""
self._mode, value = self.get_attr_string(self._mode, 'mode')
return value | [
"def",
"mode",
"(",
"self",
")",
":",
"self",
".",
"_mode",
",",
"value",
"=",
"self",
".",
"get_attr_string",
"(",
"self",
".",
"_mode",
",",
"'mode'",
")",
"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. | [
"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",
... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/port.py#L113-L121 | train | 228,178 |
ev3dev/ev3dev-lang-python | ev3dev2/port.py | LegoPort.status | 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.
"""
self._status, value = self.get_attr_string(self._status, 'status')
return value | python | 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.
"""
self._status, value = self.get_attr_string(self._status, 'status')
return value | [
"def",
"status",
"(",
"self",
")",
":",
"self",
".",
"_status",
",",
"value",
"=",
"self",
".",
"get_attr_string",
"(",
"self",
".",
"_status",
",",
"'status'",
")",
"return",
"value"
] | 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. | [
"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"... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/port.py#L143-L151 | train | 228,179 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/__init__.py | list_sensors | 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: '*'.
keyword arguments: used for matching the corresponding device
attributes. For example, driver_name='lego-ev3-touch', or
address=['in1', 'in3']. When argument value is a list,
then a match against any entry of the list is enough.
"""
class_path = abspath(Device.DEVICE_ROOT_PATH + '/' + Sensor.SYSTEM_CLASS_NAME)
return (Sensor(name_pattern=name, name_exact=True)
for name in list_device_names(class_path, name_pattern, **kwargs)) | python | 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: '*'.
keyword arguments: used for matching the corresponding device
attributes. For example, driver_name='lego-ev3-touch', or
address=['in1', 'in3']. When argument value is a list,
then a match against any entry of the list is enough.
"""
class_path = abspath(Device.DEVICE_ROOT_PATH + '/' + Sensor.SYSTEM_CLASS_NAME)
return (Sensor(name_pattern=name, name_exact=True)
for name in list_device_names(class_path, name_pattern, **kwargs)) | [
"def",
"list_sensors",
"(",
"name_pattern",
"=",
"Sensor",
".",
"SYSTEM_DEVICE_NAME_CONVENTION",
",",
"*",
"*",
"kwargs",
")",
":",
"class_path",
"=",
"abspath",
"(",
"Device",
".",
"DEVICE_ROOT_PATH",
"+",
"'/'",
"+",
"Sensor",
".",
"SYSTEM_CLASS_NAME",
")",
... | 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
attributes. For example, driver_name='lego-ev3-touch', or
address=['in1', 'in3']. When argument value is a list,
then a match against any entry of the list is enough. | [
"This",
"is",
"a",
"generator",
"function",
"that",
"enumerates",
"all",
"sensors",
"that",
"match",
"the",
"provided",
"arguments",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/__init__.py#L282-L297 | train | 228,180 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/__init__.py | Sensor._scale | 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 | 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 | [
"def",
"_scale",
"(",
"self",
",",
"mode",
")",
":",
"if",
"mode",
"in",
"self",
".",
"_mode_scale",
":",
"scale",
"=",
"self",
".",
"_mode_scale",
"[",
"mode",
"]",
"else",
":",
"scale",
"=",
"10",
"**",
"(",
"-",
"self",
".",
"decimals",
")",
"... | Returns value scaling coefficient for the given mode. | [
"Returns",
"value",
"scaling",
"coefficient",
"for",
"the",
"given",
"mode",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/__init__.py#L112-L122 | train | 228,181 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/__init__.py | Sensor.units | 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 | 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 | [
"def",
"units",
"(",
"self",
")",
":",
"self",
".",
"_units",
",",
"value",
"=",
"self",
".",
"get_attr_string",
"(",
"self",
".",
"_units",
",",
"'units'",
")",
"return",
"value"
] | Returns the units of the measured value for the current mode. May return
empty string | [
"Returns",
"the",
"units",
"of",
"the",
"measured",
"value",
"for",
"the",
"current",
"mode",
".",
"May",
"return",
"empty",
"string"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/__init__.py#L202-L208 | train | 228,182 |
ev3dev/ev3dev-lang-python | ev3dev2/sensor/__init__.py | Sensor.value | 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 value.
"""
n = int(n)
self._value[n], value = self.get_attr_int(self._value[n], 'value'+str(n))
return value | python | 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 value.
"""
n = int(n)
self._value[n], value = self.get_attr_int(self._value[n], 'value'+str(n))
return value | [
"def",
"value",
"(",
"self",
",",
"n",
"=",
"0",
")",
":",
"n",
"=",
"int",
"(",
"n",
")",
"self",
".",
"_value",
"[",
"n",
"]",
",",
"value",
"=",
"self",
".",
"get_attr_int",
"(",
"self",
".",
"_value",
"[",
"n",
"]",
",",
"'value'",
"+",
... | 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 value. | [
"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... | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sensor/__init__.py#L210-L220 | train | 228,183 |
ev3dev/ev3dev-lang-python | ev3dev2/display.py | FbMem._open_fbdev | 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)
return fbfid | python | 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)
return fbfid | [
"def",
"_open_fbdev",
"(",
"fbdev",
"=",
"None",
")",
":",
"dev",
"=",
"fbdev",
"or",
"os",
".",
"getenv",
"(",
"'FRAMEBUFFER'",
",",
"'/dev/fb0'",
")",
"fbfid",
"=",
"os",
".",
"open",
"(",
"dev",
",",
"os",
".",
"O_RDWR",
")",
"return",
"fbfid"
] | Return the framebuffer file descriptor.
Try to use the FRAMEBUFFER
environment variable if fbdev is not given. Use '/dev/fb0' by
default. | [
"Return",
"the",
"framebuffer",
"file",
"descriptor",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/display.py#L157-L166 | train | 228,184 |
ev3dev/ev3dev-lang-python | ev3dev2/display.py | FbMem._get_fix_info | 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 | 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 | [
"def",
"_get_fix_info",
"(",
"fbfid",
")",
":",
"fix_info",
"=",
"FbMem",
".",
"FixScreenInfo",
"(",
")",
"fcntl",
".",
"ioctl",
"(",
"fbfid",
",",
"FbMem",
".",
"FBIOGET_FSCREENINFO",
",",
"fix_info",
")",
"return",
"fix_info"
] | Return the fix screen info from the framebuffer file descriptor. | [
"Return",
"the",
"fix",
"screen",
"info",
"from",
"the",
"framebuffer",
"file",
"descriptor",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/display.py#L169-L173 | train | 228,185 |
ev3dev/ev3dev-lang-python | ev3dev2/display.py | FbMem._get_var_info | 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 | 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 | [
"def",
"_get_var_info",
"(",
"fbfid",
")",
":",
"var_info",
"=",
"FbMem",
".",
"VarScreenInfo",
"(",
")",
"fcntl",
".",
"ioctl",
"(",
"fbfid",
",",
"FbMem",
".",
"FBIOGET_VSCREENINFO",
",",
"var_info",
")",
"return",
"var_info"
] | Return the var screen info from the framebuffer file descriptor. | [
"Return",
"the",
"var",
"screen",
"info",
"from",
"the",
"framebuffer",
"file",
"descriptor",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/display.py#L176-L180 | train | 228,186 |
ev3dev/ev3dev-lang-python | ev3dev2/display.py | FbMem._map_fb_memory | 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 | 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
) | [
"def",
"_map_fb_memory",
"(",
"fbfid",
",",
"fix_info",
")",
":",
"return",
"mmap",
".",
"mmap",
"(",
"fbfid",
",",
"fix_info",
".",
"smem_len",
",",
"mmap",
".",
"MAP_SHARED",
",",
"mmap",
".",
"PROT_READ",
"|",
"mmap",
".",
"PROT_WRITE",
",",
"offset",... | Map the framebuffer memory. | [
"Map",
"the",
"framebuffer",
"memory",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/display.py#L183-L191 | train | 228,187 |
ev3dev/ev3dev-lang-python | ev3dev2/display.py | Display.update | 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.bits_per_pixel == 16:
self.mmap[:] = self._img_to_rgb565_bytes()
elif self.var_info.bits_per_pixel == 32:
self.mmap[:] = self._img.convert("RGB").tobytes("raw", "XRGB")
else:
raise Exception("Not supported - platform %s with bits_per_pixel %s" %
(self.platform, self.var_info.bits_per_pixel)) | python | 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.bits_per_pixel == 16:
self.mmap[:] = self._img_to_rgb565_bytes()
elif self.var_info.bits_per_pixel == 32:
self.mmap[:] = self._img.convert("RGB").tobytes("raw", "XRGB")
else:
raise Exception("Not supported - platform %s with bits_per_pixel %s" %
(self.platform, self.var_info.bits_per_pixel)) | [
"def",
"update",
"(",
"self",
")",
":",
"if",
"self",
".",
"var_info",
".",
"bits_per_pixel",
"==",
"1",
":",
"b",
"=",
"self",
".",
"_img",
".",
"tobytes",
"(",
"\"raw\"",
",",
"\"1;R\"",
")",
"self",
".",
"mmap",
"[",
":",
"len",
"(",
"b",
")",... | Applies pending changes to the screen.
Nothing will be drawn on the screen until this function is called. | [
"Applies",
"pending",
"changes",
"to",
"the",
"screen",
".",
"Nothing",
"will",
"be",
"drawn",
"on",
"the",
"screen",
"until",
"this",
"function",
"is",
"called",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/display.py#L294-L311 | train | 228,188 |
ev3dev/ev3dev-lang-python | ev3dev2/sound.py | _make_scales | 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 | 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 | [
"def",
"_make_scales",
"(",
"notes",
")",
":",
"res",
"=",
"dict",
"(",
")",
"for",
"note",
",",
"freq",
"in",
"notes",
":",
"freq",
"=",
"round",
"(",
"freq",
")",
"for",
"n",
"in",
"note",
".",
"split",
"(",
"'/'",
")",
":",
"res",
"[",
"n",
... | Utility function used by Sound class for building the note frequencies table | [
"Utility",
"function",
"used",
"by",
"Sound",
"class",
"for",
"building",
"the",
"note",
"frequencies",
"table"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sound.py#L37-L44 | train | 228,189 |
ev3dev/ev3dev-lang-python | ev3dev2/sound.py | Sound.play_tone | 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 seconds
:param float delay: Delay after tone, in seconds (can be useful when chaining calls to ``play_tone``)
:param int volume: The play volume, in percent of maximum volume
:param play_type: The behavior of ``play_tone`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:return: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the PID of the underlying beep command; ``None`` otherwise
:raises ValueError: if invalid parameter
"""
self._validate_play_type(play_type)
if duration <= 0:
raise ValueError('invalid duration (%s)' % duration)
if delay < 0:
raise ValueError('invalid delay (%s)' % delay)
if not 0 < volume <= 100:
raise ValueError('invalid volume (%s)' % volume)
self.set_volume(volume)
duration_ms = int(duration * 1000)
delay_ms = int(delay * 1000)
self.tone([(frequency, duration_ms, delay_ms)], play_type=play_type) | python | 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 seconds
:param float delay: Delay after tone, in seconds (can be useful when chaining calls to ``play_tone``)
:param int volume: The play volume, in percent of maximum volume
:param play_type: The behavior of ``play_tone`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:return: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the PID of the underlying beep command; ``None`` otherwise
:raises ValueError: if invalid parameter
"""
self._validate_play_type(play_type)
if duration <= 0:
raise ValueError('invalid duration (%s)' % duration)
if delay < 0:
raise ValueError('invalid delay (%s)' % delay)
if not 0 < volume <= 100:
raise ValueError('invalid volume (%s)' % volume)
self.set_volume(volume)
duration_ms = int(duration * 1000)
delay_ms = int(delay * 1000)
self.tone([(frequency, duration_ms, delay_ms)], play_type=play_type) | [
"def",
"play_tone",
"(",
"self",
",",
"frequency",
",",
"duration",
",",
"delay",
"=",
"0.0",
",",
"volume",
"=",
"100",
",",
"play_type",
"=",
"PLAY_WAIT_FOR_COMPLETE",
")",
":",
"self",
".",
"_validate_play_type",
"(",
"play_type",
")",
"if",
"duration",
... | 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 seconds
:param float delay: Delay after tone, in seconds (can be useful when chaining calls to ``play_tone``)
:param int volume: The play volume, in percent of maximum volume
:param play_type: The behavior of ``play_tone`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:return: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the PID of the underlying beep command; ``None`` otherwise
:raises ValueError: if invalid parameter | [
"Play",
"a",
"single",
"tone",
"specified",
"by",
"its",
"frequency",
"duration",
"volume",
"and",
"final",
"delay",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sound.py#L192-L222 | train | 228,190 |
ev3dev/ev3dev-lang-python | ev3dev2/sound.py | Sound.play_note | 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 play volume, in percent of maximum volume
:param play_type: The behavior of ``play_note`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:return: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the PID of the underlying beep command; ``None`` otherwise
:raises ValueError: is invalid parameter (note, duration,...)
"""
self._validate_play_type(play_type)
try:
freq = self._NOTE_FREQUENCIES.get(note.upper(), self._NOTE_FREQUENCIES[note])
except KeyError:
raise ValueError('invalid note (%s)' % note)
if duration <= 0:
raise ValueError('invalid duration (%s)' % duration)
if not 0 < volume <= 100:
raise ValueError('invalid volume (%s)' % volume)
return self.play_tone(freq, duration=duration, volume=volume, play_type=play_type) | python | 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 play volume, in percent of maximum volume
:param play_type: The behavior of ``play_note`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:return: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the PID of the underlying beep command; ``None`` otherwise
:raises ValueError: is invalid parameter (note, duration,...)
"""
self._validate_play_type(play_type)
try:
freq = self._NOTE_FREQUENCIES.get(note.upper(), self._NOTE_FREQUENCIES[note])
except KeyError:
raise ValueError('invalid note (%s)' % note)
if duration <= 0:
raise ValueError('invalid duration (%s)' % duration)
if not 0 < volume <= 100:
raise ValueError('invalid volume (%s)' % volume)
return self.play_tone(freq, duration=duration, volume=volume, play_type=play_type) | [
"def",
"play_note",
"(",
"self",
",",
"note",
",",
"duration",
",",
"volume",
"=",
"100",
",",
"play_type",
"=",
"PLAY_WAIT_FOR_COMPLETE",
")",
":",
"self",
".",
"_validate_play_type",
"(",
"play_type",
")",
"try",
":",
"freq",
"=",
"self",
".",
"_NOTE_FRE... | 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 play volume, in percent of maximum volume
:param play_type: The behavior of ``play_note`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:return: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the PID of the underlying beep command; ``None`` otherwise
:raises ValueError: is invalid parameter (note, duration,...) | [
"Plays",
"a",
"note",
"given",
"by",
"its",
"name",
"as",
"defined",
"in",
"_NOTE_FREQUENCIES",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sound.py#L224-L249 | train | 228,191 |
ev3dev/ev3dev-lang-python | ev3dev2/sound.py | Sound.speak | 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)
:param int volume: The play volume, in percent of maximum volume
:param play_type: The behavior of ``speak`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:returns: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the spawn subprocess from ``subprocess.Popen``; ``None`` otherwise
"""
self._validate_play_type(play_type)
self.set_volume(volume)
with open(os.devnull, 'w') as n:
cmd_line = ['/usr/bin/espeak', '--stdout'] + shlex.split(espeak_opts) + [shlex.quote(text)]
aplay_cmd_line = shlex.split('/usr/bin/aplay -q')
if play_type == Sound.PLAY_WAIT_FOR_COMPLETE:
espeak = Popen(cmd_line, stdout=PIPE)
play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
play.wait()
elif play_type == Sound.PLAY_NO_WAIT_FOR_COMPLETE:
espeak = Popen(cmd_line, stdout=PIPE)
return Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
elif play_type == Sound.PLAY_LOOP:
while True:
espeak = Popen(cmd_line, stdout=PIPE)
play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
play.wait() | python | 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)
:param int volume: The play volume, in percent of maximum volume
:param play_type: The behavior of ``speak`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:returns: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the spawn subprocess from ``subprocess.Popen``; ``None`` otherwise
"""
self._validate_play_type(play_type)
self.set_volume(volume)
with open(os.devnull, 'w') as n:
cmd_line = ['/usr/bin/espeak', '--stdout'] + shlex.split(espeak_opts) + [shlex.quote(text)]
aplay_cmd_line = shlex.split('/usr/bin/aplay -q')
if play_type == Sound.PLAY_WAIT_FOR_COMPLETE:
espeak = Popen(cmd_line, stdout=PIPE)
play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
play.wait()
elif play_type == Sound.PLAY_NO_WAIT_FOR_COMPLETE:
espeak = Popen(cmd_line, stdout=PIPE)
return Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
elif play_type == Sound.PLAY_LOOP:
while True:
espeak = Popen(cmd_line, stdout=PIPE)
play = Popen(aplay_cmd_line, stdin=espeak.stdout, stdout=n)
play.wait() | [
"def",
"speak",
"(",
"self",
",",
"text",
",",
"espeak_opts",
"=",
"'-a 200 -s 130'",
",",
"volume",
"=",
"100",
",",
"play_type",
"=",
"PLAY_WAIT_FOR_COMPLETE",
")",
":",
"self",
".",
"_validate_play_type",
"(",
"play_type",
")",
"self",
".",
"set_volume",
... | 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)
:param int volume: The play volume, in percent of maximum volume
:param play_type: The behavior of ``speak`` once playback has been initiated
:type play_type: ``Sound.PLAY_WAIT_FOR_COMPLETE``, ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` or ``Sound.PLAY_LOOP``
:returns: When ``Sound.PLAY_NO_WAIT_FOR_COMPLETE`` is specified, returns the spawn subprocess from ``subprocess.Popen``; ``None`` otherwise | [
"Speak",
"the",
"given",
"text",
"aloud",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sound.py#L289-L323 | train | 228,192 |
ev3dev/ev3dev-lang-python | ev3dev2/sound.py | Sound.play_song | 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 durations (e.g. ``q``, ``h``).
For an exhaustive list of accepted note symbols and values, have a look at the ``_NOTE_FREQUENCIES``
and ``_NOTE_VALUES`` private dictionaries in the source code.
The value can be suffixed by modifiers:
- a *divider* introduced by a ``/`` to obtain triplets for instance
(e.g. ``q/3`` for a triplet of eight note)
- a *multiplier* introduced by ``*`` (e.g. ``*1.5`` is a dotted note).
Shortcuts exist for common modifiers:
- ``3`` produces a triplet member note. For instance `e3` gives a triplet of eight notes,
i.e. 3 eight notes in the duration of a single quarter. You must ensure that 3 triplets
notes are defined in sequence to match the count, otherwise the result will not be the
expected one.
- ``.`` produces a dotted note, i.e. which duration is one and a half the base one. Double dots
are not currently supported.
Example::
>>> # A long time ago in a galaxy far,
>>> # far away...
>>> Sound.play_song((
>>> ('D4', 'e3'), # intro anacrouse
>>> ('D4', 'e3'),
>>> ('D4', 'e3'),
>>> ('G4', 'h'), # meas 1
>>> ('D5', 'h'),
>>> ('C5', 'e3'), # meas 2
>>> ('B4', 'e3'),
>>> ('A4', 'e3'),
>>> ('G5', 'h'),
>>> ('D5', 'q'),
>>> ('C5', 'e3'), # meas 3
>>> ('B4', 'e3'),
>>> ('A4', 'e3'),
>>> ('G5', 'h'),
>>> ('D5', 'q'),
>>> ('C5', 'e3'), # meas 4
>>> ('B4', 'e3'),
>>> ('C5', 'e3'),
>>> ('A4', 'h.'),
>>> ))
.. important::
Only 4/4 signature songs are supported with respect to note durations.
:param iterable[tuple(string, string)] song: the song
:param int tempo: the song tempo, given in quarters per minute
:param float delay: delay between notes (in seconds)
:return: the spawn subprocess from ``subprocess.Popen``
:raises ValueError: if invalid note in song or invalid play parameters
"""
if tempo <= 0:
raise ValueError('invalid tempo (%s)' % tempo)
if delay < 0:
raise ValueError('invalid delay (%s)' % delay)
delay_ms = int(delay * 1000)
meas_duration_ms = 60000 / tempo * 4 # we only support 4/4 bars, hence "* 4"
def beep_args(note, value):
""" Builds the arguments string for producing a beep matching
the requested note and value.
Args:
note (str): the note note and octave
value (str): the note value expression
Returns:
str: the arguments to be passed to the beep command
"""
freq = self._NOTE_FREQUENCIES.get(note.upper(), self._NOTE_FREQUENCIES[note])
if '/' in value:
base, factor = value.split('/')
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] / float(factor)
elif '*' in value:
base, factor = value.split('*')
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] * float(factor)
elif value.endswith('.'):
base = value[:-1]
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] * 1.5
elif value.endswith('3'):
base = value[:-1]
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] * 2 / 3
else:
duration_ms = meas_duration_ms * self._NOTE_VALUES[value]
return '-f %d -l %d -D %d' % (freq, duration_ms, delay_ms)
try:
return self.beep(' -n '.join(
[beep_args(note, value) for (note, value) in song]
))
except KeyError as e:
raise ValueError('invalid note (%s)' % e) | python | 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 durations (e.g. ``q``, ``h``).
For an exhaustive list of accepted note symbols and values, have a look at the ``_NOTE_FREQUENCIES``
and ``_NOTE_VALUES`` private dictionaries in the source code.
The value can be suffixed by modifiers:
- a *divider* introduced by a ``/`` to obtain triplets for instance
(e.g. ``q/3`` for a triplet of eight note)
- a *multiplier* introduced by ``*`` (e.g. ``*1.5`` is a dotted note).
Shortcuts exist for common modifiers:
- ``3`` produces a triplet member note. For instance `e3` gives a triplet of eight notes,
i.e. 3 eight notes in the duration of a single quarter. You must ensure that 3 triplets
notes are defined in sequence to match the count, otherwise the result will not be the
expected one.
- ``.`` produces a dotted note, i.e. which duration is one and a half the base one. Double dots
are not currently supported.
Example::
>>> # A long time ago in a galaxy far,
>>> # far away...
>>> Sound.play_song((
>>> ('D4', 'e3'), # intro anacrouse
>>> ('D4', 'e3'),
>>> ('D4', 'e3'),
>>> ('G4', 'h'), # meas 1
>>> ('D5', 'h'),
>>> ('C5', 'e3'), # meas 2
>>> ('B4', 'e3'),
>>> ('A4', 'e3'),
>>> ('G5', 'h'),
>>> ('D5', 'q'),
>>> ('C5', 'e3'), # meas 3
>>> ('B4', 'e3'),
>>> ('A4', 'e3'),
>>> ('G5', 'h'),
>>> ('D5', 'q'),
>>> ('C5', 'e3'), # meas 4
>>> ('B4', 'e3'),
>>> ('C5', 'e3'),
>>> ('A4', 'h.'),
>>> ))
.. important::
Only 4/4 signature songs are supported with respect to note durations.
:param iterable[tuple(string, string)] song: the song
:param int tempo: the song tempo, given in quarters per minute
:param float delay: delay between notes (in seconds)
:return: the spawn subprocess from ``subprocess.Popen``
:raises ValueError: if invalid note in song or invalid play parameters
"""
if tempo <= 0:
raise ValueError('invalid tempo (%s)' % tempo)
if delay < 0:
raise ValueError('invalid delay (%s)' % delay)
delay_ms = int(delay * 1000)
meas_duration_ms = 60000 / tempo * 4 # we only support 4/4 bars, hence "* 4"
def beep_args(note, value):
""" Builds the arguments string for producing a beep matching
the requested note and value.
Args:
note (str): the note note and octave
value (str): the note value expression
Returns:
str: the arguments to be passed to the beep command
"""
freq = self._NOTE_FREQUENCIES.get(note.upper(), self._NOTE_FREQUENCIES[note])
if '/' in value:
base, factor = value.split('/')
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] / float(factor)
elif '*' in value:
base, factor = value.split('*')
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] * float(factor)
elif value.endswith('.'):
base = value[:-1]
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] * 1.5
elif value.endswith('3'):
base = value[:-1]
duration_ms = meas_duration_ms * self._NOTE_VALUES[base] * 2 / 3
else:
duration_ms = meas_duration_ms * self._NOTE_VALUES[value]
return '-f %d -l %d -D %d' % (freq, duration_ms, delay_ms)
try:
return self.beep(' -n '.join(
[beep_args(note, value) for (note, value) in song]
))
except KeyError as e:
raise ValueError('invalid note (%s)' % e) | [
"def",
"play_song",
"(",
"self",
",",
"song",
",",
"tempo",
"=",
"120",
",",
"delay",
"=",
"0.05",
")",
":",
"if",
"tempo",
"<=",
"0",
":",
"raise",
"ValueError",
"(",
"'invalid tempo (%s)'",
"%",
"tempo",
")",
"if",
"delay",
"<",
"0",
":",
"raise",
... | 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 durations (e.g. ``q``, ``h``).
For an exhaustive list of accepted note symbols and values, have a look at the ``_NOTE_FREQUENCIES``
and ``_NOTE_VALUES`` private dictionaries in the source code.
The value can be suffixed by modifiers:
- a *divider* introduced by a ``/`` to obtain triplets for instance
(e.g. ``q/3`` for a triplet of eight note)
- a *multiplier* introduced by ``*`` (e.g. ``*1.5`` is a dotted note).
Shortcuts exist for common modifiers:
- ``3`` produces a triplet member note. For instance `e3` gives a triplet of eight notes,
i.e. 3 eight notes in the duration of a single quarter. You must ensure that 3 triplets
notes are defined in sequence to match the count, otherwise the result will not be the
expected one.
- ``.`` produces a dotted note, i.e. which duration is one and a half the base one. Double dots
are not currently supported.
Example::
>>> # A long time ago in a galaxy far,
>>> # far away...
>>> Sound.play_song((
>>> ('D4', 'e3'), # intro anacrouse
>>> ('D4', 'e3'),
>>> ('D4', 'e3'),
>>> ('G4', 'h'), # meas 1
>>> ('D5', 'h'),
>>> ('C5', 'e3'), # meas 2
>>> ('B4', 'e3'),
>>> ('A4', 'e3'),
>>> ('G5', 'h'),
>>> ('D5', 'q'),
>>> ('C5', 'e3'), # meas 3
>>> ('B4', 'e3'),
>>> ('A4', 'e3'),
>>> ('G5', 'h'),
>>> ('D5', 'q'),
>>> ('C5', 'e3'), # meas 4
>>> ('B4', 'e3'),
>>> ('C5', 'e3'),
>>> ('A4', 'h.'),
>>> ))
.. important::
Only 4/4 signature songs are supported with respect to note durations.
:param iterable[tuple(string, string)] song: the song
:param int tempo: the song tempo, given in quarters per minute
:param float delay: delay between notes (in seconds)
:return: the spawn subprocess from ``subprocess.Popen``
:raises ValueError: if invalid note in song or invalid play parameters | [
"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",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/sound.py#L380-L485 | train | 228,193 |
ev3dev/ev3dev-lang-python | ev3dev2/__init__.py | list_device_names | 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'.
name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
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.
"""
if not os.path.isdir(class_path):
return
def matches(attribute, pattern):
try:
with io.FileIO(attribute) as f:
value = f.read().strip().decode()
except:
return False
if isinstance(pattern, list):
return any([value.find(p) >= 0 for p in pattern])
else:
return value.find(pattern) >= 0
for f in os.listdir(class_path):
if fnmatch.fnmatch(f, name_pattern):
path = class_path + '/' + f
if all([matches(path + '/' + k, kwargs[k]) for k in kwargs]):
yield f | python | 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'.
name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
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.
"""
if not os.path.isdir(class_path):
return
def matches(attribute, pattern):
try:
with io.FileIO(attribute) as f:
value = f.read().strip().decode()
except:
return False
if isinstance(pattern, list):
return any([value.find(p) >= 0 for p in pattern])
else:
return value.find(pattern) >= 0
for f in os.listdir(class_path):
if fnmatch.fnmatch(f, name_pattern):
path = class_path + '/' + f
if all([matches(path + '/' + k, kwargs[k]) for k in kwargs]):
yield f | [
"def",
"list_device_names",
"(",
"class_path",
",",
"name_pattern",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"class_path",
")",
":",
"return",
"def",
"matches",
"(",
"attribute",
",",
"pattern",
")",
":",
"t... | 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'.
name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
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. | [
"This",
"is",
"a",
"generator",
"function",
"that",
"lists",
"names",
"of",
"all",
"devices",
"matching",
"the",
"provided",
"parameters",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/__init__.py#L100-L136 | train | 228,194 |
ev3dev/ev3dev-lang-python | ev3dev2/__init__.py | list_devices | 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/class.
For example, 'tacho-motor'.
name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
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.
"""
classpath = abspath(Device.DEVICE_ROOT_PATH + '/' + class_name)
return (Device(class_name, name, name_exact=True)
for name in list_device_names(classpath, name_pattern, **kwargs)) | python | 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/class.
For example, 'tacho-motor'.
name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
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.
"""
classpath = abspath(Device.DEVICE_ROOT_PATH + '/' + class_name)
return (Device(class_name, name, name_exact=True)
for name in list_device_names(classpath, name_pattern, **kwargs)) | [
"def",
"list_devices",
"(",
"class_name",
",",
"name_pattern",
",",
"*",
"*",
"kwargs",
")",
":",
"classpath",
"=",
"abspath",
"(",
"Device",
".",
"DEVICE_ROOT_PATH",
"+",
"'/'",
"+",
"class_name",
")",
"return",
"(",
"Device",
"(",
"class_name",
",",
"nam... | 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/class.
For example, 'tacho-motor'.
name_pattern: pattern that device name should match.
For example, 'sensor*' or 'motor*'. Default value: '*'.
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. | [
"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",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/__init__.py#L352-L372 | train | 228,195 |
ev3dev/ev3dev-lang-python | ev3dev2/__init__.py | Device._get_attribute | 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 Exception as ex:
self._raise_friendly_access_error(ex, name) | python | 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 Exception as ex:
self._raise_friendly_access_error(ex, name) | [
"def",
"_get_attribute",
"(",
"self",
",",
"attribute",
",",
"name",
")",
":",
"try",
":",
"if",
"attribute",
"is",
"None",
":",
"attribute",
"=",
"self",
".",
"_attribute_file_open",
"(",
"name",
")",
"else",
":",
"attribute",
".",
"seek",
"(",
"0",
"... | Device attribute getter | [
"Device",
"attribute",
"getter"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/__init__.py#L240-L249 | train | 228,196 |
ev3dev/ev3dev-lang-python | ev3dev2/__init__.py | Device._set_attribute | 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.encode()
attribute.write(value)
attribute.flush()
except Exception as ex:
self._raise_friendly_access_error(ex, name)
return attribute | python | 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.encode()
attribute.write(value)
attribute.flush()
except Exception as ex:
self._raise_friendly_access_error(ex, name)
return attribute | [
"def",
"_set_attribute",
"(",
"self",
",",
"attribute",
",",
"name",
",",
"value",
")",
":",
"try",
":",
"if",
"attribute",
"is",
"None",
":",
"attribute",
"=",
"self",
".",
"_attribute_file_open",
"(",
"name",
")",
"else",
":",
"attribute",
".",
"seek",... | Device attribute setter | [
"Device",
"attribute",
"setter"
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/__init__.py#L251-L265 | train | 228,197 |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer.shutdown | 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_right_file.close()
self.dc_left_file.close()
self.dc_right_file.close() | python | 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_right_file.close()
self.dc_left_file.close()
self.dc_right_file.close() | [
"def",
"shutdown",
"(",
"self",
")",
":",
"self",
".",
"stop_balance",
".",
"set",
"(",
")",
"# Stop balance thread",
"self",
".",
"motor_left",
".",
"stop",
"(",
")",
"self",
".",
"motor_right",
".",
"stop",
"(",
")",
"self",
".",
"gyro_file",
".",
"c... | Close all file handles and stop all motors. | [
"Close",
"all",
"file",
"handles",
"and",
"stop",
"all",
"motors",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L162-L172 | train | 228,198 |
ev3dev/ev3dev-lang-python | ev3dev2/control/GyroBalancer.py | GyroBalancer._fast_read | def _fast_read(self, infile):
"""Function for fast reading from sensor files."""
infile.seek(0)
return(int(infile.read().decode().strip())) | python | def _fast_read(self, infile):
"""Function for fast reading from sensor files."""
infile.seek(0)
return(int(infile.read().decode().strip())) | [
"def",
"_fast_read",
"(",
"self",
",",
"infile",
")",
":",
"infile",
".",
"seek",
"(",
"0",
")",
"return",
"(",
"int",
"(",
"infile",
".",
"read",
"(",
")",
".",
"decode",
"(",
")",
".",
"strip",
"(",
")",
")",
")"
] | Function for fast reading from sensor files. | [
"Function",
"for",
"fast",
"reading",
"from",
"sensor",
"files",
"."
] | afc98d35004b533dc161a01f7c966e78607d7c1e | https://github.com/ev3dev/ev3dev-lang-python/blob/afc98d35004b533dc161a01f7c966e78607d7c1e/ev3dev2/control/GyroBalancer.py#L174-L177 | train | 228,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.