question

Pedro Ortelani avatar image
1 Like"
Pedro Ortelani asked Pedro Ortelani commented

Module SDK - Flowitem positioning problem

I am working on a module and have created two objects, one that creates and destroys flowitens, and another one that works like a path where flowitens move through.

The problem I am facing is when I connect my object that creates flowitems with a queue and them with my path object, the flowitem position is updated correctly! But when I remove my queue and connect the two objects directly, my flowitem starts to move in the middle of the object.

I found out that the problem happens when updateLocations is executed, because I set the initial position of the flowitem on the onReceive method of my path object, and when I comment the updateLocations code, it stays at the start position in both cases.

Any suggestion on what I could be doing wrong? Should I be implementing another method like getPickOffset or getPlaceOffset?

That's my updateLocations method content.

if (currentState == STATE_BUSY)
{
	if (time() != lastTimeRecorded)
	{
		treenode item = holder->subnodes[1];
		setloc(item, 
			holder->find(">spatial/spatialsx")->value / crossingTime * (time() - getitemvar(item, 1)),
			yloc(item),
			zloc(item));
		lastTimeRecorded = time();
	}
}
return 0;

Thanks for the help!

FlexSim 20.0.3
module sdkdevelopment
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

·
Phil BoBo avatar image
0 Likes"
Phil BoBo answered Pedro Ortelani commented

You are using getitemvar(item, 1). Did you set that variable to something?

The itemvars are variables set by the fixed resource per item. Like labels that can be used by your object to track info per item.

If you didn't set it, then it will be whatever value the previous object set it to. If you want it set to something particular, set it.

· 6
5 |100000

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

Pedro Ortelani avatar image Pedro Ortelani commented ·

I did set its value to model time at the onReceive method.

setitemvar(item, 1, time());
1 Like 1 ·
Phil BoBo avatar image Phil BoBo ♦♦ Pedro Ortelani commented ·

We can't tell what is wrong from your description. You would need to post your module solution so that we can replicate it to debug it for you.

0 Likes 0 ·
Pedro Ortelani avatar image Pedro Ortelani commented ·

@phil.bobo

I did some debug myself and found out that the setitemvar method is not working when I have my two objects connected, but it works well when I have the Queue connected.

At my first updateLocation execution i get value 0 when I should be getting 3, and then the getitemvar is not called anymore.

Unfortunately i can't post my module solution, sorry about that.

Is it possible to know the reason why my set/getitemvar is not working properly?

I have this piece on code at the onReceive method:

setitemvar(item, 1, time());

And then i have this code at updateLocation:

setloc(item,
				(b_spatialsx / crossingTime * (time() - getitemvar(item, 1)) - xsize(item)),
				yloc(item),
				zloc(item));

Thanks for the help!

1 Like 1 ·
Pedro Ortelani avatar image Pedro Ortelani Pedro Ortelani commented ·

I switched the setitemvar for a class variable, and now it works both ways! The problem was with the itemvars as you figured from start.

Thanks for the help @phil.bobo!

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Pedro Ortelani commented ·

You probably just needed to add an initItem() call before calling setItemVar() the first time in order to initialize the item variables.

1 Like 1 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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