Asked — Edited

Can Someone Help Me With The Development Of A ARC Skill?

Can someone help me with the development of a ARC skill?  I have put together a Arduino script that is for an ESP32 it contains the EZB firmware and it also has a very robust MPU6050 logic.  I need to have the skill in ARC be able to allow some options to be set and also bring MPU data back in variables.  Like I said I have all the logic I just need help making the UI for ARC.

If you are willing to help let me know and I will send you the code.


ARC Pro

Upgrade to ARC Pro

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

#17  

Well that would explain it LOL.  Let me see if I can do something about that..:

#18  

DJ,  Tell me where I screwed up now please.  I hope you are not get mad at me....  Please understand I am doing the best I can with my limited understanding of all this stuff but I feel I am getting closer.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ARC;
using ARC.Config.Sub;

namespace ESP32_MPU6050 {

  public partial class MainForm : ARC.UCForms.FormPluginMaster {

    Configuration _config;

    System.Timers.Timer _timer;
    bool _isClosing = false;


    public MainForm() {

      InitializeComponent();

      // show a config button in the title bar. Set this to false if you do not have a config form.
      ConfigButton = false;

      _timer = new System.Timers.Timer();
      _timer.Interval = 1000;
      _timer.Elapsed += _timer_Elapsed;

      _timer.Start();

    }

    public override void SetConfiguration(PluginV1 cf)
    {

        ARC.Scripting.VariableManager.SetVariable("$AngleZ", 0);
        ARC.Scripting.VariableManager.SetVariable("$AngleY", 0);
        ARC.Scripting.VariableManager.SetVariable("$AngleX", 0);
        ARC.Scripting.VariableManager.SetVariable("$servoRvalue", 0);
        ARC.Scripting.VariableManager.SetVariable("$servoPvalue", 0);
        ARC.Scripting.VariableManager.SetVariable("$servoYvalue", 0);

        base.SetConfiguration(cf);
    }

        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
    {

        _isClosing = true;

        _timer.Stop();
        _timer.Dispose();
        _timer = null;
    }

    private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {

        if (_isClosing)
            return;

        readValues();
    }

    /// 
    /// When the project is saving, give it a copy of our config
    /// 
    public override ARC.Config.Sub.PluginV1 GetConfiguration() {

      _cf.SetCustomObjectV2(_config);

      return base.GetConfiguration();
    }

    /// 
    /// The user pressed the config button in the title bar. Show the config menu and handle the changes to the config.
    /// 
    public override void ConfigPressed() {

      using (var form = new ConfigForm()) {

        form.SetConfiguration(_config);

        if (form.ShowDialog() != DialogResult.OK)
          return;

        _config = form.GetConfiguration();
      }
    }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            ARC.EZBManager.EZBs[0].Servo.SetServoPosition(EZ_B.Servo.ServoPortEnum.D0, 10);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ARC.EZBManager.EZBs[0].Servo.SetServoPosition(EZ_B.Servo.ServoPortEnum.D0, 170);
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

    void readValues()
    {

        try
        {

            var response = EZBManager.EZBs[0].SendCommandData(12, 0x00);

            UInt16 AngleZ = BitConverter.ToUInt16(response, 0);
            UInt16 AngleY = BitConverter.ToUInt16(response, 2);
            UInt16 AngleX = BitConverter.ToUInt16(response, 4);
            UInt16 servoRvalue = BitConverter.ToUInt16(response, 6);
            UInt16 servoPvalue = BitConverter.ToUInt16(response, 8);
            UInt16 servoYvalue = BitConverter.ToUInt16(response, 10);

            ARC.Scripting.VariableManager.SetVariable("$AngleZ", AngleZ);
            ARC.Scripting.VariableManager.SetVariable("$AngleY", AngleY);
            ARC.Scripting.VariableManager.SetVariable("$AngleX", AngleX);
            ARC.Scripting.VariableManager.SetVariable("$servoRvalue", servoRvalue);
            ARC.Scripting.VariableManager.SetVariable("$servoPvalue", servoPvalue);
            ARC.Scripting.VariableManager.SetVariable("$servoYvalue", servoYvalue);

               if (Invokers.GetCheckedValue(checkBox1))
                   Invokers.SetAppendText(textBox1, true, "AngleZ: {0}, AngleY: {1}, AngelX: {3}, Yaw: {4}, Pitch: {5}, Roll: {6}", AngleZ, AngleY, AngleX, servoYvalue, servoPvalue, servoRvalue);
        }
        catch (Exception ex)
        {
             Invokers.SetAppendText(textBox1, true, ex.ToString());
        }

    }
  }
}


PRO
Synthiam
#19  

What’s wrong with it?

the only suggestions I’d have are to check if there’s a connection to the ezb otherwise you’ll throw an exception every second. But looks fine other than that

#20  

It disconnects the ESP32 EZB connection the vars are set to 0 when it starts they don't ever change in the var watcher service. and then it disconnects.

PRO
Synthiam
#21  

Id suggest taking the readvalues() out of the timer event. Put it in a button for testing.

That way you can rule out the exception that’s repeatedly thrown during disconnect. And you can verify other features of the esp32 firmware you altered is working.

Also, the disconnection would have a message in the log window. That’s useful because it’ll tell you why it disconnected

#22  

DJ, I made the changes you recommended as seen below.   When I connect to the ESP32 from ARC the firmware starts the process polling the MPU6050 ARC does not have any connection issues until I click on the Get MPU Values button.  When I do that the connection is dropped to the ESP32.  I will also attach the VS code if you want to play with that.

