From c81ba6ddc74e8afdc91481ba0c293ed9bd95b9f8 Mon Sep 17 00:00:00 2001 From: ysandler Date: Tue, 26 Jan 2021 16:15:43 -0600 Subject: [PATCH] feat: added y axis motor --- src/Robotics/Entities/MotorMover.ts | 21 +++++++++++++-------- src/Robotics/main.ts | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Robotics/Entities/MotorMover.ts b/src/Robotics/Entities/MotorMover.ts index 7efe126..e826329 100644 --- a/src/Robotics/Entities/MotorMover.ts +++ b/src/Robotics/Entities/MotorMover.ts @@ -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' + } } } diff --git a/src/Robotics/main.ts b/src/Robotics/main.ts index b0863c1..2c1c95a 100644 --- a/src/Robotics/main.ts +++ b/src/Robotics/main.ts @@ -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}`) }) }