/// <summary>
 /// Move the motor to a specific position
 /// </summary>
 /// <param name="pos">Position where the motor needs to go to</param> <!-- need to explain more about the value and if there is a max? -->
 public bool SetPosition(int pos)
 {
     if (ticController.get_variables())
     {
         if (ticController.status_vars.energized)
         {
             // Check if the pos is less than 0 as the motors home value should always be 0
             if (pos <= 0)
             {
                 pos = 0;
             }
             ticController.set_target_position(pos);
             while (ticController.get_variables())
             {
                 if (ticController.vars.current_position == pos)
                 {
                     break;
                 }
             }                                                                                                //
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
예제 #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (m_conected)
            {
                m_tic.reset_command_timeout();
                m_tic.get_variables();
                m_tic.get_status_variables();
                labelPosition.Text = m_tic.vars.current_position.ToString();


                string status = "";

                foreach (var prop in m_tic.status_vars.GetType().GetProperties())
                {
                    status = status + string.Format("{0}={1}\n\r", prop.Name, prop.GetValue(m_tic.status_vars, null));
                }

                string vars = "";


                foreach (var prop in m_tic.vars.GetType().GetProperties())
                {
                    vars = vars + string.Format("{0}={1}\n\r", prop.Name, prop.GetValue(m_tic.vars, null));
                }

                labelStatus.Text = status;
                labelVars.Text   = vars;
                if (m_moving && m_tic.in_position())
                {
                    m_moving                 = false;
                    buttonGoto.Text          = "GOTO";
                    buttonHome.Enabled       = !m_moving;
                    checkBoxJogLeft.Enabled  = !m_moving;
                    checkBoxJogRigth.Enabled = !m_moving;
                }
                if (m_homing && m_tic.in_home())
                {
                    m_homing                 = false;
                    buttonHome.Text          = "HOME";
                    buttonGoto.Enabled       = !m_homing;
                    checkBoxJogLeft.Enabled  = !m_homing;
                    checkBoxJogRigth.Enabled = !m_homing;
                }

                if (m_decelerating && m_tic.vars.current_velocity == 0)
                {
                    m_decelerating     = false;
                    buttonGoto.Enabled = true;
                    buttonHome.Enabled = true;
                }
            }
        }