Asked — Edited

Need Help With Plugin

I need some help with a plugin I am working on. I am new to C# and OOP. Have went thru the Tutorial and the SDK Tutorials also.

User-inserted image

How do I get the values from the form in to my C# code?

 public enum LocationType
            {
                Wall = 255,
                Empty = 0,
                Destination = 254,
                Source = 1
            }
            public struct Location
            {

instead of Wall = 255, how do I get Wall = textBox1.Text. textBox1 being the Textbox name.

Thanks RichardZ


ARC Pro

Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

PRO
USA
#9  

if you want to minimize the code you can use my extension method. EZ-Script doesn't have typed types, GetVariable always returns a string. My method will convert the string or array of strings to the type specified in the invocation.

Examples:


var str1 = this.GetVariable<string>("$str1");
var int1 = this.GetVariable<int>("$int1");
var arrayOfString1 = this.GetVariable<string[]>("$arrayOfString1");
var arrayOfInteger1 = this.GetVariable<int[]>("$arrayOfInteger1");

although is your responsibility to store the correct data type when using EZ-Script.


private T GetVariable<T>(string variableName)
{
	if (!VariableManager.DoesVariableExist(variableName))
	{
		return default(T);
	}

	if (!typeof(T).IsArray)
	{
		if (!VariableManager.IsVariableArray(variableName))
		{
			return (T)Convert.ChangeType(VariableManager.GetVariable(variableName), typeof(T));
		}

		//requested type is array but the variable is not an array => return null;
		return default(T);
	}

	var arraySize = VariableManager.GetArraySize(variableName);
	var elementType = typeof(T).GetElementType();
	var array = Array.CreateInstance(elementType, arraySize);

	for (var i = 0; i < arraySize; i++)
	{
		var elementValue = Convert.ChangeType(VariableManager.GetVariable(variableName, i), elementType);
		array.SetValue(elementValue, i);
	}
	return (T)(object)array;
}

PRO
USA
#10  

@PTP, I am working on a wavefront navigation plugin and $MyMap is the flat array of the house (80x80). I have written it in EZ-Script but it was extremely slow. So I decided to make a plugin. I have sense discovered that it I get rid of the variable monitor, the array initializes in less the a second instead of 20 min. I have thought of going back to the EZ-Script version but It is about time I learned C# anyway. My son if fluent in C# OOP, but he is so busy with his work and his 2 autistic children. I will read thru the code and get back with you soon. I could attach my C# project and the EZ-Script for that matter if you like.

Thanks again

RichardZ

PRO
Synthiam
#11  

Good discovery, Richard. Any of the debugging controls will dramatically slow down the project. It's because rendering a significant number of items to the screen is very taxing on the CPU.

Sounds like you have a pretty interesting and fun project over there! I bet everyone is excited to see and hear more - I sure am!

PRO
USA
#13  

DJ, Is this valid? It does not give me an error but it does not seem to work ether.


VariableManager.SetVariable("$Disp2[" + MyCount +"]", map[x1, y1]);

PRO
USA
#15  

Got it!

Ended up with this:


VariableManager.CreateVariableArray("$Disp2",0,0);


                for (int x1 = 0; x1 < map.GetLength(0); x1++)
                {
                    for (int y1 = 0; y1 < map.GetLength(1); y1++)
                    {
                        disp = map[x1, y1].ToString();
                        
                        VariableManager.AppendToVariableArray("$Disp2", disp);
                    }
            
                }

PRO
USA
#16  

I have read thru the Tutorial more time then I can count. Digging thru the Object Browser and a lot of trial & even more error, I am getting close. I will have a write up on it soon. For now, you give the plugin a map of your home. $MyMap 255 = Wall 254 = The Robot 1 = The Goal 0 = Open Space Call the plugin and it will Return an Array named $MyRoute. With in the Array Starting from the Robots position a "-" indicates the next location to move towards the goal. So if you have an 80x80 map, $MyRoute[0 - 79] is column 0, [80 - 159] is column 1and so on. On my map North and West are 0,0 To move east on the map +1 to current position, to move south +80 to current position. - 80 for north, -1 west.

Now to add movement and object avoidance. My plan is.. if an object is detected, mark the position on the map and resubmit it to the plugin to get a new solution.

Thank you both for your help. Hope to have it public soon. RichardZ