Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Can't override parameter with OMPython

Can't override parameter with OMPython

I'm trying to simulate a system made by me. I modeled a swarm of drones and the system made in openmodelica have to simulate them flying and avoiding obstacles or intruders into the flyzone. Now, i want to summarize results of the system simulation with different parameters (e.g. number of drones, number of obstacoles, ...) and i made a python script for doing it. The problem is that all this parameters is stored in a record class, named K,  and the parameters don't want to change. this is the piece of script where i change the parameters:

Code:


def startSimulation(n, intr, miss, statObs, fault, flyZone):
#Overwrite parameters
    with open("newValues.txt", 'wt') as f:
        f.write("*.const.N="+str(n)+"\n")
        f.write("*.const.nIntr="+str(intr)+"\n")
        f.write("*.const.nRocket="+str(miss)+"\n")
        f.write("*.const.nStatObs="+str(statObs)+"\n")
        for i in range(len(fault)):
            for j in range(len(fault[i])):
                f.write("fault.transMatrix["+str(i+1)+","+str(j+1)+"]="+str(fault[i][j])+"\n")
        for i in range(3):
            f.write("const.flyZone["+str(i+1)+"]="+str(flyZone)+"\n")
        f.flush()
        os.fsync(f)


    os.system("./System -overrideFile=newValues.txt >> LogOverride.txt")

for more context, this is the github repository of this project: https://github.com/BigMautone/Drones. The python file is testing.py, the system file is system.mo and the record class is called constant.mo


EDIT 1:
If i check the System_init.xml file, i can see that lots of parameter of record class K have the flag "isValueChangeble" equals to false. How can i change it?

Edited by: BigMautone - Jun-17-22 11:01:22
There are 0 guests and 0 other users also viewing this topic
You are here: