Exemplo n.º 1
0
    // Tutorial Part 2 without the Publisher object
    void AddRosMessages()
    {
        if (m_GenerateRosMessages)
        {
            // Generate ROS messages
            MessageAutoGen.GenerateSingleMessage(
                Path.Combine(k_RosSrcDirectory, k_MoveitMsgPackageName, k_MsgDirectory,
                             k_RobotTrajectoryMessageFileName),
                k_RosMessagesDirectory, k_MoveitMsgPackageName);

            MessageAutoGen.GenerateDirectoryMessages(
                Path.Combine(k_RosSrcDirectory, k_NiryoMoveitPackageName, k_MsgDirectory),
                k_RosMessagesDirectory);

            // Generate ROS services
            ServiceAutoGen.GenerateSingleService(
                Path.Combine(k_RosSrcDirectory, k_NiryoMoveitPackageName, k_SrvDirectory, k_MoverServiceFileName),
                k_RosMessagesDirectory, k_NiryoMoveitPackageName);
        }

        // Recompile ROS message scripts and external scripts
        var scripts = new List <string>();

        scripts.AddRange(Directory.GetFiles(k_RosMessagesDirectory, k_ScriptPattern, SearchOption.AllDirectories));
        scripts.AddRange(Directory.GetFiles(k_ExternalScriptsDirectory));
        RecompileScripts(scripts.ToArray());

        // Register Ros message names and their deserialize function
        foreach (var typeFullName in m_RosGeneratedTypeFullName)
        {
            m_Assembly.GetType(typeFullName).GetMethod(k_RegisterMethodName).Invoke(null, null);
        }
    }
Exemplo n.º 2
0
    // Tutorial Part 2 without the Publisher object
    private void AddRosMessages()
    {
        if (generateRosMessages)
        {
            // Generate ROS messages
            MessageAutoGen.GenerateSingleMessage(
                Path.Combine(rosSrcDirectory, moveitMsgPackageName, msgDirectory, robotTrajectoryMessageFileName),
                rosMessagesDirectory, moveitMsgPackageName);

            MessageAutoGen.GenerateDirectoryMessages(
                Path.Combine(rosSrcDirectory, niryoMoveitPackageName, msgDirectory),
                rosMessagesDirectory);

            // Generate ROS services
            ServiceAutoGen.GenerateSingleService(
                Path.Combine(rosSrcDirectory, niryoMoveitPackageName, srvDirectory, moverServiceFileName),
                rosMessagesDirectory, niryoMoveitPackageName);
        }

        // Recompile ROS message scripts and external scripts
        List <string> scripts = new List <string>();

        scripts.AddRange(Directory.GetFiles(rosMessagesDirectory, scriptPattern, SearchOption.AllDirectories));
        scripts.AddRange(Directory.GetFiles(externalScriptsDirectory));
        RecompileScripts(scripts.ToArray());
    }
Exemplo n.º 3
0
        public void TestMessageBuildDirectory_ThrowsNoExceptions(string directoryToBuild)
        {
            var msgPath      = MessageAutoGen.GetMessageClassPath(directoryToBuild, m_MessageGenOutputPath);
            var msgDirectory = Path.GetDirectoryName(msgPath);

            Debug.Log($"Generating code in {directoryToBuild}, output should be in {msgDirectory}");
            WarnIfAlreadyExists(msgDirectory, PathType.Directory);
            MessageAutoGen.GenerateDirectoryMessages(directoryToBuild, m_MessageGenOutputPath);
            AssetDatabase.Refresh();
            AssertExists(msgDirectory, PathType.Directory);
        }
