// Trajectories
// Builds the array from the list.
allActuatorsPositionsXArray = toDoubleArray(allActuatorsPositionsXList);
// Sends the array to Tango.
DeviceAttribute trajectoriesXAttribute = new DeviceAttribute("trajectories");
if(enabledActuatorsXNumber != 0) {
trajectoriesXAttribute.insert(allActuatorsPositionsXArray, totalStepsNumberX,
enabledActuatorsXNumber);
}
else {
trajectoriesXAttribute.insert(new double[] {}, 0 , 1);
}
scanServerProxy.write_attribute(trajectoriesXAttribute);
// Speed.
speedXArray = toDoubleArray(speedXList);
setAttribute("scanSpeed", speedXArray);
// Dimensions Y
// Tango exchanges trajectories as double arrays that contains the positions, in
// order,
// actuator after actuator, range after range, of the trajectories of all the
// actuators.
// There is one such array per dimension.
double[] allActuatorsPositionsYArray;
double initialValueY;
// Contains the positions in order, range after range, of the trajectories of an
// actuator.
List<Double> actuatorPositionsYList;
// Contains the positions in order, actuator after actuator, range after range, of
// the trajectories of all the actuators.
List<Double> allActuatorsPositionsYList;
// The number of points, which is the total steps numbers + 1 per range.
int totalStepsNumberY;
// The actuators used for this dimension
List<IActuator> dimensionActuatorsYList;
// Dimension
dimensionActuatorsYList = dimensionY.getActuatorsList();
// The positions, sorted as Tango expect them.
allActuatorsPositionsYList = new ArrayList<Double>();
// The number of enabled actuators.
int enabledActuatorsYNumber = 0;
// The positions must be sorted by actuator, so we loop over the actuators.
for(IActuator actuator : dimensionActuatorsYList) {
initialValueY = ActuatorConnector.getData(actuator);
actuatorPositionsYList = new ArrayList<Double>();
// For each actuators, the positions must be sorted by range.
for(ITrajectory2DY trajectory : findActuatorTrajectories(dimensionY, actuator)) {
actuatorPositionsYList.addAll(TrajectoryCalculator
.calculateLinearTrajectoriesPosition(trajectory, initialValueY));
}
allActuatorsPositionsYList.addAll(actuatorPositionsYList);
++enabledActuatorsYNumber;
}
// The number of points
totalStepsNumberY = 0;
for(IRange2DY range : dimensionY.getRangesList()) {
totalStepsNumberY += range.getStepsNumber() + 1;
}
setAttribute("pointNumber2", totalStepsNumberY);
// Builds the array from the list.
allActuatorsPositionsYArray = toDoubleArray(allActuatorsPositionsYList);
DeviceAttribute trajectoriesYAttribute = new DeviceAttribute("trajectories2");
if(enabledActuatorsYNumber > 0) {
// Sends the array to Tango.
trajectoriesYAttribute.insert(allActuatorsPositionsYArray, totalStepsNumberY, enabledActuatorsYNumber);
}
else {
trajectoriesYAttribute.insert(new double[] {}, 0 , 1);
}
scanServerProxy.write_attribute(trajectoriesYAttribute);
// Actuator delay.
double actuatorsDelay = config.getActuatorsDelay();
setAttribute("actuatorsDelay", actuatorsDelay);
// Zig zag.
boolean zigzag = config.isZigzag();
setAttribute("zigzag", zigzag);
// Enable actuator speed.
boolean enableScanSpeed = config.isEnableScanSpeed();
setAttribute("enableScanSpeed", enableScanSpeed);
// Post scan behaviour.
IPostScanBehaviour postScanBehaviour = config.getScanAddOn().getPostScanBehaviour();
Behaviour behaviour = postScanBehaviour.getBehaviour();
if(behaviour == null) {
behaviour = Behaviour.NOOP;
}
int behaviourType = behaviour.getType();
setAttribute("afterRunActionType", behaviourType);
if(behaviour.getArgumentCount() >= 1) {
int behaviourSensorIndex = postScanBehaviour.getSensor();
setAttribute("afterRunActionSensor", behaviourSensorIndex);
}
else if(behaviour.getArgumentCount() >= 2) {
int behaviourActuatorIndex = postScanBehaviour.getActuator();
setAttribute("afterRunActionActuator", behaviourActuatorIndex);
}
// Error strategies.
if(config.getScanAddOn() != null
&& config.getScanAddOn().getErrorStrategy() != null) {
IErrorStrategy errorStrat = config.getScanAddOn().getErrorStrategy();
IErrorStrategyItem[] categoriesESI = new IErrorStrategyItem[] {
errorStrat.getActuatorsErrorStrategy(),
errorStrat.getSensorsErrorStrategy(),
errorStrat.getTimebasesErrorStrategy(),
errorStrat.getHooksErrorStrategy() };
String[] categoriesStr = new String[] { "actuators", "sensors", "timebases",
"hooks" };
for(int i=0; i<categoriesStr.length; i++) {
String cat = categoriesStr[i];
IErrorStrategyItem esi = categoriesESI[i];
double errorStrategyTimeOut = esi.getTimeOut();
int errorStrategyRetryCount = esi.getRetryCount();
double errorStrategyRetryTimeOut = esi.getTimeBetweenRetries();
int errorStrategyType = esi.getStrategy().ordinal();
// Time out.
scanServerProxy.write_attribute(new DeviceAttribute(cat + "TimeOut",
errorStrategyTimeOut));
// Retry count.
scanServerProxy.write_attribute(new DeviceAttribute(cat + "RetryCount",
errorStrategyRetryCount));
// Retry time out.
scanServerProxy.write_attribute(new DeviceAttribute(cat + "RetryTimeOut",
errorStrategyRetryTimeOut));
// Error strategy.
scanServerProxy.write_attribute(new DeviceAttribute(cat + "ErrorStrategy",
errorStrategyType));
}
// Context validation error strategy.
scanServerProxy.write_attribute(new DeviceAttribute(
"contextValidationErrorStrategy", errorStrat
.getContextValidationStrategy().ordinal()));
scanServerProxy.write_attribute(new DeviceAttribute("contextValidation",
errorStrat.getContextValidationDevice()));
}
/* Hooks */
SetHooks(config.getScanAddOn(), scanServerProxy);