├── README.md ├── LICENSE ├── src ├── OpenKuka.KRL.sln └── OpenKuka.KRL │ ├── Properties │ └── AssemblyInfo.cs │ ├── OpenKuka.KRL.csproj │ ├── Types │ ├── Time.cs │ ├── System.cs │ └── Motion.cs │ └── DataParser │ ├── KrlDataParser.cs │ ├── KrlDataTokenizer.cs │ └── KrlDataAST.cs ├── .gitignore └── .gitattributes /README.md: -------------------------------------------------------------------------------- 1 | # KRL 2 | A minial C# API to Kuka Robot Language 3 | 4 | 5 | * C# types that maps to KRL system types 6 | * Parser for KRL data (unroll nested struc / type recognition) 7 | * Parser for KRL language (complex, not for now ...) 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 openkuka 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.28307.271 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenKuka.KRL", "OpenKuka.KRL\OpenKuka.KRL.csproj", "{1BA8596A-BD90-4C05-9875-97E064C2C73B}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1BA8596A-BD90-4C05-9875-97E064C2C73B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1BA8596A-BD90-4C05-9875-97E064C2C73B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1BA8596A-BD90-4C05-9875-97E064C2C73B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1BA8596A-BD90-4C05-9875-97E064C2C73B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C7F9DE69-57CE-4873-828E-3A962C2583A0} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("OpenKuka.KRL")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Lionel du Peloux")] 12 | [assembly: AssemblyProduct("OpenKuka.KRL")] 13 | [assembly: AssemblyCopyright("Copyright © 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1ba8596a-bd90-4c05-9875-97e064c2c73b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.*")] 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | [Bb]in/ 15 | [Oo]bj/ 16 | .vs/ 17 | 18 | # MSTest test Results 19 | [Tt]est[Rr]esult*/ 20 | [Bb]uild[Ll]og.* 21 | 22 | *_i.c 23 | *_p.c 24 | *_i.h 25 | *.ilk 26 | *.meta 27 | *.obj 28 | *.pch 29 | *.pdb 30 | *.pgc 31 | *.pgd 32 | *.rsp 33 | *.sbr 34 | *.tlb 35 | *.tli 36 | *.tlh 37 | *.tmp 38 | *.tmp_proj 39 | *.log 40 | *.vspscc 41 | *.vssscc 42 | .builds 43 | *.pidb 44 | *.log 45 | *.svclog 46 | *.scc 47 | 48 | # Visual C++ cache files 49 | ipch/ 50 | *.aps 51 | *.ncb 52 | *.opensdf 53 | *.sdf 54 | *.cachefile 55 | 56 | # Visual Studio profiler 57 | *.psess 58 | *.vsp 59 | *.vspx 60 | 61 | # Guidance Automation Toolkit 62 | *.gpState 63 | 64 | # ReSharper is a .NET coding add-in 65 | _ReSharper*/ 66 | *.[Rr]e[Ss]harper 67 | *.DotSettings.user 68 | 69 | # Click-Once directory 70 | publish/ 71 | 72 | # Publish Web Output 73 | *.Publish.xml 74 | *.pubxml 75 | *.azurePubxml 76 | 77 | # NuGet Packages Directory 78 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 79 | .nuget/ 80 | packages/ 81 | ## TODO: If the tool you use requires repositories.config, also uncomment the next line 82 | !packages/repositories.config 83 | 84 | # Windows Azure Build Output 85 | csx/ 86 | *.build.csdef 87 | 88 | # Windows Store app package directory 89 | AppPackages/ 90 | 91 | # Others 92 | sql/ 93 | *.Cache 94 | ClientBin/ 95 | [Ss]tyle[Cc]op.* 96 | ![Ss]tyle[Cc]op.targets 97 | ~$* 98 | *~ 99 | *.dbmdl 100 | *.[Pp]ublish.xml 101 | 102 | *.publishsettings 103 | 104 | # RIA/Silverlight projects 105 | Generated_Code/ 106 | 107 | # Backup & report files from converting an old project file to a newer 108 | # Visual Studio version. Backup files are not needed, because we have git ;-) 109 | _UpgradeReport_Files/ 110 | Backup*/ 111 | UpgradeLog*.XML 112 | UpgradeLog*.htm 113 | 114 | # SQL Server files 115 | App_Data/*.mdf 116 | App_Data/*.ldf 117 | 118 | # ========================= 119 | # Windows detritus 120 | # ========================= 121 | 122 | # Windows image file caches 123 | Thumbs.db 124 | ehthumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | # Recycle Bin used on file shares 130 | $RECYCLE.BIN/ 131 | 132 | # Mac desktop service store files 133 | .DS_Store 134 | 135 | _NCrunch* 136 | 137 | # ========================= 138 | # Rhino Files 139 | # ========================= 140 | 141 | *.3dmbak 142 | *.3dm.rhl 143 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/OpenKuka.KRL.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {1BA8596A-BD90-4C05-9875-97E064C2C73B} 8 | Library 9 | Properties 10 | OpenKuka.KRL 11 | OpenKuka.KRL 12 | v4.5 13 | 512 14 | false 15 | 16 | 17 | 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | false 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | false 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 2.2.0 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/Types/Time.cs: -------------------------------------------------------------------------------- 1 | using OpenKuka.KRL.DataParser; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace OpenKuka.KRL.Types 9 | { 10 | public struct DATE 11 | { 12 | public int? CSEC { get; set; } 13 | public int? SEC { get; set; } 14 | public int? MIN { get; set; } 15 | public int? HOUR { get; set; } 16 | public int? DAY { get; set; } 17 | public int? MONTH { get; set; } 18 | public int? YEAR { get; set; } 19 | 20 | public DATE(DateTime date) 21 | { 22 | CSEC = date.Millisecond; 23 | SEC = date.Second; 24 | MIN = date.Minute; 25 | HOUR = date.Hour; 26 | DAY = date.Day; 27 | MONTH = date.Month; 28 | YEAR = date.Year; 29 | } 30 | 31 | public DateTime ToDateTime() => new DateTime(YEAR ?? 0, MONTH ?? 0, DAY ?? 0, HOUR ?? 0, MIN ?? 0, SEC ?? 0, CSEC ?? 0, DateTimeKind.Unspecified); 32 | public override string ToString() 33 | { 34 | return ToString(); 35 | } 36 | public string ToString(bool showType = true) 37 | { 38 | var items = new List(); 39 | 40 | if (CSEC.HasValue) items.Add(string.Format("CSEC {0}", CSEC)); 41 | if (SEC.HasValue) items.Add(string.Format("SEC {0}", SEC)); 42 | if (MIN.HasValue) items.Add(string.Format("MIN {0}", MIN)); 43 | if (HOUR.HasValue) items.Add(string.Format("HOUR {0}", HOUR)); 44 | if (DAY.HasValue) items.Add(string.Format("DAY {0}", DAY)); 45 | if (MONTH.HasValue) items.Add(string.Format("MONTH {0}", MONTH)); 46 | if (YEAR.HasValue) items.Add(string.Format("YEAR {0}", YEAR)); 47 | 48 | var cmd = showType ? "{DATE: " : "{"; 49 | cmd += string.Join(", ", items) + "}"; 50 | return cmd; 51 | } 52 | 53 | public static DATE Parse(StrucData tree) 54 | { 55 | if (tree.StrucType != "DATE") 56 | throw new ArgumentException("The data provided is not of type DATE", "tree"); 57 | 58 | var date = new DATE(); 59 | 60 | date.CSEC = ((IntData)tree.Value["CSEC"]).Value; 61 | date.SEC = ((IntData)tree.Value["SEC"]).Value; 62 | date.MIN = ((IntData)tree.Value["MIN"]).Value; 63 | date.HOUR = ((IntData)tree.Value["HOUR"]).Value; 64 | date.DAY = ((IntData)tree.Value["DAY"]).Value; 65 | date.MONTH = ((IntData)tree.Value["MONTH"]).Value; 66 | date.YEAR = ((IntData)tree.Value["YEAR"]).Value; 67 | 68 | return date; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/DataParser/KrlDataParser.cs: -------------------------------------------------------------------------------- 1 | using Superpower; 2 | using Superpower.Model; 3 | using Superpower.Parsers; 4 | using System.Linq; 5 | 6 | namespace OpenKuka.KRL.DataParser 7 | { 8 | public static class KrlDataParser 9 | { 10 | public readonly static TokenListParser ScalarData = 11 | from name in Token.EqualTo(KrlDataToken.Key).OptionalOrDefault(new Token(KrlDataToken.Key, new TextSpan("NoKey"))) 12 | from token in Token.EqualTo(KrlDataToken.Bool) 13 | .Or(Token.EqualTo(KrlDataToken.Int)) 14 | .Or(Token.EqualTo(KrlDataToken.Real)) 15 | .Or(Token.EqualTo(KrlDataToken.Enum)) 16 | .Or(Token.EqualTo(KrlDataToken.Char)) 17 | .Or(Token.EqualTo(KrlDataToken.String)) 18 | select (Data)( 19 | token.Kind == KrlDataToken.Bool ? new BoolData(name.ToStringValue(), token.ToStringValue()) : 20 | token.Kind == KrlDataToken.Int ? new IntData(name.ToStringValue(), token.ToStringValue()) : 21 | token.Kind == KrlDataToken.Real ? new RealData(name.ToStringValue(), token.ToStringValue()) : 22 | token.Kind == KrlDataToken.Enum ? new EnumData(name.ToStringValue(), token.ToStringValue()) : 23 | token.Kind == KrlDataToken.Char ? new CharData(name.ToStringValue(), token.ToStringValue()) : 24 | (Data)new StringData(name.ToStringValue(), token.ToStringValue())); 25 | 26 | public readonly static TokenListParser StrucData = 27 | from name in Token.EqualTo(KrlDataToken.Key).OptionalOrDefault(new Token(KrlDataToken.Key, new TextSpan("NoKey"))) 28 | from open in Token.EqualTo(KrlDataToken.LBracket) 29 | from type in Token.EqualTo(KrlDataToken.Type) 30 | from nodes in ScalarData.Try() 31 | .Or(StrucData) // .Or(Parse.Ref(() => StrucData)) 32 | .ManyDelimitedBy(Token.EqualTo(KrlDataToken.Comma)) // , end: Token.EqualTo(MyToken.RBracket) 33 | from close in Token.EqualTo(KrlDataToken.RBracket) 34 | select (Data)(new StrucData(name.ToStringValue(), type.ToStringValue(), nodes)); 35 | 36 | public readonly static TokenListParser Data = 37 | from nodes in ScalarData.Try() 38 | .Or(StrucData) 39 | .ManyDelimitedBy(Token.EqualTo(KrlDataToken.Comma)) 40 | select nodes; 41 | 42 | public static TokenListParserResult TryParse(string input) 43 | { 44 | var tokenizer = KrlDataTokenizer.Instance; 45 | var tokens = tokenizer.Tokenize(input); 46 | 47 | //string path = @"C:\Temp\tokens.txt"; 48 | //if (!File.Exists(path)) 49 | //{ 50 | // File.Create(path).Dispose(); 51 | //} 52 | //if (File.Exists(path)) 53 | //{ 54 | // using (var tw = new StreamWriter(path, true)) 55 | // { 56 | // foreach (var token in tokens) 57 | // { 58 | // Console.WriteLine(token); 59 | // tw.WriteLine(token); 60 | // } 61 | // } 62 | //} 63 | //Console.WriteLine(" "); 64 | 65 | var res = Data.TryParse(tokens); 66 | //foreach (var data in res.Value) 67 | //{ 68 | // ((Data)data).Print(""); 69 | //} 70 | 71 | return res; 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/DataParser/KrlDataTokenizer.cs: -------------------------------------------------------------------------------- 1 | using Superpower; 2 | using Superpower.Display; 3 | using Superpower.Model; 4 | using Superpower.Parsers; 5 | using Superpower.Tokenizers; 6 | using System.Linq; 7 | 8 | namespace OpenKuka.KRL.DataParser 9 | { 10 | public enum KrlDataToken 11 | { 12 | // struct delimiters 13 | [Token(Example = "{")] 14 | LBracket, 15 | 16 | [Token(Example = "}")] 17 | RBracket, 18 | 19 | // field delimiters 20 | [Token(Example = ",")] 21 | Comma, 22 | 23 | // data 24 | Bool, 25 | Enum, 26 | Int, 27 | Real, 28 | Char, 29 | String, 30 | Type, 31 | Key, 32 | } 33 | 34 | public static class KrlDataTokenizer 35 | { 36 | public static TextParser BooleanToken { get; } = 37 | from content in Span.EqualToIgnoreCase("false").Or(Span.EqualToIgnoreCase("true")) 38 | select Unit.Value; 39 | 40 | public static TextParser IntegerToken { get; } = 41 | from sign in Character.EqualTo('-').OptionalOrDefault() 42 | from first in Character.Digit 43 | from rest in Character.Digit.IgnoreMany() 44 | select Unit.Value; 45 | 46 | public static TextParser RealToken { get; } = 47 | from sign in Character.EqualTo('-').OptionalOrDefault() 48 | from first in Character.Digit 49 | from rest in Character.Digit.Or(Character.In('.', 'e', 'E', '+', '-')).IgnoreMany() 50 | select Unit.Value; 51 | 52 | public static TextParser EnumToken { get; } = 53 | from first in Character.EqualTo('#') 54 | from second in Character.Letter.Or(Character.In('_', '$')) 55 | from rest in Character.LetterOrDigit.Or(Character.In('_', '$')) 56 | .IgnoreMany() 57 | select Unit.Value; 58 | 59 | public static TextParser CharToken { get; } = 60 | from open in Character.EqualTo('"') 61 | from content in Character.Letter 62 | from close in Character.EqualTo('"') 63 | select content; 64 | 65 | public static TextParser StringToken { get; } = 66 | from open in Character.EqualTo('"') 67 | from content in Span.EqualTo("\\\"").Value(Unit.Value).Try() 68 | .Or(Span.EqualTo("\\\\").Value(Unit.Value).Try()) 69 | .Or(Character.Except('"').Value(Unit.Value)) 70 | .IgnoreMany() 71 | from close in Character.EqualTo('"') 72 | select content; 73 | 74 | public static TextParser TypeToken { get; } = 75 | from first in Character.Letter.Or(Character.In('_', '$')) 76 | from rest in Character.LetterOrDigit.Or(Character.In('_', '$')).IgnoreMany() 77 | from close in Character.EqualTo(':') 78 | select Unit.Value; 79 | 80 | public static TextParser KeyToken { get; } = 81 | from first in Character.Letter.Or(Character.In('_', '$')) 82 | from rest in Character.Letter.Or(Character.Digit).Or(Character.In('_', '$', '[', ']')) 83 | .IgnoreMany() 84 | select Unit.Value; 85 | 86 | public static Tokenizer Instance { get; } = 87 | new TokenizerBuilder() 88 | .Ignore(Span.WhiteSpace) 89 | .Match(Character.EqualTo('{'), KrlDataToken.LBracket) 90 | .Match(Character.EqualTo('}'), KrlDataToken.RBracket) 91 | .Match(Character.EqualTo(','), KrlDataToken.Comma) 92 | .Match(CharToken, KrlDataToken.Char, requireDelimiters: false) 93 | .Match(StringToken, KrlDataToken.String, requireDelimiters: false) 94 | .Match(BooleanToken, KrlDataToken.Bool, requireDelimiters: true) 95 | .Match(IntegerToken, KrlDataToken.Int, requireDelimiters: true) 96 | .Match(RealToken, KrlDataToken.Real, requireDelimiters: true) 97 | .Match(EnumToken, KrlDataToken.Enum, requireDelimiters: true) 98 | .Match(TypeToken, KrlDataToken.Type, requireDelimiters: true) 99 | .Match(KeyToken, KrlDataToken.Key, requireDelimiters: true) 100 | .Build(); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/Types/System.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Krl.Types 6 | { 7 | public enum MODE_OP 8 | { 9 | /// 10 | /// Test 1. 11 | /// 12 | T1, 13 | 14 | /// 15 | /// Test 2. 16 | /// 17 | T2, 18 | 19 | /// 20 | /// Automatic. 21 | /// 22 | AUT, 23 | 24 | /// 25 | /// Automatic External. 26 | /// 27 | EX 28 | } 29 | 30 | public enum PRO_STATE 31 | { 32 | /// 33 | /// Program not selected. 34 | /// 35 | P_FREE, 36 | 37 | /// 38 | /// Program reset. 39 | /// 40 | P_RESET, 41 | 42 | /// 43 | /// Program active 44 | /// 45 | P_ACTIVE, 46 | 47 | /// 48 | /// Program stopped. 49 | /// 50 | P_STOP, 51 | 52 | /// 53 | /// End of program reached 54 | /// 55 | P_END 56 | } 57 | 58 | public enum PRO_MODE 59 | { 60 | /// 61 | /// IncrementalStep : lock-by-blockprocessing with a stop after each instruction (without advance run processing). 62 | /// 63 | ISTEP, 64 | 65 | /// 66 | /// Program Step: Complete processing of subprograms (without advance run processing). 67 | /// 68 | PSTEP, 69 | 70 | /// 71 | /// Motion Step: Step-by-step processing with a stop after each motion instruction (without advance run processing). 72 | /// 73 | MSTEP, 74 | 75 | /// 76 | /// Continuous Step: Step-by-step processing with a stop after each motion instruction (with advance run processing). 77 | /// 78 | CSTEP, 79 | 80 | /// 81 | /// Continuous execution to the end of the program. 82 | /// 83 | GO, 84 | 85 | /// 86 | /// Continuous execution backwards to the start of the program. 87 | /// 88 | BSTEP 89 | } 90 | 91 | public enum ASYNC_STATE 92 | { 93 | /// 94 | /// Asynchronous motions active, stopped or temporarily stored. 95 | /// 96 | BUSY, 97 | 98 | /// 99 | /// No asynchronous motions active or stopped (queue is empty); last motion terminated without an interrupt. 100 | /// 101 | IDLE, 102 | 103 | /// 104 | /// No asynchronous motions active or stopped (queue is empty); last motion was canceled. 105 | /// 106 | CANCELLED, 107 | 108 | /// 109 | /// Asynchronous motion is planned, but is not currently being executed 110 | /// 111 | PEND 112 | } 113 | 114 | public enum AXBOX 115 | { 116 | /// 117 | /// Work envelope monitoring deactivated 118 | /// 119 | OFF, 120 | 121 | /// 122 | /// The output is set if the TCP is located inside the work envelope. 123 | /// 124 | INSIDE, 125 | 126 | /// 127 | /// The output is set if the TCP is located outside the work envelope 128 | /// 129 | OUTSIDE, 130 | 131 | /// 132 | /// The output is set and the robot stopped if the TCP is located inside the work envelope 133 | /// 134 | INSIDE_STOP, 135 | 136 | /// 137 | /// The output is set and the robot stopped if the TCP is located outside the work envelope 138 | /// 139 | OUTSIDE_STOP 140 | } 141 | 142 | public enum SIG_STATE 143 | { 144 | /// 145 | /// No enabling switch pressed (default position) or switched fully pressed (panic position). 146 | /// 147 | RELEASED, 148 | 149 | /// 150 | /// One or more enabling switches pressed (enabling position). 151 | /// 152 | PRESSED 153 | } 154 | } 155 | 156 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/DataParser/KrlDataAST.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Text.RegularExpressions; 5 | 6 | namespace OpenKuka.KRL.DataParser 7 | { 8 | public enum DataType 9 | { 10 | BOOL, 11 | INT, 12 | REAL, 13 | CHAR, 14 | STRING, 15 | ENUM, 16 | STRUC 17 | } 18 | 19 | public abstract class Data 20 | { 21 | private static Regex _array = new Regex(@"\[([\d]+)\]", RegexOptions.IgnoreCase); 22 | 23 | public abstract DataType Type { get; } 24 | public string Name { get; set; } 25 | 26 | public bool IsScalar { get => Type != DataType.STRUC; } 27 | public bool IsComposite { get => Type == DataType.STRUC; } 28 | public bool IsArrayElement(out short index) 29 | { 30 | index = 0; 31 | Match match = _array.Match(Name); 32 | if (match.Success) 33 | { 34 | index = short.Parse(match.Groups[1].Value); 35 | return true; 36 | } 37 | else 38 | { 39 | return false; 40 | } 41 | } 42 | 43 | public Data(string name) 44 | { 45 | Name = name; 46 | } 47 | public abstract void Print(string indent); 48 | public abstract string ToKrlString(); 49 | } 50 | 51 | 52 | public class BoolData : Data 53 | { 54 | public override DataType Type => DataType.BOOL; 55 | public bool Value { get; private set; } 56 | public override string ToKrlString() => Value ? "TRUE" : "FALSE"; 57 | public BoolData(string name, string value) : base(name) 58 | { 59 | Value = bool.Parse(value); 60 | } 61 | public override void Print(string indent) => Console.WriteLine(indent + "+- " + Name + "<" + Type + ">" + " = " + Value); 62 | } 63 | public class EnumData : Data 64 | { 65 | public override DataType Type => DataType.ENUM; 66 | public string Value { get; private set; } 67 | public override string ToKrlString() => Value.ToString(); 68 | public EnumData(string name, string value) : base(name) 69 | { 70 | Value = value; 71 | } 72 | public override void Print(string indent) => Console.WriteLine(indent + "+- " + Name + "<" + Type + ">" + " = " + Value); 73 | } 74 | public class IntData : Data 75 | { 76 | public override DataType Type => DataType.INT; 77 | public short Value { get; private set; } 78 | public override string ToKrlString() => Value.ToString(); 79 | public IntData(string name, string value) : base(name) 80 | { 81 | Value = short.Parse(value, CultureInfo.InvariantCulture); 82 | } 83 | public override void Print(string indent) => Console.WriteLine(indent + "+- " + Name + "<" + Type + ">" + " = " + Value); 84 | } 85 | public class RealData : Data 86 | { 87 | public override DataType Type => DataType.REAL; 88 | public double Value { get; private set; } 89 | public override string ToKrlString() => Value.ToString(); 90 | public RealData(string name, string value) : base(name) 91 | { 92 | Value = double.Parse(value, CultureInfo.InvariantCulture); 93 | } 94 | public override void Print(string indent) => Console.WriteLine(indent + "+- " + Name + "<" + Type + ">" + " = " + Value); 95 | } 96 | public class CharData : Data 97 | { 98 | public override DataType Type => DataType.CHAR; 99 | public char Value { get; private set; } 100 | public override string ToKrlString() => Value.ToString(); 101 | public CharData(string name, string value) : base(name) 102 | { 103 | Value = char.Parse(value.Substring(1, value.Length - 2)); 104 | } 105 | public override void Print(string indent) => Console.WriteLine(indent + "+- " + Name + "<" + Type + ">" + " = '" + Value + "'"); 106 | } 107 | public class StringData : Data 108 | { 109 | public override DataType Type => DataType.STRING; 110 | public string Value { get; private set; } 111 | public override string ToKrlString() => Value; 112 | public StringData(string name, string value) : base(name) 113 | { 114 | Value = value.Substring(1, value.Length - 2); 115 | } 116 | public override void Print(string indent) => Console.WriteLine(indent + "+- " + Name + "<" + Type + ">" + " = \"" + Value + "\""); 117 | } 118 | public class StrucData : Data 119 | { 120 | public override DataType Type => DataType.STRUC; 121 | public string StrucType { get; private set; } 122 | public override string ToKrlString() 123 | { 124 | var krl = "{" + Type + ": "; 125 | foreach (var node in Value) 126 | { 127 | node.Value.ToKrlString(); 128 | } 129 | krl += "}"; 130 | return krl; 131 | } 132 | public Dictionary Value { get; private set; } 133 | public StrucData(string name, string strucType, IEnumerable dataList) : base(name) 134 | { 135 | Value = new Dictionary(StringComparer.InvariantCultureIgnoreCase); // case insensitive dic as KRL is case insensitive 136 | foreach (var data in dataList) Value.Add(data.Name, data); 137 | StrucType = strucType.Substring(0, strucType.Length - 1); 138 | } 139 | public override void Print(string indent) 140 | { 141 | Console.WriteLine(indent + "+- " + Name + ""); 142 | indent += "| "; 143 | foreach (var node in Value) node.Value.Print(indent); 144 | } 145 | 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/OpenKuka.KRL/Types/Motion.cs: -------------------------------------------------------------------------------- 1 | 2 | using OpenKuka.KRL.DataParser; 3 | using System; 4 | using System.Collections; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | 8 | namespace OpenKuka.KRL.Types 9 | { 10 | public interface IAxis 11 | { 12 | double? A1 { get; set; } 13 | double? A2 { get; set; } 14 | double? A3 { get; set; } 15 | double? A4 { get; set; } 16 | double? A5 { get; set; } 17 | double? A6 { get; set; } 18 | } 19 | public interface IEAxis 20 | { 21 | double? E1 { get; set; } 22 | double? E2 { get; set; } 23 | double? E3 { get; set; } 24 | double? E4 { get; set; } 25 | double? E5 { get; set; } 26 | double? E6 { get; set; } 27 | } 28 | public interface IFrame 29 | { 30 | double? X { get; set; } 31 | double? Y { get; set; } 32 | double? Z { get; set; } 33 | double? A { get; set; } 34 | double? B { get; set; } 35 | double? C { get; set; } 36 | } 37 | public interface IStatusTurn 38 | { 39 | int? S { get; set; } 40 | int? T { get; set; } 41 | STATUS? GetStatus(); 42 | TURN? GetTurn(); 43 | } 44 | 45 | public struct STATUS 46 | { 47 | private BitArray _bits; 48 | 49 | /// 50 | /// Bit 0: Position of the wrist root point(basic/overhead area) 51 | /// 52 | public bool B0 => _bits[0]; 53 | 54 | /// 55 | /// Bit 1: Arm configuration 56 | /// 57 | public bool B1 => _bits[1]; 58 | 59 | /// 60 | /// Bit 2: Wrist configuration 61 | /// 62 | public bool B2 => _bits[2]; 63 | 64 | public STATUS(int status) : this() 65 | { 66 | _bits = new BitArray(new int[] { status }); 67 | } 68 | 69 | public override string ToString() 70 | { 71 | return ToString(); 72 | } 73 | public string ToString(bool bitsRep = true) 74 | { 75 | if (bitsRep) 76 | { 77 | var cmd = "'B"; 78 | cmd += B2 ? "1" : "0"; 79 | cmd += B1 ? "1" : "0"; 80 | cmd += B0 ? "1" : "0"; 81 | cmd += "'"; 82 | return cmd; 83 | } 84 | else 85 | { 86 | return "" + ToInt(); 87 | } 88 | } 89 | public int ToInt() 90 | { 91 | int val = 0; 92 | val += B2 ? 4 : 0; 93 | val += B1 ? 2 : 0; 94 | val += B0 ? 1 : 0; 95 | return val; 96 | } 97 | } 98 | public struct TURN 99 | { 100 | private BitArray _bits; 101 | 102 | /// 103 | /// Bit 0: angle of A1 < 0 (true) 104 | /// 105 | public bool B0 => _bits[0]; 106 | 107 | /// 108 | /// Bit 1: angle of A2 < 0 (true) 109 | /// 110 | public bool B1 => _bits[1]; 111 | 112 | /// 113 | /// Bit 2: angle of A3 < 0 (true) 114 | /// 115 | public bool B2 => _bits[2]; 116 | 117 | /// 118 | /// Bit 3: angle of A4 < 0 (true) 119 | /// 120 | public bool B3 => _bits[3]; 121 | 122 | /// 123 | /// Bit 4: angle of A5 < 0 (true) 124 | /// 125 | public bool B4 => _bits[4]; 126 | 127 | /// 128 | /// Bit 5: angle of A6 < 0 (true) 129 | /// 130 | public bool B5 => _bits[5]; 131 | 132 | public TURN(int turn) : this() 133 | { 134 | _bits = new BitArray(new int[] { turn }); 135 | } 136 | 137 | public override string ToString() 138 | { 139 | return ToString(); 140 | } 141 | public string ToString(bool bitsRep = true) 142 | { 143 | if (bitsRep) 144 | { 145 | var cmd = "'B"; 146 | cmd += B5 ? "1" : "0"; 147 | cmd += B4 ? "1" : "0"; 148 | cmd += B3 ? "1" : "0"; 149 | cmd += B2 ? "1" : "0"; 150 | cmd += B1 ? "1" : "0"; 151 | cmd += B0 ? "1" : "0"; 152 | cmd += "'"; 153 | return cmd; 154 | } 155 | else 156 | { 157 | return "" + ToInt(); 158 | } 159 | } 160 | public int ToInt() 161 | { 162 | int val = 0; 163 | val += B5 ? 32 : 0; 164 | val += B4 ? 16 : 0; 165 | val += B3 ? 8 : 0; 166 | val += B2 ? 4 : 0; 167 | val += B1 ? 2 : 0; 168 | val += B0 ? 1 : 0; 169 | return val; 170 | } 171 | } 172 | 173 | public struct AXIS : IAxis 174 | { 175 | public double? A1 { get; set; } 176 | public double? A2 { get; set; } 177 | public double? A3 { get; set; } 178 | public double? A4 { get; set; } 179 | public double? A5 { get; set; } 180 | public double? A6 { get; set; } 181 | 182 | public AXIS(Data data) : this() 183 | { 184 | var tree = data as StrucData; 185 | 186 | if (tree == null) 187 | throw new ArgumentException("The data provided is not a STRUC", "data"); 188 | 189 | if (tree.StrucType != "AXIS") 190 | throw new ArgumentException("The data provided is not of type AXIS"); 191 | 192 | if (tree.Value.ContainsKey("A1")) A1 = ((RealData)tree.Value["A1"]).Value; 193 | if (tree.Value.ContainsKey("A2")) A2 = ((RealData)tree.Value["A2"]).Value; 194 | if (tree.Value.ContainsKey("A3")) A3 = ((RealData)tree.Value["A3"]).Value; 195 | if (tree.Value.ContainsKey("A4")) A4 = ((RealData)tree.Value["A4"]).Value; 196 | if (tree.Value.ContainsKey("A5")) A5 = ((RealData)tree.Value["A5"]).Value; 197 | if (tree.Value.ContainsKey("A6")) A6 = ((RealData)tree.Value["A6"]).Value; 198 | } 199 | 200 | public override string ToString() 201 | { 202 | return ToString(); 203 | } 204 | public string ToString(bool showType = true, string format = "G6") 205 | { 206 | var items = new List(); 207 | 208 | if (A1.HasValue) items.Add(string.Format("A1 {0:" + format + "}", A1)); 209 | if (A2.HasValue) items.Add(string.Format("A2 {0:" + format + "}", A2)); 210 | if (A3.HasValue) items.Add(string.Format("A3 {0:" + format + "}", A3)); 211 | if (A4.HasValue) items.Add(string.Format("A4 {0:" + format + "}", A4)); 212 | if (A5.HasValue) items.Add(string.Format("A5 {0:" + format + "}", A5)); 213 | if (A6.HasValue) items.Add(string.Format("A6 {0:" + format + "}", A6)); 214 | 215 | var cmd = showType ? "{AXIS: " : "{"; 216 | cmd += string.Join(", ", items) + "}"; 217 | return cmd; 218 | } 219 | } 220 | public struct E6AXIS : IAxis, IEAxis 221 | { 222 | public double? A1 { get; set; } 223 | public double? A2 { get; set; } 224 | public double? A3 { get; set; } 225 | public double? A4 { get; set; } 226 | public double? A5 { get; set; } 227 | public double? A6 { get; set; } 228 | 229 | public double? E1 { get; set; } 230 | public double? E2 { get; set; } 231 | public double? E3 { get; set; } 232 | public double? E4 { get; set; } 233 | public double? E5 { get; set; } 234 | public double? E6 { get; set; } 235 | 236 | public E6AXIS(Data data) : this() 237 | { 238 | var tree = data as StrucData; 239 | 240 | if (tree == null) 241 | throw new ArgumentException("The data provided is not a STRUC", "data"); 242 | 243 | if (tree.StrucType != "E6AXIS") 244 | throw new ArgumentException("The data provided is not of type E6AXIS"); 245 | 246 | if (tree.Value.ContainsKey("A1")) A1 = ((RealData)tree.Value["A1"]).Value; 247 | if (tree.Value.ContainsKey("A2")) A2 = ((RealData)tree.Value["A2"]).Value; 248 | if (tree.Value.ContainsKey("A3")) A3 = ((RealData)tree.Value["A3"]).Value; 249 | if (tree.Value.ContainsKey("A4")) A4 = ((RealData)tree.Value["A4"]).Value; 250 | if (tree.Value.ContainsKey("A5")) A5 = ((RealData)tree.Value["A5"]).Value; 251 | if (tree.Value.ContainsKey("A6")) A6 = ((RealData)tree.Value["A6"]).Value; 252 | 253 | if (tree.Value.ContainsKey("E1")) E1 = ((RealData)tree.Value["E1"]).Value; 254 | if (tree.Value.ContainsKey("E2")) E2 = ((RealData)tree.Value["E2"]).Value; 255 | if (tree.Value.ContainsKey("E3")) E3 = ((RealData)tree.Value["E3"]).Value; 256 | if (tree.Value.ContainsKey("E4")) E4 = ((RealData)tree.Value["E4"]).Value; 257 | if (tree.Value.ContainsKey("E5")) E5 = ((RealData)tree.Value["E5"]).Value; 258 | if (tree.Value.ContainsKey("E6")) E6 = ((RealData)tree.Value["E6"]).Value; 259 | } 260 | 261 | public override string ToString() 262 | { 263 | return ToString(); 264 | } 265 | public string ToString(bool showType = true, string format = "G6") 266 | { 267 | var items = new List(); 268 | 269 | if (A1.HasValue) items.Add(string.Format("A1 {0:" + format + "}", A1)); 270 | if (A2.HasValue) items.Add(string.Format("A2 {0:" + format + "}", A2)); 271 | if (A3.HasValue) items.Add(string.Format("A3 {0:" + format + "}", A3)); 272 | if (A4.HasValue) items.Add(string.Format("A4 {0:" + format + "}", A4)); 273 | if (A5.HasValue) items.Add(string.Format("A5 {0:" + format + "}", A5)); 274 | if (A6.HasValue) items.Add(string.Format("A6 {0:" + format + "}", A6)); 275 | 276 | if (E1.HasValue) items.Add(string.Format("E1 {0:" + format + "}", E1)); 277 | if (E2.HasValue) items.Add(string.Format("E2 {0:" + format + "}", E2)); 278 | if (E3.HasValue) items.Add(string.Format("E3 {0:" + format + "}", E3)); 279 | if (E4.HasValue) items.Add(string.Format("E4 {0:" + format + "}", E4)); 280 | if (E5.HasValue) items.Add(string.Format("E5 {0:" + format + "}", E5)); 281 | if (E6.HasValue) items.Add(string.Format("E6 {0:" + format + "}", E6)); 282 | 283 | var cmd = showType ? "{E6AXIS: " : "{"; 284 | cmd += string.Join(", ", items) + "}"; 285 | return cmd; 286 | } 287 | } 288 | public struct FRAME : IFrame 289 | { 290 | public double? X { get; set; } 291 | public double? Y { get; set; } 292 | public double? Z { get; set; } 293 | public double? A { get; set; } 294 | public double? B { get; set; } 295 | public double? C { get; set; } 296 | 297 | public FRAME(IEnumerable xyzabc) 298 | { 299 | X = xyzabc.ElementAt(0); 300 | Y = xyzabc.ElementAt(1); 301 | Z = xyzabc.ElementAt(2); 302 | A = xyzabc.ElementAt(3); 303 | B = xyzabc.ElementAt(4); 304 | C = xyzabc.ElementAt(5); 305 | } 306 | public FRAME(Data data) : this() 307 | { 308 | var tree = data as StrucData; 309 | 310 | if (tree == null) 311 | throw new ArgumentException("The data provided is not a STRUC", "data"); 312 | 313 | if (tree.StrucType != "FRAME") 314 | throw new ArgumentException("The data provided is not of type FRAME"); 315 | 316 | if (tree.Value.ContainsKey("X")) X = ((RealData)tree.Value["X"]).Value; 317 | if (tree.Value.ContainsKey("Y")) Y = ((RealData)tree.Value["Y"]).Value; 318 | if (tree.Value.ContainsKey("Z")) Z = ((RealData)tree.Value["Z"]).Value; 319 | if (tree.Value.ContainsKey("A")) A = ((RealData)tree.Value["A"]).Value; 320 | if (tree.Value.ContainsKey("B")) B = ((RealData)tree.Value["B"]).Value; 321 | if (tree.Value.ContainsKey("C")) C = ((RealData)tree.Value["C"]).Value; 322 | } 323 | 324 | public override string ToString() 325 | { 326 | return ToString(); 327 | } 328 | public string ToString(bool showType = true, string format = "G6") 329 | { 330 | var items = new List(); 331 | 332 | if (X.HasValue) items.Add(string.Format("X {0:" + format + "}", X)); 333 | if (Y.HasValue) items.Add(string.Format("Y {0:" + format + "}", Y)); 334 | if (Z.HasValue) items.Add(string.Format("Z {0:" + format + "}", Z)); 335 | if (A.HasValue) items.Add(string.Format("A {0:" + format + "}", A)); 336 | if (B.HasValue) items.Add(string.Format("B {0:" + format + "}", B)); 337 | if (C.HasValue) items.Add(string.Format("C {0:" + format + "}", C)); 338 | 339 | var cmd = showType ? "{FRAME: " : "{"; 340 | cmd += string.Join(", ", items) + "}"; 341 | return cmd; 342 | } 343 | } 344 | public struct POS : IFrame, IStatusTurn 345 | { 346 | public double? X { get; set; } 347 | public double? Y { get; set; } 348 | public double? Z { get; set; } 349 | public double? A { get; set; } 350 | public double? B { get; set; } 351 | public double? C { get; set; } 352 | public int? S { get; set; } 353 | public int? T { get; set; } 354 | 355 | public STATUS? GetStatus() 356 | { 357 | if (S.HasValue) return new STATUS(S.Value); 358 | return null; 359 | } 360 | public TURN? GetTurn() 361 | { 362 | if (T.HasValue) return new TURN(T.Value); 363 | return null; 364 | } 365 | 366 | public POS(Data data) : this() 367 | { 368 | var tree = data as StrucData; 369 | 370 | if (tree == null) 371 | throw new ArgumentException("The data provided is not a STRUC", "data"); 372 | 373 | if (tree.StrucType != "POS") 374 | throw new ArgumentException("The data provided is not of type POS"); 375 | 376 | if (tree.Value.ContainsKey("X")) X = ((RealData)tree.Value["X"]).Value; 377 | if (tree.Value.ContainsKey("Y")) Y = ((RealData)tree.Value["Y"]).Value; 378 | if (tree.Value.ContainsKey("Z")) Z = ((RealData)tree.Value["Z"]).Value; 379 | if (tree.Value.ContainsKey("A")) A = ((RealData)tree.Value["A"]).Value; 380 | if (tree.Value.ContainsKey("B")) B = ((RealData)tree.Value["B"]).Value; 381 | if (tree.Value.ContainsKey("C")) C = ((RealData)tree.Value["C"]).Value; 382 | 383 | if (tree.Value.ContainsKey("S")) S = ((IntData)tree.Value["S"]).Value; 384 | if (tree.Value.ContainsKey("T")) T = ((IntData)tree.Value["T"]).Value; 385 | } 386 | 387 | public override string ToString() 388 | { 389 | return ToString(); 390 | } 391 | public string ToString(bool showType = true, string format = "G6") 392 | { 393 | var items = new List(); 394 | 395 | if (X.HasValue) items.Add(string.Format("X {0:" + format + "}", X)); 396 | if (Y.HasValue) items.Add(string.Format("Y {0:" + format + "}", Y)); 397 | if (Z.HasValue) items.Add(string.Format("Z {0:" + format + "}", Z)); 398 | if (A.HasValue) items.Add(string.Format("A {0:" + format + "}", A)); 399 | if (B.HasValue) items.Add(string.Format("B {0:" + format + "}", B)); 400 | if (C.HasValue) items.Add(string.Format("C {0:" + format + "}", C)); 401 | 402 | if (S.HasValue) items.Add(string.Format("S {0}", S)); 403 | if (T.HasValue) items.Add(string.Format("T {0}", T)); 404 | 405 | var cmd = showType ? "{FRAME: " : "{"; 406 | cmd += string.Join(", ", items) + "}"; 407 | return cmd; 408 | } 409 | } 410 | public struct E6POS : IFrame, IStatusTurn, IEAxis 411 | { 412 | public double? X { get; set; } 413 | public double? Y { get; set; } 414 | public double? Z { get; set; } 415 | public double? A { get; set; } 416 | public double? B { get; set; } 417 | public double? C { get; set; } 418 | 419 | public int? S { get; set; } 420 | public int? T { get; set; } 421 | 422 | public double? E1 { get; set; } 423 | public double? E2 { get; set; } 424 | public double? E3 { get; set; } 425 | public double? E4 { get; set; } 426 | public double? E5 { get; set; } 427 | public double? E6 { get; set; } 428 | 429 | public STATUS? GetStatus() 430 | { 431 | if (S.HasValue) return new STATUS(S.Value); 432 | return null; 433 | } 434 | public TURN? GetTurn() 435 | { 436 | if (T.HasValue) return new TURN(T.Value); 437 | return null; 438 | } 439 | 440 | public E6POS(IEnumerable xyzabc) 441 | { 442 | X = xyzabc.ElementAt(0); 443 | Y = xyzabc.ElementAt(1); 444 | Z = xyzabc.ElementAt(2); 445 | A = xyzabc.ElementAt(3); 446 | B = xyzabc.ElementAt(4); 447 | C = xyzabc.ElementAt(5); 448 | 449 | S = null; 450 | T = null; 451 | E1 = null; 452 | E2 = null; 453 | E3 = null; 454 | E4 = null; 455 | E5 = null; 456 | E6 = null; 457 | } 458 | public E6POS(IEnumerable xyzabc, IEnumerable eAxis) 459 | { 460 | X = xyzabc.ElementAt(0); 461 | Y = xyzabc.ElementAt(1); 462 | Z = xyzabc.ElementAt(2); 463 | A = xyzabc.ElementAt(3); 464 | B = xyzabc.ElementAt(4); 465 | C = xyzabc.ElementAt(5); 466 | 467 | S = null; 468 | T = null; 469 | 470 | E1 = eAxis.ElementAt(0); 471 | E2 = eAxis.ElementAt(1); 472 | E3 = eAxis.ElementAt(2); 473 | E4 = eAxis.ElementAt(3); 474 | E5 = eAxis.ElementAt(4); 475 | E6 = eAxis.ElementAt(5); 476 | } 477 | 478 | public E6POS(Data data) : this() 479 | { 480 | var tree = data as StrucData; 481 | 482 | if (tree == null) 483 | throw new ArgumentException("The data provided is not a STRUC", "data"); 484 | 485 | if (tree.StrucType != "E6POS") 486 | throw new ArgumentException("The data provided is not of type E6POS"); 487 | 488 | if (tree.Value.ContainsKey("X")) X = ((RealData)tree.Value["X"]).Value; 489 | if (tree.Value.ContainsKey("Y")) Y = ((RealData)tree.Value["Y"]).Value; 490 | if (tree.Value.ContainsKey("Z")) Z = ((RealData)tree.Value["Z"]).Value; 491 | if (tree.Value.ContainsKey("A")) A = ((RealData)tree.Value["A"]).Value; 492 | if (tree.Value.ContainsKey("B")) B = ((RealData)tree.Value["B"]).Value; 493 | if (tree.Value.ContainsKey("C")) C = ((RealData)tree.Value["C"]).Value; 494 | 495 | if (tree.Value.ContainsKey("S")) S = ((IntData)tree.Value["S"]).Value; 496 | if (tree.Value.ContainsKey("T")) T = ((IntData)tree.Value["T"]).Value; 497 | 498 | if (tree.Value.ContainsKey("E1")) E1 = ((RealData)tree.Value["E1"]).Value; 499 | if (tree.Value.ContainsKey("E2")) E2 = ((RealData)tree.Value["E2"]).Value; 500 | if (tree.Value.ContainsKey("E3")) E3 = ((RealData)tree.Value["E3"]).Value; 501 | if (tree.Value.ContainsKey("E4")) E4 = ((RealData)tree.Value["E4"]).Value; 502 | if (tree.Value.ContainsKey("E5")) E5 = ((RealData)tree.Value["E5"]).Value; 503 | if (tree.Value.ContainsKey("E6")) E6 = ((RealData)tree.Value["E6"]).Value; 504 | } 505 | 506 | public override string ToString() 507 | { 508 | return ToString(); 509 | } 510 | public string ToString(bool showType = true, string format = "G6") 511 | { 512 | var items = new List(); 513 | 514 | if (X.HasValue) items.Add(string.Format("X {0:" + format + "}", X)); 515 | if (Y.HasValue) items.Add(string.Format("Y {0:" + format + "}", Y)); 516 | if (Z.HasValue) items.Add(string.Format("Z {0:" + format + "}", Z)); 517 | if (A.HasValue) items.Add(string.Format("A {0:" + format + "}", A)); 518 | if (B.HasValue) items.Add(string.Format("B {0:" + format + "}", B)); 519 | if (C.HasValue) items.Add(string.Format("C {0:" + format + "}", C)); 520 | 521 | if (E1.HasValue) items.Add(string.Format("E1 {0:" + format + "}", E1)); 522 | if (E2.HasValue) items.Add(string.Format("E2 {0:" + format + "}", E2)); 523 | if (E3.HasValue) items.Add(string.Format("E3 {0:" + format + "}", E3)); 524 | if (E4.HasValue) items.Add(string.Format("E4 {0:" + format + "}", E4)); 525 | if (E5.HasValue) items.Add(string.Format("E5 {0:" + format + "}", E5)); 526 | if (E6.HasValue) items.Add(string.Format("E6 {0:" + format + "}", E6)); 527 | 528 | if (S.HasValue) items.Add(string.Format("S {0}", S)); 529 | if (T.HasValue) items.Add(string.Format("T {0}", T)); 530 | 531 | 532 | 533 | var cmd = showType ? "{E6POS: " : "{"; 534 | cmd += string.Join(", ", items) + "}"; 535 | return cmd; 536 | } 537 | } 538 | 539 | public struct CP 540 | { 541 | public double? LIN { get; set; } 542 | public double? ORI1 { get; set; } 543 | public double? ORI2 { get; set; } 544 | 545 | public CP(Data data) : this() 546 | { 547 | var tree = data as StrucData; 548 | 549 | if (tree == null) 550 | throw new ArgumentException("The data provided is not a STRUC", "data"); 551 | 552 | if (tree.StrucType != "VEL") 553 | throw new ArgumentException("The data provided is not of type VEL"); 554 | 555 | if (tree.Value.ContainsKey("CP")) LIN = ((RealData)tree.Value["CP"]).Value; 556 | if (tree.Value.ContainsKey("ORI1")) ORI1 = ((RealData)tree.Value["ORI1"]).Value; 557 | if (tree.Value.ContainsKey("ORI2")) ORI2 = ((RealData)tree.Value["ORI2"]).Value; 558 | } 559 | 560 | public override string ToString() 561 | { 562 | return ToString(); 563 | } 564 | public string ToString(bool showType = true, string format = "G6") 565 | { 566 | var items = new List(); 567 | 568 | if (LIN.HasValue) items.Add(string.Format("CP {0:" + format + "}", LIN)); 569 | if (ORI1.HasValue) items.Add(string.Format("ORI1 {0:" + format + "}", ORI1)); 570 | if (ORI2.HasValue) items.Add(string.Format("ORI2 {0:" + format + "}", ORI2)); 571 | 572 | var cmd = showType ? "{FRAME: " : "{"; 573 | cmd += string.Join(", ", items) + "}"; 574 | return cmd; 575 | } 576 | } 577 | 578 | public enum CIRC_TYPE 579 | { 580 | /// 581 | /// Space-related orientation control 582 | /// 583 | BASE, 584 | 585 | /// 586 | /// Path-related orientation control 587 | /// 588 | PATH 589 | } 590 | 591 | public enum DIRECTION 592 | { 593 | /// 594 | /// Forwards execution 595 | /// 596 | FORWARD, 597 | 598 | /// 599 | /// Backwards execution 600 | /// 601 | BACKWARD 602 | } 603 | 604 | public enum IPO_MODE 605 | { 606 | BASE, 607 | TCP 608 | } 609 | 610 | 611 | public enum ORI_TYPE 612 | { 613 | /// 614 | /// Variable orientation with possible reduction of velocity and acceleration. 615 | /// 616 | VAR, 617 | 618 | /// 619 | /// Constant orientation. 620 | /// 621 | CONSTANT, 622 | 623 | /// 624 | /// Variable orientation without reduction of velocity and acceleration. 625 | /// 626 | JOINT 627 | } 628 | 629 | public enum TARGET_STATUS 630 | { 631 | /// 632 | /// Use Status of start point. 633 | /// 634 | SOURCE, 635 | 636 | /// 637 | /// All eight Status combinations are calculated; the one with the shortest path between the start point and end point in axis space is selected. 638 | /// 639 | BEST 640 | } 641 | 642 | public enum TRANSSYS 643 | { 644 | WORLD, 645 | BASE, 646 | ROBROOT, 647 | TCP 648 | } 649 | 650 | 651 | public static class KRL 652 | { 653 | public static string PTP(AXIS axis, string suffix = "", bool showType = true, string format = "G6") 654 | { 655 | var cmd = "PTP " + axis.ToString(showType, format) + suffix; 656 | return cmd; 657 | } 658 | public static string PTP(E6AXIS e6axis, string suffix = "", bool showType = true, string format = "G6") 659 | { 660 | var cmd = "PTP " + e6axis.ToString(showType, format) + suffix; 661 | return cmd; 662 | } 663 | public static string PTP(FRAME frame, string suffix = "", bool showType = true, string format = "G6") 664 | { 665 | var cmd = "PTP " + frame.ToString(showType, format) + suffix; 666 | return cmd; 667 | } 668 | public static string PTP(POS pos, string suffix = "", bool showType = true, string format = "G6") 669 | { 670 | var cmd = "PTP " + pos.ToString(showType, format) + suffix; 671 | return cmd; 672 | } 673 | public static string PTP(E6POS e6pos, string suffix = "", bool showType = true, string format = "G6") 674 | { 675 | var cmd = "PTP " + e6pos.ToString(showType, format) + suffix; 676 | return cmd; 677 | } 678 | 679 | public static string LIN(FRAME frame, string suffix = "", bool showType = true, string format = "G6") 680 | { 681 | var cmd = "LIN " + frame.ToString(showType, format) + suffix; 682 | return cmd; 683 | } 684 | public static string LIN(POS pos, string suffix = "", bool showType = true, string format = "G6") 685 | { 686 | var cmd = "LIN " + pos.ToString(showType, format) + suffix; 687 | return cmd; 688 | } 689 | public static string LIN(E6POS e6pos, string suffix = "", bool showType = true, string format = "G6") 690 | { 691 | var cmd = "LIN " + e6pos.ToString(showType, format) + suffix; 692 | return cmd; 693 | } 694 | } 695 | } --------------------------------------------------------------------------------