Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Tapster testing files #29

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
630cbd1
Create hi.js
jackskalitzky Jun 12, 2015
5e4b41e
Added test functions
jackskalitzky Jun 12, 2015
70c07dc
Draw.js, for testing Tapsterbot
jackskalitzky Jun 16, 2015
d35e211
Adds access to the Draw.js methods
jackskalitzky Jun 16, 2015
b421e7d
Webpage for canvas
jackskalitzky Jun 16, 2015
178a809
Methods for simplifying drawing
jackskalitzky Jun 16, 2015
3ad0f6e
Configuration file for Tapster
jackskalitzky Jun 23, 2015
8c0a426
Script for parsing SVG path data
jackskalitzky Jun 23, 2015
7de3369
Pulls values from a config
jackskalitzky Jun 23, 2015
58b0097
Pulls values from a config
jackskalitzky Jun 23, 2015
8ba6fe7
Update bot.js
jackskalitzky Jun 23, 2015
d028c24
data.json for draw.js
jackskalitzky Jun 30, 2015
aee2904
Kinematics is now configurable.
hugs Jun 30, 2015
8adbe05
ik.js is now kinematics.js
hugs Jun 30, 2015
3c195bb
Created an SVGReader object
jackskalitzky Jun 30, 2015
f32fda4
Instantiation and config location specification
jackskalitzky Jun 30, 2015
9beafd5
Created a Draw object
jackskalitzky Jun 30, 2015
c21e379
Fixed an issue with penHeight
jackskalitzky Jun 30, 2015
8fd2264
Added erase functionality
jackskalitzky Jul 1, 2015
75eaa39
Changed the erase function to support clock
jackskalitzky Jul 6, 2015
a20844b
Created functioning clock
jackskalitzky Jul 6, 2015
f7e4d79
Updated clock-related functions
jackskalitzky Jul 7, 2015
c3d003d
Updated erase functions
jackskalitzky Jul 7, 2015
28b240a
Updated test function
jackskalitzky Jul 9, 2015
f68b1b4
Updated hello functions
jackskalitzky Jul 9, 2015
603f32b
Create helloEnT.svg
jackskalitzky Jul 9, 2015
7eb1a71
Create helloChF.svg
jackskalitzky Jul 9, 2015
a57f7bf
Create helloFrF.svg
jackskalitzky Jul 9, 2015
d3f18f1
Create helloItF.svg
jackskalitzky Jul 9, 2015
c2c886b
Create helloJpF.svg
jackskalitzky Jul 9, 2015
cd633b6
Create helloSpT.svg
jackskalitzky Jul 9, 2015
5020ac8
Updated characters
jackskalitzky Jul 10, 2015
afb4fdd
Created helloRuF
jackskalitzky Jul 10, 2015
6b1a179
Fixed translation issue (heh)
jackskalitzky Jul 10, 2015
17a3b28
Fixed translation issue
jackskalitzky Jul 10, 2015
3ccdfd2
Cleanup
jackskalitzky Jul 17, 2015
2474553
Deleted redundant file
jackskalitzky Jul 17, 2015
3c23214
Angry Birds demo
jackskalitzky Jul 18, 2015
619a045
Moved angrybirds outside of bot.js
jackskalitzky Jul 28, 2015
55cdb3c
Updated draw method arguments
jackskalitzky Jul 28, 2015
51741d8
Support for relative filepaths
jackskalitzky Jul 28, 2015
0c77337
*Switch* to switch statements
jackskalitzky Jul 28, 2015
c57b427
Misc. clean up
jackskalitzky Jul 28, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions software/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var config = {}

//Side of end effector
//~~Do not touch~~
config.e = 34.64101615137754; // Math.sqrt(3) * 10 * 2

//Side of top triangle
//~~Do not touch~~
config.f = 110.85125168440814; // Math.sqrt(3) * 32 * 2

//Length of parallelogram joint
//~~Do not touch~~
config.re = 153.5; // 145 + 8.5