Exemplo n.º 4
0
    // Tutorial Part 2 without the Publisher object
    private void SetupRos()
    {
        if (generateRosMessages)
        {
            // Generate ROS messages
            MessageAutoGen.GenerateSingleMessage(
                Path.Combine(rosSrcDirectory, moveitMsgPackageName, msgDirectory, robotTrajectoryMessageFileName),
                rosMessagesDirectory, moveitMsgPackageName);

            MessageAutoGen.GenerateDirectoryMessages(
                Path.Combine(rosSrcDirectory, niryoMoveitPackageName, msgDirectory),
                rosMessagesDirectory);

            // Generate ROS services
            ServiceAutoGen.GenerateSingleService(
                Path.Combine(rosSrcDirectory, niryoMoveitPackageName, srvDirectory, moverServiceFileName),
                rosMessagesDirectory, niryoMoveitPackageName);
        }

        // Recompile ROS message scripts and external scripts
        List <string> scripts = new List <string>();

        scripts.AddRange(Directory.GetFiles(rosMessagesDirectory, scriptPattern, SearchOption.AllDirectories));
        scripts.AddRange(Directory.GetFiles(externalScriptsDirectory));
        RecompileScripts(scripts.ToArray());

        // Create RosConnect
        GameObject rosConnect = new GameObject(rosConnectName);

        rosConnection = rosConnect.AddComponent <ROSConnection>();
        rosConnection.rosIPAddress          = hostIP;
        rosConnection.rosPort               = hostPort;
        rosConnection.overrideUnityIP       = overrideUnityIP;
        rosConnection.unityPort             = unityPort;
        rosConnection.awaitDataMaxRetries   = awaitDataMaxRetries;
        rosConnection.awaitDataSleepSeconds = awaitDataSleepSeconds;
    }
 public void TestMessageBuildDirectory_ThrowsNoExceptions(string directoryToBuild)
 {
     MessageAutoGen.GenerateDirectoryMessages(directoryToBuild, m_MessageGenOutputPath);
     AssetDatabase.Refresh();
 }
