question

Marco B8 avatar image
0 Likes"
Marco B8 asked Isaac Litster converted comment to answer

Create AGV with for cicle

Good morning at all!

In my model I would like to create more than 1 agv using a for cicle.

int num_agv = 2;

for(int a=1; a<=num_agv; a++)
{
	//SHUTTLE CREATION:
	Object shuttle = createinstance(library().find("?TaskExecuter"), model());
	shuttle.name = "Shuttle" + numtostring(a);
	shuttle.location.x = 0;
	shuttle.location.y = 0;
	shuttle.location.z = 0;
	shuttle.size.x = 2;
	shuttle.size.y = 2;
	shuttle.size.z = 1;
	shuttle.color = Color.green;
	
	treenode shutref = model().find("/Tools/ProcessFlow/ProcessFlow/Shuttle>variables/reference");
	shutref.value = shuttle.name;
	
	treenode rotateOn2 = model().find("Shuttle" + numtostring(a));
	rotateOn2.value= 0;


	
	//SATTELITE CREATION:
	Object satellite = createinstance(library().find("?TaskExecuter"), model());
	satellite.name = "Satellite" + numtostring(a);
	satellite.location.x = 0;
	satellite.location.y = 0;
	satellite.location.z = 0;
	satellite.size.x = 2;
	satellite.size.y = 1;
	satellite.size.z = 0.5;

The problem is that the code create only the first shuttle and not the satellite and return this exeption:

exception: FlexScript exception: Property "value" accessed on invalid node. at /0 c: /testlink_instance i: /testlink_associated

Probably the code reguarding the reference is not correct and it doesn't recognize the agv.

Futhermore I have to insert other reference and I have to setting other data in the vehicles (like the speed or something else), does anyone have any idea how to write a correct code in the loop?

FlexSim 17.2.5
agvcodereferenceforcicle
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Joshua S avatar image
1 Like"
Joshua S answered

When you run this line of code in your loop

treenode rotateOn2 = model().find("Shuttle" + numtostring(a));
rotateOn2.value= 0;

You are essentially wiping the 3D Shuttle and everything associated with it and rewriting its data to =0, so I don't know what the purpose of those lines of code are. I removed those lines and the lines referencing your process flow since the values I won't be able to access and everything was created fine on my computer. So it might have to do with linking to your process flow or any other references you do after this loop.

To reference the speed of the task executers for example, use

getvarnode(shuttle,"maxspeed").value=10;

You can see all the nodes you can reference by looking in the model tree

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Marco B8 avatar image Marco B8 commented ·

Thanks Joshua!

I use that line of code to refer to the shuttle created by the for cycle in that loop. So, I'm wrong using that "reference". I'll try and I hope it will work!
0 Likes 0 ·