Программирование ev3 small basic

Quick Reference

For people who already know how to program with some other languages and do not want to go through the complete Small Basic tutorials, here is a short example that contains most language constructs and a short explanation of each. You can copy this program into Small Basic for testing. This example will not run directly on the EV3 brick, because it uses the Small Basic text window.

‘ Demo program explaining most of Small Basic

‘ (all comments start with single quotation mark)

A = 5 ‘ variables are implicitly declared at first use

a = a + 1 ‘ everything is case-insensitive

B[a] = 55 ‘ arrays are implicitly defined and grow as needed

X = «hi» ‘ variables can also hold text

Sub write ‘ defines a sub-program with this name (no parameters possible)

TextWindow.WriteLine(X) ‘call library function, access variable defined elsewhere

EndSub ‘ control flow of the main program runs around the Sub — definitions

TextWindow.WriteLine(«A=»+a) ‘ string concatenation with +

WRITE() ‘ call subprogram. name is also case-insensitive

write2() ‘ may call subprogram that is defined further down the code

TextWindow.Writeline(«B[6]=»+B[6]) ‘ access to arrays

For i=2 to 5 ‘ a loop from 2 to 5 (inclusive)

For i=6.5 to 10.5 step 2 ‘ a loop with fractional values and larger step

write() ‘ subprogram can call other subprograms

EndSub ‘ control flow of the main program runs around the Sub — definitions

I=99 ‘ case insensitive — overwrites previous i

while i>3 ‘ loop with condition

TextWindow.WriteLine(«PI=»+Math.PI) ‘ a library property (access without parentheses)

TextWindow.WriteLine(«SIN=»+Math.Sin(0.5)) ‘library function returning value

Источник

EV3 Basic programming

EV3 Basic is Microsoft Small Basic with the EV3 extension. Before you learn how to work with the robotic functions that the extension adds to Small Basic, you should spend some time familiarising yourself with Small Basic programming. Small Basic is a Microsoft product that has been around since 2008 so it’s well supported — it has its own website ( smallbasic.com ) and there are abundant learning materials out there to help you get familiar with the language. Because this is the case, this site does not teach you the basics of textual programming — it is assumed that you will learn the basics elsewhere, such as by working through this PDF guide , before you continue working through this site.

For all the sample programs I propose, I will assume that you are working with a robot similar to the one below. Notice that the wheel motors are attached to motor ports B and C:

The above model is the official Lego ‘driving base’ or ‘educator vehicle’ model that is used in the lessons that accompany the education version of the EV3. Building instructions are available HERE . The above photos include a sound sensor that is not part of the standard driving base, and the gyro is placed in an unconventional (better!) location.

Don’t worry if you have the ‘home’ version of the EV3 set because the education version and the home version of the EV3 set are very similar . The lessons on this site can nearly all be completed with either set, though you may need to make occasional modifications if you have the ‘home’ version of the EV3 set. For example, if you have the home version, you will need to substitute a different castor wheel at the back of the model and you will need to substitute the infrared sensor for the ultrasonic sensor. You will not be able to include the gyro sensor.

Читайте также:  Счетчики меркурий 230 программирование

Here are some general tips about writing programs in EV3 Basic:

Important note: all settings dialogs and applications such as ‘port view’ must be closed on the brick in order to be able to run programs from Small Basic or EV3 Explorer. If a dialog box is open in the brick it will still be possible, however, to use other functions of EV3 Explorer such as compiling programs to the brick.

Recall that EV3 Basic programs can be run in two different modes: PC mode and brick mode.

  • In PC mode you run the programs in Small Basic by clicking the Run button or pressing F5. The program then runs on the PC, exchanging some data with the brick as necessary in order to control the motors and obtain sensor readings. In PC mode you can make use of Small Basic features such as the graphics window or the possibility of playing sounds on the PC speaker.
  • In brick mode the program runs on the brick. To get the Small Basic program onto the brick you must use the companion program EV3 Explorer which will ‘compile’ your SB program into the RBF format the brick understands, and will store the RBF program on the brick, in the folder of your choice. Programs on the brick can be run either at the moment they were compiled, by clicking the ‘Compile and Run’ button in EV3 Explorer, or later, from the brick’s menus or using Explorer. In brick mode you cannot make use of Small Basic features such as the Small Basic graphics window or the possibility of playing sounds on the PC speaker.

Compared to PC mode, running programs in brick mode imposes additional rules about writing and saving your programs. Unless you are using Small Basic features such as the graphics window, you should aim to make your programs compatible with both PC mode and brick mode by observing these additional rules, which include:

  • Save program files with a maximum length of 25 characters and use only these characters in the program names: ABCDEFGHIJKLMNOPQRSTUVWXYZ
  • abcdefghijklmnopqrstuvwxyz0123456789 -_ (includes space).
  • Don’t use this method of making arrays: Colors=»0=UNKNOWN;1=BLACK;2=BLUE;3=GREEN»
  • Put subprogram definitions BEFORE the main program.
  • Assign values to variables before you use them.
  • For additional rules, see the Compiler Hints page .
  • Using buttons, LCD screen, LED and speaker
  • Using Motors
  • Remote control using the text or graphics window
  • Using Sensors
  • Threads
  • Robot Educator lessons . This is the same sequence of exercises as proposed in the standard Lego EV3 software (Education Edition) with EV3 Basic solutions.
  • The official EV3 Basic Library documentation

Источник

Библиотека EV3 Basic (Роботы Lego EV3)

