String indexStr = String.valueOf(dimensionIndex);
if (dimensionIndex == 1) {
indexStr = "";
}
DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName);
if ((scanServerProxy != null) && (dimension != null)) {
try {
List<String> actuatorsNamesList;
String[] actuatorsNamesArray;
List<IActuator> actuatorsList = dimension.getActuatorsList();
actuatorsNamesList = new ArrayList<String>(actuatorsList.size());
for (IActuator actuator : actuatorsList) {
if (actuator.isEnabled()) {
actuatorsNamesList.add(actuator.getName());
}
}
actuatorsNamesArray = actuatorsNamesList.toArray(new String[actuatorsNamesList.size()]);
String actuatorName = "actuators" + indexStr;
actionName = "write_attribute(\"" + actuatorName + "\"," + Arrays.toString(actuatorsNamesArray) + ")";
setAttribute(actuatorName, actuatorsNamesArray, false);
// Dimensions
// 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[] allActuatorsPositionsArray;
double initialValue;
double[] integrationsTimesArray;
// Contains the positions in order, range after range, of the
// trajectories of an
// actuator.
List<Double> actuatorPositionsList;
// Contains the positions in order, actuator after actuator,
// range after range,
// of
// the trajectories of all the actuators.
List<Double> allActuatorsPositionsList;
// The list of integrations times.
List<Double> integrationsTimesList;
int integrationTimeIndex;
// The list of speeds.
List<Double> speedList = new ArrayList<Double>();
// The number of points, which is the total steps numbers + 1
// per range.
int totalStepsNumber;
// The positions, sorted as Tango expect them.
allActuatorsPositionsList = new ArrayList<Double>();
// The number of enabled actuators.
int enabledActuatorsNumber = 0;
if (dimension instanceof IDimensionK) {
enabledActuatorsNumber = 1;
ITrajectoryK trajectoryK = ((IDimensionK) dimension).getRangeX().getTrajectory();
allActuatorsPositionsArray = TrajectoryCalculator.calculateKTrajectoriesPosition(trajectoryK);
// System.out.println("K Trajectory="
// + Arrays.toString(trajectoriesPositionsArray));
// System.out.println("K Trajectory size=" +
// trajectoriesPositionsArray.length);
integrationsTimesArray = TrajectoryCalculator.calculateIntegrationTimesK(trajectoryK);
// System.out.println("K integration size=" +
// integrationsTimesArray.length);
// System.out.println("K integration=" +
// Arrays.toString(integrationsTimesArray));
totalStepsNumber = allActuatorsPositionsArray.length;
speedList.add(trajectoryK.getSpeed());
} else {
// The positions must be sorted by actuator, so we loop over
// the actuators.
for (int index = 0; index < actuatorsList.size(); index++) {
IActuator actuator = actuatorsList.get(index);
if (actuator.isEnabled()) {
actuatorPositionsList = new ArrayList<Double>();
// For each actuators, the positions must be sorted
// by range.
List<ITrajectory> completetrajectoryList = findActuatorTrajectories(dimension, index);
List<ITrajectory> trajectoryList = new ArrayList<ITrajectory>();
if (onTheFly) {
trajectoryList.add(completetrajectoryList.get(0));
} else {
trajectoryList.addAll(completetrajectoryList);
}
initialValue = DeviceConnector.getData(actuator);
for (ITrajectory trajectory : trajectoryList) {
actuatorPositionsList
.addAll(TrajectoryCalculator.calculateLinearTrajectoriesPosition(trajectory,
initialValue, (onTheFly || (trajectory instanceof ITrajectoryHCS))));
// The speeds must be sorted in the same order,
// so we read them
// here.
speedList.add(trajectory.getSpeed());
// speedList.addAll(TrajectoryCalculator
// .calculateScanSpeedList(trajectory));
}
// System.out.println(actuator.getName() + "="
// +
// Arrays.toString(actuatorPositionsList.toArray()));
allActuatorsPositionsList.addAll(actuatorPositionsList);
++enabledActuatorsNumber;
}
}
// Integration Time and steps number.
List<? extends IRange> getRangeList = dimension.getRangeList();
List<IRange> rangeList = new ArrayList<IRange>();
if (onTheFly) {
rangeList.add(getRangeList.get(0));
} else {
rangeList.addAll(getRangeList);
}
integrationsTimesList = new ArrayList<Double>(rangeList.size());
int stepsNumber;
totalStepsNumber = 0;
for (IRange range : rangeList) {
// System.out.println("onTheFly = " + onTheFly);
if ((range instanceof IRangeHCS) || onTheFly) {
stepsNumber = 1;
} else {
stepsNumber = range.getStepsNumber();
}
// System.out.println("stepsNumber = " + stepsNumber);
if (range instanceof IRangeIntegrated) {
for (integrationTimeIndex = 0; integrationTimeIndex < stepsNumber + 1; ++integrationTimeIndex) {
integrationsTimesList.add(((IRangeIntegrated) range).getIntegrationTime());
}
}
totalStepsNumber += stepsNumber + 1;
}
// Builds the array from the list.
allActuatorsPositionsArray = toDoubleArray(allActuatorsPositionsList);
// Integration Time
integrationsTimesArray = toDoubleArray(integrationsTimesList);
}
String pointNumberName = "pointNumber" + indexStr;
actionName = "write_attribute(\"" + pointNumberName + "\"," + totalStepsNumber + ")";
setAttribute(pointNumberName, totalStepsNumber, false);
// System.out.println("pointNumber=" + totalStepsNumber);
// Trajectories.
// Sends the array to Tango.
String trajectoriesName = "trajectories" + indexStr;
DeviceAttribute trajectoriesAttribute = new DeviceAttribute(trajectoriesName);
if (enabledActuatorsNumber != 0) {
trajectoriesAttribute.insert(allActuatorsPositionsArray, totalStepsNumber, enabledActuatorsNumber);
} else {
trajectoriesAttribute.insert(new double[] {}, 0, 1);
}
// Attribute only manage in X dimension
if (dimensionIndex == 1) {
actionName = "write_attribute(\"integrationTimes\"," + Arrays.toString(integrationsTimesArray)
+ ")";
setAttribute("integrationTimes", integrationsTimesArray, false);
// Speed.
double[] speedArray = toDoubleArray(speedList);
// System.out.println("speedArray= " +
// Arrays.toString(speedArray));
actionName = "write_attribute(\"scanSpeed\"," + Arrays.toString(speedArray) + ")";
setAttribute("scanSpeed", speedArray, false);
}
actionName = "write_attribute(\"" + trajectoriesName + "\","
+ Arrays.toString(allActuatorsPositionsArray) + ")";
scanServerProxy.write_attribute(trajectoriesAttribute);
} catch (DevFailed e) {
if (actionName == null) {
actionName = "";
}