-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed sensors.raw.foo to sensors.foo. Renamed speed and steering to…
… velocity and rotation. Remote control is now a sensor. Manual control moved to inside brains. General cleanup/code-golf.
- Loading branch information
Showing
18 changed files
with
121 additions
and
124 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,28 +1,29 @@ | ||
const odometry = require('./odometry'); | ||
const virtualBumpers = require('./virtual-bumpers'); | ||
const { bus } = require('../utils'); | ||
const remoteCommand = require('./remote-command'); | ||
const { notify } = require('../ui-server'); | ||
const { bus } = require("../utils"); | ||
// const virtualBumpers = require('./virtual-bumpers'); | ||
|
||
let lastMotorCommand = { left: 0, right: 0 }; | ||
bus.on('motors', mc => lastMotorCommand = mc); | ||
|
||
module.exports = sensors => { | ||
const processed = { | ||
raw: sensors, | ||
odometry: odometry({ ticks: sensors.ticks, lastMotorCommand }), | ||
const odo = odometry({ ticks: sensors.ticks, lastMotorCommand }); | ||
|
||
const sensed = { | ||
...sensors, | ||
odometry: odo, | ||
virtualBump: virtualBumpers(odo, [ | ||
{x: -600, y: 600}, | ||
{x: -600, y: -600}, | ||
{x: 600, y: -600}, | ||
{x: 600, y: 600} | ||
]), | ||
remoteCommand: remoteCommand(), | ||
lastMotorCommand | ||
}; | ||
|
||
// processed.virtualBump = virtualBumpers(processed.odometry, [ | ||
// {x: -600, y: 600}, | ||
// {x: -600, y: -600}, | ||
// {x: 600, y: -600}, | ||
// {x: 600, y: 600} | ||
// ]); | ||
// | ||
// if(processed.virtualBump === true) console.log('VIRTUAL BUMP'); | ||
|
||
notify('sensed', processed); | ||
notify('sensed', sensed); | ||
|
||
return processed; | ||
return sensed; | ||
}; |
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 |
---|---|---|
@@ -1,20 +1,5 @@ | ||
module.exports = (odometry, polygonPoints) => { | ||
const distances = polygonPoints.map((currentPoint, index) => { | ||
const previousPoint = index === 0 ? polygonPoints[polygonPoints.length - 1] : polygonPoints[index - 1]; | ||
const inside = require('point-in-polygon'); // Isn't npm just awesome? | ||
|
||
if(previousPoint.x === currentPoint.x) { | ||
// Vertical line. Distance is difference between x values. | ||
return Math.abs(odometry.x - currentPoint.x); | ||
} else { | ||
// y = mx + c => m = slope, c = y-intercept | ||
const slope = (currentPoint.y - previousPoint.y) / (currentPoint.x - previousPoint.x); | ||
const yIntercept = currentPoint.y - (slope * currentPoint.x); | ||
|
||
// d = |Ax + By + C\ / sqrt(A^2 + B^2) where line = Ax + By + C = 0 | ||
// Converting line from y=mx+c, A = slope, B = -1, C = yIntercept | ||
return Math.abs((slope * odometry.x) - odometry.y + yIntercept) / Math.sqrt(Math.pow(slope, 2) + 1); | ||
} | ||
}); | ||
|
||
return distances.some(x => x < 50); | ||
module.exports = ({ x, y }, polygonPoints) => { | ||
return !inside([x,y], polygonPoints.map(({x,y}) => [x,y])); | ||
} |
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
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
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
Oops, something went wrong.