What is a Flag in CX-Programmer? - plc

During the reading of PLC documentation (Omron CP1L PLC and CX-Programmer), there are some missing explanation. For example, it defines "Flag" as "a bit that serves as an interface between in*struction", does that mean flag is some sort of conditional Power Flow?
It gets more confusing with the terms "Differential Up/Down", "Carry Flag"? What are flags and what do they do in the ladder logic? Are they a simple or instruction to use or just a concept that I don't really need to program in ladder?
[EDITED]
Where to add / modify / delete the flag in an instruction? I open up the edit but flag isn't there.

Ok, this is a better question.
PLCs are like any program - data is stored as different types. Think of flags as interchangeable with the term "bit", "boolean", etc. They are very important.
If you have CX-Programmer, a much better place to get information is the Instruction Reference (Help --> Instruction Reference --> yourPLC). These show time diagrams of most of the instructions and how each of the parameters and flags operate.
For example, a basic timer (TIM) works by assigning it a value. If you use a BCD type 100ms timer and assign its SV (setpoint value) a BCD value of 300 then you have created a timer with a 30 second limit (300 x 100ms). When the timer turns on it will begin counting and the PV (process value) will start from 300 and count down. When the value reaches zero the timer's flag turns ON to indicate that it has expired. If the timer's number is, say T100 then you can use T100 as a contact in another rung of logic - it will be true when the timer's execution conditions are TRUE and the timer has expired.
Differentials (UP/DOWN) are special flags which are true for only one PLC scan (ie: they are true for one execution cycle only) when their input conditions change from FALSE to TRUE (ie:OFF to ON) for UP differentials, and TRUE to FALSE (ie:ON to OFF) for DOWN differentials. You would use differentials in cases where you wanted to perform an action the moment a given condition changes.
Flags can be used for almost anything. You can use them as general booleans in your own programs, they can be parts of certain operations (ie: the CY (carry) flag is used on arithmetic operations which result in a carry - other flags are used to indicate overflows or div/0 errors, etc).
Edit again : (to answer extended question).
A basic timer's completion flag is a contact with its number. Say I have a 100ms timer, T100, which turns on when contact 10.00 is on:
10.00 ___
|-----| |---------------------------------------|TIM|
|100|
| |
|#20|
|___|
Now, once 10.00 has been ON for two seconds, the timer will elapse and the flag for timer 100, T100, will turn ON. If I had another rung where
| T100 W15.00
|-----| |-----------------------------------( )
Then work bit W15.00 would be turned on when the timer elapsed and would remain on so long as the timer's input condition remained satisfied (ie: so long as 10.00 remains ON). Flags work in different ways for different things, however. Each operation can use them in different ways.
The example from the Omron Instruction Reference (Help -> Instruction Reference -> [select PLC]) looks like this :

Well very good explanation with example and the flags value can be found in memory area it is pure binary either 0 or 1, as i was read the documentation work-bit memory location changes as per timer type e.g TIM/TIMX or TIMH or TIMHX, both are BCD timers but unit for the timer changes.

Related

Anylogic - Assembler should stop working for 2 hours after 10 assemblies done

