Long PVT Commands
PVT commands with many points can be executed by allocating a large buffer with the CreatePVTBuffer function, and then specifying additional points with the optional arguments of the PVT function.
Long PVT Command Example
The following code executes a long PVT command consisting of 40960 points.
If the PVT buffer for the commanded axis has already been created after starting the engine (the buffer is automatically created when the StartPVT, StartPT, StartVT, or StartAT function is called), the PVT buffer must first be freed with FreePVTBuffer before executing this code.
const int PT = wmx3Api::constants::maxPvtAppendPoints;
//Main PVT command for setting the parameters and the first maxPvtAppendPoints segments
Motion::PVTCommand pvt;
//Additional PVT commands for setting the additional segments
Motion::PVTAdditionalCommand addlPvt[9];
pvt.axis = 0;
//Define segments
pvt.pointCount = PT;
pvt.points[0].pos = 0;
pvt.points[0].velocity = 0;
pvt.points[0].timeMilliseconds = 0;
for (int i = 1; i < PT; i++) {
pvt.points[i].pos = pvt.points[i-1].pos+pvt.points[i-1].velocity*0.001;
pvt.points[i].velocity = pvt.points[i-1].velocity+10;
pvt.points[i].timeMilliseconds = pvt.points[i-1].timeMilliseconds+1;
}
addlPvt[0].pointCount = PT;
addlPvt[0].points[0].pos = pvt.points[PT-1].pos+pvt.points[PT-1].velocity*0.001;
addlPvt[0].points[0].velocity = pvt.points[PT-1].velocity;
addlPvt[0].points[0].timeMilliseconds = pvt.points[PT-1].timeMilliseconds+1;
for (int i = 1; i < PT; i++) {
addlPvt[0].points[i].pos = addlPvt[0].points[i-1].pos+addlPvt[0].points[i-1].velocity*0.001;
addlPvt[0].points[i].velocity = addlPvt[0].points[i-1].velocity-10;
addlPvt[0].points[i].timeMilliseconds = addlPvt[0].points[i-1].timeMilliseconds+1;
}
for (int k = 1; k < 9; k++) {
addlPvt[k].pointCount = PT;
addlPvt[k].points[0].pos = addlPvt[k-1].points[PT-1].pos+addlPvt[k-1].points[PT-1].velocity*0.001;
addlPvt[k].points[0].velocity = addlPvt[k-1].points[PT-1].velocity;
addlPvt[k].points[0].timeMilliseconds = addlPvt[k-1].points[PT-1].timeMilliseconds+1;
for (int i = 1; i < PT; i++) {
addlPvt[k].points[i].pos = addlPvt[k].points[i-1].pos+addlPvt[k].points[i-1].velocity*0.001;
addlPvt[k].points[i].velocity = addlPvt[k].points[i-1].velocity+(k%2 ? 10 : -10);
addlPvt[k].points[i].timeMilliseconds = addlPvt[k].points[i-1].timeMilliseconds+1;
}
}
//Create buffer
wmxlib_CoreMotion->motion->CreatePVTBuffer(0, 10*wmx3Api::constants::maxPvtAppendPoints);
wmxlib_CoreMotion->motion->StartPVT(&pvt, 9, addlPvt);
The following plots show the position, velocity, and acceleration when the above code is executed.
