MicroBasic Reference
MicroBasic Reference
2017 Mῃ�croBasῃ�c Reference
Microbasic Reference
Introduction
The Roboteq Mࠀcro Basࠀc ῃ�s hῃ�gh level language that ῃ�s used to generate programs that runs on Roboteq motor controllers. It uses
syntax nearly lῃ�ke Basῃ�c syntax wῃ�th some adjustments to speed program executῃ�on ῃ�n the controller and make ῃ�t easῃ�er to use.
Comments
A comment ῃ�s a pῃ�ece of code that ῃ�s excluded from the compῃ�latῃ�on process. A comment begῃ�ns wῃ�th a sῃ�nglequote character.
Comments can begῃ�n anywhere on a source lῃ�ne, and the end of the physῃ�cal lῃ�ne ends the comment. The compῃ�ler ῃ�gnores the
characters between the begῃ�nnῃ�ng of the comment and the lῃ�ne termῃ�nator. Consequently, comments cannot extend across multῃ�ple
lῃ�nes.
'Comment goes here till the end of the line.
Boolean
True and False are lῃ�terals of the Boolean type that map to the true and false state, respectῃ�vely.
Numbers
Mῃ�cro Basῃ�c supports only ῃ�nteger values ranged from 2,147,483,648 (0x80000000) to 2,147,483,647 (0x7FFFFFFF).
Numbers can be preceded wῃ�th a sῃ�gn (+ or ), and can be wrῃ�tten ῃ�n one of the followῃ�ng formats:
Decࠀmal Representatࠀon
Number ῃ�s represented ῃ�n a set of decῃ�mal dῃ�gῃ�ts (09).
120 5622 504635
Are all valῃ�d decῃ�mal numbers.
Hexadecࠀmal Representatࠀon
Number ῃ�s represented ῃ�n a set of hexadecῃ�mal dῃ�gῃ�ts (09, AF) preceded by 0x.
0xA1 0x4C2 0xFFFF
Are all valῃ�d hexadecῃ�mal numbers representῃ�ng decῃ�mal values 161, 1218 and 65535 respectῃ�vely.
Bࠀnary Representatࠀon
Number ῃ�s represented ῃ�n a set of bῃ�nary dῃ�gῃ�ts (01) preceded by 0b.
0b101 0b1110011 0b111001010
Are all valῃ�d bῃ�nary numbers representῃ�ng decῃ�mal values 5, 115 and 458 respectῃ�vely.
Strings
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 1/19
15.08.2017 Mῃ�croBasῃ�c Reference
Strῃ�ngs are any strῃ�ng of prῃ�ntable characters enclosed ῃ�n a paῃ�r of quotatῃ�on marks. Non prῃ�ntῃ�ng characters may be represented by
sῃ�mple or hexadecῃ�mal escape sequence. Mῃ�cro Basῃ�c only handles strῃ�ngs usῃ�ng the Prῃ�nt command. Strῃ�ngs cannot be stored ῃ�n
varῃ�able and no strῃ�ng handlῃ�ng ῃ�nstructῃ�ons exῃ�st.
Sࠀmple Escape Sequence
The followῃ�ng escape sequences can be used to prῃ�nt nonvῃ�sῃ�ble or characters:
Sequence Descrࠀptࠀon
\' Sῃ�ngle quote
\" Double quote
\\ Backslash
\0 Null
\a Alert
\b Backspace
\f Form feed
\n New lῃ�ne
\r Carrῃ�age return
\t Horῃ�zontal tab
\v Vertῃ�cal tab
Hexadecࠀmal Escape Sequence
Hexadecῃ�mal escape sequence ῃ�s represented ῃ�n a set of hexadecῃ�mal dῃ�gῃ�ts (09, AF) preceded by \x ῃ�n the strῃ�ng (such as \x10
for character wῃ�th ASCII 16).
Sῃ�nce a hexadecῃ�mal escape sequence can have a varῃ�able number of hex dῃ�gῃ�ts, the strῃ�ng lῃ�teral "\x123" contaῃ�ns a sῃ�ngle
character wῃ�th hex value 123. To create a strῃ�ng contaῃ�nῃ�ng the character wῃ�th hex value 12 followed by the character 3, one could
wrῃ�te "\x00123".
So, to represent a strῃ�ng wῃ�th the statement "Hello World!" followed by a new lῃ�ne, you may use the followῃ�ng syntax:
"Hello World!\n"
A label ῃ�s an ῃ�dentῃ�fῃ�er that ῃ�dentῃ�fῃ�es a partῃ�cular posῃ�tῃ�on wῃ�thῃ�n the statement block that can be used as the target of a branch
statement such as GoTo, GoSub or Return.
Label declaratῃ�on statements must appear at the begῃ�nnῃ�ng of a lῃ�ne. Label declaratῃ�on statements must always be followed by a
colon (:) as the followῃ�ng:
Print_Label:
Print("Hello World!")
Label name should start wῃ�th alphabetῃ�cal character and followed by zero or more alphanumerῃ�c characters or underscore. Label
names cannot start wῃ�th underscore. Labels names cannot match any of Mῃ�cro Basῃ�c reserved words.
Label names are case ῃ�nsensῃ�tῃ�ve that ῃ�s PrintLabel ῃ�s ῃ�dentῃ�cal to printlabel.
The scope of a label extends whole the program. Labels cannot be declared more than once ῃ�n the program.
Variables
Mῃ�cro Basῃ�c contaῃ�ns only two types of varῃ�able (Integer and Boolean) ῃ�n addῃ�tῃ�on to arrays of these types. Boolean and arrays must be
declared before use, but Integer varῃ�ables may not be declared unless you use the Option Explicit compῃ�ler dῃ�rectῃ�ve.
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 2/19
15.08.2017 Mῃ�croBasῃ�c Reference
Option Explicit
Varῃ�ables can be declared usῃ�ng DIM keyword.
Varῃ�able name should start wῃ�th alphabetῃ�cal character and followed by zero or more alphanumerῃ�c characters or underscore.
Varῃ�able names cannot start wῃ�th underscore. Varῃ�able names cannot match any of Mῃ�cro Basῃ�c reserved words.
Varῃ�able names are case ῃ�nsensῃ�tῃ�ve, that ῃ�s VAR ῃ�s ῃ�dentῃ�cal to var.
The scope of a varῃ�able extends whole the program. Varῃ�ables cannot be declared more than once ῃ�n the program.
Arrays
Arrays ῃ�s specῃ�al varῃ�ables that holds a set of values of the varῃ�able type. Arrays are declared usῃ�ng DIM command.
To access specῃ�fῃ�c element ῃ�n the array you can use the ῃ�ndexer [] (square brackets). Arrays ῃ�ndῃ�ces are zero based, so ῃ�ndex of 5
refer to the 6th element of the array.
arr[0] = 10 'Set the value of the first element in the array to 10.
a = arr[5] 'Store the 6th element of the array into variable a.
Terminology
In the followῃ�ng sectῃ�ons we wῃ�ll ῃ�ntroduce Mῃ�cro Basῃ�c commands and how ῃ�t ῃ�s used, and here ῃ�s the lῃ�st of termῃ�nology used ῃ�n the
followῃ�ng sectῃ�ons:
Mῃ�cro Basῃ�c commands and functῃ�ons wῃ�ll be marked ῃ�n blue and cyan respectῃ�vely.
Anythῃ�ng enclosed ῃ�n < > ῃ�s mandatory and must be supplῃ�ed.
Anythῃ�ng enclosed ῃ�n [ ] ῃ�s optῃ�onal, except for arrays where the square brackets ῃ�s used as ῃ�ndexers.
Anythῃ�ng enclosed ῃ�n { } and separated by | characters are multῃ� choῃ�ce optῃ�ons.
Any ῃ�tems followed by an ellῃ�psῃ�s, ... , may be repeated any number of tῃ�mes.
Any punctuatῃ�on and symbols, except those above, are part of the structure and must be ῃ�ncluded.
var ῃ�s any valῃ�d varῃ�able name ῃ�ncludῃ�ng arrays.
arr ῃ�s any valῃ�d array name.
expressῃ�on ῃ�s any expressῃ�on returnῃ�ng a result.
condῃ�tῃ�on ῃ�s any expressῃ�on returnῃ�ng a boolean result.
stmt ῃ�s sῃ�ngle Mῃ�cro Basῃ�c statement.
block ῃ�s zero or more Mῃ�cro Basῃ�c statements.
label ῃ�s any valῃ�d label name.
n ῃ�s a posῃ�tῃ�ve ῃ�nteger value.
str ῃ�s a valῃ�d strῃ�ng lῃ�teral.
Keywords
A keyword ῃ�s a word that has specῃ�al meanῃ�ng ῃ�n a language construct. All keywords are reserved by the language and may not be
used as varῃ�ables or label names. Below ῃ�s a lῃ�st of all Mῃ�cro Basῃ�c keywords:
Whῃ�le XOr
Operators
Mῃ�cro Basῃ�c provῃ�des a large set of operators, whῃ�ch are symbols or keywords that specῃ�fy whῃ�ch operatῃ�ons to perform ῃ�n an
expressῃ�on. Mῃ�cro Basῃ�c predefῃ�nes the usual arῃ�thmetῃ�c and logῃ�cal operators, as well as a varῃ�ety of others as shown ῃ�n the followῃ�ng
table.
Category Operators
Arῃ�thmetῃ�c + ‐ * / Mod
Logῃ�cal (boolean and bῃ�twῃ�se) And Or XOr Not True False
Increment, decrement ++ ‐‐
Shῃ�ft << >>
Relatῃ�onal = <> < > <= >=
Assῃ�gnment = += ‐= *= /= <<= >>=
Indexῃ�ng []
Abs Returns the absolute value of a gῃ�ven number.
Atan Returns the angle whose arc tangent ῃ�s the specῃ�fῃ�ed number.
Cos Returns the cosῃ�ne of the specῃ�fῃ�ed angle.
Sῃ�n Returns the sῃ�ne of the specῃ�fῃ�ed angle.
Sqrt Returns the square root of a specῃ�fῃ�ed number.
SetConfῃ�g Set a confῃ�guratῃ�on parameter
SetCommand Send a Real Tῃ�me command
GetConfῃ�g Read a confῃ�guratῃ�on parameter
GetValue Read an operatῃ�ng value
Timers Commands
The followῃ�ng ῃ�s a set of functῃ�ons for ῃ�nteractῃ�ng wῃ�th the tῃ�mers:
SetTῃ�merCount Set number of mῃ�llῃ�seconds for tῃ�mer to count.
SetTῃ�merState Set state of a specῃ�fῃ�c tῃ�mer.
GetTῃ�merCount Read tῃ�mer count.
GetTῃ�merState Read state of a specῃ�fῃ�c tῃ�mer.
Mῃ�cro Basῃ�c by default treats undeclared ῃ�dentῃ�fῃ�ers as ῃ�nteger varῃ�ables. If you want the compῃ�lers checks that every varῃ�able used ῃ�n
the program ῃ�s declared and generate compῃ�latῃ�on error ῃ�f a varῃ�able ῃ�s not prevῃ�ously declared, you may use Optῃ�on explῃ�cῃ�t compῃ�ler
optῃ�on by pacῃ�ng the followῃ�ng at the begῃ�nnῃ�ng of the program:
Option Explicit
#define <var> <expression>
The followῃ�ng example ῃ�llustrates how use preprocessor dῃ�rectῃ�ve:
#define CommandID _GO + 5
Print(CommandID)
Dim var As { Integer | Boolean }
The followῃ�ng example ῃ�llustrates how to declare Integer varῃ�able:
Dim intVar As Integer
Arrays declaratῃ�on uses a dῃ�fferent syntax, where you should specῃ�fy the array length between square brackets []. Array length should
be ῃ�nteger value greater than 1.
Dim arr[n] As { Integer | Boolean }
The followῃ�ng example ῃ�llustrates how to declare array of 10 ῃ�ntegers:
Dim arr[10] As Integer
To access array elements (get/set), you may need to take a look to Arrays sectῃ�on.
Varῃ�able and arrays names should follow specῃ�fῃ�catῃ�on stated ῃ�n the Varῃ�ables sectῃ�on.
If...Then Statement
Lῃ�ne If
If <condition> Then <stmt> [Else <stmt>]
Block If
If <condition> [Then]
<block>
[ElseIf <condition> [Then]
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 5/19
15.08.2017 Mῃ�croBasῃ�c Reference
<block>]
[ElseIf <condition> [Then]
<block>]
...
[Else
<block>]
End If
An If...Then statement ῃ�s the basῃ�c condῃ�tῃ�onal statement. If the expressῃ�on ῃ�n the If statement ῃ�s true, the statements enclosed by the
If block are executed. If the expressῃ�on ῃ�s false, each of the ElseIf expressῃ�ons ῃ�s evaluated. If one of the ElseIf expressῃ�ons
evaluates to true, the correspondῃ�ng block ῃ�s executed. If no expressῃ�on evaluates to true and there ῃ�s an Else block, the Else block ῃ�s
executed. Once a block fῃ�nῃ�shes executῃ�ng, executῃ�on passes to the end of the If...Then statement.
The lῃ�ne versῃ�on of the If statement has a sῃ�ngle statement to be executed ῃ�f the If expressῃ�on ῃ�s true and an optῃ�onal statement to be
executed ῃ�f the expressῃ�on ῃ�s false. For example:
Dim a As Integer
Dim b As Integer
a = 10
b = 20
' Block If statement.
If a < b Then
a = b
Else
b = a
End If
' Line If statement
If a < b Then a = b Else b = a
Below ῃ�s an example where ElseIf takes place:
If score >= 90 Then
grade = 1
ElseIf score >= 80 Then
grade = 2
ElseIf score >= 70 Then
grade = 3
Else
grade = 4
End If
For...Next Statement
Mῃ�cro Basῃ�c contaῃ�ns two types of For...Next loops:
Tradࠀtࠀonal For...Next:
Tradῃ�tῃ�onal For...Next exῃ�sts for backward compatῃ�bῃ�lῃ�ty wῃ�th Basῃ�c, but ῃ�t ῃ�s not recommended due to ῃ�ts ῃ�neffῃ�cῃ�ent executῃ�on.
Tradῃ�tῃ�onal For...Next ῃ�s the same syntax as Basῃ�c For...Next statement.
CStyle For...Next:
Thῃ�s ῃ�s a new style of For...Next statement optῃ�mῃ�zed to work wῃ�th Roboteq controllers and ῃ�t ῃ�s recommended to be used. It ῃ�s the
same semantῃ�cs as C++ for loop, but wῃ�th a dῃ�fferent syntax.
For <var> = <expression> AndWhile <condition> [Evaluate <stmt>]
<block>
Next
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 6/19
15.08.2017 Mῃ�croBasῃ�c Reference
The cstyle for loop ῃ�s executed by ῃ�nῃ�tῃ�alῃ�ze the loop varῃ�able, then the loop contῃ�nues whῃ�le the condῃ�tῃ�on ῃ�s true and after
executῃ�on of sῃ�ngle loop the evaluate statement ῃ�s executed then contῃ�nues to next loop.
Dim arr[10] As Integer
For i = 0 AndWhile i < 10
arr[i] = 1
Next
The prevῃ�ous example ῃ�llustrates how to ῃ�nῃ�tῃ�alῃ�ze array elements to 1.
The followῃ�ng example ῃ�llustrates how to use Evaluate to prῃ�nt even values from 010 ῃ�nclusῃ�ve:
For i = 0 AndWhile i <= 10 Evaluate i += 2
Print(i, "\n")
Next
While/Do Statements
Whࠀle ... End Whࠀle Statement
While <condition>
<block>
End While
Example:
a = 10
While a > 0
Print("a = ", a, "\n")
a
End While
Print("Loop ended with a = ", a, "\n")
Do Whࠀle ... Loop Statement
Do While <condition>
<block>
Loop
The Do While ... Loop statement ῃ�s the same as functῃ�onalῃ�ty of the While ... End While statement but uses a dῃ�fferent syntax.
a = 10
Do While a > 0
Print("a = ", a, "\n")
a
Loop
Print("Loop ended with a = ", a, "\n")
Do Untࠀl ... Loop Statement
Do Until <condition>
<block>
Loop
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 7/19
15.08.2017 Mῃ�croBasῃ�c Reference
Unlࠀke Do While ... Loop statement, Do Until ... Loop statement exῃ�st the loop when the expressῃ�on evaluates to true..
a = 10
Do Until a = 0
Print("a = ", a, "\n")
a
Loop
Print("Loop ended with a = ", a, "\n")
Do ... Loop Whࠀle Statement
Do
<block>
Loop While <condition>
Do ... Loop While statement grantees that the loop block wῃ�ll be executed at least once as the condῃ�tῃ�on ῃ�s evaluated and checked
after executῃ�ng the block.
a = 10
Do
Print("a = ", a, "\n")
a
Loop While a > 0
Print("Loop ended with a = ", a, "\n")
Do ... Loop Untࠀl Statement
Do
<block>
Loop Until <condition>
Unlࠀke Do ... Loop While statement, Do ... Loop Until statement exῃ�st the loop when the expressῃ�on evaluates to true..
a = 10
Do
Print("a = ", a, "\n")
a
Loop Until a = 0
Print("Loop ended with a = ", a, "\n")
Terminate Statement
The Terminate statement ends the executῃ�on of the program.
Terminate
Exit Statement
The followῃ�ng ῃ�s the syntax of Exit statement:
Exit { For | While | Do }
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 8/19
15.08.2017 Mῃ�croBasῃ�c Reference
An Exit statement transfers executῃ�on to the next statement to ῃ�mmedῃ�ately contaῃ�nῃ�ng block statement of the specῃ�fῃ�ed kῃ�nd. If the Exit
statement ῃ�s not contaῃ�ned wῃ�thῃ�n the kῃ�nd of block specῃ�fῃ�ed ῃ�n the statement, a compῃ�letῃ�me error occurs.
The followῃ�ng ῃ�s an example of how to use Exit statement ῃ�n While loop:
While a > 0
If b = 0 Then Exit While
End While
Continue Statement
The followῃ�ng ῃ�s the syntax of Continue statement:
Continue { For | While | Do }
A Continue statement transfers executῃ�on to the begῃ�nnῃ�ng of ῃ�mmedῃ�ately contaῃ�nῃ�ng block statement of the specῃ�fῃ�ed kῃ�nd. If the
Continue statement ῃ�s not contaῃ�ned wῃ�thῃ�n the kῃ�nd of block specῃ�fῃ�ed ῃ�n the statement, a compῃ�letῃ�me error occurs.
The followῃ�ng ῃ�s an example of how to use Continue statement ῃ�n While loop:
While a > 0
If b = 0 Then Continue While
End While
GoTo Statement
A GoTo statement causes executῃ�on to transfer to the specῃ�fῃ�ed label. GoTo keyword should be followed by the label name.
GoTo <label>
The followῃ�ng example ῃ�llustrates how to use GoTo statement:
GoTo Target_Label
Print("This will not be printed.\n")
Target_Label:
Print("This will be printed.\n")
GoSub/Return Statements
GoSub used to call a subroutῃ�ne at specῃ�fῃ�c label. Program executῃ�on ῃ�s transferred to the specῃ�fῃ�ed label. Unlῃ�ke the GoTo statement,
GoSub remembers the callῃ�ng poῃ�nt. Upon encounterῃ�ng a Return statement the executῃ�on wῃ�ll contῃ�nue the next statement after the
GoSub statement.
GoSub <label>
Return
Consῃ�der the followῃ�ng example:
Print("The first line.")
GoSub PrintLine
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 9/19
15.08.2017 Mῃ�croBasῃ�c Reference
Print("The second line.")
GoSub PrintLine
Terminate
PrintLine:
Print("\n")
Return
The program wῃ�ll begῃ�n wῃ�th executῃ�ng the fῃ�rst prῃ�nt statement. Upon encounterῃ�ng the GoSub statement, the executῃ�on wῃ�ll be
transferred to the gῃ�ven PrࠀntLࠀne label. The program prῃ�nts the new lῃ�ne and upon encounterῃ�ng the Return statement the executῃ�on
wῃ�ll be returnῃ�ng back to the second prῃ�nt statement and so on.
ToBool Statement
Converts the gῃ�ven expressῃ�on ῃ�nto boolean value. It wῃ�ll be return False ῃ�f expressῃ�on evaluates to zero, True otherwῃ�se.
ToBool(<expression>)
Consῃ�der the followῃ�ng example:
Print(ToBool(a), "\n")
The prevῃ�ous example wῃ�ll output False ῃ�f value of a equals to zero, True otherwῃ�se.
Print Statement
Output the lῃ�st of expressῃ�on passed.
Print({str | expression | ToBool(<expression>)}[,{str | expression | ToBool(<expression>)}]...)
The prῃ�nt statement consῃ�sts of the Print keyword followed by a lῃ�st of expressῃ�ons separated by comma. You can use ToBool keyword
to force prῃ�nt of expressῃ�ons as Boolean. Strῃ�ngs are C++ style strῃ�ngs wῃ�th escape characters as descrῃ�bed ῃ�n the Strῃ�ngs sectῃ�on.
a = 3
b = 5
Print("a = ", a, ", b = ", b, "\n")
Print("Is a less than b = ", ToBool(a < b), "\n")
+ Operator
The + operator can functῃ�on as eῃ�ther a unary or a bῃ�nary operator.
+ expression
expression + expression
- Operator
The ‐ operator can functῃ�on as eῃ�ther a unary or a bῃ�nary operator.
expression
expression expression
* Operator
The multῃ�plῃ�catῃ�on operator (*) computes the product of ῃ�ts operands.
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 10/19
15.08.2017 Mῃ�croBasῃ�c Reference
expression * expression
/ Operator
The dῃ�vῃ�sῃ�on operator (/) dῃ�vῃ�des ῃ�ts fῃ�rst operand by ῃ�ts second.
expression * expression
Mod Operator
The modulus operator (Mod) computes the remaῃ�nder after dῃ�vῃ�dῃ�ng ῃ�ts fῃ�rst operand by ῃ�ts second.
expression Mod expression
And Operator
The (And) operator functῃ�ons only as a bῃ�nary operator. For numbers, ῃ�t computes the bῃ�twῃ�se AND of ῃ�ts operands. For boolean
operands, ῃ�t computes the logῃ�cal AND for ῃ�ts operands; that ῃ�s the result ῃ�s true ῃ�f and only ῃ�f both operands are true.
expression And expression
Or Operator
The (Or) operator functῃ�ons only as a bῃ�nary operator. For numbers, ῃ�t computes the bῃ�twῃ�se OR of ῃ�ts operands. For boolean
operands, ῃ�t computes the logῃ�cal OR for ῃ�ts operands; that ῃ�s, the result ῃ�s false ῃ�f and only ῃ�f both ῃ�ts operands are false.
expression Or expression
XOr Operator
The (XOr) operator functῃ�ons only as a bῃ�nary operator. For numbers, ῃ�t computes the bῃ�twῃ�se exclusῃ�veOR of ῃ�ts operands. For
boolean operands, ῃ�t computes the logῃ�cal exclusῃ�veOR for ῃ�ts operands; that ῃ�s, the result ῃ�s true ῃ�f and only ῃ�f exactly one of ῃ�ts
operands ῃ�s true.
expression XOr expression
Not Operator
The (Not) operator functῃ�ons only as a unary operator. For numbers, ῃ�t performs a bῃ�twῃ�se complement operatῃ�on on ῃ�ts operand. For
boolean operands, ῃ�t negates ῃ�ts operand; that ῃ�s, the result ῃ�s true ῃ�f and only ῃ�f ῃ�ts operand ῃ�s false.
Not expression
True Literal
The True keyword ῃ�s a lῃ�teral of type Boolean representῃ�ng the boolean value true.
False Literal
The False keyword ῃ�s a lῃ�teral of type Boolean representῃ�ng the boolean value false.
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 11/19
15.08.2017 Mῃ�croBasῃ�c Reference
++ Operator
The ῃ�ncrement operator (++) ῃ�ncrements ῃ�ts operand by 1. The ῃ�ncrement operator can appear before or after ῃ�ts operand:
++ var
var ++
The fῃ�rst form ῃ�s a prefῃ�x ῃ�ncrement operatῃ�on. The result of the operatῃ�on ῃ�s the value of the operand after ῃ�t has been ῃ�ncremented.
The second form ῃ�s a postfῃ�x ῃ�ncrement operatῃ�on. The result of the operatῃ�on ῃ�s the value of the operand before ῃ�t has been
ῃ�ncremented.
a = 10
Print(a++, "\n")
Print(a, "\n")
Print(++a, "\n")
Print(a, "\n")
The output of prevῃ�ous program wῃ�ll be the followῃ�ng:
10
11
12
12
-- Operator
The decrement operator (‐‐) decrements ῃ�ts operand by 1. The decrement operator can appear before or after ῃ�ts operand:
var
var
The fῃ�rst form ῃ�s a prefῃ�x decrement operatῃ�on. The result of the operatῃ�on ῃ�s the value of the operand after ῃ�t has been decremented.
The second form ῃ�s a postfῃ�x decrement operatῃ�on. The result of the operatῃ�on ῃ�s the value of the operand before ῃ�t has been
decremented.
a = 10
Print(a, "\n")
Print(a, "\n")
Print(a, "\n")
Print(a, "\n")
The output of prevῃ�ous program wῃ�ll be the followῃ�ng:
10
9
8
8
<< Operator
The leftshῃ�ft operator (<<) shῃ�fts ῃ�ts fῃ�rst operand left by the number of bῃ�ts specῃ�fῃ�ed by ῃ�ts second operand.
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 12/19
15.08.2017 Mῃ�croBasῃ�c Reference
expression << expression
The hῃ�ghorder bῃ�ts of left operand are dῃ�scarded and the loworder empty bῃ�ts are zerofῃ�lled. Shῃ�ft operatῃ�ons never cause overflows.
>> Operator
The rῃ�ghtshῃ�ft operator (>>) shῃ�fts ῃ�ts fῃ�rst operand rῃ�ght by the number of bῃ�ts specῃ�fῃ�ed by ῃ�ts second operand.
expression >> expression
<> Operator
The ῃ�nequalῃ�ty operator (<>) returns false ῃ�f ῃ�ts operands are equal, true otherwῃ�se.
expression <> expression
< Operator
Less than relatῃ�onal operator (<) returns true ῃ�f the fῃ�rst operand ῃ�s less than the second, false otherwῃ�se.
expression < expression
> Operator
Greater than relatῃ�onal operator (>) returns true ῃ�f the fῃ�rst operand ῃ�s greater than the second, false otherwῃ�se.
expression > expression
<= Operator
Less than or equal relatῃ�onal operator (<=) returns true ῃ�f the fῃ�rst operand ῃ�s less than or equal to the second, false otherwῃ�se.
expression <= expression
> Operator
Greater than relatῃ�onal operator (>) returns true ῃ�f the fῃ�rst operand ῃ�s greater than the second, false otherwῃ�se.
expression > expression
>= Operator
Greater than or equal relatῃ�onal operator (>=) returns true ῃ�f the fῃ�rst operand ῃ�s greater than or equal to the second, false otherwῃ�se.
expression >= expression
+= Operator
The addῃ�tῃ�on assῃ�gnment operator.
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 13/19
15.08.2017 Mῃ�croBasῃ�c Reference
var += expression
An expressῃ�on usῃ�ng the += assῃ�gnment operator, such as
x += y
ῃ�s equῃ�valent to
x = x + y
-= Operator
The subtractῃ�on assῃ�gnment operator.
var = expression
An expressῃ�on usῃ�ng the ‐= assῃ�gnment operator, such as
x = y
ῃ�s equῃ�valent to
x = x y
*= Operator
The multῃ�plῃ�catῃ�on assῃ�gnment operator.
var *= expression
An expressῃ�on usῃ�ng the *= assῃ�gnment operator, such as
x *= y
ῃ�s equῃ�valent to
x = x * y
/= Operator
The dῃ�vῃ�sῃ�on assῃ�gnment operator.
var /= expression
An expressῃ�on usῃ�ng the /= assῃ�gnment operator, such as
x /= y
ῃ�s equῃ�valent to
x = x / y
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 14/19
15.08.2017 Mῃ�croBasῃ�c Reference
<<= Operator
The leftshῃ�ft assῃ�gnment operator.
var <<= expression
An expressῃ�on usῃ�ng the <<= assῃ�gnment operator, such as
x <<= y
ῃ�s equῃ�valent to
x = x << y
>>= Operator
The rῃ�ghtshῃ�ft assῃ�gnment operator.
var >>= expression
An expressῃ�on usῃ�ng the >>= assῃ�gnment operator, such as
x >>= y
ῃ�s equῃ�valent to
x = x >> y
[] Operator
Square brackets ([]) are used for arrays, see Arrays sectῃ�on.
Abs Function
Returns the absolute value of an expressῃ�on.
Abs(<expression>)
Example:
b = Abs(200) '200
Atan Function
Returns the angle whose arc tangent ῃ�s the specῃ�fῃ�ed number.
Number ῃ�s devῃ�ded by 1000 before applyῃ�ng atan.
The return value ῃ�s multῃ�plῃ�ed by 10.
Atan(<expression>)
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 15/19
15.08.2017 Mῃ�croBasῃ�c Reference
Example:
angle = Atan(1000) '450 = 45.0 degrees
Cos Function
Returns the cosῃ�ne of the specῃ�fῃ�ed angle.
The return value ῃ�s multῃ�plῃ�ed by 1000.
Abs(<expression>)
Example:
value = Cos(0) '1000
Sin Function
Returns the sῃ�ne of the specῃ�fῃ�ed angle.
The return value ῃ�s multῃ�plῃ�ed by 1000.
Sin(<expression>)
Example:
value = Sin(90) '1000
Sqrt Function
Returns the square root of a specῃ�fῃ�ed number.
The return value ῃ�s multῃ�plῃ�ed by 1000.
Sqrt(<expression>)
Example:
value = Sqrt(2) '1414
GetValue
Thῃ�s functῃ�on ῃ�s read operatῃ�ng parameters from the controller at runtῃ�me. The functῃ�on requῃ�res a Operatῃ�ng Item, and an Index as
parameters. The Operatῃ�ng Item can be any one from the table below. The Index ῃ�s used to select one of the Value Items ῃ�n multῃ�
channel confῃ�guratῃ�ons. When accessῃ�ng a Operatῃ�ng Item that ῃ�s not part of an array, the ῃ�ndex value 1 must be used.
Detaῃ�ls on the varῃ�ous operatῃ�ng parameters that can be read can be found ῃ�n the Controller's User Manual
GetValue(OperatingItem, Index)
Current2 = GetValue(_BAMPS, 2) ' Read Battery Amps for Motor 2
Sensor = GetValue(_ANAIN, 6) ' Read voltage present at Analog Input 1
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 16/19
15.08.2017 Mῃ�croBasῃ�c Reference
SetCommand
Thῃ�s functῃ�on ῃ�s used to send operatῃ�ng commands to the controller at runtῃ�me. The functῃ�on requῃ�res a Command Item, and a Value
as parameters. The Command Item can be any one from the table below. Detaῃ�ls on the varῃ�ous commands, theῃ�r effects and
acceptable ranges can be found ῃ�n the Controller's User Manual
SetCommand(CommandItem, [Channel], Value)
SetCommand(_GO, 1, 500) ' Set Motor 1 command level at 500
SetCommand(_DSET, 2) ' Activate Digital Output 2
SetCon៍�g / GetCon៍�g
These two functῃ�ons are used to read or/and change one of the controller's confῃ�guratῃ�on parameters at runtῃ�me. The changes are
made ῃ�n the controller's RAM and take effect ῃ�mmedῃ�ately. Confῃ�guratῃ�on changes are not stored ῃ�n EEPROM.
SetConfῃ�g Set a confῃ�guratῃ�on parameter
GetConfῃ�g Read a confῃ�guratῃ�on parameter
Both commands requῃ�re a Confῃ�guratῃ�on Item, and an Index as parameters. The Confῃ�guratῃ�on Item can be any one from the table
below. The Index ῃ�s used to select one of the Confῃ�guratῃ�on Item ῃ�n multῃ� channel confῃ�guratῃ�ons. When accessῃ�ng a confῃ�guratῃ�on
parameter that ῃ�s not part of an array, the ῃ�ndex value 1 must be used. Detaῃ�ls on the varῃ�ous confῃ�guratῃ�ons ῃ�tems, theῃ�r effects and
acceptable values can be found ῃ�n the Controller's User Manual.
Note that most but not all confῃ�guratῃ�on parameters are accessῃ�ble vῃ�a the SetConfῃ�g or GetConfῃ�g functῃ�on. No check ῃ�s performed
that the value you store ῃ�s valῃ�d so thῃ�s functῃ�on must be handled wῃ�th care.
When settῃ�ng a confῃ�guratῃ�on parameter, the new value of the parameter must be gῃ�ven ῃ�n addῃ�tῃ�on to the Confῃ�guratῃ�on Item and
Index.
SetConfig(ConfigurationItem, [Index], value)
GetConfig(ConfigurationItem, [Index])
Accel2 = GetConfig(_MAC, 2) ' Read Acceleration parameter for Motor 2
PWMFreq = GetConfig(_PWMF) ' Read Controller's PWM frequency
SetConfig(_MAC, 2, Accel2 * 2) ' Make Motor2 acceleration twice as slow
SetTimerCount/GetTimerCount
These two functῃ�ons used to set/get tῃ�mer count.
SetTimerCount(<index>, <milliseconds>)
GetTimerCount(<index>)
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 17/19
15.08.2017 Mῃ�croBasῃ�c Reference
Where, ῃ�ndex ῃ�s the tῃ�mer ῃ�ndex (14) and mῃ�llῃ�seconds ῃ�s the number of mῃ�llῃ�seconds to count.
SetTimerState/GetTimerState
These two functῃ�ons used to set/get tῃ�mer state (started or stopped).
SetTimerState(<index>, <state>)
GetTimerState(<index>)
Where, ῃ�ndex ῃ�s the tῃ�mer ῃ�ndex (14) and state ῃ�s the tῃ�mer state (1 means tῃ�mer reached 0 and/or stopped, 0 means tῃ�mer ῃ�s runnῃ�ng).
SetCANCommand(<id>, <cc>, <ch>, <vv>)
SetCANConfig(<id>, <cc>, <ch>, <vv>)
Where:
ࠀd ῃ�s the remote Node Id ῃ�n decῃ�mal.
cc ῃ�s the Command code, eg. _G.
cc ῃ�s the channel number. Put 1 for commands that do not normally requῃ�re a channel number.
vv ῃ�s the value.
FetchCANValue(<id>, <cc>, <ch>)
FetchCANConfig(<id>, <cc>, <ch>)
Where:
ࠀd ῃ�s the remote Node Id ῃ�n decῃ�mal
cc ῃ�s the Command code, eg. _G
cc ῃ�s the channel number. Put 1 for commands that do not normally requῃ�re a channel number.
The followῃ�ng functῃ�ons can be used to waῃ�t for the data to be ready for readῃ�ng.
IsCANValueReady()
IsCANConfigReady()
These functῃ�ons return a Boolean true/false value. They take no argument and apply to the last ῃ�ssued FetchCANValue or
FetchCANConfࠀg functῃ�on.
The retrῃ�eved value can then be read usῃ�ng the followῃ�ng functῃ�ons.
ReadCANValue()
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 18/19
15.08.2017 Mῃ�croBasῃ�c Reference
ReadCANConfig()
These functῃ�ons return an ῃ�nteger value. They take no argument and apply to the last ῃ�ssued FetchCANValue or FetchCANConfࠀg
functῃ�on.
ScanCANValue(<id>, <cc>, <ch>, <tt>, <bb>)
Where:
ࠀd ῃ�s the remote Node Id ῃ�n decῃ�mal.
cc ῃ�s the Query code, eg. _V.
cc ῃ�s the channel number. Put 1 for commands that do not normally requῃ�re a channel number.
tt ῃ�s the scan rate ῃ�n ms.
bb ῃ�s the buffer locatῃ�on.
The scan rate can be up to 255ms. Settῃ�ng a scan rate of 0 stops the automatῃ�c sendῃ�ng from thῃ�s node.
Unless otherwῃ�se specῃ�fῃ�ed, the buffer can store up to 32 values.
The arrῃ�val of a new value ῃ�s checked wῃ�th the functῃ�on.
IsScannedCANReady(<aa>)
Where:
aa ῃ�s the locatῃ�on ῃ�n the scan buffer.
The functῃ�on returns a Boolean true/false value.
The new value ῃ�s then read wῃ�th the functῃ�on.
ReadScannedCANValue(<aa>)
Where:
aa ῃ�s the locatῃ�on ῃ�n the scan buffer.
The functῃ�on returns an ῃ�nteger value. If no new value was receῃ�ved sῃ�nce the prevῃ�ous read, the old value wῃ�ll be read.
IsCANNodeAlive(<id>)
Where:
ࠀd ῃ�s the remote Node Id ῃ�n decῃ�mal
The functῃ�on returns a Boolean true/false value.
https://www.roboteq.com/ῃ�ndex.php/support/mῃ�crobasῃ�creference?tmpl=component&prῃ�nt=1&page= 19/19