Forum Migration Notice
We're transitioning to a more modern community platform by the end of this year. Learn about the upcoming changes and what to expect.

compute distances

Hello.

Can someone share some code to compute distances in RAPID?

I need to compute the distance from the present robot position to a target - say "jointtargetHome".

Case:
Depending on where the robot is and what tool it is carrying, I need to perform different motions depending on the distance to a target. Something like pseudo:
num DistToTarget(CurrentTool, Target T);

Best regards


Comments



  • Hello,
     
    Why don't you apply following function?
     
    Distance() - Distance between two points
    Usage: Distance is used to calculate the distance between two points in the space.
    Example:
    VAR num dist;
    CONST pos p1 := [4,0,4];
    CONST pos p2 := [-4,4,4];
    ...
    dist := Distance(p1, p2);
     
    Best Regards,


  • Hello,
    as below:???
     
    IF CurrentPos(pXX,tGripper,100)=TRUE THEN
    ...
    ENDIF
     
      FUNC bool CurrentPos(
        robtarget ComparePos,
        INOUT tooldata Tool,
        num Accuracy
        INOUT wobjdata Wobj)
        VAR num Counter:=0;
        VAR robtarget ActualPos;
        IF Present(Wobj) THEN
          ActualPos:=CRobT(Tool:=ToolWObj:=Wobj);
        ELSE
          ActualPos:=CRobT(Tool:=ToolWObj:=wobj0);
        ENDIF
        IF ActualPos.trans.x>ComparePos.trans.x-Accuracy AND ActualPos.trans.x<ComparePos.trans.x+Accuracy Counter:=Counter+1;
        IF ActualPos.trans.y>ComparePos.trans.y-Accuracy AND ActualPos.trans.y<ComparePos.trans.y+Accuracy Counter:=Counter+1;
        IF ActualPos.trans.z>ComparePos.trans.z-Accuracy AND ActualPos.trans.z<ComparePos.trans.z+Accuracy Counter:=Counter+1;
        IF ActualPos.rot.q1>ComparePos.rot.q1-0.1 AND ActualPos.rot.q1<ComparePos.rot.q1+0.1 Counter:=Counter+1;
        IF ActualPos.rot.q2>ComparePos.rot.q2-0.1 AND ActualPos.rot.q2<ComparePos.rot.q2+0.1 Counter:=Counter+1;
        IF ActualPos.rot.q3>ComparePos.rot.q3-0.1 AND ActualPos.rot.q3<ComparePos.rot.q3+0.1 Counter:=Counter+1;
        IF ActualPos.rot.q4>ComparePos.rot.q4-0.1 AND ActualPos.rot.q4<ComparePos.rot.q4+0.1 Counter:=Counter+1;
        RETURN Counter=7;
      ENDFUNC
     
    BR Tony
    ABB Robotics Senior Application Engineer
  • Distance() seems to be  the perfect solution, thank you Smile