Пример #1
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());
    }
Пример #2
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);
        }
    }
Пример #3
0
        public void TestMessageBuildSingle_ThrowsNoExceptions(string messageToBuild)
        {
            var msgPath = MessageAutoGen.GetMessageClassPath(messageToBuild, m_MessageGenOutputPath);

            Debug.Log($"Generating code for {messageToBuild}, output should be at {msgPath}");
            WarnIfAlreadyExists(msgPath, PathType.File);
            MessageAutoGen.GenerateSingleMessage(messageToBuild, m_MessageGenOutputPath);
            AssetDatabase.Refresh();
            AssertExists(msgPath, PathType.File);
        }
Пример #4
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);
        }
        public override void OnImportAsset(AssetImportContext ctx)
        {
            string inputPath  = Path.Combine(Directory.GetCurrentDirectory(), ctx.assetPath);
            string outputPath = MessageGenBrowserSettings.Get().outputPath;

            MessageAutoGen.GenerateSingleMessage(inputPath, outputPath);

            string builtPath      = MessageAutoGen.GetMessageClassPath(inputPath, outputPath);
            string builtAssetPath = Path.Combine("Assets", MessageGenBrowserSettings.ToRelativePath(builtPath));

            AssetDatabase.ImportAsset(builtAssetPath);
            Object messageClass = AssetDatabase.LoadAssetAtPath(builtAssetPath, typeof(MonoScript));

            if (messageClass != null)
            {
                ctx.AddObjectToAsset("messageClass", messageClass);
            }
        }
Пример #6
0
        CachedEntryStatus GetFileStatus(string path)
        {
            switch (Path.GetExtension(path))
            {
            case ".msg":
                string builtMessagePath = MessageAutoGen.GetMessageClassPath(path, MessageGenBrowserSettings.Get().outputPath);
                return(File.Exists(builtMessagePath) ? CachedEntryStatus.BuiltMsgFile : CachedEntryStatus.UnbuiltMsgFile);

            case ".srv":
                string[] builtServicePaths = ServiceAutoGen.GetServiceClassPaths(path, MessageGenBrowserSettings.Get().outputPath);
                return(builtServicePaths.All(file => File.Exists(file)) ? CachedEntryStatus.BuiltSrvFile : CachedEntryStatus.UnbuiltSrvFile);

            case ".action":
                string[] builtActionPaths = ActionAutoGen.GetActionClassPaths(path, MessageGenBrowserSettings.Get().outputPath);
                return(builtActionPaths.All(file => File.Exists(file)) ? CachedEntryStatus.BuiltActionFile : CachedEntryStatus.UnbuiltActionFile);
            }

            return(CachedEntryStatus.Ignored);
        }
Пример #7
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();
 }
 public void TestMessageBuildSingle_ThrowsNoExceptions(string messageToBuild)
 {
     MessageAutoGen.GenerateSingleMessage(messageToBuild, m_MessageGenOutputPath);
     AssetDatabase.Refresh();
 }
Пример #10
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);
                    }
                }
            }
        }
Пример #11
0
        private void OnGUI()
        {
            GUILayout.Label("Package messages auto generation", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            inPkgPath = EditorGUILayout.TextField("Input Package Path", inPkgPath);
            if (GUILayout.Button("Browse Package...", GUILayout.Width(150)))
            {
                inPkgPath = EditorUtility.OpenFolderPanel("Select Package...", "", "");
                if (!inPkgPath.Equals(""))
                {
                    rosPackageName = inPkgPath.Split('/').Last();
                }
            }
            EditorGUILayout.EndHorizontal();

            rosPackageName = EditorGUILayout.TextField("ROS Package Name:", rosPackageName);

            EditorGUILayout.BeginHorizontal();
            outPkgPath = EditorGUILayout.TextField("Output Location", outPkgPath);
            if (GUILayout.Button("Select Folder...", GUILayout.Width(150)))
            {
                outPkgPath = EditorUtility.OpenFolderPanel("Select Folder...", "", "");
            }
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("GENERATE!"))
            {
                if (inPkgPath.Equals(""))
                {
                    EditorUtility.DisplayDialog(
                        title: "Error",
                        message: "Empty input package path!\nPlease specify input package",
                        ok: "Bricks without straw");
                }
                else
                {
                    try {
                        string[] files = Directory.GetFiles(Path.Combine(inPkgPath, "msg"), "*.msg");
                        if (files.Length == 0)
                        {
                            EditorUtility.DisplayDialog(
                                title: "No message files found!",
                                message: "No message files found!",
                                ok: "Bricks without straw");
                            Reset();
                        }
                        else
                        {
                            // Keep a list of warnings
                            List <string> warnings = new List <string>();
                            for (int i = 0; i < files.Length; i++)
                            {
                                string file = files[i];
                                EditorUtility.DisplayProgressBar(
                                    "Working...(" + (i + 1) + "/" + files.Length + ")",
                                    "Parsing " + file,
                                    (float)(i + 1) / (float)files.Length);
                                try
                                {
                                    warnings.AddRange(MessageAutoGen.GenerateSingleMessage(file, outPkgPath, rosPackageName));
                                }
                                catch (MessageTokenizerException e)
                                {
                                    Debug.LogError(e.ToString() + e.Message);
                                    EditorUtility.DisplayDialog(
                                        title: "Message Tokenizer Exception",
                                        message: e.Message,
                                        ok: "Wait. That's illegal");
                                }
                                catch (MessageParserException e)
                                {
                                    Debug.LogError(e.ToString() + e.Message);
                                    EditorUtility.DisplayDialog(
                                        title: "Message Parser Exception",
                                        message: e.Message,
                                        ok: "Sorry but you can't ignore errors.");
                                }
                            }
                            // Done
                            EditorUtility.ClearProgressBar();
                            if (warnings.Count > 0)
                            {
                                EditorUtility.DisplayDialog(
                                    title: "Code Generation Complete",
                                    message: "Output at: " + outPkgPath + "\nYou have " + warnings.Count + " warning(s)",
                                    ok: "I like to live dangerously");
                                foreach (string w in warnings)
                                {
                                    Debug.LogWarning(w);
                                }
                            }
                            else
                            {
                                EditorUtility.DisplayDialog(
                                    title: "Code Generation Complete",
                                    message: "Output at: " + outPkgPath,
                                    ok: "Thank you!");
                            }
                            Reset();
                        }
                    }
                    catch (DirectoryNotFoundException e) {
                        EditorUtility.DisplayDialog(
                            title: "Message Folder not found",
                            message: e.Message,
                            ok: "Bricks without straw");
                        Reset();
                    }
                }
            }
        }
Пример #12
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");
            }
        }
Пример #13
0
 protected override List <string> Generate(string inPath, string outPath, string rosPackageName = "")
 {
     return(MessageAutoGen.GenerateSingleMessage(inPath, outPath, rosPackageName));
 }