PSO Example 3
The following example demonstrates using the SetPSOIntervalData function to set the data points. In this example, three channels are used, each with identical parameter settings except for the comparison type.
The parameters are set as follows.
All three channels
RangeStart = 0
RangeEnd = 4000
Interval = 1000
Channel 0
ComparisonType = Equal
Channel 1
ComparisonType = LessThan
Channel 2
ComparisonType = MoreThan
After setting the above parameters, the axis is moved from position 0 to position 5000 using a position command. The output and active index for each channel during this motion are shown in the following figure.

The data points are given by [p = rangeStart + n*interval] and [rangeStart < p <= rangeEnd] for integer n. The first equation results in the points [p = 0 + n*1000] or [0, 1000, 2000, 3000, 4000, 5000, ...]. Of these points, the ones that satisfy the second equation [0 < p <= 4000] are [1000, 2000, 3000, 4000]. The indices of these data points are assigned starting from 1 as explained in the discussion of the activeDataIndex.
Data Point |
Index |
|---|---|
1000 |
1 |
2000 |
2 |
3000 |
3 |
4000 |
4 |
For channel 1, the comparison type is Equal. Whenever the axis passes through one of the data points, the output becomes 1 for one cycle and the active index becomes equal to the index of that data point.
For channel 2, the comparison type is LessThan. At position 0, the axis position is already less than all of the data points, so the active index becomes equal to the index of the closest data point (see activeDataIndex for a discussion on how the active index is calculated when there are multiple data points that satisfy the PSO comparison). The closest data point is 1000, which has an index of 1.
The LessThan comparison type actually evaluates the comparison as “less than or equal to”. When the axis is exactly at position 1000, the axis position is still less than or equal to data point 1000, and the active index remains as 1. When the axis moves past position 1000, the active index becomes 2, as data point 2000 is now the closest data point that satisfies the PSO comparison.
In this way, the active index becomes 3 when the axis moves past position 2000 and becomes 4 when the axis moves past position 3000. When the axis moves past position 4000, the axis position is less than or equal to none of the data points, so the output becomes 0.
For channel 3, the comparison type is MoreThan. At position 0, the axis position is greater than none of the data points, so the output is 0 and the active index is unchanged at 0.
The MoreThan comparison type actually evaluates the comparison as “greater than or equal to”. When the axis is exactly at position 1000, the axis position is greater than or equal to data point 1000, so the output becomes 1 and the active index becomes 1.
When the axis moves to position 2000, the axis position is greater than or equal to data points 1000 and 2000. The closest data point is 2000, so the active index becomes 2. In this way, the active index becomes 3 when the axis reaches position 3000 and becomes 4 when the axis reaches position 4000.
The following is the code for this example.
EventControl::ComparatorSource src;
EventControl::PSOOutput out;
Motion::PosCommand pos;
src.axis = 0;
src.sourceType = EventControl::ComparatorSourceType::PosCommand;
out.outputType = EventControl::PSOOutputType::IOOutput;
out.byteAddress = 0;
out.bitAddress = 0;
out.invert = 0;
pos.axis = 0;
pos.profile.type = ProfileType::Trapezoidal;
pos.profile.velocity = 500;
pos.profile.acc = 500;
pos.profile.dec = 500;
pos.target = 5000;
wmxlib_EventControl->SetPSOConfig(0, EventControl::ComparisonType::Equal, &src, &out, 0);
out.bitAddress = 1;
wmxlib_EventControl->SetPSOConfig(1, EventControl::ComparisonType::LessThan, &src, &out, 0);
out.bitAddress = 2;
wmxlib_EventControl->SetPSOConfig(2, EventControl::ComparisonType::MoreThan, &src, &out, 0);
wmxlib_EventControl->SetPSOIntervalData(0, 0, 4000, 1000);
wmxlib_EventControl->SetPSOIntervalData(1, 0, 4000, 1000);
wmxlib_EventControl->SetPSOIntervalData(2, 0, 4000, 1000);
wmxlib_EventControl->StartPSO(0);
wmxlib_EventControl->StartPSO(1);
wmxlib_EventControl->StartPSO(2);
wmxlib_CoreMotion->motion->StartPos(&pos);