Universal Robots Forum

Is there a way to split writeChildren Function for inserting Lines before and after special childs?

i want to use appendLine for inserting for Example an “If false” and after that write some special Childrens(WaypointNodes). After this i want to use appendLine again with “end” and write the rest of the Children(Folders and comments).

In this way i want to “store” the Pose Data of the Waypoints but dont let the robot go there while program excecution. So the user can change the Waypoints easily in programmode if needed .

something like that:

System.out.println("writer -> alive");
			
			writer.appendLine("if( False ):");
			
			writer.writeChildren(); //just the waypointNodes

			System.out.println("writer -> writeChildren(): DONE");
			
			writer.appendLine("end");

writer.writeChildren(); //the rest(Folders...)

//set the waypoint variables to latest pose values by checking the programTree and writing an assignment to scriptcode

			for(Object wpn : getListOfFixedDefinedWaypointNodes()) {
				writer.assign(wpn.toString().toLowerCase(), getPoseOfFixedDefinedWaypointNode((WaypointNode)wpn).toString());
			}
			

		if(isDefined()) {			
		
			writer.appendLine("# VgP- script endet hier!");
			System.out.println("generateScript");

I don’t want to use “if condition” Node to have the Code in the Background. Or is it possible to call the writer between the createNodes() functions and do the writer.appendLine(if….) inside the writeChildren() function?

Ronny

you can do this by getting the FixedPositionDefinedWaypointNodeConfig of every Child Waypoint Node:

        TreeNode urcapTreeNode = programModel.getRootTreeNode(this);
        int waypoints = urcapTreeNode.getChildren().get(0).getChildren().size();
        //for each childnode waypoint
        for (int i = 0; i < waypoints; i++) {
            WaypointNode wp = (WaypointNode)  urcapTreeNode.getChildren().get(0).getChildren().get(i).getProgramNode();
            FixedPositionDefinedWaypointNodeConfig wpCfg = (FixedPositionDefinedWaypointNodeConfig) wp.getConfig();
            Pose pose = wpCfg.getPose();
            writer.appendLine("movel("+pose.toString()+",a=1.2 ,v=0.25,r=0)");

instead of using movel u can add the Pose to an ArrayList

Hi,
and thx for the Reply…

i allready do this in the first URCap and check if the user hase changed some waypoints. But in the second Cap I can not Looking for childs of the first Cap. So I created global Vars and set them to the data of this poses. After the Waypoints I created some Folder Nodes(PottingTime, WaitingTime,BlendRadius…etc) There the user has to set his needed Variables in assignmentnode. Unfortunally these assignments now are inside the -If(false-) part of the WaypointNodes(for the robot not moving there).

Thats why I tried to find a way to:

-write code-…
-write some Special childs(WaypointNodes)…-
and -write the rest of the code-…
and -finally write the rest of the childs(Folders and assignments)-.

I also was thinking About using an ArrayList, or better an XML file with a Class with the WaypointPose, the PottingTime WTime etc in it. In Netbeans without URCaps I got this done. But in Eclipse the XML-Files stays empty.

Now I tried to traverse the VariableAssignmentNodes and get the Names and Values, to set a finall assignment by the ScriptWriter after the -If(false)- part. I had some issues the get the Values of the Variables in the Traverse-part, but now i’m getting it from the String of the AssignmentNode after the -Colon equals- Char.

writer.appendLine("if( False ):");
			
			System.out.println("writer -> try writeChildren()");
			writer.writeChildren();
			System.out.println("writer -> writeChildren(): DONE");
			
			writer.appendLine("end");
			
			//set the waypoint variables to latest pose values by checking the programTree and writing an assignment to scriptcode
			for(Object wpn : getListOfFixedDefinedWaypointNodes()) {
				writer.assign(wpn.toString().toLowerCase(), getPoseOfFixedDefinedWaypointNode((WaypointNode)wpn).toString());
			}
				for(Object exp : getListOfAssignmentExpressionNodes() ) {
				writer.appendLine(exp.toString().replace('≔', '=')); // replace "colon equals" by "equals"
				System.out.println(exp.toString().replace('≔', '='));
			}