06-19-2020, 06:34 PM
(This post was last modified: 06-19-2020, 07:29 PM byCiaron Hamilton.)
Hello, I am trying to obtain the TCP poses of a robot as fast as possible from C# using the RoboDK API (from RoboDK.cs) as part of optimization. I require only the orientation of the pose, not necessarily rotation information. Currently I am at a bottleneck and trying to look for some solution to fasten this process.
Calling from a BackgroundWorker async thread, it is possible to obtain about 60 poses per second, which is good enough for what I need. However, there are duplicate orientations of each pose which are not wanted. Removing poses with redundant orientations only obtains about 12 points per second.
我有类似的代码:
I will also include a log of some sorts from my real code (in which the robot is moving from inputs of a script). Lines without the @ are poses obtained, showing time and orientation information. Lines starting with @ are the data points sent showing total time to send the unique data point, an average times (for obtaining any pose versus a unique pose).
Thanks in advance.
Edit: I noticed that when executing the script to move the robot that obtaining pose information decreases the average time per non-unique pose to 0.27ms on my machine (while also minimized sending messages to the log), far better than the 15.4ms times I've been getting. Just need it to work while the robots are moving as unique points ;)
Edit edit: Good Lesson learned and problem solved. In the thread moving the robots, I had a function which waits until the robot is finished moving:
void Busy(RoboDK.Item robot)
{
// Check if type is robot
if (robot.Type() != RoboDK.ITEM_TYPE_ROBOT) throw new Exception("Item must be of type robot");
// Wait until robot is not busy
while (robot.Busy())
{
}
}
I changed the while loop to include a sleep:
while (robot.Busy())
{
Thread.Sleep(1);
}
Averages have been lowered significantly to 11ms per pose with all poses being unique. Problem solved!
问题是en solved.
Calling from a BackgroundWorker async thread, it is possible to obtain about 60 poses per second, which is good enough for what I need. However, there are duplicate orientations of each pose which are not wanted. Removing poses with redundant orientations only obtains about 12 points per second.
我有类似的代码:
Code:
double[] prevPose;
EventHandler RobotPosData;
void PosLoopWorkerDoWork(object sender, EventArgs e)
{
// Obtain robot instance within thread to avoid conflicts
RoboDK _RDK = new RoboDK();
RoboDK.Item _Robo1Item = _RDK.getItem("Robot", RoboDK.ITEM_TYPE_ROBOT);
// loop to run indefinitely
while (Running)
{
// Grab the data from the robot
double[] Robot1Pose = _Robo1Item.Pose().ToTxyzRxyz();
// Check if the orientations are the same, continue if so
if (IsSamePoses(Robot1Pose)) continue;
// Send data to some event handler
if (RobotPosData!= null) RobotPosData.DataObtained(this, Robot1Pose); // EventArgs stuff is in real code, simplified here
}
}
bool IsSamePoses(double[] pose)
{
if (prevArgs != null) return IsSameOrient(pose, prevPose);
else return false
}
bool IsSameOrient(double[] d1, double[] d2)
{
return d1[0] == d2[0] && d1[1] == d2[1] && d1[2] == d2[2];
}
I will also include a log of some sorts from my real code (in which the robot is moving from inputs of a script). Lines without the @ are poses obtained, showing time and orientation information. Lines starting with @ are the data points sent showing total time to send the unique data point, an average times (for obtaining any pose versus a unique pose).
Thanks in advance.
Edit: I noticed that when executing the script to move the robot that obtaining pose information decreases the average time per non-unique pose to 0.27ms on my machine (while also minimized sending messages to the log), far better than the 15.4ms times I've been getting. Just need it to work while the robots are moving as unique points ;)
Edit edit: Good Lesson learned and problem solved. In the thread moving the robots, I had a function which waits until the robot is finished moving:
void Busy(RoboDK.Item robot)
{
// Check if type is robot
if (robot.Type() != RoboDK.ITEM_TYPE_ROBOT) throw new Exception("Item must be of type robot");
// Wait until robot is not busy
while (robot.Busy())
{
}
}
I changed the while loop to include a sleep:
while (robot.Busy())
{
Thread.Sleep(1);
}
Averages have been lowered significantly to 11ms per pose with all poses being unique. Problem solved!
问题是en solved.