Last active
August 13, 2019 20:28
-
-
Save jadonk/7b2d335364b5474d566463d9b45360fa to your computer and use it in GitHub Desktop.
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
var b = require('bonescript'); | |
var step = (function() { | |
var M1 = 1; | |
var M2 = 4; | |
var state = 0; | |
var enabled = 0; | |
return function(direction) { | |
if(!enabled) { | |
process.stdout.write("Initializing motors\n"); | |
b.rcMotor("ENABLE"); | |
enabled = 1; | |
} | |
if(direction > 0) { | |
state++; | |
} else if (direction < 0) { | |
state--; | |
} | |
if(state > 8) state = 0; | |
else if(state < 0) state = 7; | |
switch(state) { | |
case 0: | |
default: | |
b.rcMotor(M1,1); | |
b.rcMotor(M2,1); | |
break; | |
case 1: | |
b.rcMotor(M1,0); | |
b.rcMotor(M2,1); | |
break; | |
case 2: | |
b.rcMotor(M1,-1); | |
b.rcMotor(M2,1); | |
break; | |
case 3: | |
b.rcMotor(M1,-1); | |
b.rcMotor(M2,0); | |
break; | |
case 4: | |
b.rcMotor(M1,-1); | |
b.rcMotor(M2,-1); | |
break; | |
case 5: | |
b.rcMotor(M1,0); | |
b.rcMotor(M2,-1); | |
break; | |
case 6: | |
b.rcMotor(M1,1); | |
b.rcMotor(M2,-1); | |
break; | |
case 7: | |
b.rcMotor(M1,1); | |
b.rcMotor(M2,0); | |
break; | |
} | |
} | |
})(); | |
var updateStepper = (function() { | |
var position = 0; | |
var direction = 1; | |
return function() { | |
// do stepping here | |
if(position >= 128) { | |
b.rcLED("GREEN",0); | |
b.rcLED("RED",1); | |
direction = -1; | |
} else if(position <= -128) { | |
b.rcLED("GREEN",1); | |
b.rcLED("RED",0); | |
direction = 1; | |
} | |
step(direction); | |
position += direction; | |
process.stdout.write("Position: " + position + " \r"); | |
} | |
})(); | |
setInterval(updateStepper, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jadonk,
Sir...is this software for the MotorCape on the BBB or variation? I have been testing the software I keep coming up w/ on the BBBW to test for random motors.
I have failed. I talked w/ a person on #beagle on Freenode. He stated something about the .dts file needs changing. Am I going to need to supply the current .dts file, https://github.com/RobertCNelson/bb.org-overlays/blob/master/src/arm/BBORG_MOTOR-00A2.dts, to my /boot dir. under the file uEnv.txt in the u-boot overlays section?
I am asking b/c I wrote up some simple software to test for a stepper and an additional DC motor (6v).
Seth
P.S. I could not get the motors running. I know I am missing something. Please send ideas if you can find time. Thank you, sir.