All Projects → palmerabollo → rvo2-js

palmerabollo / rvo2-js

Licence: other
Reciprocal Collision Avoidance for Real-Time Multi-Agent Simulation (port to Javascript). This is an alpha release of a RVO2 port from the C# version to Javascript, only for research purposes.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to rvo2-js

AVO2
Reciprocal Collision Avoidance with Acceleration-Velocity Obstacles (C++)
Stars: ✭ 24 (-7.69%)
Mutual labels:  collision-avoidance
HRVO
The Hybrid Reciprocal Velocity Obstacle (C++)
Stars: ✭ 90 (+246.15%)
Mutual labels:  collision-avoidance
CrowdNav DSRNN
[ICRA 2021] Decentralized Structural-RNN for Robot Crowd Navigation with Deep Reinforcement Learning
Stars: ✭ 43 (+65.38%)
Mutual labels:  collision-avoidance
go-orca
Golang implementation of the Optimal Reciprocal Collision Avoidance (ORCA) algorithm
Stars: ✭ 40 (+53.85%)
Mutual labels:  collision-avoidance
Warehouse Robot Path Planning
A multi agent path planning solution under a warehouse scenario using Q learning and transfer learning.🤖️
Stars: ✭ 59 (+126.92%)
Mutual labels:  collision-avoidance

RVO2 port to Javascript

RVO2 Library: Reciprocal Collision Avoidance for Real-Time Multi-Agent Simulation.

This is an alpha release of a RVO2 port from the C# version to Javascript, only for research purposes and still not intended to be used in production environments. Paper with full details as well as C++ code can be found at the original authors' site.

See the online demo.

Basic Usage

Import core javascript files

	<script type="text/javascript" src="lib/common.js"></script>
	<script type="text/javascript" src="lib/agent.js"></script>
	<script type="text/javascript" src="lib/kdtree.js"></script>
	<script type="text/javascript" src="lib/simulator.js"></script>

Setup your custom scenario

	var simulator = Simulator.instance;

	var setupScenario = function(simulator)	{
			// Specify global time step of the simulation.
			simulator.setTimeStep(0.25);

			// Specify default parameters for agents that are subsequently added
			simulator.setAgentDefaults(
					200, // neighbor distance (min = radius * radius)
					30, // max neighbors
					600, // time horizon
					600, // time horizon obstacles
					5, // agent radius
					10.0, // max speed
					new Vector2(2, 2) // default velocity
				);

			// Put 9 agents in a circle
			for (var i=0; i<9; i++) {
				var angle = i * (2 * Math.PI) / 9;
				var x = Math.cos(angle) * 200;
				var y = Math.sin(angle) * 200;
				simulator.addAgent(new Vector2 (x, y));
 			}

			// Create agent targets
			var goals = [];
			for (var i = 0; i < simulator.getNumAgents (); ++i) {
				goals.push(simulator.getAgentPosition(i).scale(-1));
			}
			simulator.addGoals(goals);
		}

How to add one obstacle

	// Add obstacle, specifying vertices in counterclockwise order.
	var vertices = [];

	vertices.push(new Vector2 (-40.0, -90.0));
	vertices.push(new Vector2 (40.0, -90.0));
	vertices.push(new Vector2 (40.0, -10.0));
	vertices.push(new Vector2 (-40.0, -10.0));

	simulator.addObstacle (vertices);

	// Process obstacles so that they are accounted for in the simulation.
	simulator.processObstacles ();

Run the simulation

	var interval;
	var run = function() {
		setupScenario(simulator);

		var step = function() {
			setPreferredVelocities(simulator);
			simulator.run();

			// here you can do whatever you need (i.e. draw the agents)

			if (simulator.reachedGoal()) {
				clearInterval(interval);
			}
		}

		interval = setInterval(step, 10);
	}

Dynamically adapt agent velocities

	var setPreferredVelocities = function(simulator) {
		for (var i = 0; i < simulator.getNumAgents (); ++i) {
			if (RVOMath.absSq(simulator.getGoal(i).minus(simulator.getAgentPosition(i))) < 0) {
				simulator.setAgentPrefVelocity (i, new Vector2 (0, 0));
			} else {
				// Agent is far away from its goal, set preferred velocity as unit vector towards agent's goal.
				simulator.setAgentPrefVelocity(i, RVOMath.normalize(simulator.getGoal(i).minus(simulator.getAgentPosition(i))));
			}
		}
	}

License

Copyright (c) 2008-10 University of North Carolina at Chapel Hill. All rights reserved.

Permission to use, copy, modify, and distribute this software and its documentation for educational, research, and non-profit purposes, without fee, and without a written agreement is hereby granted, provided that the above copyright notice, this paragraph, and the following four paragraphs appear in all copies.

Permission to incorporate this software into commercial products may be obtained by contacting the University of North Carolina at Chapel Hill.

This software program and documentation are copyrighted by the University of North Carolina at Chapel Hill. The software program and documentation are supplied "as is", without any accompanying services from the University of North Carolina at Chapel Hill or the authors. The University of North Carolina at Chapel Hill and the authors do not warrant that the operation of the program will be uninterrupted or error-free. The end-user understands that the program was developed for research purposes and is advised not to rely exclusively on the program for any reason.

IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR ITS EMPLOYEES OR THE AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].