Skip to content

Commit

Permalink
Merge pull request #25 from project-neon/develop
Browse files Browse the repository at this point in the history
Stable (but unfinished) Iron Cup 2020 version
  • Loading branch information
Alexsandr0x authored Feb 26, 2020
2 parents 2a55597 + 0935acc commit ea9c90e
Show file tree
Hide file tree
Showing 66 changed files with 6,366 additions and 1,580 deletions.
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "standard",
"globals": {
"Zone": true
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ node_modules
# Optional REPL history
.node_repl_history
queue.js

# VS Code stuff related
.vscode
18 changes: 16 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,26 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"type": "node",
"env": {"RUN_MODE": "1"},
"request": "launch",
"name": "Launch Program",
"name": "Launch Real Life",
"program": "${workspaceFolder}/server.js"
},
{
"type": "node",
"env": {"RUN_MODE": "3"},
"request": "launch",
"name": "Launch Simulated",
"program": "${workspaceFolder}/server.js"
},
{
"type": "node",
"env": {"RUN_MODE": "4"},
"request": "launch",
"name": "Launch Passive",
"program": "${workspaceFolder}/server.js"
}
]
Expand Down
70 changes: 15 additions & 55 deletions Intention/LineIntention.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,30 @@
/******************************************
* Project Neon 2017 *
******************************************
To see more of the documentation visit:
https://github.com/Project-Neon/NoPlan/blob/master/Intention/README.md
*/
const util = require('./util')
const Intention = require('./')
const assert = require('assert')
const Vector = require('../lib/Vector')

