/// <summary>
        /// 获取机器人当前位置。姿态使用XYZ欧拉角表示
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public int getCurrentLoc(out double[] arr)
        {
            int ret = 0;

            arr = new double[6];
            if (controller == null)
            {
                ret = (int)ErrorCode.err_no_controller;
                return(ret);
            }
            controller.Logon(UserInfo.DefaultUser);
            ABB.Robotics.Controllers.RapidDomain.Task motion_task = controller.Rapid.GetTask("T_ROB1");
            if (motion_task == null)
            {
                ret = (int)ErrorCode.err_no_such_task;
                return(ret);
            }
            RobTarget current_loc = motion_task.GetRobTarget();

            arr[0] = current_loc.Trans.X;
            arr[1] = current_loc.Trans.Y;
            arr[2] = current_loc.Trans.Z;
            current_loc.Rot.ToEulerAngles(out arr[3], out arr[4], out arr[5]);
            return(ret);
        }
Exemplo n.º 2
0
        public void InitDataStream()
        {
            // This loads the Task, ensure that the task name matches in robot studio
            ABB.Robotics.Controllers.RapidDomain.Task tRob1 = controller.Rapid.GetTask("T_ROB1");
            if (tRob1 != null)
            {
                // this line reads the variable Start on Rapid and passes the value to this app
                rd_start = tRob1.GetRapidData("Module1", "Start");

                if (rd_start.Value is Num)
                {
                    // We set the process flag to the start variable
                    processFlag = (Num)rd_start.Value;
                }

                rd_begin = tRob1.GetRapidData("Module1", "flag");

                if (rd_begin.Value is Num)
                {
                    processFlag = (Num)rd_start.Value;
                }

                position = tRob1.GetRapidData("Module1", "position");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves the main task from the ABB controller, typically 't_rob1'.
        /// </summary>
        /// <returns></returns>
        private bool LoadMainTask()
        {
            if (controller == null)
            {
                Console.WriteLine("Cannot retreive main task: no controller available");
                return(false);
            }

            try
            {
                ABB.Robotics.Controllers.RapidDomain.Task[] tasks = controller.Rapid.GetTasks();
                if (tasks.Length > 0)
                {
                    tRob1Task = tasks[0];
                    Console.WriteLine("Retrieved task " + tRob1Task.Name);
                    return(true);
                }
                else
                {
                    tRob1Task = null;
                    Console.WriteLine("Could not retrieve any task from the controller");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not retrieve main task from controller");
                Console.WriteLine(ex);
            }


            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Loads a module to the device from a text resource in the assembly, with a target name on the controller.
        /// </summary>
        /// <param name="resourceName"></param>
        /// <param name="targetName"></param>
        /// <returns></returns>
        public bool LoadModuleToTask(ABBTask task, string module, string targetName)
        {
            if (!_isConnected)
            {
                throw new Exception("Cannot load program, not connected to controller");
            }

            string path = Path.Combine(Path.GetTempPath(), targetName);

            if (!IO.SaveStringToFile(path, module, Encoding.ASCII))
            {
                throw new Exception("Could not save module to temp file");
            }
            else
            {
                logger.Debug("Saved module to " + path);
            }

            if (!UploadFileToController(path))
            {
                throw new Exception($"Could not upload module {path} to controller");
            }

            if (!LoadModuleFromControllerToTask(task, targetName))
            {
                throw new Exception($"Could not load module {targetName} from controller to task {task.Name}");
            }

            return(true);
        }
Exemplo n.º 5
0
 private void button_checkProgramm_Click(object sender, EventArgs e)
 {
     try
     {
         tRob1 = controller.Rapid.GetTask("T_ROB1");
         ReadOnlyCollection <ProgramError> errors = tRob1.CheckProgram().Errors;
         if (errors == null)
         {
             MessageBox.Show("可以···未检查到程序错误!");
         }
         else
         {
             foreach (ProgramError programError in errors)
             {
                 string taskName   = programError.TaskName;
                 string moduleName = programError.ModuleName;
                 int    Line       = programError.Line;
                 int    column     = programError.Column;
                 MessageBox.Show($"(っ °Д °;)っ发现程序错误!\n Task:{taskName} \n 模块:{moduleName} \n 出现在第 {Line} 行 \n 第 {column} 列");
             }
         }
     }
     catch (Exception ex)
     { MessageBox.Show(ex.Message, "错误"); }
 }
        /// <summary>
        /// 等待机器人运行
        /// </summary>
        private void WaitForRoutineFinish()
        {
            ABB.Robotics.Controllers.RapidDomain.Task task = AbbCtrl.Rapid.GetTask("T_ROB1");//获得机器人正在执行的任务

            while (IsStart == false || task.ExecutionStatus == TaskExecutionStatus.Running || task.ExecutionStatus != TaskExecutionStatus.Ready || task.ExecutionStatus == TaskExecutionStatus.UnInitiated || task.ExecutionStatus == TaskExecutionStatus.Unknown)
            {
                Thread.Sleep(100);
            }
        }
Exemplo n.º 7
0
 private void TraceTask(ABB.Robotics.Controllers.RapidDomain.Task t)
 {
     Console.WriteLine("\t Task: {0}", t.Name);
     Module[] modules = t.GetModules();
     foreach (Module m in modules)
     {
         TraceModule(m);
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Disposes the task object. This has to be done manually, since COM objects are not
 /// automatically garbage collected.
 /// </summary>
 /// <returns></returns>
 private bool ReleaseMainTask()
 {
     if (tMainTask != null)
     {
         tMainTask.Dispose();
         tMainTask = null;
         return(true);
     }
     return(false);
 }
Exemplo n.º 9
0
        private void refreshModuleList()
        {
            listBox_moduleList.Items.Clear();

            tRob1 = controller.Rapid.GetTask("T_ROB1");
            Module[] module = tRob1.GetModules();

            foreach (Module modFiles in module)
            {
                listBox_moduleList.Items.Add(modFiles);
            }
        }
        private void button_Read_Click(object sender, EventArgs e)
        {
#if ROBOT_EXIST
            ControllerInfo controllerInfo = main_form.controllers[0]; // 我们很自信,就一个控制器,以后有多个的话,这里肯定需要修改
            Controller     ctrl           = ControllerFactory.CreateFrom(controllerInfo);
            ctrl.Logon(UserInfo.DefaultUser);
            tRob1 = ctrl.Rapid.GetTask("T_ROB1");
#endif
            string module_name = comboBox_Module.SelectedItem.ToString();
            string var_type    = comboBox_Var.SelectedItem.ToString();
            int    var_type_no = comboBox_Var.SelectedIndex;
            string var_name    = textBox_varName.Text;
#if ROBOT_EXIST
            string str_read_res = "";
            switch (var_type)
            {
            case "Num":
                RD_time      = tRob1.GetRapidData(module_name, var_name);
                ABB_Num_time = (Num)RD_time.Value;
                str_read_res = ABB_Num_time.ToString();
                break;

            case "RobTarget":
                RD_rt        = tRob1.GetRapidData(module_name, var_name);
                ABB_RT_rt    = (RobTarget)RD_rt.Value;
                str_read_res = ABB_RT_rt.ToString();
                break;

            default:
                break;
            }
            textBox1_Result.Text = str_read_res;
            textBox1_Result.Update();
            ctrl.Logoff();
            ctrl.Dispose();
#else
            switch (var_type)
            {
            case "Num":
                textBox1_Result.Text = "Num";
                break;

            case "RobTarget":
                textBox1_Result.Text = "RobTarget";
                break;

            default:
                break;
            }
            textBox1_Result.Update();
#endif
        }
Exemplo n.º 11
0
        private bool LoadFirstTask()
        {
            var tasks = controller.Rapid.GetTasks();

            if (tasks.Length == 0)
            {
                logger.Error("No tasks available on the controller");
                return(false);
            }

            tMainTask = tasks[0];

            return(true);
        }
Exemplo n.º 12
0
        public static string LoadModuleFromFile(string moduleFilePath)
        {
            //Get Station object
            Station station = Project.ActiveProject as Station;

            //Check for existance of Module
            if (System.IO.File.Exists(moduleFilePath))
            {
                try
                {
                    RsTask task = station.ActiveTask;
                    if (task != null)
                    {
                        RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent;
                        ABB.Robotics.Controllers.Controller controller =
                            new ABB.Robotics.Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));

                        if (controller != null)
                        {
                            //Request Mastership
                            using (ABB.Robotics.Controllers.Mastership m =
                                       ABB.Robotics.Controllers.Mastership.Request(controller.Rapid))
                            {
                                if (controller.Rapid.ExecutionStatus ==
                                    ABB.Robotics.Controllers.RapidDomain.ExecutionStatus.Stopped)
                                {
                                    //Load Module if Rapid Execution State is stopped
                                    ABB.Robotics.Controllers.RapidDomain.Task vTask = controller.Rapid.GetTask(task.Name);
                                    bool loadResult = vTask.LoadModuleFromFile(moduleFilePath,
                                                                               ABB.Robotics.Controllers.RapidDomain.RapidLoadMode.Replace);
                                    Thread.Sleep(1000);
                                }
                            }
                        }
                    }
                }
                catch (ABB.Robotics.GeneralException gex)
                {
                    Logger.AddMessage(new LogMessage(gex.Message.ToString()));
                }

                catch (Exception ex)
                {
                    Logger.AddMessage(new LogMessage(ex.Message.ToString()));
                }
            }
            return("Loading module: " + moduleFilePath);
        }
Exemplo n.º 13
0
 /// <summary>
 /// 加载控制器上的rapid程序
 /// </summary>
 void loadModule()
 {
     try
     {
         tRob1 = controller.Rapid.GetTask("T_ROB1");
         string filePath = controller.FileSystem.GetRemotePath(listBox2_fileStore.SelectedItem.ToString());
         Console.WriteLine("目录:" + filePath);
         string ProgramFileName = Path.ChangeExtension(filePath, ".mod");
         using (Mastership m = Mastership.Request(controller))
         {
             tRob1.LoadModuleFromFile(Path.GetFileName(filePath), RapidLoadMode.Replace);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "错误");
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Loads a module on a task from the controllers filesystem.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="filename"></param>
        /// <param name="wipeout"></param>
        /// <returns></returns>
        internal bool LoadModuleFromControllerToTask(ABBTask task, string filename, bool wipeout = true)
        {
            // For the time being, we will always wipe out previous modules on load
            if (wipeout)
            {
                if (ClearAllModules(task) < 0)
                {
                    throw new Exception($"Error clearing modules on task {task.Name}");
                }
            }

            // Load the module
            bool success = false;

            try
            {
                using (Mastership.Request(controller.Rapid))
                {
                    FileSystem fs         = controller.FileSystem;
                    string     remotePath = fs.RemoteDirectory + "/" + REMOTE_BUFFER_DIR;
                    bool       dirExists  = fs.DirectoryExists(REMOTE_BUFFER_DIR);
                    if (!dirExists)
                    {
                        logger.Error($"No directory named {remotePath} found on controller");
                        return(false);
                    }

                    // Loads a Rapid module to the task in the robot controller
                    success = task.LoadModuleFromFile($"{remotePath}/{filename}", RapidLoadMode.Replace);
                }
            }
            catch (Exception ex)
            {
                logger.Debug(ex);
                throw new Exception("ERROR: Could not LoadModuleFromControllerToTask");
            }

            if (success)
            {
                logger.Debug($"Sucessfully loaded {filename} to {task.Name}");
            }

            return(success);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Retrieves the main task from the ABB controller, typically 'T_ROB1'.
        /// </summary>
        /// <returns></returns>
        private bool LoadMainTask()
        {
            if (controller == null)
            {
                logger.Debug("Cannot retrieve main task: no controller available");
                return(false);
            }

            tMainTask = controller.Rapid.GetTask("T_ROB1");
            if (tMainTask == null)
            {
                logger.Error("Could not retrieve task T_ROB1 from the controller");

                // Quick workaround for Yumis to get the left hand
                if (!LoadFirstTask())
                {
                    return(false);
                }
            }

            logger.Debug("Retrieved task " + tMainTask.Name);
            return(true);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Deletes all existing modules from main task in the controller.
        /// </summary>
        /// <returns></returns>
        private int ClearAllModules(ABBTask task)
        {
            if (controller == null)
            {
                logger.Debug("Cannot clear modules: not connected to controller");
                return(-1);
            }

            if (task == null)
            {
                logger.Debug("Cannot clear modules: task not avaliable");
                return(-1);
            }

            int count = 0;

            try
            {
                using (Mastership.Request(controller.Rapid))
                {
                    ABB.Robotics.Controllers.RapidDomain.Module[] modules = task.GetModules();
                    foreach (ABB.Robotics.Controllers.RapidDomain.Module m in modules)
                    {
                        logger.Verbose($"Deleting module {m.Name} from {task.Name}");
                        m.Delete();
                        count++;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Debug($"CLEAR MODULES ERROR: {ex}");
            }

            logger.Debug($"Cleared {count} modules from main task");
            return(count);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 连接控制器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void connectBtn_Click(object sender, EventArgs e)
        {
            if (this.connectBtn.Text == "连接")
            {
                if (this.controllerscomboBox.SelectedItem == null)
                {
                    Data.LogString = "[msg]  请选择一个控制器";
                    return;
                }
                //字符串分割
                string[] controllerString = ((string)this.controllerscomboBox.SelectedItem).Split('/');
                //找到控制器
                ListViewItem item = this.listView1.FindItemWithText(controllerString[0]);
                if (item.Tag != null)
                {
                    try
                    {
                        ControllerInfo controllerInfo = (ControllerInfo)item.Tag;
                        if (this.abbcontroller != null)
                        {
                            this.abbcontroller.Logoff();
                            this.abbcontroller.Dispose();
                            this.abbcontroller = null;
                        }
                        this.abbcontroller = ControllerFactory.CreateFrom(controllerInfo);
                        this.abbcontroller.Logon(UserInfo.DefaultUser);             //连接到控制器

                        this.abbtask = this.abbcontroller.Rapid.GetTask("T_ROB1");  //初始化abbTask
                        this.abblog  = this.abbcontroller.EventLog;                 //初始化abblog
                        this.logcomboBox.SelectedIndex = 0;
                        this.abblog.MessageWritten    += Abblog_MessageWritten;     //给abblog添加订阅事件

                        this.connectBtn.Text      = "断开连接";
                        this.connectBtn.BackColor = Color.Green;
                        Timer_ON       = true;                          //启动定时器更新状态信息
                        Data.LogString = "ABB 机器人控制器连接成功";
                    }
                    catch (Exception exception)
                    {
                        Data.LogString = exception.Message;
                    }
                }
                else
                {
                    this.abblog.MessageWritten -= Abblog_MessageWritten;        //取消订阅
                    Data.LogString              = "选择的控制器无效";
                }
            }
            else if (this.connectBtn.Text == "断开连接")
            {
                if (this.abbcontroller != null)         //断开控制器连接
                {
                    this.abbcontroller.Logoff();
                    this.abbcontroller.Dispose();
                    this.abbcontroller = null;
                }
                //更新控件
                this.connectBtn.Text      = "连接";
                this.connectBtn.BackColor = Color.Transparent;
                Timer_ON       = false;                 //停止机器人状态更新
                Data.LogString = "ABB机器人连接断开";
            }
        }
Exemplo n.º 18
0
        public static bool LoadProgramFromFile(string filePath)
        {
            bool result = false;

            Project.UndoContext.BeginUndoStep("LoadProgramFromFile");
            //Get Station object
            #region LoadProgramFromFileStep1
            Station station = Project.ActiveProject as Station;
            #endregion

            //Check for existance of Program
            if (System.IO.File.Exists(filePath))
            {
                try
                {
                    RsTask task = station.ActiveTask;

                    if (task != null)
                    {
                        //Get RsIrc5Controller instance
                        #region LoadProgramFromFileStep2
                        RsIrc5Controller rsIrc5Controller = (RsIrc5Controller)task.Parent;
                        //Get virtual controller instance from  RsIrc5Controller
                        ABB.Robotics.Controllers.Controller controller =
                            new ABB.Robotics.Controllers.Controller(new Guid(rsIrc5Controller.SystemId.ToString()));
                        //get task
                        ABB.Robotics.Controllers.RapidDomain.Task vTask = controller.Rapid.GetTask(task.Name);
                        #endregion

                        //Request Mastership
                        #region LoadProgramFromFileStep3
                        using (ABB.Robotics.Controllers.Mastership m =
                                   ABB.Robotics.Controllers.Mastership.Request(controller.Rapid))
                        #endregion
                        {
                            if (controller.Rapid.ExecutionStatus ==
                                ABB.Robotics.Controllers.RapidDomain.ExecutionStatus.Stopped)
                            {
                                //Load Program if Rapid Execution is stopped
                                #region LoadProgramFromFileStep4
                                vTask.LoadProgramFromFile(filePath,
                                                          ABB.Robotics.Controllers.RapidDomain.RapidLoadMode.Replace);
                                #endregion
                                System.Threading.Thread.Sleep(1000);
                                result = true;
                            }
                        }
                    }
                }
                catch (ABB.Robotics.GeneralException gex)
                {
                    Logger.AddMessage(new LogMessage(gex.Message.ToString()));
                    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                    result = false;
                }
                catch (Exception ex)
                {
                    Logger.AddMessage(new LogMessage(ex.Message.ToString()));
                    Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
                    result = false;
                }
                finally
                {
                    Project.UndoContext.EndUndoStep();
                }
            }
            return(result);
        }