diff --git a/CoppeliaSimCSharpAPI.TestForm/Api.cs b/CoppeliaSimCSharpAPI.TestForm/Api.cs new file mode 100644 index 0000000..a52dea8 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Api.cs @@ -0,0 +1,29 @@ +using System; +using System.Runtime.InteropServices; + +namespace CoppeliaSimCSharpAPI.TestForm +{ + internal class Api + { + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int Connect(string address, int port); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int Disconnect(int id); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern bool IsConnected(int id); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int GetJointPosition(int id, int[] jointHandle, float[] position, int jointCount); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int GetObjectHandle(int id, string objectName); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int MoveJoint(int id, int[] jointHandle, float[] position, bool inTorqueForceMode, int jointCount); + + [DllImport("CoppeliaSimCSharpAPI.dll")] + public static extern int SendInfo(int id, string message, bool blocking); + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/App.config b/CoppeliaSimCSharpAPI.TestForm/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj new file mode 100644 index 0000000..f1729a9 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/CoppeliaSimCSharpAPI.TestForm.csproj @@ -0,0 +1,104 @@ + + + + + Debug + AnyCPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5} + WinExe + CoppeliaSimCSharpAPI.TestForm + CoppeliaSimCSharpAPI.TestForm + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + true + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs new file mode 100644 index 0000000..2ba0bad --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.Designer.cs @@ -0,0 +1,301 @@ +namespace CoppeliaSimCSharpAPI.TestForm +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonConnect = new System.Windows.Forms.Button(); + this.buttonDisconnect = new System.Windows.Forms.Button(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.numericUpDownPort = new System.Windows.Forms.NumericUpDown(); + this.buttonMove = new System.Windows.Forms.Button(); + this.numericUpDownJ1 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ2 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ3 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ4 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ5 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownJ6 = new System.Windows.Forms.NumericUpDown(); + this.buttonGetPosition = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ4)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ5)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ6)).BeginInit(); + this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); + this.SuspendLayout(); + // + // buttonConnect + // + this.buttonConnect.Location = new System.Drawing.Point(6, 78); + this.buttonConnect.Name = "buttonConnect"; + this.buttonConnect.Size = new System.Drawing.Size(159, 73); + this.buttonConnect.TabIndex = 0; + this.buttonConnect.Text = "Connect"; + this.buttonConnect.UseVisualStyleBackColor = true; + this.buttonConnect.Click += new System.EventHandler(this.buttonConnect_Click); + // + // buttonDisconnect + // + this.buttonDisconnect.Location = new System.Drawing.Point(184, 78); + this.buttonDisconnect.Name = "buttonDisconnect"; + this.buttonDisconnect.Size = new System.Drawing.Size(159, 73); + this.buttonDisconnect.TabIndex = 0; + this.buttonDisconnect.Text = "Disconnect"; + this.buttonDisconnect.UseVisualStyleBackColor = true; + this.buttonDisconnect.Click += new System.EventHandler(this.buttonDisconnect_Click); + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(27, 31); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(100, 31); + this.textBoxAddress.TabIndex = 1; + this.textBoxAddress.Text = "127.0.0.1"; + // + // numericUpDownPort + // + this.numericUpDownPort.Location = new System.Drawing.Point(198, 31); + this.numericUpDownPort.Maximum = new decimal(new int[] { + 99999, + 0, + 0, + 0}); + this.numericUpDownPort.Name = "numericUpDownPort"; + this.numericUpDownPort.Size = new System.Drawing.Size(120, 31); + this.numericUpDownPort.TabIndex = 2; + this.numericUpDownPort.Value = new decimal(new int[] { + 3000, + 0, + 0, + 0}); + // + // buttonMove + // + this.buttonMove.Location = new System.Drawing.Point(17, 98); + this.buttonMove.Name = "buttonMove"; + this.buttonMove.Size = new System.Drawing.Size(159, 73); + this.buttonMove.TabIndex = 3; + this.buttonMove.Text = "Move"; + this.buttonMove.UseVisualStyleBackColor = true; + this.buttonMove.Click += new System.EventHandler(this.buttonMove_Click); + // + // numericUpDownJ1 + // + this.numericUpDownJ1.DecimalPlaces = 1; + this.numericUpDownJ1.Location = new System.Drawing.Point(17, 46); + this.numericUpDownJ1.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ1.Name = "numericUpDownJ1"; + this.numericUpDownJ1.Size = new System.Drawing.Size(80, 31); + this.numericUpDownJ1.TabIndex = 4; + this.numericUpDownJ1.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ2 + // + this.numericUpDownJ2.DecimalPlaces = 1; + this.numericUpDownJ2.Location = new System.Drawing.Point(103, 46); + this.numericUpDownJ2.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ2.Name = "numericUpDownJ2"; + this.numericUpDownJ2.Size = new System.Drawing.Size(80, 31); + this.numericUpDownJ2.TabIndex = 4; + this.numericUpDownJ2.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ3 + // + this.numericUpDownJ3.DecimalPlaces = 1; + this.numericUpDownJ3.Location = new System.Drawing.Point(189, 46); + this.numericUpDownJ3.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ3.Name = "numericUpDownJ3"; + this.numericUpDownJ3.Size = new System.Drawing.Size(80, 31); + this.numericUpDownJ3.TabIndex = 4; + this.numericUpDownJ3.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ4 + // + this.numericUpDownJ4.DecimalPlaces = 1; + this.numericUpDownJ4.Location = new System.Drawing.Point(275, 46); + this.numericUpDownJ4.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ4.Name = "numericUpDownJ4"; + this.numericUpDownJ4.Size = new System.Drawing.Size(80, 31); + this.numericUpDownJ4.TabIndex = 4; + this.numericUpDownJ4.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ5 + // + this.numericUpDownJ5.DecimalPlaces = 1; + this.numericUpDownJ5.Location = new System.Drawing.Point(361, 46); + this.numericUpDownJ5.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ5.Name = "numericUpDownJ5"; + this.numericUpDownJ5.Size = new System.Drawing.Size(80, 31); + this.numericUpDownJ5.TabIndex = 4; + this.numericUpDownJ5.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // numericUpDownJ6 + // + this.numericUpDownJ6.DecimalPlaces = 1; + this.numericUpDownJ6.Location = new System.Drawing.Point(447, 46); + this.numericUpDownJ6.Maximum = new decimal(new int[] { + 360, + 0, + 0, + 0}); + this.numericUpDownJ6.Name = "numericUpDownJ6"; + this.numericUpDownJ6.Size = new System.Drawing.Size(80, 31); + this.numericUpDownJ6.TabIndex = 4; + this.numericUpDownJ6.Value = new decimal(new int[] { + 90, + 0, + 0, + 0}); + // + // buttonGetPosition + // + this.buttonGetPosition.Location = new System.Drawing.Point(212, 98); + this.buttonGetPosition.Name = "buttonGetPosition"; + this.buttonGetPosition.Size = new System.Drawing.Size(159, 73); + this.buttonGetPosition.TabIndex = 5; + this.buttonGetPosition.Text = "Get Position"; + this.buttonGetPosition.UseVisualStyleBackColor = true; + this.buttonGetPosition.Click += new System.EventHandler(this.buttonGetPosition_Click); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.textBoxAddress); + this.groupBox1.Controls.Add(this.numericUpDownPort); + this.groupBox1.Controls.Add(this.buttonConnect); + this.groupBox1.Controls.Add(this.buttonDisconnect); + this.groupBox1.Location = new System.Drawing.Point(27, 29); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(354, 167); + this.groupBox1.TabIndex = 6; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Connection"; + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.numericUpDownJ1); + this.groupBox2.Controls.Add(this.numericUpDownJ2); + this.groupBox2.Controls.Add(this.buttonGetPosition); + this.groupBox2.Controls.Add(this.numericUpDownJ3); + this.groupBox2.Controls.Add(this.buttonMove); + this.groupBox2.Controls.Add(this.numericUpDownJ6); + this.groupBox2.Controls.Add(this.numericUpDownJ4); + this.groupBox2.Controls.Add(this.numericUpDownJ5); + this.groupBox2.Location = new System.Drawing.Point(27, 223); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(554, 204); + this.groupBox2.TabIndex = 7; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Motion"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(664, 479); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox1); + this.Name = "Form1"; + this.Text = "CoppeliaSim C# API Test Form"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownPort)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ4)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ5)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownJ6)).EndInit(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button buttonConnect; + private System.Windows.Forms.Button buttonDisconnect; + private System.Windows.Forms.TextBox textBoxAddress; + private System.Windows.Forms.NumericUpDown numericUpDownPort; + private System.Windows.Forms.Button buttonMove; + private System.Windows.Forms.NumericUpDown numericUpDownJ1; + private System.Windows.Forms.NumericUpDown numericUpDownJ2; + private System.Windows.Forms.NumericUpDown numericUpDownJ3; + private System.Windows.Forms.NumericUpDown numericUpDownJ4; + private System.Windows.Forms.NumericUpDown numericUpDownJ5; + private System.Windows.Forms.NumericUpDown numericUpDownJ6; + private System.Windows.Forms.Button buttonGetPosition; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.GroupBox groupBox2; + } +} + diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.cs b/CoppeliaSimCSharpAPI.TestForm/Form1.cs new file mode 100644 index 0000000..9b6e960 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CoppeliaSimCSharpAPI.TestForm +{ + public partial class Form1 : Form + { + private const string _jointPrefix = "UR5_joint"; + + private int _id; + private int[] _jointHandle = new int[6]; + + public Form1() + { + InitializeComponent(); + } + + private void buttonConnect_Click(object sender, EventArgs e) + { + _id = Api.Connect(textBoxAddress.Text, (int)numericUpDownPort.Value); + if (Api.IsConnected(_id)) + { + for (int i = 0; i < _jointHandle.Length; i++) + { + _jointHandle[i] = Api.GetObjectHandle(_id, _jointPrefix + (i + 1)); + } + } + } + + private void buttonDisconnect_Click(object sender, EventArgs e) + { + Api.Disconnect(_id); + } + + private void buttonMove_Click(object sender, EventArgs e) + { + var position = new float[] + { + (float)numericUpDownJ1.Value, + (float)numericUpDownJ2.Value, + (float)numericUpDownJ3.Value, + (float)numericUpDownJ4.Value, + (float)numericUpDownJ5.Value, + (float)numericUpDownJ6.Value + }; + Api.MoveJoint(_id, _jointHandle, position, true, _jointHandle.Length); + } + + private void buttonGetPosition_Click(object sender, EventArgs e) + { + var position = new float[6]; + Api.GetJointPosition(_id, _jointHandle, position, _jointHandle.Length); + MessageBox.Show($"{position[0]}\r\n" + + $"{position[1]}\r\n" + + $"{position[2]}\r\n" + + $"{position[3]}\r\n" + + $"{position[4]}\r\n" + + $"{position[5]}", + "Now position"); + } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + try + { + buttonDisconnect.PerformClick(); + } + catch (Exception) + { + /* Do nothing. */ + } + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Form1.resx b/CoppeliaSimCSharpAPI.TestForm/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestForm/Program.cs b/CoppeliaSimCSharpAPI.TestForm/Program.cs new file mode 100644 index 0000000..04f6e71 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CoppeliaSimCSharpAPI.TestForm +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/AssemblyInfo.cs b/CoppeliaSimCSharpAPI.TestForm/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..71ba34f --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CoppeliaSimCSharpAPI.TestForm")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CoppeliaSimCSharpAPI.TestForm")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("fb8863f3-9ba4-47aa-83b2-c28513f2b7f5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.Designer.cs new file mode 100644 index 0000000..96ca360 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CoppeliaSimCSharpAPI.TestForm.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CoppeliaSimCSharpAPI.TestForm.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.resx b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.Designer.cs b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.Designer.cs new file mode 100644 index 0000000..9c1b467 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace CoppeliaSimCSharpAPI.TestForm.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.settings b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/CoppeliaSimCSharpAPI.TestForm/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/CoppeliaSimCSharpAPI.sln b/CoppeliaSimCSharpAPI.sln index e6f5b08..d60e98a 100644 --- a/CoppeliaSimCSharpAPI.sln +++ b/CoppeliaSimCSharpAPI.sln @@ -1,26 +1,46 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31105.61 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CoppeliaSimCSharpAPI", "CoppeliaSimCSharpAPI\CoppeliaSimCSharpAPI.vcxproj", "{6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CoppeliaSimCSharpAPI.TestForm", "CoppeliaSimCSharpAPI.TestForm\CoppeliaSimCSharpAPI.TestForm.csproj", "{FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|Any CPU.ActiveCfg = Debug|x64 + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|Any CPU.Build.0 = Debug|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x64.ActiveCfg = Debug|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x64.Build.0 = Debug|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x86.ActiveCfg = Debug|Win32 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Debug|x86.Build.0 = Debug|Win32 + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|Any CPU.ActiveCfg = Release|x64 + {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|Any CPU.Build.0 = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x64.ActiveCfg = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x64.Build.0 = Release|x64 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.ActiveCfg = Release|Win32 {6735F97B-5B21-4B2A-A1A4-EDFFCCD825BA}.Release|x86.Build.0 = Release|Win32 + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.ActiveCfg = Debug|x64 + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x64.Build.0 = Debug|x64 + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x86.ActiveCfg = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Debug|x86.Build.0 = Debug|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|Any CPU.Build.0 = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x64.ActiveCfg = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x64.Build.0 = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x86.ActiveCfg = Release|Any CPU + {FB8863F3-9BA4-47AA-83B2-C28513F2B7F5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp index a23546e..2f66024 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.cpp @@ -1,15 +1,8 @@ #include "pch.h" #include "CoppeliaSimCSharpAPI.h" -/* For C++ using . */ -#define _USE_MATH_DEFINES -#include - -#define TO_RAD(degree) (degree*(M_PI/180)) -#define TO_DEGREE(rad) (rad*(180/M_PI)) - -COPPELIASIMCSHARPAPI_API int Connect(char* address, int port) { - int id = simxStart((char*)"127.0.0.1", port, true, true, 2000, 5); +COPPELIASIMCSHARPAPI_API int Connect(const char* address, int port) { + int id = simxStart(address, port, true, true, 2000, 5); extApi_sleepMs(300); if (IsConnected(id)) { SendInfo(id, "[Remote API] Connected", false); @@ -36,27 +29,23 @@ COPPELIASIMCSHARPAPI_API bool IsConnected(int id) { return isConnected; } -COPPELIASIMCSHARPAPI_API int MoveJoint(int id, float position[6], int jointHandle[6], bool inTorqueForceMode) { +COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[], float position[], bool inTorqueForceMode, int jointCount) { simxPauseCommunication(id, 1); if (inTorqueForceMode) { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < jointCount; i++) { simxSetJointTargetPosition(id, jointHandle[i], TO_RAD(position[i]), simx_opmode_oneshot); } } else { - for (int i = 0; i < 6; i++) { + for (int i = 0; i < jointCount; i++) { simxSetJointPosition(id, jointHandle[i], TO_RAD(position[i]), simx_opmode_oneshot); } } return simxPauseCommunication(id, 0); } -COPPELIASIMCSHARPAPI_API int MoveCartesian(int id, float position[6], int jointHandle[6], bool inTorqueForceMode) { - return -99; -} - -COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float position[6]) { - for (int i = 0; i < 6; i++) { +COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[], float position[], int jointCount) { + for (int i = 0; i < jointCount; i++) { float pos; simxGetJointPosition(id, jointHandle[i], &pos, simx_opmode_blocking); position[i] = TO_DEGREE(pos); @@ -64,10 +53,6 @@ COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float return 0; } -COPPELIASIMCSHARPAPI_API int GetCartesianPosition(int id, int jointHandle[6], float position[6]) { - return -99; -} - COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName) { int objectHandle; simxGetObjectHandle(id, objectName, &objectHandle, simx_opmode_blocking); @@ -75,6 +60,5 @@ COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName) { } COPPELIASIMCSHARPAPI_API int SendInfo(int id, const char* message, bool blocking) { - int opMode = blocking ? simx_opmode_blocking : simx_opmode_oneshot; - return simxAddStatusbarMessage(id, message, opMode); + return simxAddStatusbarMessage(id, message, blocking ? (simxInt)simx_opmode_blocking : (simxInt)simx_opmode_oneshot); } \ No newline at end of file diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h index 0cdfeeb..82c94fd 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.h @@ -6,19 +6,24 @@ #define COPPELIASIMREMOTEAPI_API __declspec(dllimport) #endif +/* For C++ using . */ +#define _USE_MATH_DEFINES +#include + extern "C" { #include "extApi.h" } -extern "C" COPPELIASIMCSHARPAPI_API int Connect(char* address, int port); +#define TO_RAD(degree) (degree * (M_PI / 180)) +#define TO_DEGREE(rad) (rad * (180 / M_PI)) + +extern "C" COPPELIASIMCSHARPAPI_API int Connect(const char* address, int port); extern "C" COPPELIASIMCSHARPAPI_API int Disconnect(int id); extern "C" COPPELIASIMCSHARPAPI_API bool IsConnected(int id); -extern "C" COPPELIASIMCSHARPAPI_API int MoveJoint(int id, float position[6], int jointHandle[6], bool inTorqueForceMode); -extern "C" COPPELIASIMCSHARPAPI_API int MoveCartesian(int id, float position[6], int jointHandle[6], bool inTorqueForceMode); +extern "C" COPPELIASIMCSHARPAPI_API int MoveJoint(int id, int jointHandle[], float position[], bool inTorqueForceMode, int jointCount); -extern "C" COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[6], float position[6]); -extern "C" COPPELIASIMCSHARPAPI_API int GetCartesianPosition(int id, int jointHandle[6], float position[6]); +extern "C" COPPELIASIMCSHARPAPI_API int GetJointPosition(int id, int jointHandle[], float position[], int jointCount); extern "C" COPPELIASIMCSHARPAPI_API int GetObjectHandle(int id, const char* objectName); extern "C" COPPELIASIMCSHARPAPI_API int SendInfo(int id, const char* message, bool blocking); diff --git a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj index c2cadd7..feb45d0 100644 --- a/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj +++ b/CoppeliaSimCSharpAPI/CoppeliaSimCSharpAPI.vcxproj @@ -29,26 +29,26 @@ DynamicLibrary true - v142 + v143 Unicode DynamicLibrary false - v142 + v143 true Unicode DynamicLibrary true - v142 + v143 Unicode DynamicLibrary false - v142 + v143 true Unicode diff --git a/README.md b/README.md new file mode 100644 index 0000000..627cf47 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# CoppeliaSim C# API + +The CoppeliaSim (V-REP) remote control API for C#. Using [CoppeliaSim Legacy remote API](https://www.coppeliarobotics.com/helpFiles/en/legacyRemoteApiOverview.htm). + +# Demo + +[Demo video (YouTube)](https://youtu.be/4fqbw-M2QbY) + +# Reference +- [CoppeliaRobotics/bubbleRobClient](https://github.com/CoppeliaRobotics/bubbleRobClient) + +# Dependency +- [CoppeliaRobotics/include](https://github.com/CoppeliaRobotics/include) +- [CoppeliaRobotics/remoteApi](https://github.com/CoppeliaRobotics/remoteApi) \ No newline at end of file