ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 04-03-2009
Shanon Loughton Shanon Loughton is offline
Flexsim User
 
Join Date: Mar 2009
Posts: 3
Downloads: 6
Uploads: 0
Thanks: 5
Thanked 0 Times in 0 Posts
Rep Power: 0
Shanon Loughton is on a distinguished road
Default Frame Animation based on Time

HI,

How do I make a basic custom load animation based on time using frames?

I can change a frame once on some trigger, but I want a series of frames to change over say every quarter of a second to create a simple motion for an action such as Load.
I can change frames based on position:
http://www.flexsim.com/community/for...ghlight=frames
But thats not what I want.

I have a
1) BasicTE, and custom image frames to cycle through during load, or even offset triggers.
2) loading from a queue
3) pivoting to unload at a source
I dont want to use crane or robot arm standard libraries.

Currently, I can send a message in BeginOffset from BasicTE to itself, then OnMessage

Code:
/**Custom Code*/
treenode current = ownerobject(c);
double loadtime = getlabelnum(current,"loadtime");
double starttime = time();
int state = msgparam(1);
double i = starttime;
while( i <= (starttime + loadtime) )
{
    if (i >= (starttime + loadtime))                      // End Frame
        setframe(current,5);
    else if (i >= (starttime + (3.0 * loadtime / 4.0)))    // 3/4 time Frame
        setframe(current,4);
    else if (i >= (starttime + (loadtime / 2.0)))        // 1/2 time Frame
        setframe(current,3);
    else if (i >= (starttime + (loadtime / 4.0)))        // 1/4 time Frame
        setframe(current,2);
    i = time();
}
All the above is supposed to do is to divide the frames amongst the available time during loadtime. But this crashes Flexsim. Probably because of the use of time() and dividing double floating types, but I dont know why - is it too complex?

Is there an example/thread on how to do this?
  #2  
Old 04-03-2009
Carsten Seehafer's Avatar
Carsten Seehafer Carsten Seehafer is offline
FlexSim Geek
 
Join Date: Oct 2008
Location: Ritterhude, Deutschland
Posts: 230
Downloads: 45
Uploads: 1
Thanks: 474
Thanked 320 Times in 143 Posts
Rep Power: 379
Carsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud ofCarsten Seehafer has much to be proud of
Default

Just a few hints...

- "i" is a command in flexsim. You can overload a command with a new command (like your i) but it could be a source of failure.
- "else if" isn't a command in c++ or flexsim. Your code looks normally like this:

Code:
if(...)
{
       ...
}
else
{
       if(...)
       {
             ...
       }
       else
       {
             if(...)
             {
                   ...
             }
             else
             {
                   if(...)
                  {
                         ...
                  }
            }
       }
}
- it looks like your while loop is running endless because "i" will not grow. time() gives back only the simulation time of this event.


Maybe this is a little help

Last edited by Carsten Seehafer; 04-03-2009 at 04:46 AM. Reason: add warp <code>
  #3  
Old 04-03-2009
Rachid Kolfin Rachid Kolfin is offline
Simulation Consultant
 
Join Date: May 2008
Location: Amsterdam
Posts: 21
Downloads: 18
Uploads: 0
Thanks: 58
Thanked 37 Times in 16 Posts
Rep Power: 169
Rachid Kolfin will become famous soon enoughRachid Kolfin will become famous soon enough
Default Frame Animation based on Time

Hi Shanon,

I see why your code crashes Flexsim. The code which you are executing takes place at one instance in time. So i will always be smaller than (starttime + loadtime) and you get caught in a neverending loop. I think you can simply solve this problem by using delayed messages for each phase of the loading proces. So ,

senddelayedmessage(current, 1/4 * loadtime, current, 1, 0, 0);

You can just use a different parameter for each phase and for each framenumber.

I hope this helps you. Good luck !!

Rachid
The Following User Says Thank You to Rachid Kolfin For This Useful Post:
Shanon Loughton (04-06-2009)
  #4  
Old 04-03-2009
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Carsten,

You can use if() else if() chains in Flexscript and C++ just fine.

This code is just fine:
int fred = 3;

if(fred == 1)
{
pt("fred is 1\n");
}
else if(fred == 2)
{
pt("fred is 2\n");
}
else if(fred == 3)
{
pt("fred is 3\n");
}

For a refresher on basic C++ syntax: http://www.sscnet.ucla.edu/geog/gessler/borland/cpp.htm
Everything on that page except the goto/exit works in Flexscript the same way.



As for why Shanon's code crashes, Rachid explained it pretty well.
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post:
RalfGruber (04-06-2009)
  #5  
Old 04-06-2009
Cliff King's Avatar
Cliff King Cliff King is offline
Vice President Technical Services
 
Join Date: Jul 2007
Location: Utah
Posts: 272
Downloads: 158
Uploads: 14
Thanks: 102
Thanked 304 Times in 110 Posts
Rep Power: 412
Cliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud of
Default Use Custom Draw Code trigger

Rather than create your own chain of events using the OnMessage trigger, you should consider using the Custom Draw Code trigger. It's a naturally reoccurring event that only fires when there is a 3D view window open. Use a variables (e.g. labels) in your code to reference the start time, and duration of the animation phase.
The Following 2 Users Say Thank You to Cliff King For This Useful Post:
Shanon Loughton (04-06-2009)


Thread Thread Starter Forum Replies Last Post
Displaying the simulation time with the various date/time formats. Regan Blackett Tips and Tricks 12 11-12-2012 08:01 AM
State report based on the operational time Simon Farsah Q&A 8 06-07-2011 01:42 AM
Image Swap Based on Position Logic William Clausen Q&A 8 08-06-2008 11:42 AM
Make sure you stop model with the stop button before collecting state based statistics Paul Dowling Tips and Tricks 2 06-10-2008 08:10 AM
Inter Arrival Time by Time of Day Mod Brandon Peterson Tips and Tricks 0 04-23-2008 11:13 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.