ESP32_MPU6050.zip

using System;
using System.Windows.Forms;
using ARC;
using ARC.Config.Sub;

namespace ESP32_MPU6050 {

  public partial class MainForm : ARC.UCForms.FormPluginMaster {

    Configuration _config;

    readonly string _CMD_GET_VALUES = "GetValues";
    readonly string _CMD_DEBUG_ON = "DebugOn";
    readonly string _CMD_DEBUG_OFF = "DebugOff";

        System.Timers.Timer _timer;
    bool _isClosing = false;


    public MainForm() {

      InitializeComponent();

      // show a config button in the title bar. Set this to false if you do not have a config form.
      ConfigButton = false;

      _timer = new System.Timers.Timer();
      _timer.Interval = 1000;
      _timer.Elapsed += _timer_Elapsed;

    }

    public override void SetConfiguration(PluginV1 cf){

        ARC.Scripting.VariableManager.SetVariable("$AngleZ", 0);
        ARC.Scripting.VariableManager.SetVariable("$AngleY", 0);
        ARC.Scripting.VariableManager.SetVariable("$AngleX", 0);
        ARC.Scripting.VariableManager.SetVariable("$servoRvalue", 0);
        ARC.Scripting.VariableManager.SetVariable("$servoPvalue", 0);
        ARC.Scripting.VariableManager.SetVariable("$servoYvalue", 0);

        base.SetConfiguration(cf);
    }

        private void FormMain_FormClosing(object sender, FormClosingEventArgs e){

        _isClosing = true;

        _timer.Stop();
        _timer.Dispose();
        _timer = null;
    }

    private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e){

        if (_isClosing)
            return;

        readValues();
    }

    public override object[] GetSupportedControlCommands()
    {
      return new string[] {
      Common.Quote(_CMD_GET_VALUES),
      Common.Quote(_CMD_DEBUG_ON),
      Common.Quote(_CMD_DEBUG_OFF)
    };
    }

    public override void SendCommand(string windowCommand, params string[] values)
    {

        if (windowCommand.Equals(_CMD_GET_VALUES, StringComparison.InvariantCultureIgnoreCase))
        {
            readValues();
        }
        else if (windowCommand.Equals(_CMD_DEBUG_OFF, StringComparison.InvariantCultureIgnoreCase))
        {
            Invokers.SetChecked(cbDebug, false);
        }
        else if (windowCommand.Equals(_CMD_DEBUG_ON, StringComparison.InvariantCultureIgnoreCase))
        {
            Invokers.SetChecked(cbDebug, true);
        }
        else
        {
            base.SendCommand(windowCommand, values);
        }
    }

    /// 
    /// When the project is saving, give it a copy of our config
    /// 
    public override ARC.Config.Sub.PluginV1 GetConfiguration() {

      _cf.SetCustomObjectV2(_config);

      return base.GetConfiguration();
    }

    /// 
    /// The user pressed the config button in the title bar. Show the config menu and handle the changes to the config.
    /// 
    public override void ConfigPressed() {

      using (var form = new ConfigForm()) {

        form.SetConfiguration(_config);

        if (form.ShowDialog() != DialogResult.OK)
          return;

        _config = form.GetConfiguration();
      }
    }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void cbDebug_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

    void readValues()
    {
        try
        {

            var response = EZBManager.EZBs[0].SendCommandData(12, 0x00);

            UInt16 AngleZ = BitConverter.ToUInt16(response, 0);
            UInt16 AngleY = BitConverter.ToUInt16(response, 2);
            UInt16 AngleX = BitConverter.ToUInt16(response, 4);
            UInt16 servoRvalue = BitConverter.ToUInt16(response, 6);
            UInt16 servoPvalue = BitConverter.ToUInt16(response, 8);
            UInt16 servoYvalue = BitConverter.ToUInt16(response, 10);

            ARC.Scripting.VariableManager.SetVariable("$AngleZ", AngleZ);
            ARC.Scripting.VariableManager.SetVariable("$AngleY", AngleY);
            ARC.Scripting.VariableManager.SetVariable("$AngleX", AngleX);
            ARC.Scripting.VariableManager.SetVariable("$servoRvalue", servoRvalue);
            ARC.Scripting.VariableManager.SetVariable("$servoPvalue", servoPvalue);
            ARC.Scripting.VariableManager.SetVariable("$servoYvalue", servoYvalue);

            if (Invokers.GetCheckedValue(cbDebug))
                Invokers.SetAppendText(textBox1, true, "AngleZ: {0}, AngleY: {1}, AngelX: {3}, Yaw: {4}, Pitch: {5}, Roll: {6}", AngleZ, AngleY, AngleX, servoYvalue, servoPvalue, servoRvalue);
            }
               catch (Exception ex)
            {
               Invokers.SetAppendText(textBox1, true, ex.ToString());
        }

    }

        private void button1_Click(object sender, EventArgs e)
        {
            readValues();
        }

        private void cbUpdate_CheckedChanged(object sender, EventArgs e)
        {
            if (cbUpdate.Checked)
                _timer.Start();
            else
                _timer.Stop();
        }
    }
}

PRO
Synthiam
#23  

That's good progress. Now you can look at the debug log window that i have suggested so you can see why it's disconnecting

#24  

When I run this from the VS debugger I get no errors that I can see.   also nothing shows up in the text area of the skill is there another debug log I can look at?  Sorry if this is a stupid question.