Asked — Edited
Resolved Resolved by CochranRobotics!

Converting A String To Integer In Ez Scripting

I am using the plug in for the XV-11 Lidar. The output of the plug in an array in which each value is a string that represents the distance at the angle and the signal strength. To use this for control of the robot, I need numbers at these angles. The format is shown in the attached example. How do I parse and convert this in EZ Scripting into an integer?

In C there is the string.split command

and then the string to integer convert.

Is there a way to do this in the EZ scripting?

User-inserted image


Upgrade to ARC Pro

With Synthiam ARC Pro, you're not just programming a robot; you're shaping the future of automation, one innovative idea at a time.


Yeah it's split()

Look in the examples folder for syntax usage examples

Although, the makes more sense to sanitize the data before going into a variable and not have to reactively parse the variable.


I will look at making a change for this tonight. If I remember right, the first number is mm distance. The second is the intensity value and the ID of the array element is the angle. I don't swear by this as it has been a long time since I looked at it. I will break these out to 3 arrays each containing 360 elements.

Here is the question... Would you rather be able to get all of the information by querying one element in one array and then break apart the information, or would you rather get individual elements in 3 different arrays? I see this as a loss in both fronts.

Either you will have to take the variable and parse it to get the data when needed or you would need to get three elements and use more memory on the computer for this. I guess because these 3 arrays would be number values, each element would be smaller than string values, so maybe it wouldn't be more memory...

I am open for suggestions. I am good either way. The benefit to the second way is that it would be an integer that code wouldn't need to split on and then cast as an int.


Another option is to drop the intensity all together and just give you the distance with the angle being the ID of the item in the array.

Let me know which you would prefer. I am open to any ideas.


Data organizational practices, which applies to variables, is to store only the relevant data. Meaning, storing two types of data in a single variable is not good practice. This adds the responsibility on the user, which introduced high chance of error - and additional effort, such as demonstrated in this thread.

Put the data as separate array variable names for each respective attribute - and voila.


Sounds good DJ. I will do that. BTW, my memory isn't that bad. I just checked the code and I did remember what the values were. Sometimes I surprise my self:)

EZ_Builder.Scripting.VariableManager.VariablesArray["$LIDAR"].ElementAt(direction2).SetValue(distancetext + "|" + intensity.ToString());

I will break this out to 2 different variable arrays with the ID of the element being the angle. This will still allow the user to decide to use the intensity if needed and the ID is still the angle.



Wow! this community is outstanding.DJ and Mr. Cochran I would like to have angle and distance even if it were in two related variables. The intensity number is probably not as useful even though it does tell you about the quality of the data. Just getting the data into variables that can be used would probably be sufficient as a first step. I can't wait to see where this goes with this collaboration!


This is completed and published. The array index is the angle. The $LIDARDistance variable is the distance in mm, and the $LIDARIntensity is the intensity reading from the LIDAR at that angle. $LIDARDistance[0] belongs with $LIDARIntensity[0].


Outstanding. I can't wait to try this out. I hope I get to fiddle with it tonight. Thank you David


I had one small issue. Fixed it. I think I will add a configuration setting to enable intensity if someone wants it.


it looks like it is going to have to wait until tomorrow. There will be no focusing on my projects this evening due to being in the living room and others thinking that they should make as many distractions as they possibly can.


LOL. Life and family interferes again with out hobbies!


I have something acting weird on my GetSurreal controller. 2 of the ones I had are out on loan to others, and the other one is pretty securely mounted inside of Rafiki. I just placed an order for another one and they are in stock so I don't think it will be long before I receive it.

I tested things last night before posting the plugin and everything seemed like it was working fine with what was published. @mstephens_42, would you mind trying the new plugin and letting me know if you have any issues? It might be wise to first make a backup of the plugin in C:\Users\Public\Documents\EZ-Builder\Plugins\bf3200ea-7b00-4566-a6d8-9eb0690bbb33 before installing the new one just because of what I am seeing with mine.

Thanks David


That is good news. I have loaded on some test firmware on the one I use for programming. I suspect the issue that I see is with that.

