This example will demonstrate how to dynamically create a Polygon at run time using line segments that are moved into place from CAN position data to create a Polygon using rectangle widgets and scripting animation.
Powervision does not allow "creating" new graphical widgets during run time so the line segments used to create a polygon must be added in the page designer during the development cycle and hidden from view when not used.
Basic steps used in this example
- To create a line, add a rectangle widget with a width of 1 pixel and no border.
- Create four of these line segments which is enough to make a four sided polygon.
- The nominal length of the line segment is 100 pixels and is oriented horizontally with the origin on the left side at 0,0. 100 is an easy number to scale in scripting at run time.
- Create custom CAN messages which will define the x/y coordinates of the line endpoints, this allows external control of the polygon shape at run time.
- Use the animate position script function to move the lines origin to the desired x/y coordinate from the CAN data.
- To set the lines endpoint we must convert the cartesian x/y coordinates to polar coordinates which will provide the lines angle and length needed by the animation functions.
- To find the angle use the atan function then use the animate rotation script function to rotate the line segment.
- To find the line length use the quadratic equation then calculate a scaling factor based on the lines original length of 100. Use the animate scale scripting function to set the line length.
- Repeat this process for all the lines used.
- A User Event with a recurring 100mSec timer is used to call the scripts.
- All the code is located in the ~Animation folder.
- Additional lines segments are easily added by creating a new CAN message then copy pasting the Script SCE Animate LineX.
- For optimal display performance these lines would be located on an upper layer page view that is only displayed when needed.
Testing the Configuration
- Send CAN data PGN's 65350 - 65353 to set the line x/y endpoints, see library in the config for definitions.
- Reference blocks with coordinates are placed on the screen to make it easy to draw a border around them to verify coordinates.
- Lines are color coded to distinguish each one.
- Use the attached CANCapture workspace or tool of your choice to send dynamic or static CAN data to control each line segments position.
Download Example Configuration built with 2.9.23044 for a PV1100 display
Download CANcapture Workspace used to send CAN data to control the polygon