how to use tetrix
#contents
Overview
TETRIX is an expansion product for LEGO Mindstorms sold by Pitsco Education.
It includes aluminum frames, high-torque motors, and other components, making it possible to build full-scale robots.
Specifications
- DC Motor
| Voltage | 12V |
|---|---|
| Stall Torque | 2.1 N·m |
| Rotation Speed | 152 rpm |
- RC Servo
| Name | HS-485HB (HITEC) |
|---|---|
| Voltage | 6V |
| Stall Torque | 0.59 N·m |
| Rotation Speed | 56 rpm |
Motor Drivers
The TETRIX Base Set includes a DC motor driver (DC Motor Controller for TETRIX) and an RC servo driver (Servo Controller for TETRIX).
By connecting these motor drivers to the EV3, it becomes possible to control DC motors and RC servos.
Connection Method
Connect the devices as shown below.
After making the connection and turning on the motor driver power, power on the EV3.
Operation
Communication between the EV3 and the motor drivers is performed via I2C.
If the connection is successful, one of the device files i2c-3, i2c-4, i2c-5, or i2c-6 should appear under /dev.
The number corresponds to the port number plus 2. For example, if connected to Port 1, the device file will be i2c-3.
The following sections describe how to control the motor drivers from C++ and Python on ev3dev.
First, include the files required for I2C communication.
- C++
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
- Python
import smbus
Start I2C communication.
- C++
int fd; = open("/dev/i2c-3", O_RDWR);
- Python
sm = smbus.SMBus(3)
The motor driver’s default address is 0x01. When connected in a daisy chain, addresses 0x02 through 0x08 are assigned.
In the example connection above, the DC motor driver should be set to 0x01, and the RC servo driver should be set to 0x02.
First, let’s control the DC motor driver.
DC Motor Driver
Set the control mode.
The control mode can be configured by writing the following values to register 0x44 for Motor 1 or 0x47 for Motor 2.
Note: Encoders are not included in the TETRIX Base Set. If you want to use speed control or position control modes, you must purchase encoders separately.
| Input Value | Control Mode |
|---|---|
| 0b00 | PWM |
| 0b01 | Speed Control |
| 0b10 | Position Control |
| 0b11 | Encoder Reset |
Set PWM mode.
- C++
ioctl(fd, I2C_SLAVE, 0x01)
unsigned char buf[2] = {0x44, 0x00};
write(fd, buf, 2);
- Python
sm.write_i2c_block_data(0x01, 0x44, [0x00])
Finally, set the PWM width.
This can be configured by writing to register 0x45 for Motor 1 or 0x46 for Motor 2.
PWM values:
1to127: Forward rotation-127to-1: Reverse rotation0: Float stop mode-
128: Brake stop mode - C++
unsigned char buf[2] = {0x45, 0x30};
write(fd, buf, 2);
- Python
sm.write_i2c_block_data(0x01, 0x45, [0x30])
RC Servo Driver
The RC servo driver can control up to six RC servos.
Control is performed by writing the target angle to registers 0x42 through 0x47.
Pulse widths can be set between 0.75 ms and 2.25 ms.
- C++
ioctl(fd, I2C_SLAVE, 0x02)
unsigned char buf[2] = {0x42, 0x60};
write(fd, buf, 2);
- Python
sm.write_i2c_block_data(0x02, 0x42, [0x60])
Example Application
The following is an example of a vehicle built using DC motors.
Two L motors are attached to the handle section, allowing the vehicle to be controlled by rotating the motors.
The RTCs used are described below.
TetrixVehicle
A component for controlling the vehicle shown above.
- https://github.com/Nobu19800/TetrixVehicle
| TetrixVehicle | ||
|---|---|---|
| InPort | ||
| Name | Data Type | Description |
| target_velocity | RTC::TimedVelocity2D | Target velocity |
| update_position | RTC::TimedPose2D | Reset position |
| OutPort | ||
| Name | Data Type | Description |
| position | RTC::TimedPose2D | Current position |
| Configuration Parameters | ||
| Name | Default Value | Description |
| wheelRadius | 0.04 | Wheel radius |
| wheelDistance | 0.34 | Distance between wheels |
| portNum | 1 | Port number |
| rot_dir_left_motor | 1 | Left wheel rotation direction |
| rot_dir_righteft_motor | -1 | Right wheel rotation direction |
| GearRatio | 3.0 | Gear ratio |
VehicleController
A component that outputs the target vehicle velocity based on the angles of the L motors.
| VehicleController | ||
|---|---|---|
| OutPort | ||
| Name | Data Type | Description |
| out | RTC::TimedVelocity2D | Target velocity |
| Configuration Parameters | ||
| Name | Default Value | Description |
| rotation_by_angle | -0.6 | Amount of target angular velocity change based on the base motor angle |
| velocity_by_angle | -0.1 | Amount of target velocity change based on the tip motor angle |


