Join us today!

Creating a Moving O...
 
Notifications
Clear all

Creating a Moving Object on HMI Screen using the Transform Attribute

5 Posts
2 Users
5 Reactions
845 Views
ehixenbaugh
Posts: 33
Topic starter
(@ehixenbaugh)
Trusted Member
Joined: 2 years ago

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

MoveForward binding
MoveReset binding

When creating the rectangle (or any Controls object), there is an Action called Transform: 

MovingRectangle Action

The Transform attribute, as defined by Beckhof InfoSys, is the following:

  Definition of a transformation of a control:

  • Translate: Translate in X-, Y-, Z-direction
  • Rotate: Rotate by an angle
  • Scale: Zoom by a factor
  • Skew: Sides shown skewed by an angle
  • Origin: Set the origin of the transformation relative to the position of the control  
  • Perspective: Set the perspective of the transformations of all child elements.

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)

SquareCommand Action
Transform DataDefinition

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.

MovingObject Code

Let me know your thoughts and suggestions on this topic

-Evan H.

Reply
4 Replies
4 Replies
runtimevictor
(@runtimevictor)
Joined: 2 years ago

Estimable Member
Posts: 156

@ehixenbaugh ,

can you put the project to download?, thank you very much

Reply
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 33
ehixenbaugh
(@ehixenbaugh)
Joined: 2 years ago

Trusted Member
Posts: 33

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.

Reply
runtimevictor
(@runtimevictor)
Joined: 2 years ago

Estimable Member
Posts: 156

@ehixenbaugh ,

Thank you.... 👍 😉 

Reply
Share: