Join us today!
Creating a Moving Object on HMI Screen using the Transform Attribute
I discovered this while working on a TwinCAT HMI Project, so I thought I would share how to create an object and move it.
Let's say I want to move a rectangle across the an HMI Screen, how would I do that?
I want to start with three controls:
>The rectangle to be moved
>The button to start the movement
>The button to stop the movement
The buttons themselves are simple enough, create your project and data bind the buttons to the BOOLs you want. For my example:
b_MoveSquare_Forward is bound to MoveForward_PB Button
b_MoveSquare_Reset is bound to ResetMove_PB
When creating the rectangle (or any Controls object), there is an Action called Transform:
The Transform attribute, as defined by Beckhof InfoSys, is the following:
Definition of a transformation of a control:
|
As the above definition lays out, once you drag and drop the action into your action for the rectangle, you can select which transformation and by how much. (Drag the action into your project and then click on the ellipses button (...) to edit the action.
(In our example, we are going to create a conditional statement for the rectangles transform using a BOOL in the MAIN program called b_SquareCommand)
When I first played around with the command, it would only translate a finite amount when the condition was TRUE, then when the condition went FALSE, the translation was reset.
In order create an object that would constantly move across the screen, I bound the translation amount in the x-direction to a variable where I would set a timing pulse and true condition so that for every one second, the translation amount would increment 10, which would then change the translated position of the rectangle, which gives it the appearance of moving across the screen. Below is my code and a video.
Let me know your thoughts and suggestions on this topic
-Evan H.
can you put the project to download?, thank you very much
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
Also, FYI @runtimevictor, there is a function block in there called FB_StatusLight. The function block creates a Status Light object that is supposed to be a light that turns on and off at time intervals inputted by the programmer. In my program, I am only using it to control an On and Off signal that uses 1 second ON time and 1 ms Off time, so its practically just a 1 second pulse.
In the future, I will need to update the FB and rename it to something more accurate, because I end up using for stuff other than a Status Light.
-Evan H.
Thank you.... 👍 😉
https://github.com/runtimevic
https://github.com/TcMotion
https://www.youtube.com/playlist?list=PLEfi_hUmmSjFpfdJ6yw3B9yj7dWHYkHmQ
https://github.com/VisualPLC
- 17 Forums
- 267 Topics
- 924 Posts
- 1 Online
- 737 Members