-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#45 Add Circular Collision Avoidance Scene
- Loading branch information
1 parent
049065f
commit 6cd255d
Showing
6 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/common/utils/positionsGenerators/circularPositionsGenerator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
export default function getCircularPositionsGenerator(posNum, radius, envWidth, envHeight) { | ||
const circleRadius = (Math.min(envWidth, envHeight) * 20) / 42; | ||
const resolution = (Math.PI * 2) / posNum; | ||
const envCenter = { x: envWidth / 2, y: envHeight / 2 }; | ||
|
||
if (circleRadius * resolution < radius * 4) { | ||
throw new Error('Invalid inputs, number and size of robots are too high for this environment size!'); | ||
} | ||
|
||
const positions = []; | ||
const start = Math.random() * Math.PI * 2; | ||
let i = start; | ||
while (i < start + Math.PI * 2) { | ||
const newX = envCenter.x + circleRadius * Math.cos(i); | ||
const newY = envCenter.y + circleRadius * Math.sin(i); | ||
const newGoalX = envCenter.x - circleRadius * Math.cos(i); | ||
const newGoalY = envCenter.y - circleRadius * Math.sin(i); | ||
const newPos = { x: newX, y: newY }; | ||
const newGoalPos = { x: newGoalX, y: newGoalY }; | ||
|
||
positions.push(newPos); | ||
positions.push(newGoalPos); | ||
|
||
i += resolution + (Math.random() * resolution) / 100 - resolution / 50; | ||
} | ||
|
||
if (positions.length < posNum * 2) { | ||
throw new Error('Invalid inputs, number and size of robots are too high for this environment size!'); | ||
} | ||
|
||
const getPos = () => { | ||
if (positions.length === 0) { | ||
throw new Error('No positions available!'); | ||
} | ||
return positions.pop(); | ||
}; | ||
|
||
return getPos; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import randomCollisionFree from './randomPositionsGenerator'; | ||
import circularPositionsGenerator from './circularPositionsGenerator'; | ||
|
||
export default { | ||
randomCollisionFree | ||
randomCollisionFree, | ||
circularPositionsGenerator | ||
}; |
1 change: 0 additions & 1 deletion
1
src/common/utils/positionsGenerators/randomPositionsGenerator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { | ||
CoreActuators, | ||
CoreSensors, | ||
ExtraSensors, | ||
CorePositionsGenerators, | ||
CorePerformanceTrakers, | ||
CoreControllers | ||
} from '@common'; | ||
|
||
import SceneRenderables from '@common/scene/renderables'; | ||
import RobotRenderables from '@common/robot/renderables'; | ||
import PuckRenderables from '@common/puck/renderables'; | ||
|
||
const renderables = [ | ||
{ module: 'Scene', elements: SceneRenderables }, | ||
{ module: 'Puck', elements: PuckRenderables }, | ||
{ module: 'Robot', elements: RobotRenderables } | ||
]; | ||
|
||
const simConfig = { | ||
env: { | ||
width: 800, | ||
height: 500, | ||
renderSkip: 1 | ||
}, | ||
robots: { | ||
count: 25, | ||
radius: 7, | ||
params: { | ||
velocityScale: 10 | ||
}, | ||
controllers: { | ||
waypoint: CoreControllers.waypoint.bvcWaypointController, | ||
// velocity: CoreControllers.velocity.omniDirVelocityController | ||
velocity: { | ||
controller: CoreControllers.velocity.diffVelocityController, | ||
params: { angularVelocityScale: 0.01 } | ||
}, | ||
supportsUserDefinedControllers: false | ||
}, | ||
sensors: [...Object.values(CoreSensors), ...Object.values(ExtraSensors)], | ||
actuators: Object.values(CoreActuators), | ||
useVoronoiDiagram: true | ||
}, | ||
pucks: { | ||
groups: [], | ||
useGlobalPuckMaps: false | ||
}, | ||
objects: [], | ||
positionsGenerator: CorePositionsGenerators.circularPositionsGenerator, | ||
renderables | ||
}; | ||
|
||
// TODO: add other waypoint controller to benchmark | ||
const benchmarkConfig = { | ||
simConfigs: [ | ||
{ | ||
name: '5 Robots', | ||
simConfig: { | ||
env: { | ||
renderSkip: 50 | ||
}, | ||
robots: { | ||
count: 5, | ||
params: { | ||
velocityScale: 50 | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
name: '20 Robots', | ||
simConfig: { | ||
env: { | ||
renderSkip: 50 | ||
}, | ||
robots: { | ||
params: { | ||
velocityScale: 50 | ||
} | ||
} | ||
} | ||
} | ||
], | ||
trackers: [ | ||
CorePerformanceTrakers.RobotToGoalDistanceTracker, | ||
CorePerformanceTrakers.PucksOutsideGoalTracker, | ||
CorePerformanceTrakers.MinRobotRobotDistanceTracker | ||
], | ||
maxTimeStep: 50000, | ||
timeStep: 1000 | ||
}; | ||
|
||
const description = { | ||
html: `<p>Object sorting using Buffered Voronoi Cells (BVC). Each robot chooses an intermediate goal location within its BVC. This avoids the possibility of collision or conflict with other robots. Their goal is to incremental shift the pucks towards their respective goal locations.</p> | ||
<p>Rather than pushing pucks directly towards their goals, the robots make use of a goal map for each type of pucks. A goal map specifies the direction a puck should be pushed in order to reach the goal, accounting for obstacles that might be in the way.</p> | ||
<p> | ||
<a href=https://link.springer.com/chapter/10.1007/978-3-031-20176-9_27 target=_blank> | ||
Abdullhak, Mohammed, and Andrew Vardy. "Distributed Sorting in Complex Environments." Swarm Intelligence: 13th International Conference, ANTS 2022, Málaga, Spain, November 2–4, 2022, Proceedings. Cham: Springer International Publishing, 2022. | ||
</a> | ||
</p> | ||
` | ||
}; | ||
|
||
export default { | ||
title: 'Collision Avoidance', | ||
name: 'collisionAvoidance', | ||
simConfig, | ||
benchmarkConfig, | ||
description | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters