Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Fast way to calculate Cartesian targets using the API

#1
Is there a more efficient means to get the Cartesian location of each joint than individual API calls? The lower loop in the example code I provide below executes in around 1-3ms which is quite good, but for my application the time saved by a single API call would be very beneficial. 


Code:
private List<IItem> _robotLinks = new List<IItem>();

int numJoints = robot.Joints().Length;

...

if (_robotLinks is null || _robotLinks.Count == 0 )
{
   for (int i = 0; i < numJoints; i++)
   {
      _robotLinks.Add(robot.ObjectLink(i));
   }
}

...

for (int i = 0; i < numJoints; i++)
{
   var link = _robotLinks[i].PoseAbs();
}
#2
The Plugin Interface is an order of magnitude faster but it requires using c++ code. You can find more information here:
https://robodk.com/doc/en/PlugIns/index.html

You could use the plugin interface for the operations you would like to speed up while keeping your main application in C#.
#3
Thanks, it took a bit of setting up but I'm making progress.
#4
Great, thank you for your feedback. You can also pass commands from the API to your plugin by using the PluginCommand call:
https://robodk.com/doc/en/PythonAPI/robo...ginCommand

You can also use setParam and getParam to set and get binary data attached to an item. You can find more information here:
https://robodk.com/doc/en/PythonAPI/robo...k.setParam
#5
Ah, so is getParam / setParam the intended means to get data from the plugin to the API? I'm currently piping it directly.

Are PlugInLoad / PlugInCommand implemented in the C# API? I'm not seeing them.
#6
It is great if you already implemented your own pipe for inter process communication, this is probably more efficient. I was suggesting an alternative that also allows you to hold custom binary data attached to items. This data is also saved with your RoboDK project.

The PluginCommand is available with the C# API (including both the NuGet Package and the one-file RoboDK.cs file):
https://github.com/RoboDK/RoboDK-API/blo...K.cs#L2215
https://github.com/RoboDK/RoboDK-API/blo...K.cs#L5028
#7
Running down the github IRoboDK there are various methods I'm (or intellisense is) not seeing - I'm running the NuGet 5.6.2 (current), so I'm at a bit of a loss as to what's wrong.

E.g., starting at line 971:
*GetCursorXYZ - yes
*AddTargetJ - yes
*EmbedWindow - no
*GetPoints - no
*MeasurePose - no
*PluginCommand - no
*PluginLoad - no
...

Here's IRoboDK [decompiled] - nothing past AddTargetJ:

Code:
#region Assembly RoboDkApi, Version=5.0.2.0, Culture=neutral, PublicKeyToken=null
// C:\Users\benwe\.nuget\packages\robodkapi\5.6.2\lib\netcoreapp3.1\RoboDkApi.dll
// Decompiled with ICSharpCode.Decompiler 8.1.1.7464
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using RoboDk.API.Model;

namespace RoboDk.API;

public interface IRoboDK
{
    string Name { get; set; }

    Process Process { get; }

    string LastStatusMessage { get; }

    string ApplicationDir { get; }

    int RoboDKServerPort { get; }

    int RoboDKClientPort { get; }

    int DefaultSocketTimeoutMilliseconds { get; set; }

    Func<IItem, IItem> ItemInterceptFunction { get; set; }

    bool Connect();

    bool Connected();

    void Disconnect();

    IRoboDK CloneRoboDkConnection(RoboDK.ConnectionType connectionType = RoboDK.ConnectionType.Api);

    IntPtr GetWindowHandle();

    IRoboDKEventSource OpenRoboDkEventChannel();

    void CloseRoboDK();

    string Version();

    void SetWindowState(WindowState windowState = WindowState.Normal);

    void Copy(IItem tocopy, bool copy_children = true);

    IItem Paste(IItem paste_to = null);

    List<IItem> Paste(IItem paste_to, int paste_times);

    IItem AddFile(string filename, IItem parent = null);

    IItem AddText(string text, IItem parent = null);

    IItem AddTarget(string name, IItem parent = null, IItem robot = null);

    IItem AddProgram(string name, IItem robot = null);

    IItem AddStation(string name);

    IItem AddMachiningProject(string name = "Curve follow settings", IItem itemrobot = null);

    List<IItem> GetOpenStation();

