Motor
The cube has two motors, with one connected to the left wheel and one to the right wheel (see Parts). These motors can be controlled using the following characteristics.
| Property | Value |
|---|---|
| Characteristic UUID | 10B20102-5B3B-4571-9508-CF3EFCD7BBAE |
| Properties | Write without response, Read, Notify |
| Descriptor | Motor Control |
Write operations
Motor Control
The motor can be controlled by writing the following configuration data. The motors continue to run at the specified speed until the next write operation is performed.
| Data location | Type | Content | Example |
|---|---|---|---|
| 0 | UInt8 | Control type | 0x01 (Motor control) |
| 1 | UInt8 | ID of motor controlled | 0x01 (Left) |
| 2 | UInt8 | Motor rotation direction | 0x01 (Forward) |
| 3 | UInt8 | Motor speed command values | 0x64 (100) |
| 4 | UInt8 | ID motor controlled | 0x02 (Right) |
| 5 | UInt8 | Motor rotation direction | 0x02 (Backward) |
| 6 | UInt8 | Motor speed command values | 0x14 (20) |
ID motor controlled
Specifies the ID of the motor being controlled. The ID of the left motor is 1 and the ID of the right motor is 2.
As there are two locations for which motor ID are specified, if both are specified with the same ID, an error occurs and the write operation is ignored.
Motor rotation direction
Specifies the rotation direction for the motor that was just specified.
The value for moving the cube forward is 1 and the value for moving it backward is 2.
Motor speed command values
Specify the rotation speed for the motor that was just specified.
Motor speed command values can range from 0 to 255. The actual wheel speed changes only for values from 8 to 115. Values below 8 result in 0 rpm. Values of 115 or higher result in a constant speed of 494 rpm.
From 8 to 115, the command value and actual wheel speed have a linear relationship. The graph below shows this relationship.
Motor control with specified duration
The duration of the operation can be specified with the control of the motors by writing the following configuration data. The motor stops after the specified time has elapsed.
| Data location | Type | Content | Example |
|---|---|---|---|
| 0 | UInt8 | Control type | 0x02 (Motor control with specified duration) |
| 1 | UInt8 | ID of motor controlled | 0x01 (Left) |
| 2 | UInt8 | Motor rotation direction | 0x01 (Forward) |
| 3 | UInt8 | Motor speed command values | 0x64 (100) |
| 4 | UInt8 | ID motor controlled | 0x02 (Right) |
| 5 | UInt8 | Motor rotation direction | 0x02 (Backward) |
| 6 | UInt8 | Motor speed command values | 0x14 (20) |
| 7 | UInt8 | Motor control duration | 0x0A (100 msec) |
Motor control duration
The duration in which the motor is controlled is specified with values ranging from 0 to 255. A value of 0 means that there is no time limit and the motor continues to run at the specified speed until the next write operation is performed. For values ranging between 1 and 255, the motor for 10 times the specified value in milliseconds, then stops.
Motor control with target specified
Motors can be controlled with a target state specified to make the cube move autonomously. Targets that can be set are made up of the following.
- X coordinate of the target point's Position ID
- Y coordinate of the target point's Position ID
- Θ angle of the cube at the target point
The cube stops the motors when the central X coordinate, Y coordinate, and angle reach the target, and responds with 0x00: Normal end. Or, if an error such as a timeout occurs, it responds with the corresponding error. For more information about the responses, refer to Responses to motor control with target specified.
The state of having reached the target is defined as "values of X and Y coordinates within 15 and the difference in angles within 4 degrees."
| Data location | Type | Content | Example |
|---|---|---|---|
| 0 | UInt8 | Control type | 0x03 (Motor control with target specified) |
| 1 | UInt8 | Control distinction value | 0x00 |
| 2 | UInt8 | Timeout period | 0x05 (5 seconds) |
| 3 | UInt8 | Movement type | 0x00 (Moving while rotating) |
| 4 | UInt8 | Value indicating maximum motor speed | 0x50 (80) |
| 5 | UInt8 | Motor speed change types | 0x00 (Constant speed) |
| 6 | UInt8 | Reserved | 0x00 |
| 7 | UInt16 | X coordinate value of the target point | 0x02bc (700) |
| 9 | UInt16 | Y coordinate value of the target point | 0x0182 (386) |
| 11 | UInt16 | Θ angle of the cube at the target point | 0x005a (90 degrees) |
Byte order is little-endian. For other ways data structures are expressed, see Function usage - Data structures.
Control distinction value
These values are used to distinguish between the corresponding Responses to motor control with target specified. The value set for this is also included in the corresponding response. This allows for the identification of the corresponding response when performing write operations consecutively. This can be freely set to a value ranging between 0 and 255.