Using labels in Roborun
7 years 2 days ago #29532080
by maple
Using labels in Roborun was created by maple
The ability to add custom labels to inputs/outputs is very convenient.
Unfortunately it is not very useful for coding. The majority of microbasic scripts are universal enough to be used in various controller models. However because of the differences in pinouts and capabilities we have to adjust the code every time. It would be great to be able to use labels for portability.
1. Allow labels to be added to "Motor # Output" in Power Output tree
2. Alternative format for SetCommand/GetValue/SetConfig/GetConfig functions, using label instead of index:
SetConfig(_AMOD, "Throttle", 2)
speed = GetValue(_ANAIN, "Throttle")
SetCommand(_G, "Left wheel", speed)
3. Helper integer function Find(<label>) for channel discovery. Note that this function alone can replace (2) for very simple support of the same functionality. The scripts will be a little longer but no need to modify existing functions:
throttle = Find("Throttle")
SetConfig(_AMOD, throttle, 2)
speed = GetValue(_ANAIN, throttle)
motor = Find("Left wheel")
SetCommand(_G, motor, speed)
As a side note, "Pulse In" panel on Run tab is much smaller than "Analog inputs" panel. Even with 8 characters restriction custom labels do not fit in there. At least on my screen (Windows 7, display configured for 125% text size)
Unfortunately it is not very useful for coding. The majority of microbasic scripts are universal enough to be used in various controller models. However because of the differences in pinouts and capabilities we have to adjust the code every time. It would be great to be able to use labels for portability.
1. Allow labels to be added to "Motor # Output" in Power Output tree
2. Alternative format for SetCommand/GetValue/SetConfig/GetConfig functions, using label instead of index:
SetConfig(_AMOD, "Throttle", 2)
speed = GetValue(_ANAIN, "Throttle")
SetCommand(_G, "Left wheel", speed)
3. Helper integer function Find(<label>) for channel discovery. Note that this function alone can replace (2) for very simple support of the same functionality. The scripts will be a little longer but no need to modify existing functions:
throttle = Find("Throttle")
SetConfig(_AMOD, throttle, 2)
speed = GetValue(_ANAIN, throttle)
motor = Find("Left wheel")
SetCommand(_G, motor, speed)
As a side note, "Pulse In" panel on Run tab is much smaller than "Analog inputs" panel. Even with 8 characters restriction custom labels do not fit in there. At least on my screen (Windows 7, display configured for 125% text size)
Please Log in or Create an account to join the conversation.
7 years 2 days ago #29532081
by blake
Replied by blake on topic Using labels in Roborun
Thank you again for your feedback, it will be very useful as we continue to develop Roborun.
Regarding the labels from your second and third points. The can be accomplished using the #define function. For example:
#define Throttle 1
SetConfig(_AMOD, Throttle, 2) ---> This would then be the same as SetDonfig(_AMOD, 1, 2)
This would set the value of "Throttle" as 1. Then you can use "Throttle" in your SetConfig/SetCommand etc syntax. If you ever change the pin number of your "Throttle" input you would only need to change the number in the #define function and wouldn't need to change it for every Set/Get function. This also eliminates the need for an additional Find function.
Regarding the size of the Pulse In panel, great point we will work on getting this corrected.
By the way, we have fixed the Help button on the scripting tab per your mention in a previous post. The revised version of Roborun will be on our website within the next couple of days. If you would like it immediately please contact me at This email address is being protected from spambots. You need JavaScript enabled to view it. and I can send it to you.
Regarding the labels from your second and third points. The can be accomplished using the #define function. For example:
#define Throttle 1
SetConfig(_AMOD, Throttle, 2) ---> This would then be the same as SetDonfig(_AMOD, 1, 2)
This would set the value of "Throttle" as 1. Then you can use "Throttle" in your SetConfig/SetCommand etc syntax. If you ever change the pin number of your "Throttle" input you would only need to change the number in the #define function and wouldn't need to change it for every Set/Get function. This also eliminates the need for an additional Find function.
Regarding the size of the Pulse In panel, great point we will work on getting this corrected.
By the way, we have fixed the Help button on the scripting tab per your mention in a previous post. The revised version of Roborun will be on our website within the next couple of days. If you would like it immediately please contact me at This email address is being protected from spambots. You need JavaScript enabled to view it. and I can send it to you.
Please Log in or Create an account to join the conversation.
7 years 1 day ago - 7 years 1 day ago #29532084
by maple
Replied by maple on topic Using labels in Roborun
I was using #define macro before. However my customer uses a lot of different Roboteq controllers, often mixing several models in a single device, to accommodate power requirements. Some of them have DB15 connector, some have DB25. Even though the microbasic code is exactly the same the constants have to be changed every time, which slows down the development and has a potential for dangerous mistakes.
The idea to use labels accessible from microbasic solves this problem without the need to keep several scripts. Roborun can be used to assign labels to inputs, outputs and motors and then same script will work properly regardless on which model it is loaded to.
I only suggested Find() function because it is simplest way of accomplishing this goal without changing anything else. Of course alternative syntax described in (2) would produce a bit more readable code.
Regarding Help button - thanks a lot! I'll wait for next published version, no rush.
The idea to use labels accessible from microbasic solves this problem without the need to keep several scripts. Roborun can be used to assign labels to inputs, outputs and motors and then same script will work properly regardless on which model it is loaded to.
I only suggested Find() function because it is simplest way of accomplishing this goal without changing anything else. Of course alternative syntax described in (2) would produce a bit more readable code.
Regarding Help button - thanks a lot! I'll wait for next published version, no rush.
Please Log in or Create an account to join the conversation.
7 years 20 hours ago #29532085
by LROBBINS
Replied by LROBBINS on topic Using labels in Roborun
Hmm. Intrigued by your discussion of #define, something more than a little familiar for those of us who write C, I searched the nxtgen user's manual for it and can find no reference to it. Where can I find information about this "function" or (as the OP called it) "macro"?
Please Log in or Create an account to join the conversation.
7 years 20 hours ago - 7 years 20 hours ago #29532086
by blake
Replied by blake on topic Using labels in Roborun
Lenny you are right, #define isn't detailed in the manual. It is however described in our
Microbasic Reference Guide.
My verbiage wasn't exactly right in my previous post as #define is technically a preprocessor directive. It simply is used to create a macro as OP said. If you are familiar with C++ you will definitely recognize it.
Please Log in or Create an account to join the conversation.
7 years 19 hours ago #29532087
by LROBBINS
Replied by LROBBINS on topic Using labels in Roborun
My bad. When I looked at the MicroBasic Reference web page a long time ago, I decided that it was just a repeat of what was in the manual and never looked at it again. Yes indeed, #define is there, as are the added trig functions and RoboCAN calls. Thanks for the heads up.
Please Log in or Create an account to join the conversation.
Moderators: tonysantoni
Time to create page: 0.069 seconds