module.exports = class LineIntention extends Intention{
constructor(name, params) {
module.exports = class LineIntention extends Intention {
constructor (name, params) {
super(name, params)

// Asserting that the parameters exist
assert(params)
this.params = params

// Target has to exist
assert.notEqual(this.params.target, null)
this.target = this.params.target

// Theta has to exist
assert.notEqual(this.params.theta, null)
this.theta = this.params.theta

// Decay has to exist
assert.notEqual(this.params.decay, null)
this.decay = this.params.decay

// Linesize has to exist

assert.notEqual(this.params.lineSize, null)
this.lineSize = this.params.lineSize

// LineDist has to exist
this.lineSize = this.params.lineSize

assert.notEqual(this.params.lineDist, null)
this.lineDist = this.params.lineDist

this.lineDistMax = this.params.lineDistMax || false

// Use this to make the line work on only one size
Expand All @@ -50,68 +35,43 @@ module.exports = class LineIntention extends Intention{
this.multiplier = this.params.multiplier || 1
}

// getIntentionInfo() {
// return {
// 'type': LineIntention.name,
// 'name': this.name,
// 'params': JSON.parse(JSON.stringify(util.mapDict(this.params, x => util.callOrReturn(x))))
// }
// }

compute({x, y, theta}) {
compute ({x, y}) {
// Instanciate target values
let targetLine = util.callOrReturn(this.target)
let targetTheta = util.callOrReturn(this.theta)
let lineDistMax = util.callOrReturn(this.lineDistMax)
let multiplier = util.callOrReturn(this.multiplier)

// Create vectors
let toLine = Vector.sub({x, y}, targetLine)
let toLineScalar = Vector.size(toLine)
let toLineWithTheta = Vector.rotate(toLine, -targetTheta)

// Position at line: toLineWithTheta.y
// Distance from line: toLineWithTheta.x

// Output 0 if outside line segment
if (this.lineSize && Math.abs(toLineWithTheta.x) > this.lineSize) {
// console.log('Outside line segment')
return {vx: 0, vy: 0, vtheta: 0}
}
if (this.lineSize && Math.abs(toLineWithTheta.x) > this.lineSize) return {vx: 0, vy: 0, vtheta: 0}

// Output 0 if on the other side of the line and single side is active
if (this.lineSizeSingleSide && toLineWithTheta.x < 0) {
// console.log('On other side of line size')
return {vx: 0, vy: 0, vtheta: 0}
}
if (this.lineSizeSingleSide && toLineWithTheta.x < 0) return {vx: 0, vy: 0, vtheta: 0}

// Output 0 if outside maximum distance
if (lineDistMax && Math.abs(toLineWithTheta.y) > lineDistMax) {
// console.log('Outside maximum distance')
return {vx: 0, vy: 0, vtheta: 0}
}
if (lineDistMax && Math.abs(toLineWithTheta.y) > lineDistMax) return {vx: 0, vy: 0, vtheta: 0}

// Output 0 if on the other side of the line and single side is active
if (this.lineDistSingleSide && toLineWithTheta.y < 0) {
// console.log('on other side of line dist')
return {vx: 0, vy: 0, vtheta: 0}
}

if (this.lineDistSingleSide && toLineWithTheta.y < 0) return {vx: 0, vy: 0, vtheta: 0}

// Normalizing vector
let toLineNorm = Vector.norm(Vector.rotate({y: toLineWithTheta.y, x: 0}, targetTheta))

// Normalized Scalar
let toLineScalarNorm = Math.max(0, Math.min(1, (Math.abs(toLineWithTheta.y) / this.lineDist)))
//console.log(toLineNorm, toLineScalarNorm, )

// Apply decay function to normalized distance from the beginning to the end of the field
let force = util.applyReflectedDecay(this.decay, toLineScalarNorm)

return {
// Returning result vector times the multiplier as output.
// Returning result vector times the multiplier as output.
vx: toLineNorm.x * force * multiplier,
vy: toLineNorm.y * force * multiplier,
vtheta: 0
}
}
}
}
34 changes: 12 additions & 22 deletions Intention/LookAtIntention.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,47 @@
/******************************************
* Project Neon 2017 *
******************************************
To see more of the documentation visit:
https://github.com/Project-Neon/NoPlan/blob/master/Intention/README.md
*/
const util = require('./util')
const Intention = require('./')
const assert = require('assert')
const Vector = require('../lib/Vector')

module.exports = class LookAtIntention extends Intention{
constructor(name, params) {
module.exports = class LookAtIntention extends Intention {
constructor (name, params) {
super(name, params)

// Asserting that the params exist
// Asserting that the params exist
assert(params)
this.params = params

// Either target or theta has to be declared
assert.notEqual(this.params.theta || this.params.target, null)
this.theta = this.params.theta
this.target = this.params.target

// Decay has to be declared
assert.notEqual(this.params.decay, null)

this.decay = this.params.decay
this.theta = this.params.theta
this.target = this.params.target

// If multiplier is not declared it is 1
this.multiplier = this.params.multiplier || 1
}

getIntentionInfo() {
getIntentionInfo () {
return {
'type': LookAtIntention.name,
'name': this.name,
'params': JSON.parse(JSON.stringify(util.mapDict(this.params, x => util.callOrReturn(x))))// util.mapDict(this.params , function(v, k, o) { return util.callOrReturn(v)})
'params': JSON.parse(JSON.stringify(util.mapDict(this.params, x => util.callOrReturn(x))))
}
}

compute({x, y, theta}) {
compute ({x, y, theta}) {
// Instaciate theta values
let absRobotAngle = theta
let absTargetAngle = util.callOrReturn(this.theta)

// If no theta was used but target was:
if (absTargetAngle == null) {
let targetLookAt = util.callOrReturn(this.target)
absTargetAngle = Vector.angle(Vector.sub(targetLookAt, {x,y}))
absTargetAngle = Vector.angle(Vector.sub(targetLookAt, {x, y}))
}

// The difference between angles.
let deltaAngle = Vector.normalRelativeAngle(absRobotAngle - absTargetAngle)

Expand All @@ -73,4 +63,4 @@ module.exports = class LookAtIntention extends Intention{
vtheta: vtheta * this.multiplier
}
}
}
}
44 changes: 24 additions & 20 deletions Intention/OrbitalIntention.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
/******************************************
* Project Neon 2017 *
******************************************
To see more of the documentation visit:
https://github.com/Project-Neon/NoPlan/blob/master/Intention/README.md
*/
const util = require('./util')
const Intention = require('./')
const assert = require('assert')
const Vector = require('../lib/Vector')

module.exports = class OrbitalIntention extends Intention{
constructor(name, params) {
module.exports = class OrbitalIntention extends Intention {
constructor (name, params) {
super(name, params)

// Asserting that the parameters exist
Expand All @@ -27,35 +18,48 @@ module.exports = class OrbitalIntention extends Intention{
assert.notEqual(this.params.clockwise, null)
this.clockwise = this.params.clockwise

assert.notEqual(this.params.decay, null)
this.decay = this.params.decay

// Radius of the orbitation movement
assert.notEqual(this.params.radius, null)
this.radius = this.params.radius

// Is there a maximum radius?
this.radiusMax = this.params.radiusMax || false

// If multiplier is not declared it is 1
this.multiplier = this.params.multiplier || 1
}

compute({x, y, theta}) {
compute ({x, y}) {
// Instanciate target values
let target = util.callOrReturn(this.target)
let multiplier = util.callOrReturn(this.multiplier)
let clockwise = util.callOrReturn(this.clockwise)

let angleToTarget = -Math.atan2(target.y - y, x - target.x);
let K = 100
let angleToTarget = Math.atan2(target.y - y, target.x - x)
let K = 1/200
let distanceBetweenTarget = Vector.distBetween({x, y}, target)
let endAngle
let radiusMax = this.radiusMax

// Out of max radius ? output is 0
if (radiusMax && distanceBetweenTarget > radiusMax) return {vx: 0, vy: 0, vtheta: 0}

if (distanceBetweenTarget > this.radius) {
endAngle = angleToTarget + clockwise * Math.PI/2 * (2 + (this.radius + K)/(distanceBetweenTarget + K))
endAngle = angleToTarget + clockwise * (Math.PI / 2) * (2 - ((this.radius + K) / (distanceBetweenTarget + K)))
} else {
endAngle = angleToTarget + clockwise * Math.PI/2 * Math.sqrt(distanceBetweenTarget/this.radius)
endAngle = angleToTarget + clockwise * (Math.PI / 2) * Math.sqrt(distanceBetweenTarget / this.radius)
}

let toTargetScalarNorm = Math.max(0, Math.min(1, distanceBetweenTarget / (this.radius)))
let finalVector = Vector.norm(Vector.fromTheta(endAngle))

let force = util.applyReflectedDecay(this.decay, toTargetScalarNorm)

return {
// Returning result vector times the multiplier as output.
vx: finalVector.x * this.multiplier,
vy: finalVector.y * this.multiplier,
vx: finalVector.x * force * this.multiplier,
vy: finalVector.y * force * this.multiplier,
vtheta: 0
}
}
Expand Down
Loading

0 comments on commit ea9c90e

Please sign in to comment.