using ev3 devices

✏️ Edit this page on GitHub

#contents

LEGO Mindstorms Sensors and Motors

The LEGO Mindstorms EV3 comes standard with the following motors and sensors:

  • Gyro Sensor ×1
  • Color Sensor ×1
  • Touch Sensor ×2
  • Ultrasonic Distance Sensor ×1
  • Motor (L) ×2
  • Motor (M) ×1

The sensors provide various types of data. The touch sensor can provide ON/OFF values, the ultrasonic and gyro sensors can output continuous values, and the color sensor can recognize several colors.

There are two types of motors (L and M). Both support PWM (torque) control, speed control, and position control. The control gains and related parameters can also be adjusted.

The specifications of the EV3 sensors and motors are shown below.

</tr>
Gyro Sensor Angle Mode: Accuracy +/- 3°
Angular Velocity Mode: Up to 440 deg/sec
Sampling Rate: 1,000 Hz
Color Sensor Measurements: Reflected red light, ambient light intensity, color
Number of detectable colors: 8 (None, Black, Blue, Green, Yellow, Red, White, Brown)
Sampling Rate: 1,000 Hz
Detection Distance: Approximately 1 mm to 18 mm (measured by Afrel)
Touch Sensor On (1), Off (0)
Switch Travel Distance: Approximately 4 mm
Ultrasonic Sensor Distance Measurement Range: 3 cm to 250 cm
Measurement Accuracy: +/- 1 cm
Front Indicator Light: On = ultrasonic transmission, Flashing = ultrasonic observation
EV3 Large Motor (L) Feedback Resolution: 1°
Rotation Speed: 160–170 RPM
Rated Torque: 0.21 N·m (30 oz·in)
Stall Torque: 0.42 N·m (60 oz·in)
Weight: 76 g
EV3 Medium Motor (M) Feedback Resolution: 1°
Rotation Speed: 240–250 RPM
Rated Torque: 0.08 N·m (11 oz·in)
Stall Torque: 0.12 N·m (17 oz·in)
Weight: 36 g

Accessing Devices via sysfs

To access these devices from ev3dev, a mechanism called sysfs is used.

sysfs is a virtual file system located under /sys. By reading from and writing to files within this file system, it is possible to control motors and access sensor data.

Detailed information on accessing devices through sysfs can be found in the following ev3dev documentation.

Specifically, devices can be accessed as shown below.

Motor Control Example

To make a motor rotate continuously, connect a motor (either L or M) to Port A and enter the following commands from the command line.

 # echo 50 > /sys/class/tacho-motor/motor0/duty_cycle_sp
 # echo run-forever > /sys/class/tacho-motor/motor0/command

To display the current speed, enter the following command. Press Ctrl+C to stop displaying it.

 # while true; do echo -en "\033[0G$(cat /sys/class/tacho-motor/motor0/speed)   "; done

To stop the motor, enter the following command.

 # echo stop > /sys/class/tacho-motor/motor0/command

Sensor Example

Sensors can be accessed in the same way.

Connect the color sensor to Port 1. Place a red object approximately 1 cm in front of the sensor.

Enter the following commands to display 5.

 # echo "COL-COLOR" > /sys/class/lego-sensor/sensor1/mode
 # cat /sys/class/lego-sensor/sensor1/value1
 5

The color sensor supports several operating modes. In the example above, color detection mode is used.

In this mode, the following eight colors can be recognized (where 0 indicates that no color is detected).

Color None Black Blue Green Yellow Red White Brown
Number 0 1 2 3 4 5 6 7

Although devices can be accessed from the command line as shown above, performing these operations directly from a program requires a considerable amount of cumbersome processing.

To simplify device access from programs, dedicated access libraries are available and should be used.