perciplex / raas

Reality as a Service: OpenAI Gym environments in real life
https://raas.perciplex.com
7 stars 1 forks source link

Figure out pendulum dynamics #27

Open declanoller opened 4 years ago

declanoller commented 4 years ago

Doesn't actually need to match Pendulum-v0, but they need to be able to simulate the non-hardware version of Pendulum-raas and expect that it'll work about the same when they use it with the hardware version.

This involves setting the torque, making sure the velocity is in a reasonable range, etc.

declanoller commented 4 years ago

Some updates:

I did a test to get a sense of the power of the torque. To do this, I ran const_tests.py in the raas-experiments repo, which basically sets the torque, waits a second for it to normalize, then takes the observation at that angle, sweeping through ranges [-2, 2] and then [2, -2].

The first thing is that we can see it has some hysteresis:

torque_ang_hysteresis

Also looking at it, you can see (in long flat regions) that it probably has lots of static friction, which I'm guessing is causing the hysteresis.

This may not be a huge deal, hysteresis probably won't matter when it's swinging around a bunch. But it could make it a bit tricky to match our simulation version to.

the other thing to thing about is the angle. In openAI gym's Pendulum env, the upright angle (i.e., the goal) is theta = 0, and the position when it's down is -pi and pi. Our motor controller by default sets the down (i.e., hanging with no torque) position.

So our motor_controller.py has angles: down = 0/2pi, increase to top = pi. To make this equivalent with openAI gym, which has: down = -pi/pi, increase to top = 0, I think it should make sense to just say theta = theta_motor - np.pi. So I've edited PendulumEnv.py to reflect that, but someone check my math.

philzook58 commented 4 years ago

We calculated the dynamics from the spec of the motors, however they only have "rated torque" which is a technical term for continuously deliverable torque at rated speed. We probably care more about stall torque which is a larger number. Declan has some new measurements that approximate the appropriate torque number at ~ 10x the calculation based on "rated torque"

These are resonance curves

angles_vs_torques (1) image (4) image (5)