Codesys variable incrementer

lesmar96

Lifetime Supporting Member
Join Date
May 2017
Location
PA
Posts
520
SoMachine v.4.3.

I have an interesting question, hoping someone here as some advice.

My customer has a Lexium 32 servo drive. We are reading the absolute position of the motor encoder into a variable in codesys, using the MC_ReadActualPosition_LXM function block.

All that aside, the customer is asking for another variable that works independently from the current_absolute_position. For example, he wants to be able to zero this 2nd variable at any given place and get a readout position readout +/- of the place he zeroed it. This variable is okay to zero when we HOME, but we must be able to zero it whenever we want without homing the servo.

I was thinking of implementing some logic that would increment/decrement the 2nd value when the current_absolute_position goes up or down, but I wasn't sure that was the best way.

Any thoughts on the best way to do this?
 
I would do it this way:


current_absolute_position = the real position reported from MC_ReadActualPosition_LXM.


relative_zero_position = whatever current_absolute_position was when the "zero button" is hit


relative_absolute_position = current_absolute_position - relative_zero_position


In ST:
IF zeroButtonOneShot.Q THEN
relative_zero_position := current_absolute_position;
END_IF

relative_absolute_position := current_absolute_position - relative_zero_position;
 
Last edited:
Clever. I knew some one would think of something better. I'm still learning! Thanks!
 
relative_absolute_position = current_absolute_position - relative_zero_position

Sweet; I have to wonder about the variable names though ...

relative_absolute_position? Isn't it simply the relative_position?

not that anything is really absolute in the first place...

just sayin'
 

Similar Topics

Hello, I have a codesys controller which I am looking to communicate with an external. User interface via mqtt. I subscribe to a topic and...
Replies
6
Views
1,411
Hi , I am not able to expand any global variable in offline mode, also not able to add comments to the elements of the variable since it does not...
Replies
13
Views
3,197
Hi all, I'm just starting out in the plc world. For school we had some introduction into codesys v3.5, basically we get given visualizations and...
Replies
9
Views
2,340
Hello, i am kinda new at codesys and i want to make a comunication between one ifm cr0403 plc and a cr0451 hmi i have read a lot on the forums and...
Replies
3
Views
1,894
Hi, I am new to codesys programming and need some help converting a word variable into 2 byte variables. If anyone provides the sample in Codesys...
Replies
9
Views
22,836
Back
Top Bottom