Linux lego mindstorm ev3

LEGO MINDSTORMS EV3¶

By default, a sysfs device is created for each input and output port on the EV3. See the input ports and output ports driver descriptions for more information on how these work. There is a single module for input and output ports named ev3_ports . This module has some module parameters.

Input Ports¶

LEGO MINDSTORMS EV3 has four input ports labeled 1, 2, 3 and 4. These ports are used with LEGO MINDSTORMS EV3 and NXT compatible sensors and other devices. Most sensors can be automatically detected when plugged in. Unlike the EV3, however, NXT analog sensors cannot be detected, so to use these sensors, the port has to be placed in nxt-analog mode manually.

General Info¶

Module ev3_ports
Driver name ev3-input-port
Connection types NXT/Analog, NXT/I2C, Other/I2C, EV3/Analog, EV3/UART, Other/UART
Connection prefix in
Number of modes 9

Modes¶

Name Description
auto [1] Automatically detect most sensors.
nxt-analog [2] Configures the port for NXT/Analog sensors
nxt-color [3] Configures the port for the LEGO NXT Color sensor
nxt-i2c Configure for I2C communications and load the nxt-i2c-host device.
other-i2c Configure for I2C communications but do not probe for NXT sensors. Also configure pin 1 to output 9V (battery voltage).
ev3-analog Configures the port for EV3/Analog sensors
ev3-uart Configure for UART communications and load the ev3-uart-host device.
other-uart Configure for UART communications but do not load any device.
raw [4] Provide access to low level drivers.

Notes¶

[1] In auto mode, the port will attempt to automatically detect the type of sensor that was connected and load the appropriate driver. See the list of Supported Sensors to determine if a sensor can be automatically detected.
[2] This loads the generic NXT/Analog sensor nxt-analog driver. Use set_device to load the appropriate device/driver.
Читайте также:  Linux knights and merchants
[3] NXT Color sensor driver has not been implemented yet, so right now, this mode does nothing.
[4] Exports gpios and analog/digital converter values to sysfs so that they can be controlled directly.

Output Ports¶

The EV3 has four output ports labeled A, B, C and D. These ports are used with LEGO MINDSTORMS EV3, NXT and RCX compatible motors and other devices. EV3 motors can be automatically detected when plugged in. Other motors with position feedback (such as the NXT motor) are usually detected as an EV3 Large Motor. RCX motors and LEDs cannot be automatically detected and the mode of the output port must be manually set to use these types of devices.

General Info¶

Module ev3_ports
Driver name ev3-output-port
Connection types tacho-motor, dc-motor, led
Connection prefix out
Number of modes 5

Modes¶

Name Description
auto [5] Automatically detect motors when they are connected.
tacho-motor [6] Configure the port for NXT/EV3 motors.
dc-motor [7] Load the port for RCX/Power Functions motors.
led [8] Load the port for RCX/Power Functions LEDs.
raw [9] Provide access to low level drivers.

Notes¶

[5] Only the EV3/NXT large motors and the EV3 medium motor can be automatically detected. All other devices must be manually configured.
[6] Configures the port to use the tacho-motor Subsystem . The default driver is the EV3 Large Motor ( lego-ev3-l-motor ). You can change the driver using the set_device attribute.
[7] This can be use with MINDSTORMS RCX motors, Power Functions motors and any other “plain” DC motor. By “plain”, we mean the motor is just a motor without any feedback.
[8] This can be used with MINDSTORMS RCX LEDs, Power Functions LEDs or any other LED connected to pins 1 and 2 of the output port.
[9] Exports gpios, pwm and analog/digital converter values to sysfs so that they can be controlled directly.

Buttons¶

The EV3 buttons use the standard Linux input subsystem. You can find the event device node at /dev/input/by-path/platform-gpio-keys.0-event . The buttons are mapped to Linux key codes as shown in the table below.

Читайте также:  Дистрибутив для новичка линукс

Button map ¶

Button Linux key code (value)
Back KEY_BACKSPACE (14)
Center KEY_ENTER (28)
Up KEY_UP (103)
Left KEY_LEFT (105)
Right KEY_RIGHT (106)
Down KEY_DOWN (108)

