Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: the dynamics in diff drive expects u_rot to be angular velocity #53

Closed
Zartris opened this issue May 25, 2023 · 2 comments
Closed

Comments

@Zartris
Copy link

Zartris commented May 25, 2023

Hi,
So normally we have the u_rot to be specified as torque (or at least this is what the simulator wants it to be), however, the dynamics need angular velocity as u_rot (since runge_kutta expects the change of rotation over time).
This is not specified anywhere so some description would be nice, because the example is somewhat wrong.

Example code:

    def process_action(self, agent: Agent):
        try:
            agent.dynamics.process_force()
        except AttributeError:
            pass

However, this would give unpredictable behavior. It is barely seen in the example given as you have a u_rot_multiplier of 0.001, so this is barely visible, but if you zoom in and tweaks the agent parameters enough, you can see the misbehavior.

The process_action code should look something like this instead:

    def process_action(self, agent: Agent):
        if hasattr(agent, 'dynamics'):
            # assuming input is in forces
            torque = agent.action.u_rot
            angular_vel = torque / agent.moment_of_inertia * self.dt
            agent.action.u_rot = angular_vel
            agent.dynamics.process_force()
            agent.action.u_rot = torque
            
            # or assuming input is in velocities
            agent.dynamics.process_force()
            angular_vel =  agent.action.u_rot
            torque = angular_vel * agent.moment_of_inertia / self.dt
            agent.action.u_rot = torque

By adding docs to the dynamics.process_force() code, these input units would be much more apparent.

Correct me if I'm wrong, as I might be.

@matteobettini
Copy link
Member

Uhhh thanks for spotting this, I'll have a look and let you know

@matteobettini
Copy link
Member

Coming back to this after a while (sorry about it).

If you look closely at the dynamics we are not actually computing any integral (the name euler and rk4 may not have helped here).

But if you look at the simple euler case, all we are doing is a change of coordinates.

The inputs and the outputs are all torque and forces (just in a different frame)
In fact you can see that in both cases the input u_rot is left untouched (and considered as torque)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants