I have to run an optimization on tendon stiffnesses in a modelled leg. Changing the spring constants manually causes no issues and the physical model seems to work well. The issue presents itself when I attempt to optimize for these values.
Since this is an optimization problem, I have to run the simulation for 1.5 seconds and then reset the robot to its initial state, with slightly different spring constants. To do this I have the robot model saved as a "Robot.wbo" file. At the end of each optimization iteration, I remove the existing robot node and use "def importMFNode" to create a new robot node, which creates the robot in the initial state. At the start of each new iteration, I then set new spring constants and setting these causes the model to behave unexpectedly. I have pinned down the issue to these two lines.
knee_spring_constant.setSFFloat(int(x[2]))
heel_spring_constant.setSFFloat(int(x[3]))
All these two lines do is change the spring constants of two slider joints. If I do it using these two commands, the model fails. If I do it manually, it works.
Instead of the model behaving normally, it just behaves erratically and not like it is supposed to. However, if I manually make a new copy of the robot node right after it is imported by the supervisor code, and delete the old one, the robot behaves as it is supposed to.