LEDs¶

The EV3 brick status LEDs used the standard Linux LEDs subsystem. You can find the LED devices at /sys/class/leds/ . There are two bi-color LEDs. The color for each LED is controlled separately, so there is a green and red device node for each LED. Turning both of these on at the same time will make the LED appear orange(ish).

The LEDs are controlled by a PWM signal, so you can vary the brightness between 0 and max_brightness .

Display¶

The EV3 display uses the standard Linux frame buffer subsystem (fbdev). The display memory can be directly accessed by reading and writing or memory mapping /dev/fb0 . Display attributes such as width, height and row stride can be read using FBIOGET_VSCREENINFO and FBIOGET_FSCREENINFO ioctls.

You must make sure that you control the active virtual console before drawing on the display, otherwise other programs could be writing to the display at the same time, causing unexpected results.

Sound¶

The snd-legoev3 module provedes an ALSA driver for PCM playback and a Linux input device with sound capabilities ( EV_SND ) for producing tones.

The ALSA driver can be used with standard tools such as alsamixer and aplay . Tones can be produced by using the beep command, ioctls such as KDMKTONE (must run on local console or as root for ioctls) or by writing SND_* events to the event device (must be member of input group for this).

Battery¶

  • This driver is used to get information about the EV3 battery.
  • It uses the power_supply subsystem.
  • It registers a sysfs device node at /sys/class/power_supply/lego-ev3-battery/ .
Читайте также:  Epic privacy browser linux

© Copyright 2014-2017, ev3dev.org Revision 1b387f3b .

Источник

Linux на LEGO Mindstorms EV3

image

Некоторое время работаю с Education версией LEGO Mindstorms EV3. Однажды подумалось: «Плохо, что нельзя писать под EV3 программы на Python, всё таки создавать в визуальной среде программирования более-менее серьёзные программы достаточно сложно и долго. Хотя. ». Гугл сказал, что таки можно. EV3DEV, Debian Linux-based система, просто скачиваем образ системы, записываем на MicroSD, устанавливаем её в соответствующий разъём «программируемого блока» и включаем блок. Видим как с MicroSD запускается система — отображается лого EV3DEV и светодиоды под блоком кнопок сигнализируют о дисковой активности, далее запускается Brickman — менеджер при помощи которого мы можем запускать скрипты и производить некоторые настройки блока.

На сайте ev3dev.org дана подробная инструкция по началу работы с системой. Четвёртым шагом идёт настройка сети через USB. Проблем возникнуть не должно, подключаемся, ставим нужные пакеты, я сразу поставил mc и htop.

image

Ресурсов конечно не густо. Подключить zram у меня пока не получилось. Тем не менее python запускается и работает, причём скрипты работают заметно шустрее, чем программы сделанные в визуальной среде. Для управления блоком (т.е. для доступа к сенсорам, моторам, дисплею, кнопкам, светодиодам и звуку) есть API ev3dev-lang (библиотека уже есть в системе), достаточно простое и удобное. В библиотеке есть примеры её использования, на сайте ev3dev.org есть подробное описание API, а так же как обращаться к устройствам напрямую. Есть и готовые проекты, один из них на Bash, а мне больше всего понравился Ev3 Print3rbot.

#!/usr/bin/python import ev3dev.ev3 as ev3 import time ANGLE = 5 l_motor = ev3.LargeMotor(ev3.OUTPUT_B) r_motor = ev3.LargeMotor(ev3.OUTPUT_C) c_sensor = ev3.ColorSensor() l_motor.reset() r_motor.reset() l_motor.duty_cycle_sp = 100 r_motor.duty_cycle_sp = 100 l_motor.stop_command = "brake" r_motor.stop_command = "brake" l_motor.position_sp = ANGLE r_motor.position_sp = ANGLE c_sensor.command = "COL-REFLECT" # by default while True: motor = l_motor if c_sensor.value() > 50 else r_motor motor.run_to_rel_pos() while "running" in motor.state: time.sleep(0.01) 

Ну и на последок, в лучших традициях, раз это не сделали до меня — я был просто обязан это сделать.

Источник

Оцените статью
Adblock
detector