Adding Label in manual generated script

Hellow,

In my URCap, I create program nods and manually generate script. I mostli use move and waypoint nodes. I wanna add som complex/clever actions in between but I don’t waana showi those action in program tree. Actually that’s the reason why i generate script manually. The issue is that when the script is generated automatically, by method ScriptWriter.writeChildren(), label with node number and name are added. In script manual we can read:

“Program label code lines, with an “$” as first symbol, are special lines in programs generated by PolyScope that make it possible to track the execution of a program.”

e.g

$ 2 “var_1= True”
global var_1= True

Thanks to these labels, we can keep track of currently executed program step indicated by the arrow (like shown below).

SCR_01

Fragment of auto-generated script with labels

while (True):
    $ 1 "Robot Program"
    $ 2 "MoveJ"
    $ 3 "Waypoint_1" "breakAfter"
    movej(get_inverse_kin(Waypoint_1_p, qnear=Waypoint_1_q), a=1.3962634015954636, v=1.0471975511965976)
    $ 4 "Waypoint_2" "breakAfter"
    movej(get_inverse_kin(Waypoint_2_p, qnear=Waypoint_2_q), a=1.3962634015954636, v=1.0471975511965976)
    $ 5 "Waypoint_3" "breakAfter"
    movej(get_inverse_kin(Waypoint_3_p, qnear=Waypoint_3_q), a=1.3962634015954636, v=1.0471975511965976)
    $ 6 "Waypoint_4" "breakAfter"
    movej(get_inverse_kin(Waypoint_4_p, qnear=Waypoint_4_q), a=1.3962634015954636, v=1.0471975511965976)
    $ 7 "Waypoint_5" "breakAfter"
    movej(get_inverse_kin(Waypoint_5_p, qnear=Waypoint_5_q), a=1.3962634015954636, v=1.0471975511965976)
    $ 8 "Waypoint_6" "breakAfter"
    movej(get_inverse_kin(Waypoint_6_p, qnear=Waypoint_6_q), a=1.3962634015954636, v=1.0471975511965976)
    $ 9 "Waypoint_7" "breakAfter"
    movej(get_inverse_kin(Waypoint_7_p, qnear=Waypoint_7_q), a=1.3962634015954636, v=1.0471975511965976)
  end

How can I generate such labels manually? Is there some method to get actual program node number?

Or maybe there is a way to insert own script between automatically generated ones? Method ScriptWriter.writeChildren() return script for all subnode at once so I can’t insert anything between.

Hello @kontakt1 ,

the label “$” is automatically added and should only be provided by Polyscope and not by the user.

The writeChildren() - Method allows you in one point of your parent nodes Script code to insert the code provided by the Child Nodes. It is not possible to split this any further.

If you want to add your custom script code between them, you would need to create your correspondent URCap nodes, which are inserted at the desired position in the sub-tree.

@sko thank you for your reply,

I understand that “$” sign is generated automatically, but actually there is nothing to stop me for inserting into script anything i want. So why can’t I take advantage of it?

I don’t want to use the writeChildren() method for the reasons I mentioned before. Also, I don’t want to insert my URCap everywhere I needs extra action. It’s better for the typical customer if only waypoints are visible.

I checked this type of solution by manually putting line number and it looks like everything is working just fine.

Below is running program:

Example Java code to generate script (without extra action):

int j = 3;
writer.appendLine("$ " + j++ + " \"MoveL\"");

waypointIterator = wpWaitNodesList.iterator();

while(waypointIterator.hasNext()) {
	waypointName = waypointIterator.next().toString();
	writer.appendLine("$ " + j++ + " \"" + waypointName + "\" \"breakAfter\"");
	writer.appendLine("movel(" + waypointName + "_p, a=" + SHARED_TOOL_ACCELERATION/1000
			+ ", v=" + SHARED_TOOL_SPEED/1000 + ")");
}

Fragment of generated script:

$ 2 "DOOR_op (G1)"
set_tcp(p[-0.12891,0.0,0.11291,0.0,-0.7853981633974483,0.0])
$ 3 "MoveL"
$ 4 "M30_wait" "breakAfter"
movel(M30_wait_p, a=1.2, v=0.75)
$ 5 "MoveL"
$ 6 "DOORop_1" "breakAfter"
movel(DOORop_1_p, a=1.2, v=0.75)
$ 7 "DOORop_2" "breakAfter"
movel(DOORop_2_p, a=0.6, v=0.1)
$ 8 "DOORop_3" "breakAfter"
movel(DOORop_3_p, a=0.6, v=0.1)
$ 9 "DOORop_4" "breakAfter"
movel(DOORop_4_p, a=1.2, v=0.75)

The only information I needed, to initiate j index, was the line number where URCap was inserted.

Is there really no way to get the line number where URCap has been inserted?

Hi @s.bucholc

Thank you for your elaborated feedback!

No, currently it is not possible to retrieve the line number on inserting the Program node. This Feature is also not something a URCap should insert itself, but being handled by Polyscope. You would also need to continuously update this value, as you cannot guarantee the node being moved around etc.

Inserting Waypoint nodes should be done using the correspondent ProgramnNodeFactory with the correspondent configuration, as shown for example in the EllipseSwing - URCap sample.

Hi @sko

Thanks for the further explanation.

@sko

You would also need to continuously update this value, as you cannot guarantee the node being moved around etc.

I don’t think you are quite right as I only have to do this when the script is generated. Whenever this happens, generateScript() method is called for each program node. So if there was a method to get line number I would have called it from generateScript() and job is done. Correct me if I’m wrong?

Inserting Waypoint nodes should be done using the correspondent ProgramnNodeFactory with the correspondent configuration, as shown for example in the EllipseSwing - URCap sample.

I already look at on this example. We decided to manually generate script because I couldn’t find a way to lock the settings in Move node. In our case, customers should be able to only change some parameters and we have to make sure that parameters are in the right range. E.g. they aren’t allowed to change move type from MoveL to MoveJ. I could rewrite settings for the Move Node, what am actually doing in open/closeView() method, but user still can change value in Waypoint Node and save program without open/close URCap view.

Let’s recap, we want to simplify configuration for the user as much as possible and make robot algorithm to look not so complicated. This is the reason why we need to hide additional actions and generate script manually. Unless there is a better way to do this?

I hope now it is clear what we want to achieve?

Hi @s.bucholc

I agree with you, if this feature would be implemented, this could be the way to do it.

So your goal would be to have the Polyscope Program Nodes shown in the Program tree, but they cannot be altered by the user?

What functionality do you need from the Polyscope Provided Waypoint nodes? You could hide them completely within the URCap’s Script Code and add the needed functions in your own URCap UI.