Polymer({
is: "pedal-assist",
properties:{
ppc:{
type:Number,
value:30,
},
gap:{
type:Number,
computed:"getGap(lPedel,rPedel)",
},
cycle:{
type:Number,
value:.5,
},
},
left: function(undefined){
this.lPedel = performance.now()
},
right: function(undefined){
this.rPedel = performance.now()
},
getGap: function(lPedel,rPedel){
var newGap = Math.sqrt((lPedel - rPedel) * (lPedel - rPedel))
var r1 = this.gapOld / this.gap
var r2 = this.gap / newGap
console.log(r1,r2,newGap)
if (r1 < 1.2 && r1 > .8 && r2 < 1.2 && r2 > .8) {
this.runMotor(this.cycle,this.ppc,this.gap)
}
this.gapOld = this.gap
return newGap
},
runMotor: function(cycle,ppc,time){
var n= Math.floor(ppc*cycle)
for (var i=1;i<n;i++) {
setTimeout(function(that){
if (that.black == 0) {
that.set("black", 12)
that.yellow = 0
that.red = -12
} else if (that.yellow == 0) {
that.black = -12
that.yellow = 12
that.red = 0
} else if (that.red == 0) {
that.black = 0
that.yellow = -12
that.red = 12
}
}, (time*cycle)*(i/n),this)
console.log((time*cycle)*(i/n))
}
setTimeout(function(that){
that.black = 0
that.yellow = 0
that.red = 0
}, (time*cycle)+10,this)
},
})
// TODO: Replace examples and use TDD development by writing your own tests
// These are some CW specific test methods available:
// Test.expect(boolean, [optional] message)
// Test.assertEquals(actual, expected, [optional] message)
// Test.assertSimilar(actual, expected, [optional] message)
// Test.assertNotEquals(actual, expected, [optional] message)
// NodeJS assert is also automatically required for you.
// assert(true)
// assert.strictEqual({a: 1}, {a: 1})
// assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
// You can also use Chai (http://chaijs.com/) by requiring it yourself
// var expect = require("chai").expect;
// var assert = require("chai").assert;
// require("chai").should();
describe("Solution", function(){
it("should test for something", function(){
Test.assertEquals("actual", "expected", "This is just an example of how you can write your own TDD tests");
});
});