The "Assembler" should stop working for 2 hours after 10 assemblies are done.
How can I achieve that?
There are so many ways to do this depending on what it means to stop working and what the implications are for the incoming parts.. but here's one option
create a resourcePool called Machine, this will be used along with the technicians:
on the "on exit" action of the assembler do this (I use 9 instead of 10 because the out.count() doesn't count until the agent is completely out, so when it counts 9, it means that you have produced 10)
if(self.out.count()==9){
machine.set_capacity(0);
create_MyDynamicEvent(2, HOUR);
}
In your dynamice event (that you have to create) you will add the following code:
machine.set_capacity(1);
A second option is to have a variable countAssembler count the number of items produced... then
on exit you write countAssembler++;
on enter delay you write the following:
if(countAssembler==10){
self.suspend(agent);
create_MyDynamicEvent(2, HOUR,agent);
}
on the dynamic event you write:
assembler.resume(agent);
Don't forget to add the parameter needed in the dynamic event:
Create a variable called countAssembler of type int. Increment this as agents pass through the assembler. Also create a variable called assemblerStopTime. You also record the assembler stop time with assemblerStopTime=time()
Place a selectOutputOut block before the and let them in if countAssembler value is less than 10. Otherwise send to a Wait block.
Now, to maintain the FIFO rule, in the first selectOutputOut condition, you need to check also if there is any agent in the wait block and if the current time - assemblerStopTime is greater than 2. If there is, you free it and send to the assembler with wait.free(0) function. And send the current agent to wait. You also need to reset the countAssembler to zero.

FBD for TwinCat Beckhoff... Function Block Input Output How is this working

Seems IW_PR_Schrittnummer is only referenced in 3 spots... where it's declared and where its read in the fbd routine... I guess what I'm asking is something writing a number to this variable... or what? If so how would I find it... also what is the action being performed by this first function block? looks like there are 4 inputs, Auto, is Auto Active, does tasknumber = 0, and is Press Free. if all 4 of these are true... then End Auto. Does that sound right??? someone else programmed this for a job that does work. The tags are in German.
1st FBD
Variable Reference
Variable Declaration
2nd fbd just for reference
The IW_PR_Schrittnummer is linked to input I/O using AT %ID716 command. So it gets its value from I/O memory. That basically means that "take this value from input memory at address 716 and the size is D (double word, 32 bits).
I'm not sure how you can check what is in that address when it's defined with direct addressing like this. Hopefully someone else knows a good tip for this!
More info about addresses: https://infosys.beckhoff.com/english.php?content=../content/1033/tc3_plc_intro/18014401038842507.html&id=6547931155168793261
More info about addresses: https://help.codesys.com/webapp/_cds_at_declaration;product=codesys;version=3.5.15.0
That logic from your 1st image works as you said. So AutoFinde will be TRUE, if Auto, AutoAktiv, IstFrei are all TRUE and the input IW_PR_Schrittnummer is 0. Otherwise the AutoFinde will always be FALSE.

Setting up openai gym

I've been given a task to set up an openai toy gym which can only be solved by an agent with memory. I've been given an example with two doors, and at time t = 0 I'm shown either 1 or -1. At t = 1 I can move to correct door and open it.
Does anyone know how I would go about starting out? I want to show that a2c or ppo can solve this using an lstm policy. How do I go about setting up environment, etc?
To create a new environment in gym format, it should have the 5 functions mentioned in the gym.core file.
https://github.com/openai/gym/blob/e689f93a425d97489e590bba0a7d4518de0dcc03/gym/core.py#L11-L35
To lay this down in steps-
Define observation space and action space for your environment, preferably using gym.spaces module.
Write down the step function which performs agent's action and returns a 4 tuple containing - next set of observations from the environment , reward ,
done - a boolean indicating whether the episode is over , and some extra info if you want.
Write a reset function for the environment to reinitialise the episode to a random start state and return a 4 tuple similar to step.
These functions are enough to be able to run an RL agent on your environment.
You can skip the render, seed and close functions if you want.
For the task you have defined,you can model the observation and action space using Discrete(2). 0 for first door and 1 for second door.
Reset would return in it's observation which door has the reward.
Then agent would choose either of the door - 0 or 1.
Then perform a environment step by calling step(action), which will return agent's reward and done flag as true - signifying that the episode is over.
Frankly, the problem you describe seems too simple to accomplish for any reinforcement learning algorithm, but I assume you have provided that as an example.
Remembering for longer horizons is usually harder.
You can read their documentation and toy environments to understand how to create one.

PLC Ladder Logic

I am trying to use PLC's to monitor a race track. I will be using 3 Photo sensors to show which car crossed the finish line first. Each sensor will have be OTL (Latched) instruction. Each lane will have a light to indicate which car was in first place. The car not in first lights will not come. There will be 3 judges. At the completionof each race, once the winner has been recorded, the 3 judges will use their respective switches to reset the indicator lamps to an off state (Unlatched) in preparation for the next race.To inhibit any attempt at cheating by the race judges , the judges switches are programmed so that all 3 judges must agree to reset and a reset can only occur after all 3 cars have passed the finish line. The judges will be programmed with a One Shot Rising (OSR) instruction. It sh.ould be noted that we're working with a SLC 500 PLC. I fail to mention that Iam using Rockwell Automation software RS Logics, so please use Rockwell's instructions on your ladder logic.
This is rather straight forward. I'm answering generically for the PLC make isn't defined.
// You need 3 of these sets, one for each Lane, prefixed 1, 2, 3, accordingly
|---|Photo1|----------------|-----------(OTL1)----|
|---|OTL1|-----|/ResetCmd|--|
|--|OTL1|---|/OTL2|---|/ OTL3|----------(Light1)--|
// We have two work booleans, used in relation with the reset logic.
// All3In is an AND of all 3 OTLs indicating that all 3 cars have passed the finish line
// SomeOTLON is an OR of the 3 OTLs indicating that one or more OTL latches hasn't been reset
|--|OTL1|---|OTL2|----|OTL3|----------------------(All3In)--|
|--|OTL1|----|---------------------------------(SomeOTLON)--|
| |
|--|OTL2|----|
| |
|--|OTL3|----|
// We need 3 latches like the following, one per judge
// Essentially the Latch comes on when all 3 cars are in and the judge presses his button
// The latch comes off after all 3 OTLs dropped
|--|Judge1|---|All3In|----------|-------------(Judge1Latch)--|
| |
|--|Judge1Latch|---|SomeOTLON|--|
// Finally the Reset Command
|--|Judge1Latch|---|Judge2Latch|---|Judge3Latch|--|------(ResetCmd)--|
| |
|--|ResetCmd|------|SomeOTLON|--------------------|
Et voilà. Only possible trouble is if the "JudgeN" switches are not One Shot Rising (but they seem to be as per the problem text), it would be possible for a judge to make his/her push button stick and still have the ResetCmd latch on when all 3 cars arrive.

Question on critical section algorithm

The Operating System Concepts 6th edition present one trival algorithm to implementate ciritical section.
do{
while (turn != i);
critical section
trun = j;
remainder section
} while(1);
Note,Pi is the process with identifier i,Pj is the process with identifier j.To simlify the question,the book limit the i,j to 0 and 1,the two processes constriant enviroment.
Question1 is,dose this algorithm voilate the Progress requirement which is one of the three requirements to ciritical section solution?
In my opinion,when Pi is in its remainder section,it cannot participate in the decision on whether Pj can enter the critical section.Then it is bound to the requirement.
Or my understanding of progress requirement is totally wrong.So because if Pi retired from the remainder section,It could not get into the cirtical section immediate,this alg violate the rule.
Question2,
If turn == 0 and P1 is ready to enter
itscritical section,P1 cannot do
so,even thought P0 may be in its
remainder section
Whats the meaning of this statement?As far as I could think,I could not understand why turn == 0 and p0 be in its remainder section could be exist concurrently...
So is this statement wrong?
Suppose that turn = 0 initially. P0 does its critical section and sets turn = 1. Now, P1 must execute its critical section before P0 may execute its one again. But just because both threads have a critical section doesn't mean that they're going to want to alternate their use of it in this way — in fact, P1 may never take its turn. (And in the general case, you can't determine this at compile time.)
So basically the problem is that the threads are forced to alternate their turns, even if one of them actually doesn't want to enter its critical section for an indefinitely long time.
By the way, your answer to Question 1 is correct. The algorithm doesn't fail the Progress condition, it fails the Bounded Waiting condition.