Path Creation using .Net

Hi,

 

We currently try to set path, or some others statements, to a robot, using .NET…

In Python script it was Ok, but in C#… Every time, we use “AddStatement” we get issues, and we are not sure about the TypeofStatement to use…

 

Do you have any example ? or clues that can help us ?

 

Thanks

It took me a long time to figure out path statements in .NET…

So I’ll post some example code here to help others.

// Examples of creating common statements

IJointMotionStatement jointStatement = prog.MainRoutine.AddStatement<IJointMotionStatement>();
jointStatement.Positions[0].Name = "HOME";
jointStatement.JointSpeed = 0.25;
Matrix mat = new Matrix();
jointStatement.Positions[0].TransformationInReference = mat;
jointStatement.Target = mat;
jointStatement.Base = robCont.CurrentBase;
jointStatement.Tool = robCont.CurrentTool;

ICommentStatement strsi = prog.MainRoutine.AddStatement<ICommentStatement>();
strsi.Comment = "Start RSI";

IWhileStatement mainLoop = prog.MainRoutine.AddStatement<IWhileStatement>();
mainLoop.Condition = "True";
// Examples of path statements

IPathStatement statement = (IPathStatement)schemaPathStatement.Statement;
statement.Name = "Path1";
statement.Base = robCont.CurrentBase;
statement.Tool = robCont.CurrentTool;
statement.ClearPositions();

object[] objArray = new object[7]
{
    GetDef("MaxCartesianSpeed", 1000.0, robot),
    GetDef("MaxCartesianAccel", 2000.0, robot),
    GetDef("MaxCartesianDecel", 2000.0, robot),
    1,
    0.0,
    0.0,
    false
};

int[] numArray = statement.AddSchemaProperties(new Tuple<string, Type, object>[7]
{
    new Tuple<string, Type, object>("MaxSpeed", typeof (double), objArray[0]),
    new Tuple<string, Type, object>("Acceleration", typeof (double), objArray[1]),
    new Tuple<string, Type, object>("Deceleration", typeof (double), objArray[2]),
    new Tuple<string, Type, object>("AccuracyMethod", typeof (int), objArray[3]),
    new Tuple<string, Type, object>("AccuracyValue", typeof (double), objArray[4]),
    new Tuple<string, Type, object>("CycleTime", typeof (double), objArray[5]),
    new Tuple<string, Type, object>("IsContinuous", typeof (bool), objArray[6])
});

int count = myListOfPoses.Count;
statement.BeginBatchUpdate(count);
List<double> doubleList = new List<double>();
foreach (IJoint externalJoint in robot.RobotController.ExternalJoints)
{
    doubleList.Add(externalJoint.Value);
}
((ISchemaPositionFrame)statement.WholePath).EnsureExternalJoints(doubleList);
((ISchemaPositionFrame)statement.WholePath).SetExternalJoints(doubleList);
IPositionFrame frame = null;
IPositionFrame[] positionFrameArray = new IPositionFrame[1];

int index = -1;
foreach (Pose pose in myListOfPoses)
{
    index++;
    statement.GetFrame(index, ref frame);
    if (frame == null)
    {
        throw new Exception("Failed to get frame " + index + ", " + statement.SchemaItemCount);
    }
    positionFrameArray[0] = frame;
    Matrix posMat = new Matrix();
    // Manipulate posMat to be what you want here...
    frame.TransformationInReference = posMat;
    frame.Status = PositionStatus.Valid;
    frame.IsReference = index == 0 || index == count - 1;
    objArray[0] = velocity;
    objArray[3] = AccuracyMethod.Velocity;
    objArray[4] = 0.0;
    objArray[5] = 0.0;
    objArray[6] = true;
    statement.SetSchemaValues(positionFrameArray, numArray, objArray);
}

statement.EndBatchUpdate(count);
IoC.Get<ISelectionManager>().SetSelection(schemaPathStatement);
IoC.Get<IRenderService>().RequestRender();

Note that I have just quickly copy pasted this and altered it to genericise it, it might not compile but should give you the gist of how to do it…