I'm new to blender scripting, but not to blender or python. I am trying to set up a rotary inverted pendulum. The initial state of the pendulum is upright with an angular velocity of 0. I would like to run a simulation a few hundred times with different parameters and need to be able to "reset" the pendulum to its initial state after each episode.
I am aware of the bug/feature of
setAngularVelocity in which you have to set to a vector of very small numbers and not 0 to stop a rotation, however it still does not work for me.
Here is the code that I use in a module. The function is called every other frame with an "Always" actuator. So the pole should fall freely for max_steps steps and then be stopped and brought upright. When I run the game engine it only acts like this the first time.
# Take action base.setAngularVelocity([0,0,data.action], True) # Get angle and speed xyz = pole.localOrientation.to_euler() roty = math.degrees(xyz) spd = pole.getAngularVelocity(True) # True for local spdy = spd print(spdy) [...stuff...] data.step += 1 if data.step > data.max_steps or R == -50: data.action = 0 data.step = 0 pole.worldOrientation = ([1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]) base.setAngularVelocity([0.00001,0.00001,0.00001], True) pole.setAngularVelocity([0.00001,0.00001,0.00001], True)
Edit: I forgot to mention that setting the angular velocity for the base on line 2 works fine, but not in the if statement