AdvancedTransporter_PicAtom-Command

All topics on coding 4Dscript in Enterprise Dynamics.
Post Reply
Andreas
Posts: 6
Joined: Thursday 09 April, 2015 - 19:42

AdvancedTransporter_PicAtom-Command

Post by Andreas »

Hi,

i’m trying to create a simulation but i have only little experience in using ED.
In the end I want to control an Advanced Transporter by another Atom. This should test if a specific value is available. If this is true the AT should pick the Atom.
To get in contact with the code I try to control an AD in a test simulation. Therefore I wrote a createevent –command in the trigger on exit of another atom with a reference to the atom which should control the AD. In the onEvent-handler I use the Pick_Atom-command. The (quiete simple code) is shown below:

do(
eventcode,
if(

content(atombyid(476, Model)) = 0,

AdvancedTransporter_PickAtom(atombyid(605, Model),atombyid(475, Model), first(in(1, c))),

{AdvancedTransporter_PlaceAtom(AtomByID(208, Model), out(1, c), first(c)),}
OpenAllIC(reflogistiker2)

)
)

When I start the simulation the Transporter doesn’t move (I removed the marking at the load automatically command).
I don’t see the mistake. Can anyone help me?

thanks in advance
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: AdvancedTransporter_PicAtom-Command

Post by HarryBunnik »

Hello Andreas,

I see a few things. First of all, you can't use EventCode like that. EventCode is a number that can be used within the Atom code on the OnEvent to indicate which (out of a list of events especially written for that Atom) needs to be executed. So here it's not really adding anything, since you have only one event (that is why it's always used with a case statement). At least that is how I understand the code in your question.

Secondly, using AtomByID is not a really safe way to indicate an atom. When you load your model again in the same ED session, the ID will have been changed (each atom in a model gets a unique ID for that session only). So a better way to refer to an atom is creating either a connection via a channel (this allows you to refer to an atom using in(1,c) or something like that. Or you can make a global variable and use a "Initialize" atom in which you can create the reference using AtomByName (you don't want to use this in the code directly, since it is a rather slow way to refer to an atom). So the last would result in some code like:

Code: Select all

Dim([refReferenceToAT], vbAtom, AtomByName([NameOfYourAT], model))
Finally, using OpenAllIC gives a reasonable chance that you're going to mix up some of the internal code that is predefined on the atom. Of course you can try, but it might result in unexpected behaviour.

Perhaps you can attach your model so we can have a look at it to give some more pinpointed help?

Regards,

Harry
Andreas
Posts: 6
Joined: Thursday 09 April, 2015 - 19:42

Re: AdvancedTransporter_PicAtom-Command

Post by Andreas »

Hi Harry,

first of all thank you for your help.

I try to control an Advanced Transporter by referencing another atom. If a server atom is empty the AD should be sent to one or even more atoms to pick products. Thereby a label value should be regarded as well (if the lable has a specific value this Label should be picked).

By implementing the code I tried different ways to reference other atoms, for example the first(in(1, c)) command or the atombyname-command. The effect was always the same: the AD doesn’t move. Nonetheless is the explanation regarding the atombyid-command very usefull.

The latest version serves me to learn how to control atoms by other atoms. In this test I include a conditional control atom.
I even added the description you gave me regarding the reference of other atoms.

I don't see how to reference another current and involved atom. I added the (very simple) model. Maybe anyone can find the mistake.

Thank you in advance.
Attachments
Test atom-control.mod
(20.35 KiB) Downloaded 284 times
User avatar
HarryBunnik
Posts: 362
Joined: Monday 07 February, 2011 - 11:22

Re: AdvancedTransporter_PicAtom-Command

Post by HarryBunnik »

Ha Andreas,

I've made some adjustments to your model and hope I understood your questioning correctly.
Test atom-control v2.mod
(22.18 KiB) Downloaded 284 times
First I've added an initialize atom, that sets some global variables, so I know what I'm referring to.
Then I've adjusted the code on the "Condition control "a bit. I first check if the content of the server is 0 and the check if a product in one of the 2 warehouse has a label([KF], ...) = 5 using an IndexMatch over the content of the warehouse. You have to connect the conditional control to the warehouse, so it can detect if something is happening. Otherwise the conditional control can't detect a change.

If this has happened, the "User action on true" is executed. This I also changed a bit, accordingly to what I did at the condition.

And now the advanced transporter is picking up all products in the warehouse that have label([dk], ...) = 5, when the server is empty.

I hope this helps you further,

Cheers,

Harry

P.S.

Of course there are other ways to handle such problems as well, like using a table to register all products that fit dk = 5 for instance. That way you don't have to search so much using IndexMatch. And additionally a conditional control is not the fasted way to deal with such things, since it constantly has to check the status of all connected atoms.

P.P.S.

Not that the reference "i" can only be used on the OnEntry and OnExit triggers (and in OnEvent when specified). In all other cases, you have to use first (c) or rank(#, c) to refer to an atom.
Andreas
Posts: 6
Joined: Thursday 09 April, 2015 - 19:42

Re: AdvancedTransporter_PicAtom-Command

Post by Andreas »

Hi Harry,

Amazing, if something is done in the right way it works :o).
I read your adjustments and understand them, this is a huge benefit.
I integrated it in a more complex model, we'll see which further problems occur.

Thanks a lot for your help
Post Reply