В 2015 году появилось замечательное расширение для MS Small Basic — EV3 Basic для программирования роботов LEGO EV3 Mindstorms. Юные программисты и робототехники фактически получили новую, гораздо более удобную среду программирования для платформы LEGO EV3 Mindstorms, на простом языке программирования MS Small Basic. EV3 Basic так же прост и понятен, как и сам Small Basic и гораздо проще и понятнее, чем EV3-G (Среда «программирования» от Lego). В то же время EV3 Basic обладает перед EV3-G рядом неоспоримых преимуществ, присущих текстовым языкам программирования.

Читайте также:  Язык программирования значение символа

Для тех, кто переходит с системы программирования LEGO EV3-G на EV3 Basic мы рекомендуем следующую таблицу соответствия команд EV3-G и EV3 Basic.

Описание набора Lego Mindstorms EV3

Описание работы с программным комплексом Lego EV3 Basic

Классы EV3 Basic:

КЛАСС ASSERT

Класс реализует тестовые функции, которые помогают проверить на корректность программный код.

КЛАСС BUTTONS

Класс кнопок блока EV3, позволяет прочитать состояния и нажатия (включая щелчки) кнопок на блоке.

КЛАСС EV3FILE

Класс для доступа к файловой системе блока EV3, позволяет выполнить чтение и запись данных в файлы.

КЛАСС LCD

Управление ЖК-экраном блока EV3.

КЛАСС EV3

Полезные функции блока EV3.

КЛАСС MOTOR

Управление моторами, подключенными к блоку EV3.

КЛАСС SENSOR

Работа с датчиками, подключенными к блоку EV3.

КЛАСС MAILBOX

Отправка сообщений между блоками EV3 посредством Bluetooth.

КЛАСС SPEAKER

Использование динамика на блоке EV3.

КЛАСС THREAD

Класс предназначен для обеспечения многопоточности в программе.

КЛАСС VECTOR

Объект для выполнения операций над большими объемами числовых данных.

Также советуем посмотреть:

Источник

The EV3 Extension

Before trying to use the Small Basic EV3 extension you should make sure you are familiar with basic programming concepts such as ‘variables’, ‘For loops’, ‘While loops’ and ‘arrays’. If you don’t yet have such knowledge then a great way to start would be to work through the Small Basic tutorial HERE (PDF file).

Some of the text below comes from this page which gives a good introduction to Small Basic and the Small Basic EV3 extension.

Once you have installed Small Basic on your Windows computer you will need to also install the Small Basic EV3 extension suite in order to be able to program the EV3 using EV3 Basic. The term ‘EV3 Basic’ refers to Microsoft Small Basic with the EV3 extension . EV3 Basic is an easy-to-use development environment where you can build and run programs that control the EV3 Robots.

Note that although the EV3 extension has now been updated more than twenty times and is quite stable, there is always the possibility (as with any software) that there may be some bugs. The software is provided ‘as is’ and you use it at your own risk. Neither the developer of the extension nor the author of this site can accept any responsibility for any damage caused to your computer or EV3 brick.

Download the installer file EV3BasicInstaller.msi from the current release at github.com/c0pperdragon/EV3Basic/releases . When you run the installer you may get a security message from Windows — you will have to give permission for the file to be installed in order to continue (in Windows 8 or 10, click ‘more info’ then ‘install anyway’).

You should also download from GitHub the Small Basic manual and the example files.

Читайте также:  Принцип современных систем программирования

If you are updating the EV3 Basic extension then you should use the Control Panel to uninstall the old version of the extension before installing the newer version. Be sure to uninstall only the extension and not Small Basic itself!

A tip from user Mr. S. T. Prasad: If you have a problem getting the EV3 extension to work with Windows 10 then open Control Panel >> Programs >> Programs and Features >> Turn Windows Features on or off and make sure that the checkbox for .NET Framework 3.5 is turned on.

Make sure the standard Lego EV3 software is not running (see the note at the bottom of this page). Start ‘Microsoft Small Basic‘. Type ‘m’ (without the quotes) in the blank program area. If all is well you should see a reference to ‘Motor’ in the ‘Intellisense’ box that appears. This means that Small Basic has recognised the presence of the extension. If not, try reinstalling the extension.

You can use the Intellisense documentation to learn about the various parts of the EV3 extension.

You are now ready to start exploring the power of Small Basic. If you are a novice to programming, use the link “Beginning Small Basic” on the Small Basic homepage to learn about fundamental concepts and how to generally create programs.

When an EV3 is connected (by USB cable or Bluetooth or Wifi ) you can run your EV3 Basic programs instantly on the EV3 by clicking the Run button or pressing the F5 key. We call this ‘working in PC mode ‘. Note that pressing the Run button or the F5 key does NOT download the program into the EV3’s memory. Alternatively, you can use EV3 Explorer to compile the EV3 Basic program into a form that the EV3 can understand and download it into the brick’s memory so that it runs there instead of on the PC. This way of working is called ‘ brick mode’ and it is the recommended way of working with wireless connections except if your program makes use of functions that require Small Basic features such as the Small Basic graphic window.

Important note: EV3 Explorer and the Lego EV3 software (EV3-G) each demand exclusive control over the brick, therefore you must close the Lego EV3 software before attempting to use EV3 Basic (Small Basic with the EV3 extension) or EV3 Explorer . You can run Small Basic and EV3 Explorer at the same time in which case EV3 Explorer will have the connection to the brick and it will not be possible to run EV3 Basic programs directly from Small Basic. Running Small Basic and EV3 Explorer at the same time is nevertheless very useful when you have a wireless (WiFi or Bluetooth) connection to the brick and want to run your programs in brick mode rather than PC mode (brick mode is more reliable than PC mode when using wireless connections). You can simply save your program in Small Basic and (compile and) run it in EV3 Explorer with just a couple of clicks and without closing either program.

OK, now the fun starts! Click this link to start learning EV3 Basic Programming .

Источник

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