On a side note, the GetSurreal controller is going to be having an update that will drop all obvious errors from the XV-11 soon. I will test it out and post about it when I am comfortable that they have it working right, but if you want to try it, it is in their github dev branch.


When I load the plugin, it pops up an message box that reads "com3" does not exist. And it then locks up ARC, forcing me to end the task in task manager.


Interesting. Mine also tries come first and then allows me to use the config screen to then go choose the com port.


Are you sure it locks it up or is it loading/building the blank arrays? By doing 720 array elements it takes a bit.


A second message box should pop up saying that the com port wasn't initialized. I wonder if it is hidden.


I got that com 3 message too. But it continues and works once I select the correct com port. You also have to make sure you load the "tinsey" USB driver on your computer or it won't see the Lidar.


That is true. Also, I have an update written but I dont want to deploy it until I know it works. Unfortunately I cant really test it until I get another controller. This update has the ability to either enable or disable intensity settings (the array population of the intensity values). By default they are disabled. The map will still change the color of the points based on the intensity values in the config screen.

I will look at changing the error handling on the initial startup for the com port.

Thanks David


Not sure why mine crashes then - I will have to run it in visual studio and see if there's an exception.

Are you using this to create the initial ARC variable array? Or are you "appending" to the array 360 times?

CreateVariableArray(string variableName, object defaultValue, int size);

With that you can ...

CreateVariableArray("$lidar", 0, 360);

And it will be fast.


I'm pretty sure that is what I am doing. Will look in a bit. Definately not appending 360 times.


