/******************************************************************************/ 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); }
/// <summary> /// Callback function to update _spd_mf_array from speed FuzzyMemFunc /// </summary> private void UpdateSpdFuncs(int index, FuzzyMemFuncs.TrapezoidalFunc func) { _spd_mf_array[0 + (index * 4)] = func.p0; _spd_mf_array[1 + (index * 4)] = func.p1; _spd_mf_array[2 + (index * 4)] = func.s0; _spd_mf_array[3 + (index * 4)] = func.s1; if(_picBxSpd != null) { //_picBxSpd.Image = DrawSpdGraph(); _picBxSpd.Image = ResizeImage(DrawSpdGraph(), BM_WIDTH, BM_HEIGHT); } }
private bool SetText(FuzzyMemFuncs.TrapezoidalFunc func) { int pt0_top, pt1_top; if((int)func.p0 >= (int)func.p1) { return false; } pt0_top = (int)func.p0; if(func.s0 != 0) { pt0_top += (0xFF / (int)func.s0); } pt1_top = (int)func.p1; if(func.s1 != 0) { pt1_top -= (0xFF / (int)func.s1); } if(pt0_top > pt1_top) { return false; } _text_box_list[0].TextChanged -= new EventHandler(p0_TextChanged); _text_box_list[0].Text = func.p0.ToString("X2"); _text_box_list[0].SelectionStart = _text_box_list[0].Text.Length; _text_box_list[0].TextChanged += new EventHandler(p0_TextChanged); _text_box_list[0].LostFocus += new EventHandler(p0_LostFocus); _text_box_list[0].Enabled = _enabled; _text_box_list[1].TextChanged -= new EventHandler(p1_TextChanged); _text_box_list[1].Text = func.p1.ToString("X2"); _text_box_list[1].SelectionStart = _text_box_list[1].Text.Length; _text_box_list[1].TextChanged += new EventHandler(p1_TextChanged); _text_box_list[1].LostFocus += new EventHandler(p1_LostFocus); _text_box_list[1].Enabled = _enabled; _text_box_list[2].TextChanged -= new EventHandler(s0_TextChanged); _text_box_list[2].Text = func.s0.ToString("X2"); _text_box_list[2].SelectionStart = _text_box_list[2].Text.Length; _text_box_list[2].TextChanged += new EventHandler(s0_TextChanged); _text_box_list[2].LostFocus += new EventHandler(s0_LostFocus); _text_box_list[2].Enabled = _enabled; _text_box_list[3].TextChanged -= new EventHandler(s1_TextChanged); _text_box_list[3].Text = func.s1.ToString("X2"); _text_box_list[3].SelectionStart = _text_box_list[3].Text.Length; _text_box_list[3].TextChanged += new EventHandler(s1_TextChanged); _text_box_list[3].LostFocus += new EventHandler(s1_LostFocus); _text_box_list[3].Enabled = _enabled; return true; }
/// <summary> /// Callback function to update _pos_mf_array from position FuzzyMemFunc /// </summary> private void UpdatePosFuncs(int index, FuzzyMemFuncs.TrapezoidalFunc func) { _pos_mf_array[0 + (index * 4)] = func.p0; _pos_mf_array[1 + (index * 4)] = func.p1; _pos_mf_array[2 + (index * 4)] = func.s0; _pos_mf_array[3 + (index * 4)] = func.s1; if(_picBxPosErr != null) { //_picBxPosErr.Image = DrawPosGraph(); _picBxPosErr.Image = ResizeImage(DrawPosGraph(), BM_WIDTH, BM_HEIGHT); } }