Questions about logging state changes, calculating energy consumption

Questions about logging state changes, calculating energy consumption

caner_p
Not applicable
13 Views
11 Replies
Message 1 of 12

Questions about logging state changes, calculating energy consumption

caner_p
Not applicable

[ FlexSim 19.0.0 ]

Hi all,

There is a model I'm working on. I'm using the virtual distance feature for paths. There are AGVs (ships) loading crates from a "dock" and unloading them at another "dock". And I need to introduce an energy consumption and recharging calculation so that each AGV,


1) If they are in "Travel Loaded" state, they must spend some energy per unit of distance (e.g., 3000 units of energy stored onboard, consumes x units of energy per unit of distance (Please note that there will be four types of AGVs (ships) with different rates of energy consumption when this study finishes),

2) If they are in an "Idle" state and if their "Loc" labels are set to a particular "dock" (e.g., BOS, KSK, ALS or KSK1, and so on), they must gain energy at an adjustable rate. (e.g. y units of energy per second),

3) The energy values of each AGV must be logged and visualized.

Bonus step: Visualasing distances traveled (as they increase) and state changes of AGVs for each AGV in two seperate time plots with timestamps would be great.


I think I need to define variables about energy, but I don't know how to.

Sorry but I'm stuck. I feel stupid for not fixing this and ashamed of taking peoples' time.

Any help will be appreciated.


V3_Ships_are_sailing.fsm

0 Likes
Accepted solutions (1)
14 Views
11 Replies
Replies (11)
Message 2 of 12

moehlmann_fe
Observer
Observer
Accepted solution

If you were using AGV paths, you could use the built in battery system for this. But since they don't offer the same virtual distance property as network nodes (as far as I'm aware), they don't seem to be an option.

You can build your own system though. Define a kinetic tracked variable on each agv that serves as the battery level. Three more labels define the charge/discharge rate and the maximum charge the battery can hold, so these can be set differently for the different types.

In the attached model I use an instanced process to listen to the state changes of the agv and adjust the rate at which the tracked variable changes when it switches to "travel loaded" or "idle". A statistics collector listens to these activities and logs the current value whenever the rate changes (since the rate is linear, the graph only needs to know those data points).

The rate of a tracked variable is of course by time rather than distance but since the speed is going to be near constant due to the large distances the error seems negligible.

v3-ships-are-sailing_fm.fsm

The function is only added to F3 and F4 so far.

Message 3 of 12

caner_p
Not applicable

Thank you so much. I've studied what changes you have made and I get it now. You need to make a Custom Code, define variables and track them in order to get battery, consumption and recharging possible. I expanded it onto F1 and F2. I will expand it all AGVs.


Now I want to limit where charging is available and at what rate. For example, it is possible to setup a zone around BOS and when a ship enters that zone, it's charging rate changes to a value?


Also, is there an easier way to adjust the Battery, dischargeRate, chargeRate,and maxCharge values like setting labels and values for group members at the beginning of the sim? I know how to set labels but couldn't figure out how to set a tracked kinetic level label for a group. Do I set the label first for the group and then make them tracked somehow? I have done it manually for all AGVs for it would be a lot easier to experiment with capacities.


v3-ships-are-sailing-fm.fsm



0 Likes
Message 4 of 12

moehlmann_fe
Observer
Observer

The only way to have "zones" around the locations where the travellers are charged would be to place intermediate network nodes around them. Then you can react to a task executer travelling over them and set the battery rate depending on the direction they travel ("toEdge").

1642009043667.png

1642010115819.png

1642010131438.png

You can select multiple objects by holding down "shift" and dragging a box around them or holding "ctrl" and selecting them one by one. Then you can use the buttons in the bottom right corner of the label tab to copy labels from the highlighted object to all of them.

1642010261416.png

1642010291502.png

Message 5 of 12

caner_p
Not applicable
Thank you! Can you please share the model as well?
0 Likes
Message 6 of 12

moehlmann_fe
Observer
Observer

Sure, though I haven't adjusted the virtual distance of the new connections yet, so the movement is very fast at the moment.

v3-ships-are-sailing-fm_autosave.fsm

0 Likes
Message 7 of 12

caner_p
Not applicable

Sorry, but adding those nodes seems to break everything. Even after I corrected distances between nodes, AGVs are going where they are not supposed to go. Also, stats are not working after that.

Can we take another approach? I'm already assigning "Loc" labels to all AGVs on each trip to let them know which port they are at now (so that they know if the cargo at the port is theirs to transport). Can't we use these labels to define charging rates instead?

For example (sorry, this must be the worst coding-like you have ever seen but bear with me, please), can we do something like below?


if AGV.Label.Loc="Bos" than chargeRate=500,

if AGV.Label.Loc="Bos_F" than chargeRate=500,

if AGV.Label.Loc="KSK" than chargeRate=250,

if else chargeRate=0

0 Likes
Message 8 of 12

moehlmann_fe
Observer
Observer

I think some labels on the agvs might have been altered when I copied some values between them, mostly the starting "Loc" value.

Similarly, because I got rid of the other logic for setting the charge rates, the events/activities the statistics collector listens to ("BatteriesAndDistanceCollector") have to be updated.

v3-ships-are-sailing-fm_zone_fixed.fsm


The reason I suggested this approach because I understood your "zone" to mean that the agv should start charging before they actually fully reach the destination.

Otherwise your idea would have been my approach as well. Accessing the tracked variable labels and setting their rates is already demonstrated in my attached models. Everything else should be found in the manual.

Writing Logic in FlexSim

Your pseudo code would look something like the following:

/**Custom Code*/
Object current = param(1);
treenode activity = param(2);
Token token = param(3);
Variant assignTo = param(4);
string labelName = param(5);
treenode processFlow = ownerobject(activity);

TrackedVariable battery = current.labels["Battery"];
double chargeRate;
if(current.Loc == "BOS_F")
{
    chargeRate = 500;
}
else if(current.Loc == "KSK")
{
    chargeRate = 250;
}
else
{
    // Charge rate will be set in the custom code activity
    return 0;
}

// Set battery rate
battery.rate = chargeRate;

// Return time until full with current rate
return (current.maxCharge - battery.value)/chargeRate;

Instead of setting the rate to 0 directly if no condition is met, I stop the execution of the code by returning a zero. Because the code is written in a "Assign Labels" activity, this returned value then gets assigned to chosen label. If the label is zero, the token won't be delayed and the rate is set to zero in the custom code activity instead. I do this so I don't have to worry about possibly dividing by 0 in the last line. Although you code also simply add another check to only execute that line if the charge rate is larger than zero.

v3-ships-are-sailing-fm_1.fsm

Message 9 of 12

caner_p
Not applicable
Thank you! You are amazing! Thanks for directing me in the correct direction. The FM-1 model is simply what I needed and I'll try to edit the code so that I can experiment with the charging combinations.
Message 10 of 12

caner_p
Not applicable
Hey there, again. I don't know if it is possible, allowed or just if you prefer, can I buy you a beer, somehow? So that I can bug you in the future without feeling remorse.

Anyways, you have been a great help! I wish you good health my friend!

Message 11 of 12

ryan_c10
Not applicable

Hi @C, was Felix Möhlmann's answer helpful? If so, please click the "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes
Message 12 of 12

moehlmann_fe
Observer
Observer
No worries, that's what the forum is there for. I do appreciate the gesture though! Good luck with your project.