Exemplo n.º 6
0
        void ShowCachedEntry(CachedEntry entry)
        {
            if (entry.status == CachedEntryStatus.Ignored)
            {
                return;
            }
            else if (entry.status != CachedEntryStatus.Folder)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(entry.label);

                if (entry.hasBuildButton && GUILayout.Button(entry.buildLabel, GUILayout.Width(BUTTON_WIDTH)))
                {
                    // build this msg, srv, or action file
                    switch (entry.status)
                    {
                    case CachedEntryStatus.BuiltMsgFile:
                    case CachedEntryStatus.UnbuiltMsgFile:
                        MessageAutoGen.GenerateSingleMessage(entry.path, MessageGenBrowserSettings.Get().outputPath);
                        break;

                    case CachedEntryStatus.BuiltSrvFile:
                    case CachedEntryStatus.UnbuiltSrvFile:
                        ServiceAutoGen.GenerateSingleService(entry.path, MessageGenBrowserSettings.Get().outputPath);
                        break;

                    case CachedEntryStatus.BuiltActionFile:
                    case CachedEntryStatus.UnbuiltActionFile:
                        ActionAutoGen.GenerateSingleAction(entry.path, MessageGenBrowserSettings.Get().outputPath);
                        break;
                    }
                    AssetDatabase.Refresh();
                    m_IsCacheDirty = true;
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                bool isFoldedOut = m_FoldedOutHash.Contains(entry.path);

                EditorGUILayout.BeginHorizontal();
                bool shouldBeFoldedOut = EditorGUILayout.Foldout(isFoldedOut, entry.label, true, EditorStyles.foldout);
                if (entry.hasBuildButton && GUILayout.Button(entry.buildLabel, GUILayout.Width(BUTTON_WIDTH)))
                {
                    // build this directory
                    MessageAutoGen.GenerateDirectoryMessages(entry.path, MessageGenBrowserSettings.Get().outputPath);
                    ServiceAutoGen.GenerateDirectoryServices(entry.path, MessageGenBrowserSettings.Get().outputPath);
                    ActionAutoGen.GenerateDirectoryActions(entry.path, MessageGenBrowserSettings.Get().outputPath);
                    AssetDatabase.Refresh();
                    m_IsCacheDirty = true;
                }
                EditorGUILayout.EndHorizontal();

                if (isFoldedOut)
                {
                    EditorGUI.indentLevel++;
                    foreach (CachedEntry subEntry in entry.contents)
                    {
                        ShowCachedEntry(subEntry);
                    }
                    EditorGUI.indentLevel--;
                }

                if (shouldBeFoldedOut != isFoldedOut)
                {
                    m_IsCacheDirty = true;

                    if (shouldBeFoldedOut)
                    {
                        m_FoldedOutHash.Add(entry.path);
                    }
                    else
                    {
                        m_FoldedOutHash.Remove(entry.path);
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            // Arguments
            string inputPath = "";

            bool verbose = false;

            bool service = false;
            bool action  = false;

            bool   recursive      = false;
            bool   package        = false;
            string rosPackageName = "";
            string outputPath     = defaultOutputDirectory;

            // Parse Arguments
            if (args.Length == 0)
            {
                Console.WriteLine("No argument: Display usage");
                Console.WriteLine(usage);
                return;
            }

            if (args[0].Equals("--help") || args[0].Equals("-h"))
            {
                Console.WriteLine("Help: Displays usage");
                Console.WriteLine(usage);
                return;
            }

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];

                if (arg.Equals("-s") || arg.Equals("--service"))
                {
                    if (action)
                    {
                        Console.Error.WriteLine("Option '--service' conflict with '--action'.");
                        if (verbose)
                        {
                            Console.Error.WriteLine("Make up your mind!");
                        }
                        return;
                    }
                    service = true;
                    if (verbose)
                    {
                        Console.WriteLine("'--service' flag seen. Expecting *.srv input");
                    }
                    continue;
                }

                if (arg.Equals("-a") || arg.Equals("--action"))
                {
                    if (service)
                    {
                        Console.Error.WriteLine("Option '--action' conflict with '--service'.");
                        if (verbose)
                        {
                            Console.Error.WriteLine("Make up your mind!");
                        }
                        return;
                    }
                    action = true;
                    if (verbose)
                    {
                        Console.WriteLine("'--action' flag seen. Expecting *.action input");
                    }
                    continue;
                }

                if (arg.Equals("-r") || arg.Equals("--recursive"))
                {
                    if (package)
                    {
                        Console.Error.WriteLine("Option '--recursive' conflict with '--package'.");
                        if (verbose)
                        {
                            Console.Error.WriteLine("Make up your mind!");
                        }
                        return;
                    }
                    if (recursive)
                    {
                        Console.WriteLine("Duplicate flag '--recursive'.");
                        if (verbose)
                        {
                            Console.Error.WriteLine("I got it already!");
                        }
                    }
                    if (!rosPackageName.Equals(""))
                    {
                        Console.WriteLine("'--recursive' option enabled, ignoring ROS package name");
                    }
                    recursive = true;
                    continue;
                }

                if (arg.Equals("-p") || arg.Equals("--package"))
                {
                    if (recursive)
                    {
                        Console.Error.WriteLine("Option '--package' conflict with '--recursive'.");
                        if (verbose)
                        {
                            Console.Error.WriteLine("Make up your mind!");
                        }
                        return;
                    }
                    if (package)
                    {
                        Console.WriteLine("Duplicate flag '--package'.");
                        if (verbose)
                        {
                            Console.Error.WriteLine("I got it already!");
                        }
                    }
                    package = true;
                    continue;
                }

                if (arg.Equals("-n") || arg.Equals("--ros-package-name"))
                {
                    if (i == args.Length - 1)
                    {
                        Console.Error.WriteLine("Missing ROS package name. Will get name from path");
                    }
                    else if (validOptions.Contains(args[i + 1]))
                    {
                        Console.Error.WriteLine("Missing ROS package name. Will get name from path");
                    }
                    else if (recursive)
                    {
                        Console.WriteLine("'--recursive' option enabled, ignoring ROS package name");
                    }
                    else
                    {
                        rosPackageName = args[i + 1];
                        i++;
                    }
                    continue;
                }

                if (arg.Equals("-o") || arg.Equals("--output"))
                {
                    if (i == args.Length - 1)
                    {
                        Console.Error.WriteLine("Missing output path. Using default output path.");
                    }
                    else if (validOptions.Contains(args[i + 1]))
                    {
                        Console.Error.WriteLine("Missing output path. Using default output path.");
                    }
                    else
                    {
                        outputPath = args[i + 1];
                        outputPath = Path.Combine(outputPath, "RosSharpMessages");
                        i++;
                    }
                    continue;
                }

                if (arg.Equals("-v") || arg.Equals("--verbose"))
                {
                    Console.WriteLine("Verbose flag detected. Warning: A huge wave of text incoming!");
                    verbose = true;
                    continue;
                }

                if (inputPath.Equals(""))
                {
                    inputPath = arg;
                }
                else
                {
                    Console.Error.WriteLine("Ignored invalid argument: " + arg);
                    if (verbose)
                    {
                        Console.Error.WriteLine("Mumble mumble. Run 'RosMsgGen.exe -h' or 'RosMsgGen.exe --help' to see usage");
                    }
                }
            }

            // Do work
            // Parse Individual Messages
            if (!package && !recursive)
            {
                if (inputPath.Equals(""))
                {
                    Console.Error.WriteLine("Please specify input file");
                    if (verbose)
                    {
                        Console.Error.WriteLine("Bricks without straw");
                    }
                    return;
                }
                if (!IsValidPath(inputPath, false))
                {
                    if (IsValidPath(inputPath, true))
                    {
                        Console.Error.WriteLine("Input path is a directory. Please use --package or --recursive option");
                    }
                    else
                    {
                        Console.Error.WriteLine("Invalid input path");
                    }
                    return;
                }
                List <string> warnings;
                if (service)
                {
                    warnings = ServiceAutoGen.GenerateSingleService(inputPath, outputPath, rosPackageName, verbose);
                }
                else if (action)
                {
                    warnings = ActionAutoGen.GenerateSingleAction(inputPath, outputPath, rosPackageName, verbose);
                }
                else
                {
                    warnings = MessageAutoGen.GenerateSingleMessage(inputPath, outputPath, rosPackageName, verbose);
                }
                PrintWarnings(warnings);
                return;
            }
            // Parse Package Messages
            if (package)
            {
                if (inputPath.Equals(""))
                {
                    Console.Error.WriteLine("Please specify input package");
                    if (verbose)
                    {
                        Console.Error.WriteLine("Bricks without straw");
                    }
                    return;
                }
                if (!IsValidPath(inputPath, true))
                {
                    if (IsValidPath(inputPath, false))
                    {
                        Console.Error.WriteLine("Input path is a file. Please drop --package option");
                    }
                    else
                    {
                        Console.Error.WriteLine("Invalid input path");
                    }
                    return;
                }
                try
                {
                    Console.WriteLine("Working...");
                    List <string> warnings;
                    if (service)
                    {
                        warnings = ServiceAutoGen.GeneratePackageServices(inputPath, outputPath, rosPackageName, verbose);
                    }
                    else if (action)
                    {
                        warnings = ActionAutoGen.GeneratePackageActions(inputPath, outputPath, rosPackageName, verbose);
                    }
                    else
                    {
                        warnings = MessageAutoGen.GeneratePackageMessages(inputPath, outputPath, rosPackageName, verbose);
                    }
                    PrintWarnings(warnings);
                }
                catch (DirectoryNotFoundException) {
                    if (service)
                    {
                        Console.Error.WriteLine("Didn't find service folder in given package");
                    }
                    else
                    {
                        Console.Error.WriteLine("Didn't find message folder in given package");
                    }
                    if (verbose)
                    {
                        Console.Error.WriteLine("Bricks without straw");
                    }
                }
                return;
            }
            // Parse Directory Message
            if (recursive)
            {
                if (inputPath.Equals(""))
                {
                    Console.Error.WriteLine("Please specify input directory");
                    if (verbose)
                    {
                        Console.Error.WriteLine("Bricks without straw");
                    }
                    return;
                }
                if (!IsValidPath(inputPath, true))
                {
                    if (IsValidPath(inputPath, false))
                    {
                        Console.Error.WriteLine("Input path is a file. Consider as base case");
                        // Parse Single Message
                        List <string> singleMsgWarnings;
                        if (service)
                        {
                            singleMsgWarnings = ServiceAutoGen.GenerateSingleService(inputPath, outputPath, rosPackageName, verbose);
                        }
                        else if (action)
                        {
                            singleMsgWarnings = ActionAutoGen.GenerateSingleAction(inputPath, outputPath, rosPackageName, verbose);
                        }
                        else
                        {
                            singleMsgWarnings = MessageAutoGen.GenerateSingleMessage(inputPath, outputPath, rosPackageName, verbose);
                        }
                        PrintWarnings(singleMsgWarnings);
                    }
                    else
                    {
                        Console.Error.WriteLine("Invalid input path");
                    }
                    return;
                }
                Console.WriteLine("Working...Checkout xkcd.com/303");
                List <string> warnings;
                if (service)
                {
                    warnings = ServiceAutoGen.GenerateDirectoryServices(inputPath, outputPath, verbose);
                }
                else if (action)
                {
                    warnings = ActionAutoGen.GenerateDirectoryActions(inputPath, outputPath, verbose);
                }
                else
                {
                    warnings = MessageAutoGen.GenerateDirectoryMessages(inputPath, outputPath, verbose);
                }
                PrintWarnings(warnings);
                return;
            }

            // Otherwise I don't know...
            Console.Error.WriteLine("Unrecognized combination of arguments.");
            if (verbose)
            {
                Console.WriteLine("Mumble Mumble. Run 'RosMsgGen.exe -h' or 'RosMsgGen.exe --help' to see usage");
            }
        }