Example #1
0
 private void sethome_request(Object sender, EventArgs e)
 {
     command_request = _command_request.SETHOME;
 }
Example #2
0
 private void setbrake_request(Object sender, EventArgs e)
 {
     command_request = _command_request.SETBRAKE;
 }
Example #3
0
        private void gui_admin_func(Object source, System.Timers.ElapsedEventArgs e)
        {
            if (this.InvokeRequired)
            {
                try
                {
                    this.BeginInvoke(new System.Timers.ElapsedEventHandler(gui_admin_func), new object[2] {
                        source, e
                    });
                    return;
                }
                catch (ObjectDisposedException exception_catched)
                {
                    Console.WriteLine(exception_catched.Message);
                    gui_admin.Stop();
                    return;
                }
            }
            label7.Text   = trackBar1.Value.ToString();
            label8.Text   = trackBar2.Value.ToString();
            label9.Text   = trackBar3.Value.ToString();
            textBox1.Text = arduino.motors[0].position.ToString();
            textBox2.Text = arduino.motors[1].position.ToString();
            textBox3.Text = (pitch_rotation * 360).ToString();
            textBox4.Text = arduino.motors[0].setpoint.ToString();
            textBox5.Text = arduino.motors[1].setpoint.ToString();
            switch (arduino.state)
            {
            case _state.DISCONNECTED:
                this.Text = "DISCONNECTED";
                String[] ports = arduino.available_ports();
                if (this.actual_ports.Length == 255)
                {
                    foreach (String port in ports)
                    {
                        comboBox1.Items.Add(port);
                    }
                    comboBox1.Refresh();
                }
                else if (!this.actual_ports.SequenceEqual(ports))
                {
                    comboBox1.Items.Clear();
                    foreach (String port in ports)
                    {
                        comboBox1.Items.Add(port);
                    }
                    comboBox1.Refresh();
                }
                this.actual_ports = ports;
                break;

            case _state.INITIALIZING:
                this.Text       = "INITIALIZING";
                trackBar1.Value = Convert.ToInt32(arduino.motors[0].position);
                trackBar2.Value = Convert.ToInt32(arduino.motors[1].position);
                break;

            case _state.CONTROLLING:
                //this.Text = "CONTROLLING";

                current_time += 5;
                chart1.Series["Setpoint1"].Points.AddXY(Convert.ToDouble(current_time) / 1000, arduino.motors[0].setpoint);
                chart1.Series["Position1"].Points.AddXY(Convert.ToDouble(current_time) / 1000, arduino.motors[0].position);
                chart1.Series["Setpoint2"].Points.AddXY(Convert.ToDouble(current_time) / 1000, arduino.motors[1].setpoint);
                chart1.Series["Position2"].Points.AddXY(Convert.ToDouble(current_time) / 1000, arduino.motors[1].position);
                chart1.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
                chart1.ChartAreas[0].AxisY.LabelStyle.Enabled = false;
                chart1.ChartAreas[0].AxisX.Maximum            = Math.Round(Convert.ToDouble(current_time) / 1000, 2);
                chart1.ChartAreas[0].AxisX.Minimum            = Math.Round((Convert.ToDouble(current_time) / 1000) - 5.0, 2);
                chart1.ChartAreas[0].AxisX.Interval           = 1;
                chart1.ChartAreas[0].AxisY.Maximum            = 1024;
                chart1.ChartAreas[0].AxisY.Minimum            = 0;
                chart1.ChartAreas[0].AxisY.Interval           = 1024 / 16;

                switch (command_request)
                {
                case _command_request.SETPOINT:
                {
                    arduino.set_homming_calibration(trackBar4.Value == 1);
                    long[] setpoints;
                    if (trackBar4.Value == 1)
                    {
                        if (arduino.command_type == command_types.HOME)
                        {
                            this.Text = "CONTROLLING - HOME";
                            setpoints = new long[] { arduino.motors[0].home, arduino.motors[1].home };
                        }
                        else if (arduino.command_type == command_types.START)
                        {
                            this.Text = "CONTROLLING - START";
                            setpoints = new long[] { arduino.motors[0].start, arduino.motors[1].start };
                        }
                        else
                        {
                            this.Text = "CONTROLLING - NORMAL";
                            setpoints = new long[] { convert_to_arduino(pitch_rotation), convert_to_arduino(pitch_rotation) };
                        }
                    }
                    else
                    {
                        if (arduino.command_type == command_types.HOME)
                        {
                            this.Text = "CONTROLLING - HOME";
                            setpoints = new long[] { arduino.motors[0].home, arduino.motors[1].home };
                        }
                        else if (arduino.command_type == command_types.START)
                        {
                            this.Text = "CONTROLLING - START";
                            setpoints = new long[] { arduino.motors[0].start, arduino.motors[1].start };
                        }
                        else
                        {
                            this.Text = "CONTROLLING - NORMAL";
                            setpoints = new long[] { trackBar1.Value, trackBar2.Value };
                        }
                    }


                    arduino.command(arduino_command.CONTROLLING, setpoints);
                }
                break;

                case _command_request.SETHOME:
                {
                    long[] sethomepoints = { trackBar1.Value, trackBar2.Value };
                    arduino.command(arduino_command.SETHOME, sethomepoints);
                    command_request = _command_request.SETPOINT;
                }
                break;

                case _command_request.SETBRAKE:
                {
                    long[] setbrakevalues = { trackBar3.Value, trackBar3.Value };
                    arduino.command(arduino_command.SETBRAKE, setbrakevalues);
                    command_request = _command_request.SETPOINT;
                }
                break;
                }
                break;

            case _state.HOMMING_LOCK:
                this.Text = "HOMMING_LOCK";
                break;
            }
        }