📜 ⬆️ ⬇️

Linux on LEGO Mindstorms EV3

image

Some time working with the Education version of the LEGO Mindstorms EV3. Once it was thought: “It’s bad that you cannot write programs for Python under EV3, yet it’s quite difficult and long to create more or less serious programs in the visual programming environment. Although...". Google said that you can. EV3DEV , Debian Linux-based system, simply download the system image, write to MicroSD, install it into the appropriate “programmable unit” connector and turn on the unit. We can see how the system starts up with MicroSD - the EV3DEV logo is displayed and the LEDs below the button block indicate disk activity, then Brickman is launched, with the help of which we can run scripts and make some block settings.

The ev3dev.org website provides detailed instructions for getting started with the system. The fourth step is setting up the network via USB. There should be no problems, we connect, put the necessary packages, I immediately put mc and htop.
')
image

Resources certainly not a lot. I did not manage to connect the zram. Nevertheless, python runs and works, and the scripts are much faster than the programs made in the visual environment. To control the unit (i.e., to access sensors, motors, display, buttons, LEDs, and sound) there is an API ev3dev-lang (the library is already in the system), which is fairly simple and convenient. There are examples of its use in the library, on ev3dev.org there is a detailed description of the API, as well as how to access devices directly. There are ready-made projects , one of them on Bash , and I liked the Ev3 Print3rbot the most .

My example of the simplest Line follower
#!/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) 

And lastly, in the best traditions, since they did not do it before me - I was simply obliged to do this.

Bad apple

Source: https://habr.com/ru/post/371631/


All Articles