Make an ARC Skill

Example: Saving/Loading Configuration

In all plugins, there is a _cf variable which is provided by the inherited class which defines the Form. The _cf (configuration file) contains the data saved with your project. The _cf.STORAGE[key] is where your plugin configuration is kept. However, due to ARC providing the UCServoSelection user control, there is also a _cf.SERVOS[key] to store servo configuration.

The UCServoSelection user control is the common displayed control across all configuration screens in EZ-Builder. This user control allows configuration of servo ports, min and max distances. As well as multi servo support, etc.. So, if your plugin is to use the UCServoSelection, we highly recommend doing so. To move servos with UCServoSelection configuration data, the example source code in the above mentioned project should be reviewed. In short, it's easy to pass UCServoSelection.Config() data to the ARC.EZBManager.SetServoPosition(), which will take care of the magic - including relationship scaling between multiple servos, min, max and inverted options from UCServoSelection.

Configuration settings must be initialized with default values in the SetConfiguration override. This will ensure that when your plugin is loaded, there is some default configuration data assigned to the keys. Because the data is initialized using the _cf.STORAGE.AddIfNotExist(), the default data will only be added if the key doesn't exist. If the key does exist, following the user loading a project with saved configuration data, the default configuration will not be applied to the key. As demonstrated...


    public override void SetConfiguration(EZ_Builder.Config.Sub.PluginV1 cf) {

      cf.SERVOS.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });
      cf.SERVOS.AddIfNotExist(ConfigurationDictionary._VERTICAL_SERVOS, new EZ_Builder.Config.Sub.ServoDescriptor[] { });

      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._HORIZONTAL_DEGREES, 0.14m);
      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._VERTICAL_DEGREES, 0.14m);
      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_ENABLED, true);
      cf.STORAGE.AddIfNotExist(ConfigurationDictionary._EDGE_SIZE, 10);

      base.SetConfiguration(cf);
    }

The base.SetConfiguration in the above example is necessary to set the configuration with the inherited base. This ensures the initialized configuration is applied.

Also in the above example, the ConfigurationDictionary is a class which contains read-only static strings to reference the resource keys. We use these strings so the configuration data can be referenced without worrying about spelling mistakes where ever the data is to be accessed. Here is a look at the above example ConfigurationDictionary...


  public class ConfigurationDictionary {

    public static readonly string _HORIZONTAL_SERVOS = "horizontal servos";
    public static readonly string _VERTICAL_SERVOS = "vertical servos";

    public static readonly string _HORIZONTAL_DEGREES = "horizontal degrees";
    public static readonly string _VERTICAL_DEGREES = "vertical degrees";

    public static readonly string _EDGE_SIZE = "edge size";
    public static readonly string _EDGE_ENABLED = "edge enabled";
  }

Now to use the configuration data from the _cf in your project, simply cast the object from the _cf.STORAGE to the correct type. For _cf.SERVOS, pass the key result directly into the ARC.EZBManager helper methods. Like so...


      if (Convert.ToBoolean(_cf.STORAGE[ConfigurationDictionary._EDGE_ENABLED])) {

        int edgeSize = Convert.ToInt16(_cf.STORAGE[ConfigurationDictionary._EDGE_SIZE]);
        var servosX = _cf.SERVOS[ConfigurationDictionary._HORIZONTAL_SERVOS];
        var servosY = _cf.SERVOS[ConfigurationDictionary._VERTICAL_SERVOS];

        if (_mousePoint.X  _cameraControl.Camera.CaptureWidth - 10)
          ARC.EZBManager.SetServoIncrement(servosX, 1);

        if (_mousePoint.Y  _cameraControl.Camera.CaptureHeight - 10)
          ARC.EZBManager.SetServoIncrement(servosY, 1);
      }

Any data in the _cf.STORAGE and _cf.SERVOS will be automatically saved with the users project. And when that project is loaded again in the future, the _cf data will be reloaded as well. This allows your plugin to save the custom configuration applied by the user.


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

United Kingdom
#1  

Is this out of date? There doesn't seem to be a GetConfiguration function within EZ_Builder.Config.Sub.PluginV1

PRO
Synthiam
#2  

Look at the tutorial step titled Code: Saving/Loading Configuration

The get and set configuration methods are overrides of the form. There’s a great video on the first step of this tutorial that demonstrates the step by step of building a plugin. I recommend watching that because it helps fill in any steps that were missed.

When you’ve done it once, it makes sense and voila, you can rinse and repeat:)

United Kingdom
#3  

Excellent, thanks - I will do. I really must learn not to just jump ahead in the process:)

PRO
Synthiam
#4  

Hey no problem - I do it all the time, and end up frustrated because I dont know what it was that I missed. Excitement gets the best of me

United Kingdom
#5  

Trying to follow the tutorials but can't find where the plugin page has gone. How do I add a new plugin to the ez-robot / Synthiam site to get the XML?

United Kingdom
#6  

Never mind. Just found the "Create skill control" link:)

#7  

I am trying to follow the instructions for adding my own plugin but I cannot seem to find the place to register the plugin based on the instructions.

Any help is appreciated.

Thanks

PRO
Synthiam
#8   — Edited

The new button to create a plugin skill control is less than an inch below the button you pressed to create this question. :)

User-inserted image