Skip to content

Conversation

@Jianye-Xu
Copy link
Contributor

This pull request introduces new dynamics for car-like robots – the kinematic bicycle model, a simplified representation of car-like robot dynamics that is particularly well-suited for scenarios where lateral dynamics are of interest, while the simplifications still provide sufficient accuracy for most user cases.

Key Contributions:

  • Implemented the kinematic bicycle model equations and provided two solvers: Euler's method and fourth-order Runge-Kutta method (see vmas/simulator/dynamics/kinematic_bicycle.py)
  • Added a debug file to validate the correctness of the model's behavior (see vmas/scenarios/debug/kinematic_bicycle.py)
  • Updated the README to indicate the new model

The addition of the kinematic bicycle model allows for more accurate simulation of car-like robots, especially in scenarios that involve significant turning. This feature is expected to benefit researchers and developers working on areas such as autonomous driving.

If there are any concerns or additional modifications required for integration, please let me know.

Thank you for considering this contribution to the VMAS repository.

PS: Based on this new feature, I plan to implement an environment consisting of multiple car-like robots with the kinematic bicycle model and add lanes to simulate more closely real traffic situations, which is expected to benefit researchers who work on multi-agent reinforcement learning in the context of connected and automated vehicles (like me).

Jianye Xu added 3 commits November 8, 2023 11:49
- Define kinematic bicylce model dynamics
- Add the corresponding debug file
- Update README
Copy link
Member

@matteobettini matteobettini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you immensly for this!

This contribution will greately improve the simulator.

I am also very interested in the autonomous driving scenario your are proposing as I also think that would be a really useful scenario to add!

I left some comments. The main point is about the use of the vectorized dimension of the simulator in the dynamics.

Thanks again, can't wait to merge this!

- **Action preprocessing**: By implementing the `process_action` function of a scenario, you can modify the agents' actions before they are passed to the simulator. This is used in `controllers` (where we provide different types of controllers to use) and `dynamics` (where we provide custom robot dynamic models).
- **Controllers**: Controllers are components that can be appended to the neural network policy or replace it completely. We provide a `VelocityController` which can be used to treat input actions as velocities (instead of default vmas input forces). This PID controller takes velocities and outputs the forces which are fed to the simulator. See the `vel_control` debug scenario for an example.
- **Dynamic models**: VMAS simulates holonomic dynamics models by default. Custom dynamic constraints can be enforced in an action preprocessing step. We implement `DiffDriveDynamics`, which can be used to simulate differential drive robots. See the `diff_drive` debug scenario for an example.
- **Dynamic models**: VMAS simulates holonomic dynamics models by default. Custom dynamic constraints can be enforced in an action preprocessing step. Implementations now include `DiffDriveDynamics` for differential drive robots and `KinematicBicycleDynamics` for kinematic bicycle model. See `diff_drive` and `kinematic_bicycle` debug scenarios for examples.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing!
We might also want to add it to the table of debug scenarios where we have a description and a rendering for each.
If you send me a gif of the scenario I can upload it and give you the link to use in the README

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
Sure. I attached the gif file. Please give me the link after you have uploaded it.

kinematic_bicycle_model

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

agent = Agent(
name=f"agent_{i}",
shape=Box(length=l_f+l_r, width=width),
collide=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
collide=True,
collide=False,

Box on box collisions are quite expensive currently and require some tuning.
I suggest we turn it off for this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree!

k4 = f(state + self.dt * k3)
return state + (self.dt / 6) * (k1 + 2 * k2 + 2 * k3 + k4)

def process_force(self):
Copy link
Member

@matteobettini matteobettini Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throughout this function your are treating physical properties (such as pos) to have shape [1, n_physical_dims].
This is only valid when using interactive rendering, but in general these properites have shape [n_envs, n_physical_dims].

For example:

  • self.agent.action.u has shape [n_envs, 2]
  • self.agent.action.u_rot has shape [n_envs, 1]

You should adapt the code to consider this and compute the quantities treating this first dimension as a batch (so that we compute force and torque independently over all environments)

To test your scenario you can use the use_vmas_env.py file which will use 32 as n_envs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I will work on it and update the pull request once done.

Copy link
Contributor Author

@Jianye-Xu Jianye-Xu Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fixed by the new commit 2336485.

During the test with the use_vmas_env.py file, I noticed a small issue in line 28 to line 30:

simple_2d_action = (
    [0, 0.5] if continuous_actions else [3]
)  # Simple action tell each agent to go down

where the variable gets a single value "3" if continuous_actions = False. However, this would lead to an error since my agents have two actions: straight-line move & rotate. Therefore, I have to change "[3]" to have two values like "[3,1]" to be able to run without errors.

To reproduce, change scenario_name in the use_vmas_env.py file to have a string value "kinematic_bicycle" and run the file, you will get an error:
AssertionError: Action for agent agent_0 has shape 1, but should have shape 2.

Then change [3] in line 29 of the use_vmas_env.py file to [3,1] and run the file again, you will see no error.

Suggestion to fix:
Check if env.agents[0].action.u_rot_range != 0 holds and decide which dimension the variable simple_2d_action should have.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I agree, will fix immeditely thanks for pointing it out!

Copy link
Member

@matteobettini matteobettini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks again for this, much appreciated

@matteobettini matteobettini merged commit 60eff7f into proroklab:main Nov 10, 2023
@Jianye-Xu
Copy link
Contributor Author

LGTM thanks again for this, much appreciated

You're welcome

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

Successfully merging this pull request may close these issues.

2 participants