We were talking to the guys at DesignSpark and the conversation got around to what we could do if we had an extra hour, walk about 4 miles, watch an episode of Game of Thrones, clean the fridge (thanks Pete) or try to stay away from our smart phones.
After getting to the silly answers the guys at DesignSpark set us a challenge, the only criteria was that we had 1 hour, we had to use PanelPilotACE Design Studio, we had to write a blog and record the challenge (see video below).
This is what we came up with...
Measuring the Angle of a Vector with PanelPilotACE
Of the features added to the PanelPilotACE Design Studio software with the recent release of a public BETA, the maths builder was the one I wanted to get to grips with first. This feature adds much needed control and flexibility to the Design Studio software, allowing users to actually work with the analogue and digital inputs and introduce more control elements into projects.
The idea behind the project was to use two analogue inputs (both ±5V d.c.) each representing a distance of ±50mm on the X and Y axis. I wanted to use the maths builder to calculate and display the angle that these two distances create when describing a vector.
I do recommend reading this article with the software open so that you can aee how the project elements go together. I have split the porject in to 4 stages.
1. Creating the Background in Adobe Illustrator
The drawing tools in PanelPilotACE Design Studio are fairly basic so I use Adobe Illustrator to create the dial which will show the angle. To do this I make two circles each with 5 pixel strokes to create the two-tone outside of the dial. I then use the pen tool to create a mark on the dial. This mark is rotated and copied around the centre point of the circle by 10°. The ‘Transform Again (CTRL-D)’ tool repeats this operation to create a mark every 10° around the circumference of the circle. Markings for the analogue inputs and an X/Y axis in the middle of the circle are also added.
Lastly the pointer/arrow for the angle dial is created and a new ‘artboard’ added so that this exports as a separate image file. Using transparency, the bottom centre point is located at the correct distance for the centre of the dial.
You can see the size of the arrow image with the dotted lines. Other than the yellow artwork the rest of the image is transparent so it appears to revolve around a remote point.
The artwork is exported to .png using ‘artboards’ and ‘transparency’
2. Creating the Analogue Scales in PanelPilotACE Design Studio
Having opened up the BETA release of the software I drop the two images (one-by-one) from an Explorer window straight onto the project screen.
I then add the main visual elements which include four rectangles (90 x 2 px) to describe the ±50mm scales of the analogue inputs and seven text boxes (three for readings: X, Y, and angle; the rest for units/labels).
The two analogue inputs are set to ±5Vd.c. (x_axis_vin & y_axis_vin). Four fill meters (x_axis_neg, x_axis_pos, y_axis neg, & y_axis_pos) are added which together with the four rectangles created above make the centred X and Y axis.
Finally, two digital meters (x_axis_dig & y_axis_dig) are added and linked to the same analogue inputs and the respective text boxes to give a numerical readout of the X/Y values.
3. Calculating Vector Angle with the Mathematics Builder
The scaled analogue voltages describe the X and Y distance from the origin and hence provide the values I need to calculate the angle:
If Y is positive:
Tan-1 x (Xmm / Ymm) x 180/π
If Y is negative:
(Tan-1 x (Xmm / Ymm) x 180/π) + 180
As such I set up two maths builder functions (calc_angle_if & calc_angle_else) and a logic builder to test the value of Y (if_y_positive).
Think of the maths builder values like a variable. The number is stored there at all times, but nothing is done with it unless you equate something like a visual element to it. The most effective way to use the information in a maths builder is to run an ‘Action (Set Rule)’ element. So two of these are added. One for when the Y value is positive, and one for when it is negative. Both do broadly the same thing in equating the angle text box (angle_text) to the result of the respective maths builder, and then the angle of the pointer/arrow to the value of this text box.
Finally I use a timer (set to run every 250ms) to run the ‘if_y_positive’ logic builder, which sets off the chain of events described above!
Here’s a block diagram of what’s happening:
4. Moving an Object Using Analogue Inputs and Maths Builder
I wanted to show a pointer that represented the end-point of the vector we’re calculating the angle of. I start by creating a 4px x 4px ellipse and placing this on the cross of the axis in the centre of the dial. I record the X and Y coordinates of this position.
I then add two more maths builder elements one to add the X-axis mm reader to the recorded X coordinate, and the other to do likewise for the Y-axis. Finally I equate the X and Y properties of the ellipse to the results of the two maths functions using the ‘Action (Set Rule)’ elements created above.
Here is the video we recorded, sped up so that you can watch it in under 2 mins.
Screenshot from the video of the final emulator screen
Note: Workaround for BETA bug
The code for supressing decimal places is not yet working in the public BETA. As such, when taking number information out of the maths builder you may need to add a ‘String Builder’ element to remove unwanted decimal places. In this case within the String Builder select the appropriate maths builder value from the drop-down and use the slider to reduce the decimal places as required. Then change the ‘Action (Set Rule)’ to equate the Angle text box to the String Builder result instead of the Maths Builder. This will be resolved for the next full release version.
Your Hour Challenge And You Could Win a PanelPilotACE Development Kit:
So what do you think that you can achieve with PanelPilotACE Design Studio?
We have a challenge for DesignSpark members to create a project and load it to DesignSpark where the PanelPilot team will judge the best and award the prize. The Winner will receive a Lacar PanelPilot ACE TFT Development Kit including the PanelPilot ACE Display