I am trying to recreate the physics engine of Pymunk, but when I compare my results with those from Pymunk, they are not the same.
What I wanted to do was to approximate my system, which is a circle, as a dot to minimize the computational cost. However, even in a straight-line dynamic (when the torque is zero), I am having a hard time figuring it out.
Here is the code I use to simulate it :
def _apply_force(agent: np.ndarray, force: np.ndarray, dt: float):
"""
Args:
agent : np.ndarray
Agent state [x, y, theta, vx, vy, rotation]
force : np.ndarray
force to apply to the agent [forward, lateral, rotation]
"""
linear_force = process_forward_lateral(force[0:2])
linear_acc = (linear_force - agent[3:5] * FRICTION_ENTITY )/ DRONE_MASS
# Apply force to drone
agent[3:5] = np.clip(agent[3:5] + linear_acc * dt, -MAX_VELOCITY, MAX_VELOCITY)
agent[0:2] += agent[3:5] * dt + 0.5 * linear_acc * dt ** 2
# Apply rotation to drone
agent[5] = max(min(force[2] * ROTATION_CONSTANT, MAX_ROTATION), -MAX_ROTATION)
agent[2] += agent[5] * dt
return agent
New contributor
Augustin Bresset is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.