Rotation#
Initializing the Rotation Class#
A Rotation Sensor is created by using the following constructor:
Rotation(port, reverse)
This constructor use one parameter:
Parameter |
Description |
---|---|
|
A valid Smart Port that the Rotation Sensor is connected to. |
|
Optional. Set to |
# Construct a Rotation Sensor "rotation" with the
# Rotation class.
rotation = Rotation(Ports.PORT1)
This rotation
object will be used in all subsequent examples throughout this API documentation when referring to Rotation class methods.
Class Methods#
set_reversed()#
The set_reversed(value)
method sets the rotation direction to be reversed.
This is a non-waiting method and allows the next method to run without delay.
Parameters |
Description |
---|---|
value |
|
Returns: None.
# Set the direction to be reversed.
rotation.set_reversed(True)
angle()#
The angle(units)
method returns the angle measured by the Rotation Sensor.
Parameters |
Description |
---|---|
units |
Optional. A valid RotationUnits type. The default is |
Returns: The angle measured by the Rotation Sensor in the specified units.
# Print the current angle of the Rotation Sensor to the
# Brain's screen.
brain.screen.print(rotation.angle())
reset_position()#
The reset_position()
method resets the position of the Rotation Sensor to 0.
Returns: None.
set_position()#
The set_position(value, units)
method sets the position of the Rotation Sensor. The position returned by the position()
method is set to this value.
Parameters |
Description |
---|---|
value |
The position value to set. |
units |
Optional. A valid RotationUnits type. The default is |
Returns: None.
position()#
The position(units)
method returns the current position of the Rotation Sensor.
Parameters |
Description |
---|---|
units |
Optional. A valid RotationUnits type. The default is |
Returns: The current position of the Rotation Sensor in the specified units.
velocity()#
The velocity(units)
method returns the velocity of the Rotation Sensor.
Parameters |
Description |
---|---|
units |
Optional. A valid VelocityUnits type. The default is |
Returns: The velocity of the Rotation Sensor in the specified units.
changed()#
The changed(callback, arg)
method registers a callback function for when the value measured by the Rotation Sensor changes.
Parameters |
Description |
---|---|
callback |
The callback function to be called when the value measured by the Rotation Sensor changes. |
arg |
Optional. A tuple of arguments to pass to the callback function. |
Returns: None
# Define a function rotation_changed().
def rotation_changed():
# The Brain will print that the rotation value changed
# on the Brain's screen.
brain.screen.print("rotation value changed")
# Run rotation_changed when the value of the
# Rotation Sensor changes.
rotation.changed(rotation_changed)
installed()#
The installed()
method checks if the Rotation Sensor is connected.
Returns: True
if the Rotation Sensor is installed. False
if it is not.
timestamp()#
The timestamp()
method returns the timestamp of the last received status packet from the Rotation Sensor.
Returns: The timestamp of the last received status packet in milliseconds.