//Length of upper joint
//~~Do not touch~~
config.rf = 52.690131903421914; // Math.sqrt(52**2 + 8.5**2)

//Input ranges for servos
//~~Do not touch~~
config.servo1 = {in_min: 0, in_max: 90};
config.servo2 = {in_min: 0, in_max: 90};
config.servo3 = {in_min: 0, in_max: 90};

//Default output ranges for servos
//CHANGE THESE
config.servo1.out_min = 12;
config.servo1.out_max = 93;
config.servo2.out_min = 8;
config.servo2.out_max = 90;
config.servo3.out_min = 14;
config.servo3.out_max = 96;

//Dimensions of the base plate
config.baseHeight = 95;
config.baseWidth = 80;

//Default Z-Level of the pen
config.penHeight = -140;

//Default drawing height of the pen
config.drawHeight = -152.75;

//Delay for commands in SVGReader
//Note that some commands will take longer than this
//Default value is 150
config.delay = 200;

//The default easing type to be used
//When no easing is specified, this is the type that will be used
//"none" means that if no easing is specified, do not ease
//For a list of possible easing types, look in motion.js
config.defaultEaseType = "linear";

module.exports = config;
6 changes: 4 additions & 2 deletions software/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"engines":{
"node":"0.x.x"
},
"dependencies":{
"johnny-five":"0.7.x"
"dependencies": {
"johnny-five": "0.8.x",
"svg-path-parser": "^1.0.1",
"xml2js": "^0.4.9"
}
}
167 changes: 167 additions & 0 deletions software/recorder/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@

<!doctype html>
<html lang="en">
<head lang=en>
<meta charset="utf-8">
<title>Tracing a line with d3.js</title>
<style>

svg {
background: #ddd;
font: 10px sans-serif;
cursor: crosshair;
}

.line {
cursor: crosshair;
fill: none;
stroke: #000;
stroke-width: 2px;
stroke-linejoin: round;
}

#output {
position: relative;
top: -2em;
left: 0.67em;
font: 12px/1.4 monospace;
}


</style>
</head>

<body>
<div id="sketch"></div>
<div id="output"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="simplify.js"></script>

<script>
// based on http://bl.ocks.org/cloudshapes/5661984 by cloudshapes

var margin = {top: 0, right: 0, bottom: 0, left: 0},
width = 300 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;


// var npoints = 100;
var ptdata = [];
var session = [];
var path;
var drawing = false;

var output = d3.select('#output');

var line = d3.svg.line()
.interpolate("bundle") // basis, see http://bl.ocks.org/mbostock/4342190
.tension(1)
.x(function(d, i) { return d.x; })
.y(function(d, i) { return d.y; });

var svg = d3.select("#sketch").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)

svg.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

svg
.on("mousedown", listen)
.on("touchstart", listen)
.on("touchend", ignore)
.on("touchleave", ignore)
.on("mouseup", ignore)
.on("mouseleave", ignore);


// ignore default touch behavior
var touchEvents = ['touchstart', 'touchmove', 'touchend'];
touchEvents.forEach(function (eventName) {
document.body.addEventListener(eventName, function(e){
e.preventDefault();
});
});


function listen () {
drawing = true;
output.text('event: ' + d3.event.type);
ptdata = []; // reset point data
path = svg.append("path") // start a new line
.data([ptdata])
.attr("class", "line")
.attr("d", line);

if (d3.event.type === 'mousedown') {
svg.on("mousemove", onmove);
} else {
svg.on("touchmove", onmove);
}
}

function ignore () {
var before, after;
output.text('event: ' + d3.event.type);
svg.on("mousemove", null);
svg.on("touchmove", null);

// skip out if we're not drawing
if (!drawing) return;
drawing = false;

before = ptdata.length;
console.group('Line Simplification');
console.log("Before simplification:", before)

// simplify
ptdata = simplify(ptdata);
after = ptdata.length;

console.log("After simplification:", ptdata.length)
console.groupEnd();

var percentage = parseInt(100 - (after/before)*100, 10);
output.html('Points: ' + before + ' => ' + after + '. <b>' + percentage + '% simplification.</b>');

// add newly created line to the drawing session
session.push(ptdata);

// redraw the line after simplification
tick();
}


