-
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.
- Loading branch information
0 parents
commit d894417
Showing
7 changed files
with
1,373 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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,16 @@ | ||
AlphaBot | ||
=== | ||
|
||
***Work in progress.*** | ||
|
||
This app controls the [AplhaBot](http://www.waveshare.com/wiki/AlphaBot). | ||
|
||
To install the app: | ||
* `git clone` or download and unzip this repo. | ||
* `cd` to the checkout, and type in `npm install`. | ||
|
||
To run the app: | ||
|
||
``` | ||
sudo npm start | ||
``` |
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,7 @@ | ||
module.exports = { | ||
// Duration between actions in the bot. Sensor polling interval, if you like. | ||
// Too low, and you don't have enough sensor data to act | ||
// Too high, and you react too sluggishly | ||
// 50ms is a good number. | ||
clock: 50, // milliseconds | ||
} |
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,48 @@ | ||
// This is a duplex stream that pipes out data from the sensors | ||
// every config.clock milliseconds. | ||
// Motor commands can be piped into this stream, which then get sent | ||
// to the motors. | ||
|
||
const { Duplex } = require('stream'); | ||
const hal = require('alphabot-hal')(); | ||
const config = require('./config'); | ||
|
||
const hardware = new Duplex({ | ||
readableObjectMode: true, | ||
writableObjectMode: true, | ||
write(chunk, encoding, done) { | ||
hal.wheels.left((chunk.wheels && chunk.wheels.left) || 0); | ||
hal.wheels.right((chunk.wheels && chunk.wheels.right) || 0); | ||
|
||
done(); | ||
}, | ||
read() {} | ||
}); | ||
|
||
// Buffer up tick counts | ||
var ticks = { left: 0, right: 0 }; | ||
hal.on('leftTick', () => ticks.left++); | ||
hal.on('rightTick', () => ticks.right++); | ||
|
||
// Write to the stream every config.clock milliseconds | ||
setInterval(() => { | ||
hardware.push({ | ||
ticks, | ||
obstacleSensors: { | ||
left: hal.obstacleSensors.left(), | ||
right: hal.obstacleSensors.right() | ||
}, | ||
batteryVoltage: hal.batteryVoltage(), | ||
ts: Date.now() | ||
}); | ||
|
||
ticks.left = ticks.right = 0; | ||
}, config.clock); | ||
|
||
process.on('exit', () => { | ||
// Stop motors when exiting | ||
hal.wheels.left(0); | ||
hal.wheels.right(0); | ||
}); | ||
|
||
module.exports = hardware; |
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,10 @@ | ||
const hardware = require('./hardware'); | ||
const { obj: map } = require('through2-map'); | ||
|
||
// Give the robot a placeholder brain. | ||
// Act braindead, ignore sensors, don't move | ||
const brains = map(sensors => ({ | ||
wheels: { left: 0, right: 0 } | ||
})) | ||
|
||
hardware.pipe(brains).pipe(hardware); |
Oops, something went wrong.