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 = () => {
if (this.movementState === 'CLOCKWISE') return
this.moveProcess?.kill()
this.moveProcess = null
else {
if (!this.moveProcess?.killed) this.moveProcess?.kill()
}
const motorProcessArguments = [
'src/Robotics/moveStepper.py',
@ -38,9 +38,9 @@ class MotorMover implements IMotorMover {
public moveCounterClockwise = () => {
if (this.movementState === 'COUNTERCLOCKWISE') return
this.moveProcess?.kill()
this.moveProcess = null
else {
if (!this.moveProcess?.killed) this.moveProcess?.kill()
}
const motorProcessArguments = [
'src/Robotics/moveStepper.py',
@ -52,13 +52,18 @@ class MotorMover implements IMotorMover {
this.pauseIntervalTime.toString()
]
console.log('start counterclockwise')
this.moveProcess = childProcesses.spawn('python', motorProcessArguments)
this.movementState = 'COUNTERCLOCKWISE'
}
public stopMovement = () => {
this.moveProcess?.kill()
this.movementState = 'IDLE'
if (this.movementState === 'IDLE') return
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
})
const yAxisMotorMover: IMotorMover = makeMotorMover({
motor: { pinOne: 13, pinTwo: 15, pinThree: 19, pinFour: 21 },
pauseIntervalTime: 0.05
})
eventManager.listen('onReceiveOffsets', (offsets: any[]) => {
if (offsets[0]?.x > 50) {
xAxisMotorMover.moveCounterClockwise()
@ -26,7 +31,15 @@ const main = () => {
} else {
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}`)
})
}