Example #1
0
        /******************************************************************************/
        public MainForm()
        {
            _app_ver = Assembly.GetExecutingAssembly().GetName().Version;
              _dll_ver = Master.Version;

              InitializeComponent();

              // Hide settings menus and controls until servo network is detected
              tabControl1.Hide();

              _servo_ht = new SortedDictionary<byte, Servo>();

              _active_servo = null;

              // Drill down to locate containers where programatically constructed elements located (yuck!)
              GroupBox _rules_container = null;
              // Unfocus label required to remove focus from rules comboboxes after selection - hide under another control (yuck!)
              Label _unfocus_lbl = null;
              foreach(Control c_0 in this.Controls)
              {
            if(c_0.Name == "tabControl1")
            {
              TabControl tab_ctl_0 = (TabControl)c_0;
              foreach(Control c_1 in tab_ctl_0.Controls)
              {
            if(c_1.Name == "tabPageSetup")
            {
              TabPage tab_page_0 = (TabPage)c_1;
              foreach(Control c_2 in tab_page_0.Controls)
              {
                if(c_2.Name == "tabServoSettings")
                {
                  TabControl tab_ctl_1 = (TabControl)c_2;
                  foreach(Control c_3 in tab_ctl_1.Controls)
                  {
                    if(c_3.Name == "tabPageSetupFuzzy")
                    {
                      TabPage tab_page_1 = (TabPage)c_3;
                      foreach(Control c_4 in tab_page_1.Controls)
                      {
                        if(c_4.Name == "gbSetFuzzyRules")
                        {
                          GroupBox gbx = (GroupBox)c_4;
                          _rules_container = gbx;
                          foreach(Control c_5 in gbx.Controls)
                          {
                            if(c_5.Name == "lblUnfocus")
                            {
                              _unfocus_lbl = (Label)c_5;
                            }
                          }
                          /*foreach(Control c_5 in gbx.Controls)
                          {
                            if(c_5.Name == "pnlFuzzyRules")
                            {
                              _rules_container = (Panel)c_5;
                            }
                            if(c_5.Name == "lblUnfocus")
                            {
                              _unfocus_lbl = (Label)c_5;
                            }
                          }*/
                        }
                        if(c_4.Name == "gbSetFuzzyMF")
                        {
                          _fuzzy_mem_funcs_obj = new FuzzyMemFuncs((GroupBox)c_4);
                        }
                      }

                      if(_rules_container != null && _unfocus_lbl != null)
                      {
                        _fuzzy_rules_obj = new FuzzyRules(_rules_container, _unfocus_lbl);
                      }
                      else
                      {
                        _fuzzy_rules_obj = null;
                        MsgBox.Show("Fuzzy Rules Panel not found");
                      }

                      if(_fuzzy_mem_funcs_obj == null)
                      {
                        MsgBox.Show("Fuzzy Mem Func groupbox not found");
                      }
                    }

                    if(c_3.Name == "tabPageSetupControl")
                    {
                      // Set top level groupboxes in "Servo Control" tab to have bold text
                      TabPage tab_page_2 = (TabPage)c_3;
                      foreach(Control c_5 in tab_page_2.Controls)
                      {
                        if(c_5 is GroupBox)
                        {
                          c_5.Font = new Font(c_5.Font, FontStyle.Bold);
                          foreach(Control c_5_ctl in c_5.Controls)
                          {
                            c_5_ctl.Font = new Font(c_5.Font, FontStyle.Regular);
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
              }
            }
              }

              // Populate comboboxes
              InitializeControls();

              // Disable symmetric control points.
              cbxMemFuncCtlPts.Checked = false;
              CtlPtsActive(false);
        }
Example #2
0
        private bool GetServoNodes()
        {
            // First slave selector is "no slave" selection
              _slave_selector = new List<slaveSelector>();
              Slave _null_slave = null;
              _slave_selector.Add(new slaveSelector(_null_slave));

              if(Master.SlaveHashtable != null)
              {
            // Node zero always exists if any non-zero nodes present
            _group = Master.GroupNode;

            Dictionary<byte, Slave>.ValueCollection valueColl = Master.SlaveHashtable.Values;
            foreach(Slave slave in valueColl)
            {
              // Build new Servo object if not already existent
              if(!_servo_ht.ContainsKey(slave.Id) && slave.IsReady)
              {
            Servo servo = new Servo(slave);
            _servo_ht.Add(slave.Id, servo);
            _slave_selector.Add(new slaveSelector(slave));
              }
            }
              }
              else
              {
            MsgBox.Show(this, String.Format("{0} does not connect to a slave network\n", _port), "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            return false;
              }

              // Populate Slave Node combobox
              cboSlaveNode.DataSource = _slave_selector;
              cboSlaveNode.DisplayMember = "Description";
              cboSlaveNode.ValueMember = "Id";
              if(_slave_selector.Count == 2)
              {
            // Single servo node - Update controls with selection
            cboSlaveNode.SelectedIndex = 1;
              }

              return true;
        }
 /******************************************************************************/
 /// <summary>
 /// plotData - Display statistics
 /// </summary>
 private void plotData(Servo servo)
 {
     if(cbxShowStatsPrev.Checked)
       {
     plot(servo.StatsPrev);
     setCtlPts(servo.CtlPtsPrev);
       }
       else
       {
     plot(servo.StatsCur);
     setCtlPts(servo.CtlPtsCur);
       }
 }
Example #4
0
        private void cboSlaveNode_SelectedIndexChanged(object sender, EventArgs e)
        {
            // first "null" selection returns obj instead of value ?!?
              if(cboSlaveNode.SelectedValue is slaveSelector)
              {
            _active_servo = null;
              }
              else
              {
            if((byte)cboSlaveNode.SelectedValue != NULL_NODE &&
               _servo_ht != null &&
               _servo_ht.ContainsKey((byte)cboSlaveNode.SelectedValue))
            {
              _active_servo = _servo_ht[(byte)cboSlaveNode.SelectedValue];

              // Prevent calling this if combobox selections not initialized
              this.InvokeOnClick(btnServoCtlLoad, EventArgs.Empty);

              this.InvokeOnClick(btnStatusRead, EventArgs.Empty);
              this.InvokeOnClick(btnMotionCtlLoad, EventArgs.Empty);
              this.InvokeOnClick(btnLimitCtlLoad, EventArgs.Empty);

              // Automatically populate fuzzy vars
              this.InvokeOnClick(btnGetMF, EventArgs.Empty);
              this.InvokeOnClick(btnGetRules, EventArgs.Empty);
            }
            else
            {
              _active_servo = null;
            }
              }
        }
Example #5
0
 /******************************************************************************/
 public RndForm(Servo servo)
 {
     InitializeComponent();
       _servo = servo;
 }