# Evaluate functions in template

## Recommended Posts

Hello guys,

I'm new here and I have a little problem I'm sure you can handle

I will present you my model so if you want you can suggest different solution than mine

[MODEL]

I'm trying to model the stiffness of a spring acting on a shift moving along his X axis by putting a force. The "difficulty" is that we have different responses whether the shift is moving along +X or -X. So I have two curves (force vs displacement), one for the stiffness while the shift is moving along +X and the other one for the stiffness while the shift is moving along -X.

[SOLUTION]

The idea was to create 2 forces (with one curve attached to each other) at the point where the spring acts, and for example deactivate one force while the shift is moving in one direction and when it moves in the other direction, deactivate this force and activate the the other one etc.

So I wanted to create a template in which I activate/deactivate the concerned forces as a function of the sense of the velocity of the shift by using two markers (see picture).

[PROBLEM]

So I use the VX({marker0},{marker1}) function in the template but it says " Unknown function "VX" in expression: velx = VX({m_1.idstring},{m_0.idstring}) "

I tried with " ` ` " but it had non effect.

So my question is : How to evaluate this function is the template ?

I join you a picture of the model and the little script I use for the Simulation Commands (Write text to solver command file).

I'm a beginner with the scripted simulation so it can be totally wrong

Thank you !

Here the script :

<Simulate

analysis_type  = "Transient"

end_time       = "1.0"

print_interval = "0.001"

/>

{velx = VX({m_1.idstring},{m_0.idstring})}

{if (velx<0)}

<Activate

element_type = "FORCE"

element_id   = "30101"

/>

<Deactivate

element_type = "FORCE"

element_id   = "30102"

/>

{elseif(velx>0)}

<Activate

element_type = "FORCE"

element_id   = "30102"

/>

<Deactivate

element_type = "FORCE"

element_id   = "30101"

/>

{endif}

<Stop/>

##### Share on other sites

Hi @CdricCd

Use ` ` (the key below Esc on keyboard) and check if there are any syntax errors.

If everything is fine and you still get the same error, please share the model file. (use the flie transfer link in my signature)

##### Share on other sites

Hi,

I already tried this and had this error : { Syntax error in expression: velx = `VX({m_1.idstring},{m_0.idstring})` }

The file is small i linked it with my message.

Thanks

model.mdl

##### Share on other sites

Wrong message

Edited by CdricCd
Wrong message

##### Share on other sites

Hi,

VX({m_1.idstring},{m_0.idstring})`  is a MotionSolve runtime expression

it is evaluated by MotionSolve..

template cannot do it...

But this can be done through expression, I will update to you soon.

##### Share on other sites

Try this model:

Also try to increase number of points on curve. They need to be smooth when AKIMA interpolation is switched ON in the curves panel

##### Share on other sites

Thanks !

The "IF" function in expression was my second idea but I had no idea how to introduce curves. I will investigate your solution.

##### Share on other sites
19 hours ago, CdricCd said:

[MODEL]

I'm trying to model the stiffness of a spring acting on a shift moving along his X axis by putting a force. The "difficulty" is that we have different responses whether the shift is moving along +X or -X. So I have two curves (force vs displacement), one for the stiffness while the shift is moving along +X and the other one for the stiffness while the shift is moving along -X.

I also stuck in the same problem. Though couldnt find out the solution. Your idea is pretty cool

##### Share on other sites

So I come back for the news and the solution works perfectly. I just have to use the LINSPL function instead of the AKISPL one and add a lot of point on the curve in order to make a correct interpolation.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.