Hello.
I am trying to develop my original MoveC Node (named “MyCircleMove”) that realizes circular move and having a problem on executing this program node.
I was able to get pose of WaypointNode of “via_point” and “end_point”, which compose the arc, and the configuration of MoveP Node.
Finally, the robot moved as it is programmed by generating movec command in URScript.
However, after I loaded the program and executed again, the NullPointerException occured. After checking, I found this error occurs when casting WaypointNodeConfig
to FixedPositionDefinedWaypointNodeConfig
in generateScript()
.
I tried to investigate further, but I couldn’t figure out why this error happens only on loading the program.
The code is below…
package com.falfan.MyCircleMove.impl;
import com.ur.urcap.api.contribution.ProgramNodeContribution;
import com.ur.urcap.api.contribution.program.CreationContext;
import com.ur.urcap.api.contribution.program.ProgramAPIProvider;
import com.ur.urcap.api.domain.program.nodes.ProgramNodeFactory;
import com.ur.urcap.api.domain.program.nodes.builtin.WaypointNode;
import com.ur.urcap.api.domain.program.nodes.builtin.MoveNode;
import com.ur.urcap.api.domain.program.nodes.builtin.configurations.movenode.MovePMotionParameters;
import com.ur.urcap.api.domain.program.nodes.builtin.configurations.movenode.MovePMoveNodeConfig;
import com.ur.urcap.api.domain.program.nodes.builtin.configurations.movenode.builder.MovePConfigBuilder;
import com.ur.urcap.api.domain.program.nodes.builtin.configurations.waypointnode.FixedPositionDefinedWaypointNodeConfig;
import com.ur.urcap.api.domain.program.structure.TreeNode;
import com.ur.urcap.api.domain.program.structure.TreeStructureException;
import com.ur.urcap.api.domain.program.ProgramModel;
import com.ur.urcap.api.domain.script.ScriptWriter;
import com.ur.urcap.api.domain.undoredo.UndoRedoManager;
import com.ur.urcap.api.domain.value.blend.Blend;
import com.ur.urcap.api.domain.value.simple.Acceleration;
import com.ur.urcap.api.domain.value.simple.Angle;
import com.ur.urcap.api.domain.value.simple.Length;
import com.ur.urcap.api.domain.value.simple.Speed;
import com.ur.urcap.api.domain.ProgramAPI;
import com.ur.urcap.api.domain.data.DataModel;
public class MyCircleMoveProgramNodeContribution implements ProgramNodeContribution{
private final ProgramAPIProvider apiProvider;
private final ProgramAPI programAPI;
private final UndoRedoManager undoRedoManager;
private final MyCircleMoveProgramNodeView view;
private final DataModel model;
private final ProgramModel programModel;
private final ProgramNodeFactory factory;
private boolean hasNode;
private MoveNode moveP;
private MovePConfigBuilder movePConfigBuilder;
private WaypointNode via, end;
private Integer circleMoveMode;
public MyCircleMoveProgramNodeContribution(
ProgramAPIProvider apiProvider,
MyCircleMoveProgramNodeView view,
DataModel model,
CreationContext context) {
this.apiProvider = apiProvider;
this.programAPI = apiProvider.getProgramAPI();
this.undoRedoManager = apiProvider.getProgramAPI().getUndoRedoManager();
this.view = view;
this.model = model;
this.programModel = programAPI.getProgramModel();
this.factory = programModel.getProgramNodeFactory();
if(context.getNodeCreationType() == CreationContext.NodeCreationType.NEW)
createChildNode();
}
@Override
public void openView() {
}
@Override
public void closeView() {
}
@Override
public String getTitle() {
return "My Circle Move";
}
@Override
public boolean isDefined() {
return true;
}
@Override
public void generateScript(ScriptWriter writer) {
// Get Configuration of "via_point" and "end_point" WaypointNode
FixedPositionDefinedWaypointNodeConfig via_cfg = (FixedPositionDefinedWaypointNodeConfig)via.getConfig(); // <-- NullPointer Exception occured
FixedPositionDefinedWaypointNodeConfig end_cfg = (FixedPositionDefinedWaypointNodeConfig)end.getConfig();
// Set
final double[] viaPose = via_cfg.getPose().toArray(Length.Unit.M, Angle.Unit.RAD);
final double[] endPose = end_cfg.getPose().toArray(Length.Unit.M, Angle.Unit.RAD);
// Get Parameters of "MoveP" ProgramNode
final MovePMotionParameters motionParameters = getParameters();
final Speed toolSpeed = motionParameters.getToolSpeed();
final Acceleration toolAcceleration = motionParameters.getToolAcceleration();
final Blend blend = motionParameters.getBlend();
circleMoveMode = view.getCircleMode();
// generate movec command
writer.appendLine(
"movec(p["+viaPose[0] +", "+viaPose[1]+", "+viaPose[2]+", "+viaPose[3]+", "+viaPose[4]+", "+viaPose[5]+"], "
+ "p["+endPose[0]+", "+endPose[1]+", "+endPose[2]+", "+endPose[3]+", "+endPose[4]+", "+endPose[5]+"], "
+ "a=" + toolAcceleration.getAs(Acceleration.Unit.M_S2) + ", "
+ "v=" + toolSpeed.getAs(Speed.Unit.M_S) + ", "
+ "r=" + blend.getRadiusLength().getAs(Length.Unit.M) + ", "
+ "mode=" + circleMoveMode + ")"
);
}
// get MotionParameters of MoveP
private MovePMotionParameters getParameters() {
MovePMoveNodeConfig movePconfig = (MovePMoveNodeConfig)moveP.getConfig();
return movePconfig.getMotionParameters();
}
// create childNodes after MyCiecleMoveNode
private void createChildNode() {
moveP = factory.createMoveNodeNoTemplate();
movePConfigBuilder = moveP.getConfigBuilders().createMovePConfigBuilder();
moveP.setConfig(movePConfigBuilder.build());
via = factory.createWaypointNode("via_point");
end = factory.createWaypointNode("end_point");
TreeNode treeNode = programModel.getRootTreeNode(this);
try {
TreeNode movePTreeNode = treeNode.addChild(moveP);
movePTreeNode.addChild(via);
movePTreeNode.addChild(end);
} catch (TreeStructureException e) {
e.printStackTrace();
}
}
}
Is there any solution for this error?
Any suggestion will be appreciated!
Thank you.