UML state for vending machine - branches dilemma? - uml

I'm trying to draw UML state diagram for vending machine, maybe its basic but im a beginner and havent found the appropriate solution on internet
Task: - the vending machine receives 1,2 and 5 $, the price of drink is 2 $
- it dispenses the drink if enough money is entered and refunds change
- machine has power on and power off)
I marked each state and transitions the numbers (STATES = s1,2 ..., TRANSITIONS = p1,2 ...), to make it easier to answer without drawing
(e.g. "p1 is wrong, there should be written this" etc)
Here is my diagram:
Questions:
Does it eventually return to IDLE - which seems to me more logical -
or it must go to the final state (rounded black point) as power off?
Or can there be two final states, so the S5 goes to another final state?
should it be after P3 or P4 maybe two branches?
maybe a new branch where the exact price amount is inserted (so there is no need for refund )
if so, where to put it?
If I understand the principle, on the arrows there should be written in this form - correct?
trigger event
[condition if it exists] /
action
Is there any basic errors I made?
Thanks in advance, I appreciate any feedback.

You can have as many finals as you need.
I'd make Dispensing an optional state after Waiting (for the > case) while the = case will directly go to selection. Just from a logical perspective. Of course you can make machines do dispense and change in parallel. In that case you need to fork to Dispense and Refund.
Correct
You should model Power off as Signal which can be triggered at any time. The power can be disconnected at any time during the machine is running, not just when it's idle.

Related

Detecting damaged car parts

I am trying to build a system that on providing an image of a car can assess the damage percentage of it and also find out which parts are damaged in the car.
Is there any possible way to do this using Python and open-cv or tensorflow ?
The GitHub repositories I found that were relevant to my work are these
https://github.com/VakhoQ/damage-car-detector/tree/master/DamageCarDetector
https://github.com/neokt/car-damage-detective
But what they provide is a qualitative output( like they say the car damage is high or low), I wanted to print out a quantitative output( percentage of damage ) along with the individual part names which are damaged
Is this possible ?
If so please help me out.
Thank you.
To extend the good answers given by #yves-daoust: It is not a trivial task and you should not try to do it at once with one single approach.
You should question yourself how a human with a comparable task, i.e. say an expert who reviews these cars after a leasing contract, proceeds with this. Then you have to formulate requirements and also restrictions for your system.
For instance, an expert first checks for any visual occurences and rates these, then they may check technical issues which may well be hidden from optical sensors (i.e. if the car is drivable, driving a round and estimate if the engine is running smoothly, the steering geometry is aligned (i.e. if the car manages to stay in line), if there are any minor vibrations which should not be there and so on) and they may also apply force (trying to manually shake the wheels to check if the bearings are ok).
If you define your measurement system as restricted to just a normal camera sensor, you are somewhat limited within to what extend your system is able to deliver.
If you just want to spot cosmetic damages, i.e. classification of scratches in paint and rims, I'd say a state of the art machine vision application should be able to help you to some extent:
First you'd need to detect the scratches. Bear in mind that visibility of scratches, especially in the field with changing conditions (sunlight) may be a very hard to impossible task for a cheap sensor. I.e. to cope with reflections a system might need to make use of polarizing filters, special effect paints may interfere with your optical system in a way you are not able to spot anything.
Secondly, after you detect the position and dimension of these scratches in the camera coordinates, you need to transform them into real world coordinates for getting to know the real dimensions of these scratches. It would also be of great use to know the exact location of the scratch on the car (which would require a digital twin of the car - which is not to be trivially done anymore).
After determining the extent of the scratch and its position on the car, you need to apply a cost model. Because some car parts are easily fixable, say a scratch in the bumper, just respray the bumper, but scratch in the C-Pillar easily is a repaint for the whole back quarter if it should not be noticeable anymore.
Same goes with bigger scratches / cracks: The optical detection model needs to be able to distinguish between scratches and cracks (which is very hard to do, just by looking at it) and then the cost model can infer the cost i.e. if a bumper needs just respray or needs complete replacement (because it is cracked and not just scratched). This cost model may seem to be easy but bear in mind this needs to be adopted to every car you "scan". Because one cheap damage for the one car body might be a very hard to fix damage for a different car body. I'd say this might even be harder than to spot the inital scratches because you'd need to obtain the construction plans/repair part lists (the repair handbooks / repair part lists are mostly accessible if you are a registered mechanic but they might cost licensing fees) of any vehicle you want to quote.
You see, this is a very complex problem which is composed of multiple hard sub-problems. The easiest or probably the best way to do this would be to do a bottom up approach, i.e. starting with a simple "scratch detector" which just spots scratches in paint. Then go from there and you easily see what is possible and what is not

Washing machine petri net

