编辑:有关更多信息,请参阅链接的论坛讨论(here)
我是OpenModelica的新用户。我使用Raspberry Pi作为(opc ua)测试服务器,它会自动设置一些服务器节点。我还通过UaExpert连接到服务器,以从我的PC读取/写入节点。我想将OM模型连接到此服务器,以便可以提取服务器节点值作为模型模拟的输入
我潜入OM论坛,发现了一个topic similar to this。在该讨论中,OM模型如下所示:
model SimulationTest
input Real RPM;
Real Torque;
equation
RPM = Torque;
end SimulationTest;
他们还有一个连接到服务器的python脚本,并修改了一些节点值。下面是一个类似的测试脚本:
from opcua import Client
from opcua import ua
import time
import logging
from opcua.ua.uatypes import VariantType
# Define the URL on which the server is broadcasting
url = "opc.tcp://my.pi.ip.address:4840/"
if __name__ == "__main__":
client = Client(url)
logging.basicConfig(level=logging.WARN)
try:
client.set_user("username")
client.set_password("password")
client.connect()
print("Client connected!")
# Set default node values
engineRPM_command = client.get_node("ns=4;s=engineRPM_command")
engineRPM_command.set_value(800, VariantType.Int32)
RPM = engineRPM_command.get_value()
print("Current state of engineRPM_command : {}".format(RPM))
engineTORQUE_current = client.get_node("ns=4;s=engineTORQUE_current")
engineTORQUE_current.set_value(1.0, VariantType.Float)
Torque = engineTORQUE_current.get_value()
print("Current state of engineTORQUE_current : {}".format(engineTORQUE_current.get_value()))
# Change node values over time
while (True):
engineRPM_command.set_value(int(1.1*RPM), VariantType.Int32)
RPM = engineRPM_command.get_value()
engineTORQUE_current.set_value(1.5*Torque, VariantType.Float)
Torque = engineTORQUE_current.get_value()
print("RPM value is: ", RPM)
print("Torque value is: ", Torque)
time.sleep(2)
print("="*40)
except KeyboardInterrupt:
print("Stopping sequence!")
finally:
print("Done!")
client.disconnect()
为了获得交互式仿真环境设置,我在仿真设置下的仿真标志选项卡中配置了Additional Simulation Flags (Optional): -rt 1.0 -embeddedServer opc-ua
。当我模拟模型时,会生成一些文件(.exe、.log、.json、.xml和.mat),但我在OMEdit中看不到任何绘图
最大的问题是(1)如何从OMEdit正确连接到pi服务器,(2)如何为模拟提取节点值,以及(3)我可以在模拟时从OMEdit内访问此opcua节点数据
谢谢
OMEdit实现了自己的客户机,并将其用于读取数据和打印
如果您想使用自己的客户机,那么我建议您不要使用OMEdit,而是使用
simulate
命令从命令行运行模拟。见https://build.openmodelica.org/Documentation/OpenModelica.Scripting.simulate.html。基本上,您可以调用类似simulate(SimulationTest, simflags="-rt=1.0 -embeddedServer=opc-ua -embeddedServerPort=4841")
的函数,然后使用python客户端中接收的数据来绘制结果相关问题 更多 >
编程相关推荐