    void SetActiveStation(IItem station);

    IItem GetActiveStation();

    void Render(bool alwaysRender = false);

    void Update();

    IItem GetItemByName(string name, ItemType itemType = ItemType.Any);

    List<string> GetItemListNames(ItemType itemType = ItemType.Any);

    List<IItem> GetItemList(ItemType itemType = ItemType.Any);

    IItem ItemUserPick(string message = "Pick one item", ItemType itemType = ItemType.Any);

    void ShowRoboDK();

    void FitAll();

    void HideRoboDK();

    void SetWindowFlags(WindowFlags flags);

    void SetItemFlags(ItemFlags itemFlags = ItemFlags.All);

    void ShowMessage(string message, bool popup = true);

    void Save(string filename, IItem itemsave = null);

    IItem AddShape(Mat trianglePoints, IItem addTo = null, bool shapeOverride = false, Color? color = null);

    IItem AddShape(List<Mat> listTrianglePoints, IItem addTo = null, bool shapeOverride = false, List<Color> listColor = null);

    IItem AddCurve(Mat curvePoints, IItem referenceObject = null, bool addToRef = false, ProjectionType projectionType = ProjectionType.AlongNormalRecalc);

    IItem AddPoints(Mat points, IItem referenceObject = null, bool addToRef = false, ProjectionType projectionType = ProjectionType.AlongNormalRecalc);

    Mat ProjectPoints(Mat points, IItem objectProject, ProjectionType projectionType = ProjectionType.AlongNormalRecalc);

    void CloseStation();

    void Delete(List<IItem> item_list);

    IItem AddFrame(string name, IItem parent = null);

    int RunProgram(string function);

    int RunCode(string code, bool codeIsFunctionCall = false);

    void RunMessage(string message, bool messageIsComment = false);

    bool IsInside(IItem objectInside, IItem objectParent);

    int SetCollisionActive(CollisionCheckOptions collisionCheck = CollisionCheckOptions.CollisionCheckOn);

    void EnableCollisionCheckingForAllItems();

    void DisableCollisionCheckingForAllItems();

    bool SetCollisionActivePair(CollisionCheckOptions collisionCheck, CollisionPair collisionPair);

    bool SetCollisionActivePair(List<CollisionCheckOptions> checkState, IReadOnlyList<CollisionPair> collisionPairs);

    int Collisions();

    bool Collision(IItem item1, IItem item2, bool useCollisionMap = true);

    List<CollisionItem> GetCollisionItems();

    List<CollisionPair> GetCollisionPairs();

    void SetSimulationSpeed(double speed);

    double GetSimulationSpeed();

    void SetRunMode(RunMode runMode = RunMode.Simulate);

    RunMode GetRunMode();

    List<KeyValuePair<string, string>> GetParameterList();

    string GetParameter(string parameter);

    void SetParameter(string parameter, string value);

    void SetParameter(string parameter, double value);

    string Command(string cmd, string value = "");

    string Command(string cmd, bool value);

    string Command(string cmd, double value);

    string Command(string cmd, int value);

    double[] LaserTrackerMeasure(double[] estimate, bool search = false);

    void StereoCameraMeasure(out Mat pose1, out Mat pose2, out int npoints1, out int npoints2, out int time, out int status);

    bool CollisionLine(double[] p1, double[] p2);

    List<Mat> SolveFK(List<IItem> robotList, List<double[]> jointsList, List<bool> solutionOkList = null);

    List<double[]> SolveIK(List<IItem> robotList, List<Mat> poseList);

    List<double[]> SolveIK(List<IItem> robotList, List<Mat> poseList, List<double[]> japroxList);

    List<Mat> SolveIK_All(List<IItem> robotList, List<Mat> poseList);

    List<double[]> JointsConfig(List<IItem> robotList, List<double[]> jointsList);

    void SetVisible(List<IItem> itemList, List<bool> visibleList, List<int> visibleFrames = null);

    void SetColor(List<IItem> item_list, List<Color> color_list);

    void SetColor(List<IItem> item_list, List<double[]> color_list);

    void ShowAsCollided(List<IItem> item_list, List<bool> collided_list, List<int> robot_link_id = null);

    List<double[]> Joints(List<IItem> robotItemList);

    void SetJoints(List<IItem> robotItemList, List<double[]> jointsList);

