Example #1
0
        static int Main(string[] args)
        {
            var now = RobotRaconteurNode.s.NowUTC;

            bool   shouldShowHelp          = false;
            string robot_info_file         = null;
            bool   left_arm                = false;
            bool   right_arm               = false;
            bool   left_electric_gripper   = false;
            bool   right_electric_gripper  = false;
            string left_gripper_info_file  = null;
            string right_gripper_info_file = null;

            var options = new OptionSet {
                { "robot-info-file=", n => robot_info_file = n },
                { "left-arm", n => left_arm = n != null },
                { "right-arm", n => right_arm = n != null },
                { "left-electric-gripper", n => left_electric_gripper = n != null },
                { "right-electric-gripper", n => right_electric_gripper = n != null },
                { "left-gripper-info-file=", n => left_gripper_info_file = n },
                { "right-gripper-info-file=", n => right_gripper_info_file = n },
                { "h|help", "show this message and exit", h => shouldShowHelp = h != null }
            };

            List <string> extra;

            try
            {
                // parse the command line
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                // output some error message
                Console.Write("BaxterRobotRaconteurDriver: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `BaxterRobotRaconteurDriver --help' for more information.");
                return(1);
            }

            if (shouldShowHelp)
            {
                Console.WriteLine("Usage: BaxterRobotRaconteurDriver [Options+]");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return(0);
            }

            if (robot_info_file == null)
            {
                Console.WriteLine("error: robot-info-file must be specified");
                return(1);
            }

            string nodename = "baxter_robot";

            BaxterRobotArmSelection arm_selection;

            if ((!left_arm && !right_arm) || right_arm && left_arm)
            {
                arm_selection = BaxterRobotArmSelection.both;
            }
            else if (left_arm)
            {
                arm_selection = BaxterRobotArmSelection.left;
                nodename      = "baxter_robot_left_arm";
            }
            else if (right_arm)
            {
                arm_selection = BaxterRobotArmSelection.right;
                nodename      = "baxter_robot_right_arm";
            }
            else
            {
                throw new ArgumentException("Invalid arm selection");
            }

            ushort port = 58660;

            if (arm_selection == BaxterRobotArmSelection.right)
            {
                port = 58661;
            }

            Tuple <RobotInfo, LocalIdentifierLocks> robot_info      = null;
            Tuple <ToolInfo, LocalIdentifierLocks>  left_tool_info  = null;
            Tuple <ToolInfo, LocalIdentifierLocks>  right_tool_info = null;

            BaxterRobot           robot         = null;
            BaxterElectricGripper left_gripper  = null;
            BaxterElectricGripper right_gripper = null;

            try
            {
                robot_info = RobotInfoParser.LoadRobotInfoYamlWithIdentifierLocks(robot_info_file);
                if (left_electric_gripper)
                {
                    left_tool_info = ToolInfoParser.LoadToolInfoYamlWithIdentifierLocks(left_gripper_info_file);
                    left_tool_info.Item1.device_info.parent_device      = robot_info.Item1.device_info.device;
                    left_tool_info.Item1.device_info.device_origin_pose = new NamedPose
                    {
                        parent_frame = new Identifier {
                            name = "left_hand"
                        },
                        pose = new Pose {
                            orientation = new Quaternion {
                                w = 1
                            }
                        }
                    };
                }
                if (right_electric_gripper)
                {
                    right_tool_info = ToolInfoParser.LoadToolInfoYamlWithIdentifierLocks(right_gripper_info_file);
                    right_tool_info.Item1.device_info.parent_device      = robot_info.Item1.device_info.device;
                    right_tool_info.Item1.device_info.device_origin_pose = new NamedPose
                    {
                        parent_frame = new Identifier {
                            name = "right_hand"
                        },
                        pose = new Pose {
                            orientation = new Quaternion {
                                w = 1
                            }
                        }
                    };
                }

                ros_csharp_interop.ros_csharp_interop.init_ros(args, "baxter_robotraconteur_driver", true);

                robot = new BaxterRobot(robot_info.Item1, arm_selection, "");
                robot._start_robot();

                if (left_tool_info != null)
                {
                    left_gripper = new BaxterElectricGripper(left_tool_info.Item1, "left_gripper", "");
                    left_gripper._start_tool();
                }

                if (right_tool_info != null)
                {
                    right_gripper = new BaxterElectricGripper(right_tool_info.Item1, "right_gripper", "");
                    right_gripper._start_tool();
                }

                using (var node_setup = new ServerNodeSetup(nodename, port, args))
                {
                    RobotRaconteurNode.s.RegisterService("robot", "com.robotraconteur.robotics.robot", robot);
                    if (left_gripper != null)
                    {
                        RobotRaconteurNode.s.RegisterService("left_gripper", "com.robotraconteur.robotics.tool", left_gripper);
                    }
                    if (right_gripper != null)
                    {
                        RobotRaconteurNode.s.RegisterService("right_gripper", "com.robotraconteur.robotics.tool", right_gripper);
                    }

                    Console.WriteLine("Press enter to exit");
                    Console.ReadKey();
                }
            }
            finally
            {
                robot_info?.Item2?.Dispose();
                left_tool_info?.Item2?.Dispose();
                right_tool_info?.Item2?.Dispose();
                robot?.Dispose();
                left_gripper?.Dispose();
                right_gripper?.Dispose();
            }

            return(0);
        }
        static int Main(string[] args)
        {
            bool   shouldShowHelp    = false;
            string robot_info_file   = null;
            string robot_name        = null;
            bool   wait_signal       = false;
            bool   electric_gripper  = false;
            bool   vacuum_gripper    = false;
            string gripper_info_file = null;
            string gripper_name      = null;

            var options = new OptionSet {
                { "robot-info-file=", "the robot info YAML file", n => robot_info_file = n },
                { "robot-name=", "override the robot device name", n => robot_name = n },
                { "h|help", "show this message and exit", h => shouldShowHelp = h != null },
                { "electric-gripper", "rethink electric gripper is attached", n => electric_gripper = n != null },
                { "vacuum-gripper", "rethink vacuum gripper is attached", n => vacuum_gripper = n != null },
                { "gripper-info-file=", "gripper info file", n => gripper_info_file = n },
                { "gripper-name=", "override the gripper device name", n => gripper_name = n },
                { "wait-signal", "wait for POSIX sigint or sigkill to exit", n => wait_signal = n != null }
            };

            List <string> extra;

            try
            {
                // parse the command line
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                // output some error message
                Console.Write("SawyerRobotRaconteurDriver: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `SawyerRobotRaconteurDriver --help' for more information.");
                return(1);
            }

            if (shouldShowHelp)
            {
                Console.WriteLine("Usage: SawyerRobotRaconteurDriver [Options+]");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                return(0);
            }

            if (robot_info_file == null)
            {
                Console.WriteLine("error: robot-info-file must be specified");
                return(1);
            }

            if (vacuum_gripper && electric_gripper)
            {
                throw new ArgumentException("--vacuum-gripper and --electric-gripper are mutually exclusive");
            }

            Tuple <RobotInfo, LocalIdentifierLocks> robot_info = null;
            Tuple <ToolInfo, LocalIdentifierLocks>  tool_info  = null;
            SawyerRobot    robot   = null;
            ISawyerGripper gripper = null;


            try
            {
                robot_info = RobotInfoParser.LoadRobotInfoYamlWithIdentifierLocks(robot_info_file, robot_name);

                ros_csharp_interop.ros_csharp_interop.init_ros(args, "sawyer_robotraconteur_driver", false);

                if (electric_gripper || vacuum_gripper)
                {
                    tool_info = ToolInfoParser.LoadToolInfoYamlWithIdentifierLocks(gripper_info_file, gripper_name);
                    tool_info.Item1.device_info.parent_device      = robot_info.Item1.device_info.device;
                    tool_info.Item1.device_info.device_origin_pose = new NamedPose
                    {
                        parent_frame = new Identifier {
                            name = "right_hand", uuid = new com.robotraconteur.uuid.UUID
                            {
                                uuid_bytes = new byte[16]
                            }
                        },
                        pose = new Pose {
                            orientation = new Quaternion {
                                w = 1
                            }
                        }
                    };
                }

                robot = new SawyerRobot(robot_info.Item1, "");
                if (electric_gripper)
                {
                    gripper = new SawyerElectricGripper(tool_info.Item1, "right_gripper", "");
                    gripper._start_tool();
                }
                else if (vacuum_gripper)
                {
                    gripper = new SawyerVacuumGripper(tool_info.Item1, "right_vacuum_gripper", "");
                    gripper._start_tool();
                }

                robot._start_robot();
                using (var node_setup = new ServerNodeSetup("sawyer_robot", 58653, args))
                {
                    var robot_service_ctx = RobotRaconteurNode.s.RegisterService("robot", "com.robotraconteur.robotics.robot", robot);
                    robot_service_ctx.SetServiceAttributes(AttributesUtil.GetDefaultServiceAtributesFromDeviceInfo(robot_info.Item1.device_info));
                    if (gripper != null)
                    {
                        var tool_service_ctx = RobotRaconteurNode.s.RegisterService("gripper", "com.robotraconteur.robotics.tool", gripper);
                        tool_service_ctx.SetServiceAttributes(AttributesUtil.GetDefaultServiceAtributesFromDeviceInfo(tool_info.Item1.device_info));
                    }

                    if (!wait_signal)
                    {
                        Console.WriteLine("Press enter to exit");
                        Console.ReadKey();
                    }
                    else
                    {
                        UnixSignal[] signals = new UnixSignal[] {
                            new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
                            new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
                        };

                        Console.WriteLine("Press Ctrl-C to exit");
                        // block until a SIGINT or SIGTERM signal is generated.
                        int which = UnixSignal.WaitAny(signals, -1);

                        Console.WriteLine("Got a {0} signal, exiting", signals[which].Signum);
                    }
                }
            }
            finally
            {
                robot_info?.Item2?.Dispose();
                tool_info?.Item2?.Dispose();
                robot?.Dispose();
                gripper?.Dispose();
            }

            return(0);
        }
        static int Main(string[] args)
        {
            bool   shouldShowHelp = false;
            string tool_info_file = null;
            string robot_url      = null;
            bool   wait_signal    = false;

            var options = new OptionSet {
                { "tool-info-file=", n => tool_info_file = n },
                { "robot-url=", "url for the robot with signals", n => robot_url = n },
                { "wait-signal", "wait for POSIX sigint or sigkill to exit", n => wait_signal = n != null },
                { "h|help", "show this message and exit", h => shouldShowHelp = h != null }
            };

            List <string> extra;

            try
            {
                // parse the command line
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                // output some error message
                Console.Write("RobotSignalToolRobotRaconteurDriver: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `RobotSignalToolRobotRaconteurDriver --help' for more information.");
                return(1);
            }

            if (shouldShowHelp)
            {
                Console.WriteLine("Usage: RobotSignalToolRobotRaconteurDriver [Options+]");
                Console.WriteLine();
                Console.WriteLine("Options:");
                options.WriteOptionDescriptions(Console.Out);
                Console.WriteLine("Also supports standard --robotraconteur- node options");
                return(0);
            }

            if (tool_info_file == null)
            {
                Console.WriteLine("error: robot-info-file must be specified");
                return(1);
            }

            if (robot_url == null)
            {
                Console.WriteLine("error: robot-url must be specified");
                return(1);
            }


            Tuple <ToolInfo, LocalIdentifierLocks> tool_info = null;

            tool_info = ToolInfoParser.LoadToolInfoYamlWithIdentifierLocks(tool_info_file);

            using (tool_info.Item2)
                using (var node_setup = new ServerNodeSetup("robot_signal_tool", 58323, args))
                {
                    using (var tool = new UR_CB2_SoftGripper(robot_url, tool_info.Item1))
                    {
                        var tool_service_ctx = RobotRaconteurNode.s.RegisterService("tool", "com.robotraconteur.robotics.tool", tool);
                        tool_service_ctx.SetServiceAttributes(AttributesUtil.GetDefaultServiceAtributesFromDeviceInfo(tool_info.Item1.device_info));

                        if (!wait_signal)
                        {
                            Console.WriteLine("Press enter to exit");
                            Console.ReadKey();
                        }
                        else
                        {
                            UnixSignal[] signals = new UnixSignal[] {
                                new UnixSignal(Mono.Unix.Native.Signum.SIGINT),
                                new UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
                            };

                            Console.WriteLine("Press Ctrl-C to exit");
                            // block until a SIGINT or SIGTERM signal is generated.
                            int which = UnixSignal.WaitAny(signals, -1);

                            Console.WriteLine("Got a {0} signal, exiting", signals[which].Signum);
                        }
                    }
                }

            return(0);
        }