function onmove (e) {
var type = d3.event.type;
var point;

if (type === 'mousemove') {
point = d3.mouse(this);
output.text('event: ' + type + ': ' + d3.mouse(this));
} else {
// only deal with a single touch input
point = d3.touches(this)[0];
output.text('event: ' + type + ': ' + d3.touches(this)[0]);
}

// push a new data point onto the back
ptdata.push({ x: point[0], y: point[1] });
tick();
}

function tick() {
path.attr("d", function(d) { return line(d); }) // Redraw the path:
}

function exportData() {
for (var i = 0; i < session.length; i++)
console.log(JSON.stringify(session[i], null, '\t'));
}
</script>
</body>
</html>




133 changes: 133 additions & 0 deletions software/recorder/simplify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
(c) 2013, Vladimir Agafonkin
Simplify.js, a high-performance JS polyline simplification library
mourner.github.io/simplify-js
*/

(function () { 'use strict';

// to suit your point format, run search/replace for '.x' and '.y';
// for 3D version, see 3d branch (configurability would draw significant performance overhead)

// square distance between 2 points
function getSqDist(p1, p2) {

var dx = p1.x - p2.x,
dy = p1.y - p2.y;

return dx * dx + dy * dy;
}

// square distance from a point to a segment
function getSqSegDist(p, p1, p2) {

var x = p1.x,
y = p1.y,
dx = p2.x - x,
dy = p2.y - y;

if (dx !== 0 || dy !== 0) {

var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);

if (t > 1) {
x = p2.x;
y = p2.y;

} else if (t > 0) {
x += dx * t;
y += dy * t;
}
}

dx = p.x - x;
dy = p.y - y;

return dx * dx + dy * dy;
}
// rest of the code doesn't care about point format

// basic distance-based simplification
function simplifyRadialDist(points, sqTolerance) {

var prevPoint = points[0],
newPoints = [prevPoint],
point;

for (var i = 1, len = points.length; i < len; i++) {
point = points[i];

if (getSqDist(point, prevPoint) > sqTolerance) {
newPoints.push(point);
prevPoint = point;
}
}

if (prevPoint !== point) newPoints.push(point);

return newPoints;
}

// simplification using optimized Douglas-Peucker algorithm with recursion elimination
function simplifyDouglasPeucker(points, sqTolerance) {

var len = points.length,
MarkerArray = typeof Uint8Array !== 'undefined' ? Uint8Array : Array,
markers = new MarkerArray(len),
first = 0,
last = len - 1,
stack = [],
newPoints = [],
i, maxSqDist, sqDist, index;

markers[first] = markers[last] = 1;

while (last) {

maxSqDist = 0;

for (i = first + 1; i < last; i++) {
sqDist = getSqSegDist(points[i], points[first], points[last]);

if (sqDist > maxSqDist) {
index = i;
maxSqDist = sqDist;
}
}

if (maxSqDist > sqTolerance) {
markers[index] = 1;
stack.push(first, index, index, last);
}

last = stack.pop();
first = stack.pop();
}

for (i = 0; i < len; i++) {
if (markers[i]) newPoints.push(points[i]);
}

return newPoints;
}

// both algorithms combined for awesome performance
function simplify(points, tolerance, highestQuality) {

if (points.length <= 1) return points;

var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;

points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
points = simplifyDouglasPeucker(points, sqTolerance);

return points;
}

// export as AMD module / Node module / browser or worker variable
if (typeof define === 'function' && define.amd) define(function() { return simplify; });
else if (typeof module !== 'undefined') module.exports = simplify;
else if (typeof self !== 'undefined') self.simplify = simplify;
else window.simplify = simplify;

})();
Loading