I need help with a project I am working on, I am very new to Ignition and python, We have a gauge that needs to be aligned with respect to a string, the gauge outputs its position with respect to the string as center(Y-axis) and power(X-axis). the center(Y-axis) is pretty straight forward, it returns a positive value if the gauge is too far back and a negative value I the gauge is too far forward. unfortunately for the power(X-axis) the gauge only returns positive values as the output signal is a square function.
I am having trouble with two things, one is how to get values from an expression tag into an OPC tag, I am using a SQL query to pull averages of the power(x-axis) and center(y-axis) values from the local database and I want to save it into the OPC tag I created to send it to the Arduino.
2nd problem.
I am having trouble writing the logic to flip the direction in power(x-axis) if the power values get bigger over time. I wanted to write something that will create like a moving average and compare it to the current value and maybe then move the gauge and then waits to check if the power(x-value) got smaller, else it flips the direction of the motor and moves the gauge the other way.
for my setup, I am using an Arduino UNO connected to ignition through Modbus. and the Arduino is connected to two stepper motors
any help would be much appreciated
(forgive my terrible code)
def tensiongaugemovement():
import time
import threading
import system
import sys
# adding Tag paths
averagepowervalue = "Tension Interface/Status/Average Tension Gauge Power Reading"
averagecentervalue = "Tension Interface/Status/Average Tension Gauge Fiber Center"
center_gauge = "Tension_Arduino/Center_Gauge" # this is the center value going to the arduino
power_gauge = "Tension_Arduino/Power_Gauge" # this is the power value going to the arduino
center_potentiometer = "Tension_Arduino/Center Potentiometer" # potentiometer value coming from the center
power_potentiometer = "Tension_Arduino/Power Potentiometer" # potentiometer value coming from the power
center = "Tension_Arduino/Center" # current center value, need to pull this data from the local database, average of last 5 mins
power = "Tension_Arduino/Power" # same for power
linespeed = "Line Heater Controllers/Linespeed 1" #pull in current linespeed
if (linespeed > 10):
center_gauge = center # send center values to arduino
for counter in range(5, 0 , -1):
average = [long1, long2, long3, long5, long5]
if (x < len(average)):
average[x] = averagepowervalue
x += 1
else:
power_average = sum(average)/len(average)
power_gauge = power_average
x = 0
counter = 5
time.sleep(1000)
if(power_average - power < 0):
power_gauge = -power_gauge; #flip direction of the motor
else
# do nothing
Thank you
Gijo