I just put the latest code out and updated the project.

      private void MainForm_Load(object sender, EventArgs e)
            //button1.Enabled = false;

           // EZ_Builder.Scripting.VariableManager.CreateVariableArray("$LIDARDistance", 0, 360);
           // if (Convert.ToBoolean(_cf.STORAGE[ConfigDictionary.chkUseIntensity]))
           // { EZ_Builder.Scripting.VariableManager.CreateVariableArray("$LIDARIntinsity", 0, 360); }

            try {
                if (Convert.ToString(_cf.STORAGE[ConfigDictionary.comportname]).Length > 3)
                MessageBox.Show("Select the COM port being used by the LIDAR on the config screen.");
            backgroundWorker1_DoWork(null, null);

       private void loadConfig()
            drawline = Convert.ToBoolean(_cf.STORAGE[ConfigDictionary.DrawLines]);
            drawArea = panel1.CreateGraphics();
            string pc = Convert.ToString(_cf.STORAGE[ConfigDictionary.thePenColor]);
            string bc = Convert.ToString(_cf.STORAGE[ConfigDictionary.backgroundcolor]);
            Pen pointpen = new Pen(Color.FromName(pc));
            drawArea.DrawRectangle(pointpen, panel1.Width / 2, panel1.Height / 2, 4, 4);

         private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
            EZ_Builder.Scripting.VariableManager.CreateVariableArray("$LIDARDistance", 0, 360);
            {EZ_Builder.Scripting.VariableManager.CreateVariableArray("$LIDARIntensity", 0, 360); }

      private void initializecomport()
            try {
                _serialPort.BaudRate = _baudRate;
                _serialPort.DataBits = _dataBits;
                _serialPort.Handshake = _handshake;
                _serialPort.Parity = _parity;
                _serialPort.PortName = (string)_cf.STORAGE[ConfigDictionary.comportname];
                _serialPort.StopBits = _stopBits;
                _serialPort.ReadBufferSize = Convert.ToInt32(_cf.STORAGE[ConfigDictionary.BufferSizeValue]);
                _serialPort.DataReceived += new SerialDataReceivedEventHandler(_serialPort_DataReceived);
                comportInitialized = true;
                //_cf = cf;
            catch(Exception ex)
                MessageBox.Show("COM port not initialized");

This is the portion that initializes the array(s) and also the comp port.


@David, mine also locks ARC up, yesterday was it working, the only this I changed today is updated the latest ARC. Now I can not get it working again.


I forgot to say, I loaded a new project when this happened, I also backup yesterdays plugin. What is funny is both my project's and new project have the latest ARC Version 2016.02.20.00

So with a new project and yesterdays plugin it still lockup. However, using my project and yesterdays plugin it works?


Okay, that would indicate that it is a config setting that isn't set by default. I wish I could duplicate the issue. I also downloaded the latest ARC to make sure it worked with the new version. I can't seem to get it to lockup. I do have an issue with my controller though. My new one should be here Monday so that I can do some testing and debugging.


I just checked your plugin date I am using and it was 2/18/1016 not yesterday, sorry about that. Thanks David.


@Mike and @DJ, I suspect that this release this morning will solve the issue you are seeing. Please let me know. I am hesitant to change the com port 3 default setting until I know if this works for you.

Thanks David


Morning David, it lets me configure the com port and then when I click start lidar it locks up ARC.



Download and installed successfully ver13

So this is strange. I opened a new project, installed your Ver13 plugin. Add it to the new project it locks up. I open my own project with your plugin ver13 deleting the lidar plugin and adding the new ver13 plugin and it still locks up.

I then restore my backup ver11 plugin opened my own project with the plugin ver11 all ready add and it works. So I deleted the lidar plugin and re-added it and it locks up.

So I'm not sure way it worked with my project that ver11 was saved in ARC and not able to delete and re-add the same ver11 plugin.

If maybe I I am doing something wrong, I still have teamviewer installed.



It is strange. Okay, I will have to wait until tomorrow to try to address. It is hard to know what is going on without a reliable Get Surreal controller on hand. It really has me wondering what is going on. I may connect to your computer tomorrow or Tuesday after I have a chance to look into it more.


Sounds good. Thanks David.


The part I need didn't arrive today. Maybe tomorrow it will be here.


Thanks David, you have my number


The controller arrived. I haven't had time to build it yet as work has been a lot of fun today. I should have something for you tonight still if work calms down.


Well, from the looks of it, I will be working late into the night tonight. I have to find one record in a 35TB database that is causing a process to break. Unfortunately I am the only one in the company that knows this data to the level of detail to resolve the issue. The good thing is that this database is going away in a couple of months, but until then I am trying to make it limp along until decommissioned. Because of this, I now doubt that I will have time to look at this tonight. I did get the Get Surreal controller built and flashed so now it is just finding the issue.

@mstephens_42, is yours locking up now too?


@Merne or @DJ

Can you try something for me? Please try to increase the data buffer size on your config screen? Please try maybe up to 4096 and see if you still lock up.


Actually, try this if you would...

  1. open ARC

  2. Add LIDAR control

  3. Click ok to messages about com port

  4. Click the settings button

  5. Change com port

  6. Change buffer to 4096

  7. Save config

  8. Save the project

  9. Start LIDAR What happens here?

  10. Close ARC

  11. Open ARC

  12. Open saved project

  13. Start LIDAR What happens here?

Thank you for helping to find and resolve issue.


David, I just downloaded the latest version of ARC and loaded your last plug in. My buffer is set to 2048 and I am running Windows 10. It's working fine for me. The lidar is spinning, the chart is updating and the variable watch is working fine.


Thanks @mstephens_42. At least I know that I dont have the only working one:)


Yep. It is not locking up but all of the data may not be making it to the variables. See this screenshot. I would not expect so many zeros in the data variables based on where the Lidar is placed. I tried setting to 2048 and 4096 and still got the same result.

User-inserted image


Okay, hmm. Did you stop the lidar and then restart it by chance when this happened?


I think I know what it is. If the points are out range for the Lidar, then it records that angle as a distance of zero. If I move the lidar around I get a better 360 view and a lot more data. I was in the corner of my kitchen which is about 10 ft wide by 20 feet long. I think the range of the Lidar is about 10 feet so it could not see the far walls 0 which probably accounts for the zero data.

One final thing on this Lidar, that I have experienced and also seen documented on-line is that angle of the data is not aligned with the natural axis of the device. It seems that the first sample of the first packet is in fact looking at a -10° angle, not 0°. If a future version of the plug in algorithm could compensate for this it would be great.


It is there already kind of. Image rotation setting in the settings will adjust the image. I cant remember if I adjust the variables though. I will need to look at it.

Yes, by default, when I have a bad value, I set it to 0. There is code that the Get Surreal maker is working on that will just not report these points back from the Get Surreal controller. I should see him early next month. I will check with him on where he is with this update and when he thinks it would be complete.


I could have it register as something like 4000 if there is no returned value. Let me think on that a bit.

I pushed a version that sets the variable to something outside of the range of the LIDAR if the LIDAR doesn't return a value(5000) for that angle. Also, it runs a bit faster now and starts the LIDAR automatically when the com port is activated or when the plugin loads.

This should prevent the first cycle of data from being off as by the time you start the LIDAR, the first set of data has already tried to be passed from the Get Surreal to the computer, but the port isn't open until you click the Start LIDAR button.


Ok. Thanks. That should show at least a virtual wall or boundary if the Lidar does not see an object at that angle.


@David, I just got home, been a long day. I will try it in a few. Thanks


@David, I am win7 loaded new project install Lidar plugin and set to com2 4096 and it is working. Thanks,

Question, I need help watching the variables. At the top it has type, size, and value.

I have many 500s and 600 orate for value, nothing In type. How do I see angles?

Thank you for fixing


Right after typing my last post my Lidar stop turning and my pic said device not connected, going to down load the getsurreal drive, and try again


The angle is the item of the array.

$LIDARDistance[0] would be for the value for angle 0 $LIDARDistance[1] would be for the value for angle at 1 degree . . .

The distances you are seeing would be something at about 19 1/2 inches from the LIDAR.

The distance value / 25.4 should give you the inches at that angel.


yea, it sounds like it is an issue with the com port. I bet if you install the Teensy Serial Driver you would be okay. You might need to uninstall the existing Teensy driver before installing it again.


It could also be the cable I suppose. I use a 1.5 foot cable. It is pretty heavy grade for a usb cable. I have run it before with a much longer (10 foot) cable without any problem though. This was from a powered usb hub.


Uninstalled com2 drive, download your for the Lidar sub serial driver, opened ARC changed to c8 saved and it locked up.

Rebooted pic still locking up, ugh! Am I the only one running win7?

Any suggestions thanks


Ok no luck. Getting real frustrated now calling it a night I got a headache and I'm tired look into it tomorrow thanks David


One more quick thing David I'm not mad at you I'm just frustrated because it's been running for a long time with the version 2-18 date I believe it was. confused


Not a problem. I am going to send you a version that will tell us exactly what it is doing when it locks up. I will make it tomorrow and send it your way. I'll call you to walk you through getting it in place to run.


Not being able to duplicate the issue makes it really tough to figure out what is going on. Get some rest. I had one of those days yesterday.


@David, I believe my Lidar control is the issue, not sure. Normally when I start my pc the Lidar starts turning, now it does not. Have you had to replace you USB controller on your Lidar. I ask be cause list night when I swapped sub cables I noticed it was pretty hot.

Anyway I welcome your invitation to have a look if you can tonight.

Note to self, never work on my robot when you have hard day at work. Lol:D

Thanks David for all your hard work for this community.


An interesting note... Last night I let the lidar plugin run while my computer went to sleep. This morning I did have a locked up ARC. I suspect that if the com port has an issue it is locking up ARC.

I will look at catching that and making it report an error.

The replacement of the controller was due to me flashing it with some dev code that I really didnt want to loose. It is interesting that yours was hot. I haven't experienced that. Can you make sure that the part that is between the lidar connections and the teeny board isnt making contact with the teensy board? This is a voltage regulator with a heat sync. I want to make sure that it isnt shorting out something.

Also, the teensy board can be removed. Under it there is a diode and a pull up resistor. Make sure that those are soldered well. You can do this from the bottom of the board without removing the teensy device.

You should also make sure that there isnt any solder bridges on the teensy or on the connectors on the bottom of the board. I did verify a few weeks back that these are hand made. It is possible that there could be a solder bridge between a couple of the ports.


Hey David. I ordered another controller version 1.2 just in case so you might wait until I get in to see if it's working or not thanks


Okay. I should still be checking for com port issues anyway. I will put this off until the weekend probably though.