    double[] CalibrateTool(Mat posesJoints, out double[] errorStats, EulerType format = EulerType.EulerRxRyRz, TcpCalibrationType algorithm = TcpCalibrationType.CalibrateTcpByPoint, IItem robot = null);

    Mat CalibrateReference(Mat joints, ReferenceCalibrationType method = ReferenceCalibrationType.Frame3P_P1OnX, bool useJoints = false, IItem robot = null);

    int ProgramStart(string progname, string defaultfolder = "", string postprocessor = "", IItem robot = null);

    void SetViewPose(Mat pose);

    Mat GetViewPose(ViewPoseType preset = ViewPoseType.ActiveView);

    bool SetRobotParams(IItem robot, double[][] dhm, Mat poseBase, Mat poseTool);

    IItem BuildMechanism(int type, List<IItem> listObj, List<double> param, List<double> jointsBuild, List<double> jointsHome, List<double> jointsSenses, List<double> jointsLimLow, List<double> jointsLimHigh, Mat baseFrame = null, Mat tool = null, string name = "New robot", IItem robot = null);

    long Cam2DAdd(IItem item, string cameraParameters = "");

    bool Cam2DSnapshot(string fileSaveImg, long camHandle = 0L);

    bool Cam2DClose(long camHandle = 0L);

    bool Cam2DSetParameters(string cameraParameters, long camHandle = 0L);

    string GetLicense();

    List<IItem> GetSelectedItems();

    void SetSelectedItems(List<IItem> item_list);

    IItem MergeItems(List<IItem> item_list);

    IItem Popup_ISO9283_CubeProgram(IItem robot = null);

    void SetInteractiveMode(InteractiveType modeType = InteractiveType.MoveReferences, DisplayRefType defaultRefFlags = DisplayRefType.DEFAULT, List<IItem> customItems = null, List<DisplayRefType> customRefFlags = null);

    IItem GetCursorXYZ(int xCoord = -1, int yCoord = -1, List<double> xyzStation = null);

    IItem AddTargetJ(IItem pgm, string targetName, double[] joints, IItem robotBase = null, IItem robot = null);
}
#if false // Decompilation log
'270' items in cache
------------------
Resolve: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Runtime.dll'
------------------
Resolve: 'System.Runtime.InteropServices, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Runtime.InteropServices, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Runtime.InteropServices.dll'
------------------
Resolve: 'System.Collections, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Collections, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.1.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Collections.dll'
------------------
Resolve: 'System.Drawing.Primitives, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Drawing.Primitives, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.1.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Drawing.Primitives.dll'
------------------
Resolve: 'System.Diagnostics.Process, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Diagnostics.Process, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Diagnostics.Process.dll'
------------------
Resolve: 'System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Runtime.Extensions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Runtime.Extensions.dll'
------------------
Resolve: 'System.Net.Sockets, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Net.Sockets, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Net.Sockets.dll'
------------------
Resolve: 'Microsoft.Win32.Registry, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'Microsoft.Win32.Registry, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.1.3.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\Microsoft.Win32.Registry.dll'
------------------
Resolve: 'System.Net.NetworkInformation, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Net.NetworkInformation, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Net.NetworkInformation.dll'
------------------
Resolve: 'System.Net.Primitives, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Net.Primitives, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.1.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Net.Primitives.dll'
------------------
Resolve: 'System.Threading.Thread, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Threading.Thread, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.1.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Threading.Thread.dll'
------------------
Resolve: 'System.Console, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Console, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.1.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Console.dll'
------------------
Resolve: 'System.Linq, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Linq, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.2.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Linq.dll'
------------------
Resolve: 'System.IO.FileSystem, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.IO.FileSystem, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '4.1.2.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.IO.FileSystem.dll'
------------------
Resolve: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Found single assembly: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Runtime.dll'
------------------
Resolve: 'System.Runtime.CompilerServices.Unsafe, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null'
Found single assembly: 'System.Runtime.CompilerServices.Unsafe, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
WARN: Version mismatch. Expected: '3.1.0.0', Got: '7.0.0.0'
Load from: 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\7.0.14\ref\net7.0\System.Runtime.CompilerServices.Unsafe.dll'
#endif
  




Users browsing this thread:
1 Guest(s)