Skip to content

Commit

Permalink
#45 Add Circular Collision Avoidance Scene
Browse files Browse the repository at this point in the history
  • Loading branch information
m-abdulhak committed Jul 7, 2023
1 parent 049065f commit 6cd255d
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/common/robot/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default class Robot {
}

reached(point) {
const ret = this.getDistanceTo(point) <= this.radius / 50;
const ret = this.getDistanceTo(point) <= this.radius / 5;
return ret;
}

Expand Down
39 changes: 39 additions & 0 deletions src/common/utils/positionsGenerators/circularPositionsGenerator.js
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;
}
4 changes: 3 additions & 1 deletion src/common/utils/positionsGenerators/index.js
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
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-underscore-dangle */
// Module to generate random initial positions for robots and pucks

import { getDistance } from '../geometry';
Expand Down
113 changes: 113 additions & 0 deletions src/scenes/CollisionAvoidance/index.js
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
};
3 changes: 2 additions & 1 deletion src/scenes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import voronoiSorting from './VoronoiSorting';
import simpleSorting from './Sorting';
import demo from './Demo';
import labyrinth from './Labyrinth';
import collisionAvoidance from './CollisionAvoidance';

export default {
labyrinth,
Expand All @@ -17,5 +18,5 @@ export default {
fieldManipulation,
simpleSorting,
voronoiSorting,
ExternalEngine
collisionAvoidance
};

0 comments on commit 6cd255d

Please sign in to comment.