feat: added y axis motor

This commit is contained in:
ysandler 2021-01-26 16:15:43 -06:00 committed by joshuashoemaker
parent aa43319490
commit c81ba6ddc7
2 changed files with 27 additions and 9 deletions

View File

@ -17,9 +17,9 @@ class MotorMover implements IMotorMover {
public moveClockwise = () => { public moveClockwise = () => {
if (this.movementState === 'CLOCKWISE') return if (this.movementState === 'CLOCKWISE') return
else {
this.moveProcess?.kill() if (!this.moveProcess?.killed) this.moveProcess?.kill()
this.moveProcess = null }
const motorProcessArguments = [ const motorProcessArguments = [
'src/Robotics/moveStepper.py', 'src/Robotics/moveStepper.py',
@ -38,9 +38,9 @@ class MotorMover implements IMotorMover {
public moveCounterClockwise = () => { public moveCounterClockwise = () => {
if (this.movementState === 'COUNTERCLOCKWISE') return if (this.movementState === 'COUNTERCLOCKWISE') return
else {
this.moveProcess?.kill() if (!this.moveProcess?.killed) this.moveProcess?.kill()
this.moveProcess = null }
const motorProcessArguments = [ const motorProcessArguments = [
'src/Robotics/moveStepper.py', 'src/Robotics/moveStepper.py',
@ -52,13 +52,18 @@ class MotorMover implements IMotorMover {
this.pauseIntervalTime.toString() this.pauseIntervalTime.toString()
] ]
console.log('start counterclockwise')
this.moveProcess = childProcesses.spawn('python', motorProcessArguments) this.moveProcess = childProcesses.spawn('python', motorProcessArguments)
this.movementState = 'COUNTERCLOCKWISE' this.movementState = 'COUNTERCLOCKWISE'
} }
public stopMovement = () => { public stopMovement = () => {
this.moveProcess?.kill() if (this.movementState === 'IDLE') return
this.movementState = 'IDLE' else {
if (!this.moveProcess?.killed) this.moveProcess?.kill()
console.log('start idle')
this.movementState = 'IDLE'
}
} }
} }

View File

@ -18,6 +18,11 @@ const main = () => {
pauseIntervalTime: 0.05 pauseIntervalTime: 0.05
}) })
const yAxisMotorMover: IMotorMover = makeMotorMover({
motor: { pinOne: 13, pinTwo: 15, pinThree: 19, pinFour: 21 },
pauseIntervalTime: 0.05
})
eventManager.listen('onReceiveOffsets', (offsets: any[]) => { eventManager.listen('onReceiveOffsets', (offsets: any[]) => {
if (offsets[0]?.x > 50) { if (offsets[0]?.x > 50) {
xAxisMotorMover.moveCounterClockwise() xAxisMotorMover.moveCounterClockwise()
@ -26,7 +31,15 @@ const main = () => {
} else { } else {
xAxisMotorMover.stopMovement() xAxisMotorMover.stopMovement()
} }
console.log(`moving ${xAxisMotorMover.movementState}`)
if (offsets[0]?.y > 50) {
yAxisMotorMover.moveClockwise()
} else if (offsets[0]?.y < - 50) {
yAxisMotorMover.moveCounterClockwise()
} else {
yAxisMotorMover.stopMovement()
}
// console.log(`moving ${xAxisMotorMover.movementState}`)
}) })
} }