toio.cube.api.motor module¶
- class toio.cube.api.motor.MotorControl(left: int, right: int, duration_ms: int | None)[source]¶
Bases:
CubeCommand
Motor control command
References
https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control
- class toio.cube.api.motor.MovementType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
Movement type
References
https://toio.github.io/toio-spec/en/docs/ble_motor#movement-type
- Curve = 0¶
- CurveWithoutReverse = 1¶
- Linear = 2¶
- class toio.cube.api.motor.RotationOption(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
Rotation Option
Angle of the cube at the target point
References
https://toio.github.io/toio-spec/en/docs/ble_motor#%CE%B8-angle-of-the-cube-at-the-target-point
- AbsoluteOptimal = 0¶
- AbsolutePositive = 1¶
- AbsoluteNegative = 2¶
- RelativePositive = 3¶
- RelativeNegative = 4¶
- WithoutRotation = 5¶
- SameAsAtWriting = 6¶
- class toio.cube.api.motor.TargetPosition(cube_location: CubeLocation, rotation_option: RotationOption = RotationOption.AbsoluteOptimal)[source]¶
Bases:
object
Target position parameter
- cube_location: CubeLocation¶
Target position of the cube
- rotation_option: RotationOption = 0¶
Rotation option
- __init__(cube_location: CubeLocation, rotation_option: RotationOption = RotationOption.AbsoluteOptimal) None ¶
- class toio.cube.api.motor.SpeedChangeType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
Speed change type
References
https://toio.github.io/toio-spec/en/docs/ble_motor#motor-speed-change-types
- Constant = 0¶
- Acceleration = 1¶
- Deceleration = 2¶
- AccelerationAndDeceleration = 3¶
- class toio.cube.api.motor.Speed(max: int = 0, speed_change_type: SpeedChangeType = SpeedChangeType.Constant)[source]¶
Bases:
object
Speed parameter
- max: int = 0¶
Max speed
- speed_change_type: SpeedChangeType = 0¶
Speed change type
- __init__(max: int = 0, speed_change_type: SpeedChangeType = SpeedChangeType.Constant) None ¶
- class toio.cube.api.motor.MotorControlTarget(timeout: int, movement_type: MovementType, speed: Speed, target: TargetPosition)[source]¶
Bases:
CubeCommand
Target specified motor control command
References
https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control-with-target-specified
- __init__(timeout: int, movement_type: MovementType, speed: Speed, target: TargetPosition)[source]¶
- class toio.cube.api.motor.WriteMode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
Write mode of MotorControlMultipleTargets()
References
https://toio.github.io/toio-spec/en/docs/ble_motor#additional-write-operation-settings
- Overwrite = 0¶
- Append = 1¶
- class toio.cube.api.motor.MotorControlMultipleTargets(timeout: int, movement_type: MovementType, speed: Speed, mode: WriteMode, target_list: list[toio.cube.api.motor.TargetPosition])[source]¶
Bases:
CubeCommand
Multiple targets specified motor control command
References
https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control-with-multiple-targets-specified
- __init__(timeout: int, movement_type: MovementType, speed: Speed, mode: WriteMode, target_list: list[toio.cube.api.motor.TargetPosition])[source]¶
- class toio.cube.api.motor.AccelerationRotation(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
Rotational direction when the cube is changing orientation
References
- Positive = 0¶
- Negative = 1¶
- class toio.cube.api.motor.AccelerationDirection(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
Direction of cube travel
References
https://toio.github.io/toio-spec/en/docs/ble_motor/#direction-of-cube-travel
- Forward = 0¶
- Backward = 1¶
- class toio.cube.api.motor.AccelerationPriority(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
IntEnum
Priority to the translational speed or the rotational velocity
References
https://toio.github.io/toio-spec/en/docs/ble_motor/#priority-designation
- TranslationalVelocity = 0¶
- RotationalVelocity = 1¶
- class toio.cube.api.motor.MotorControlAcceleration(translation: int, acceleration: int, rotation_velocity: int, rotation_direction: AccelerationRotation, cube_direction: AccelerationDirection, priority: AccelerationPriority, duration_ms: int)[source]¶
Bases:
CubeCommand
Acceleration specified motor control command
References
https://toio.github.io/toio-spec/en/docs/ble_motor/#motor-control-with-acceleration-specified
- __init__(translation: int, acceleration: int, rotation_velocity: int, rotation_direction: AccelerationRotation, cube_direction: AccelerationDirection, priority: AccelerationPriority, duration_ms: int)[source]¶
- class toio.cube.api.motor.MotorResponseCode(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
Enum
Response code of motor control APIs
References
https://toio.github.io/toio-spec/en/docs/ble_motor#response-content
- SUCCESS = 0¶
- ERROR_TIMEOUT = 1¶
- ERROR_ID_MISSED = 2¶
- ERROR_INVALID_PARAMETER = 3¶
- ERROR_INVALID_CUBE_STATE = 4¶
- SUCCESS_WITH_OVERWRITE = 5¶
- ERROR_NOT_SUPPORTED = 6¶
- ERROR_FAILED_TO_APPEND = 7¶
- class toio.cube.api.motor.ResponseMotorControlTarget(payload: bytearray)[source]¶
Bases:
CubeResponse
Target specified motor control response
- response_code¶
Response code
- Type:
References
https://toio.github.io/toio-spec/en/docs/ble_motor#responses-to-motor-control-with-target-specified
- class toio.cube.api.motor.ResponseMotorControlMultipleTargets(payload: bytearray)[source]¶
Bases:
CubeResponse
Multiple target specified motor control response
- response_code¶
Response code
- Type:
References
- class toio.cube.api.motor.ResponseMotorSpeed(payload: bytearray)[source]¶
Bases:
CubeResponse
Motor speed response
- left¶
motor speed (left)
- Type:
int
- right¶
motor speed (right)
- Type:
int
References
https://toio.github.io/toio-spec/en/docs/ble_motor#obtaining-motor-speed-information
- toio.cube.api.motor.MotorResponseType¶
Response types of motor characteristic
alias of
Union
[ResponseMotorControlTarget
,ResponseMotorControlMultipleTargets
,ResponseMotorSpeed
]
- class toio.cube.api.motor.Motor(interface: CubeInterface)[source]¶
Bases:
CubeCharacteristic
Motor characteristic
References
https://toio.github.io/toio-spec/en/docs/ble_motor
- static is_my_data(payload: bytearray) ResponseMotorControlTarget | ResponseMotorControlMultipleTargets | ResponseMotorSpeed | None [source]¶
If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.
- Parameters:
payload (GattReadData) – received data from the cube.
- __init__(interface: CubeInterface)[source]¶
- async motor_control(left: int, right: int, duration_ms: int | None = None) None [source]¶
Send motor control command
- Parameters:
left (int) – Motor speed (left)
right (int) – Motor speed (right)
duration_ms (Optional[int], optional) – Motor driving period [ms]. Defaults to None.
References
https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control
- async motor_control_target(timeout: int, movement_type: MovementType, speed: Speed, target: TargetPosition) None [source]¶
Send target specified motor control command
- Parameters:
timeout (int) – Timeout [s] (Note: not [ms])
movement_type (MovementType) – Movement type
speed (Speed) – Speed parameter
target (TargetPosition) – Target parameter
References
https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control-with-target-specified
- async motor_control_multiple_targets(timeout: int, movement_type: MovementType, speed: Speed, mode: WriteMode, target_list: list[toio.cube.api.motor.TargetPosition]) None [source]¶
Send multiple target specified motor control command
- Parameters:
timeout (int) – Timeout [s] (Note: not [ms])
movement_type (MovementType) – Movement type
speed (Speed) – Speed parameter
mode (WriteMode) – Write mode
target_list (list[TargetPosition]) – Target parameter
References
https://toio.github.io/toio-spec/en/docs/ble_motor#motor-control-with-multiple-targets-specified
- async motor_control_acceleration(translation: int, acceleration: int, rotation_velocity: int, rotation_direction: AccelerationRotation, cube_direction: AccelerationDirection, priority: AccelerationPriority, duration_ms: int) None [source]¶
Send acceleration specified motor control command
- Parameters:
translation (int) – Speed at which the cube moves in relation to the direction of travel.
acceleration (int) – Specify the increment (or decrement) in speed every 100 milliseconds.
rotation_velocity (int) – Rotational velocity when the cube is changing orientation.
rotation_direction (AccelerationRotation) – Rotational direction when the cube is changing orientation.
cube_direction (AccelerationDirection) – Direction the cube travels.
priority (AccelerationPriority) – Priority to the translational speed or the rotational velocity.
duration_ms (int) – Motor driving period [ms].
References
https://toio.github.io/toio-spec/en/docs/ble_motor/#motor-control-with-acceleration-specified