Friday, April 8, 2016

MindControl 1.0 for Python

http://www.legoism.info/p/mindcontrol.html

Recent weeks I have been working on a Python module (library) for controlling Mindstorms EV3 and NXT, and ― here it is! I have set up a separate page for it as it may receive updates, documentation changes, etc., so head there to find more about it and download it. Of course, you can freely use it for your own projects.

Its name is MindControl and, briefly, it is a module that conveniently links Python, a programming language, to EV3 and NXT Mindstorms devices, letting you control motors, sensors, etc. directly from the scripts on your computer (or anything else you run Python on). It can control multiple EV3 and NXT devices simultaneously, communicates with them via Bluetooth, is synchronized, and is fully native on both sides, i.e. you can run it using standard LEGO firmware and without any exotic Python extensions.

For example, rotating four motors with various angles on EV3 is as simple as this:

import mindctrl
device=mindctrl.EV3('COM8')
device.rotate(90,-180,270,-360,speed=65)

And add this to keep the motor 1 spinning step-by-step until the touch sensor on port 1 is pressed:

while not device.sensor(1): device.rotate(30)

You can use other functions and parameters (documentation is, remember, at the dedicated page along with the downloads and the rest) for controlling relative motor movements, sensor measurements, playing tones, logging, etc.

The aim was to provide a library which has sufficiently many features to cover 99% of Mindstorms projects, yet to be simple enough for nearly everyone to use and not burden the user with low-level communications and flow control. And Python (v 3.x in this case) is, in my humble opinion, just a perfect language for that.

Happy coding!

No comments:

Post a Comment