It is my first time doing a Petri net, and I want to model a washing machine. I have started and it looks like this so far:
Do you have any corrections or help? I obviously know its not correct, but I am a beginner and not aware of the mistakes you guys might see. Thanks in advance.
First comments on your net's way of working:
there is no arrow back to the off state. So once you switch on your washing machine, won't you never be able to switch it off again ?
drain and dry both conduct back to idle. But when idle has a token, it will either go to delicate or to T1. The conditions ("program" chosen by the operator) don't vanish, so they would be triggered again and again.
Considering the last point, I'd suggest to have a different idle for the end of the program to avoid this cycling. If you have to pass several times through the same state but take different actions depending on the progress, you have to work with more tokens.
Some remarks about the net's form:
you don't need to put the 1 on every arc. You could make this more readable by Leaving the 1 out and indicating a number on an arc, only when more than one tokens would be needed.
usually, the transitions are not aligned with the arcs (although nothing forbids is) but rather perpendicular to the flow (here, horizontal)
In principle, "places" (nodes) represent states or resources, and "transitions" (rectangles) represent an event that changes the state (or an action that consumes resources). Your naming convention should better reflect this
Apparently you're missing some condition to stop the process. Now once you start your washing will continue in an endless loop.
I think it would be nice to leave the transition graphics unshaded or unfilled if it is not enabled. Personally I fill it green if it is enabled.
If you want someone to check if you modeled a logic properly in your Petri Net then it would be nice if you include a description of your system logic in prose.

What would the actor be in a use case where stock is reordered automatically when it hits a certain point

Say there is 5 bags of potatoes, when it hits two bags, an order is sent to the supplier automatically. Who/What is the actor?
Clearly you have an actor to watch the queue like this:
Even if the Potato Watcher is something implemented inside the SUC, it would be an actor on its own. You may drag it inside the SUC boundary. In a final implementation it might be a system task to poll a queue or a subscriber to the queue. But from the added value viewpoint it's just a simple actor to watch a queue and do something with it.
Since "an order is sent... automatically" the system is the actor. Assuming you are automating using software system.
However in real life it all goes wrong and businesses are far away from sending orders automatically.
Badgerbadger, you need to be carefull about statement "sent an order".
It is easy to overlook actual business process and previous subfunction-level answers are giving a nudge.
More realistic scenario is that the system is the actor who just initiates the check of stocks, maybe orchestrates. And then there is a complicated process of getting approval, finding budget, checking if goods are really required to be ordered and so on. In theory all of those can be automated, but usually in practice there is a work for human actor as well. Of course you may be lucky and avoid all of this.
Example of pessimistic scenario to consider:
It was eight bags, but now hits three. John just bought five bags from us, hooray!
System automatically places an order and pays for 10 more bags.
In ten minutes someone ordered one more.
System automatically places an order again and pays for 10 more bags.
We don't have enough money on account so we are facing overdraft.
At the same time regular inspection found that one bag is rotten.
System: 10 more bags please!
Our colleague just told us that we've missed 20% discount from supplier on simultaneous orders of 25+ bags which can be obtained only by calling a company manager.
John cancels his order in an hour after placing it.
Now we have 36 bags and a hole in our budget.
And our marketing manager just told us that the green bags system ordered are actually now selling with a discount, we are getting rid of them in favour of new line of blue bags.
You have to possibilities here:
Each time the stock is used the system checks if the condition to order is met and if yes then order it. As ordering will probably involve another actor (e.g. supplier's system), you might need to model it as a separate UC and use extend relationship. In this case you will not have any additional actor initiating the order, only the actor initiating stock usage.
The system checks on a regular basis what stocks reached the automated order level and make a single mass order. In this case you'll have to model Scheduler as an actor (in reality it's another system running on the server so it's fine to call it an actor). Some people prefer modelling such actor as "time" but it's discouraged.

How would you solve this finite-state-machine (Moore)?

I am trying to solve an exercise using Moore's machine, but I am a bit confused. I don't know how many states are needed.
Inputs:
A (switch): change between auto and manual mode.
P (push-button): give high level while is pressed.
D (motion detector): give high level if detect movement
Outputs:
L (lamp).
Conditions:
If we are in manual mode, L will change (from 0 to 1) or (1 to 0) if we push "P". We need to re-press the button to change the L again (it is not valid hold the finger).
If we are in automatic mode, L will be enabled while "D" detect movement.
User will never push "A" and "P" at the same time.
When you change from auto to manual or manual to auto, the lamp have to pass low level.
When you change from auto to manual, the lamp will stay with a high level while detect movement.
The big problems are the last conditions. I don't know how can I handle them. Do I need to create extra-states for those conditions? What steps would you follow to solve the exercise?
Thanks in advance
First, design separate finite state machines for the automatic and manual case. The automatic case needs only two states (lamp on or off). The manual case needs 4 states to keep track of whether the button has been released since the last press.
Then add transitions between these machines based on the value of the switch A. Only add transitions between states where the lamp is off. This will ensure that the last two conditions hold. If the lamp is on when A is toggled, nothing will happen until the machine transitions to a "lamp off" state.

How to build FSM when there are too many states?

I am working on a vending machine project and trying to build a state machine, as I saw from other examples. The machine that I am trying to build holds up to 100 dollars. And it takes nickel, dime and quarter. So, I should define about 2000 states one by one. How can I build an FSM in an easier way? I just want a suggestion to proceed.
Thanks :)
Why do you feel that every possible value of the machine's cash balance needs a separate state? That sounds like a poor use of a FSM.
Just use an integer register which holds the total balance of the machine, or separate registers which hold the number of various coins and bills and calculate the total from that.
States might be things like process payment, dispense item, or refund change. Not the balance of the machine.
Just because you have 2000 "states" doesn't mean you have to enumerate every single one of them in a case statement.
As others have mentioned, you need to store some of your state in counters.

Resources