feat: shoots cat when in range
This commit is contained in:
parent
50e2ffea02
commit
371fb65aec
13
src/Robotics/Entities/WaterPump.ts
Normal file
13
src/Robotics/Entities/WaterPump.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import IWaterPump from '../Interfaces/IWaterPump'
|
||||||
|
|
||||||
|
class WaterPump implements IWaterPump {
|
||||||
|
public pinOne: number
|
||||||
|
public pinTwo: number
|
||||||
|
|
||||||
|
constructor (props: IWaterPump) {
|
||||||
|
this.pinOne = props.pinOne
|
||||||
|
this.pinTwo = props.pinTwo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default WaterPump
|
46
src/Robotics/Entities/WaterPumper.ts
Normal file
46
src/Robotics/Entities/WaterPumper.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import IWaterPump from '../Interfaces/IWaterPump'
|
||||||
|
import * as childProcesses from 'child_process'
|
||||||
|
import IWaterPumperConstructor from '../Interfaces/IWaterPumperConstructor'
|
||||||
|
import IWaterPumper from '../Interfaces/IWaterPumper'
|
||||||
|
import makeWaterPump from '../UseCases/Factories/makeWaterPump'
|
||||||
|
|
||||||
|
class WaterPumper implements IWaterPumper {
|
||||||
|
public waterPump: IWaterPump
|
||||||
|
public isActive: boolean = false
|
||||||
|
private pumpProcess: childProcesses.ChildProcessWithoutNullStreams | null = null
|
||||||
|
private pumpActiveTimeInSeconds: number
|
||||||
|
private pumpCoolDownTimeInSeconds: number
|
||||||
|
|
||||||
|
constructor (props: IWaterPumperConstructor) {
|
||||||
|
this.waterPump = makeWaterPump({
|
||||||
|
pinOne: props.pinOne,
|
||||||
|
pinTwo: props.pinTwo
|
||||||
|
})
|
||||||
|
|
||||||
|
this.pumpActiveTimeInSeconds =props.pumpActiveTimeInSeconds
|
||||||
|
this.pumpCoolDownTimeInSeconds = props.pumpCoolDownTimeInSeconds
|
||||||
|
}
|
||||||
|
|
||||||
|
private async coolDown () {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, this.pumpCoolDownTimeInSeconds * 1000))
|
||||||
|
}
|
||||||
|
|
||||||
|
public async pump () {
|
||||||
|
if (this.isActive) return
|
||||||
|
|
||||||
|
const pumpProcessArguments = [
|
||||||
|
'src/Robotics/moveDcMotor.py',
|
||||||
|
this.waterPump.pinOne.toString(),
|
||||||
|
this.waterPump.pinTwo.toString(),
|
||||||
|
this.pumpActiveTimeInSeconds.toString()
|
||||||
|
]
|
||||||
|
|
||||||
|
this.pumpProcess = childProcesses.spawn('python', pumpProcessArguments)
|
||||||
|
|
||||||
|
this.isActive = true
|
||||||
|
await this.coolDown()
|
||||||
|
this.isActive = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default WaterPumper
|
6
src/Robotics/Interfaces/IWaterPump.ts
Normal file
6
src/Robotics/Interfaces/IWaterPump.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
interface IWaterPump {
|
||||||
|
pinOne: number,
|
||||||
|
pinTwo: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IWaterPump
|
9
src/Robotics/Interfaces/IWaterPumper.ts
Normal file
9
src/Robotics/Interfaces/IWaterPumper.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import IWaterPump from "./IWaterPump";
|
||||||
|
|
||||||
|
interface IWaterPumper {
|
||||||
|
pump(): void
|
||||||
|
isActive: boolean
|
||||||
|
waterPump: IWaterPump
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IWaterPumper
|
8
src/Robotics/Interfaces/IWaterPumperConstructor.ts
Normal file
8
src/Robotics/Interfaces/IWaterPumperConstructor.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
interface IWaterPumperConstructor {
|
||||||
|
pinOne: number,
|
||||||
|
pinTwo: number,
|
||||||
|
pumpActiveTimeInSeconds: number,
|
||||||
|
pumpCoolDownTimeInSeconds: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export default IWaterPumperConstructor
|
8
src/Robotics/UseCases/Factories/makeWaterPump.ts
Normal file
8
src/Robotics/UseCases/Factories/makeWaterPump.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import WaterPump from "../../Entities/WaterPump"
|
||||||
|
import IWaterPump from "../../Interfaces/IWaterPump"
|
||||||
|
|
||||||
|
function makeWaterPump (props: IWaterPump) {
|
||||||
|
return new WaterPump(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default makeWaterPump
|
8
src/Robotics/UseCases/Factories/makeWaterPumper.ts
Normal file
8
src/Robotics/UseCases/Factories/makeWaterPumper.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import WaterPumper from "../../Entities/WaterPumper"
|
||||||
|
import IWaterPumperConstructor from "../../Interfaces/IWaterPumperConstructor"
|
||||||
|
|
||||||
|
function makeWaterPumper (props: IWaterPumperConstructor) {
|
||||||
|
return new WaterPumper(props)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default makeWaterPumper
|
@ -1,12 +1,14 @@
|
|||||||
import IEventManager from './Interfaces/IEventManager'
|
import IEventManager from './Interfaces/IEventManager'
|
||||||
import IMotorMover from './Interfaces/IMotorMover'
|
import IMotorMover from './Interfaces/IMotorMover'
|
||||||
|
import IWaterPumper from './Interfaces/IWaterPumper'
|
||||||
|
|
||||||
import makeServer from './UseCases/Factories/makeServer'
|
import makeServer from './UseCases/Factories/makeServer'
|
||||||
import makeEventManager from './UseCases/Factories/makeEventManager'
|
import makeEventManager from './UseCases/Factories/makeEventManager'
|
||||||
import makeMotorMover from './UseCases/Factories/makeMotorMover'
|
import makeMotorMover from './UseCases/Factories/makeMotorMover'
|
||||||
|
import makeWaterPumper from './UseCases/Factories/makeWaterPumper'
|
||||||
|
|
||||||
const main = () => {
|
const main = () => {
|
||||||
console.log('starting')
|
console.log('Starting Robotics')
|
||||||
|
|
||||||
const port = 5005
|
const port = 5005
|
||||||
makeServer(port)
|
makeServer(port)
|
||||||
@ -23,6 +25,13 @@ const main = () => {
|
|||||||
pauseIntervalTime: 0.05
|
pauseIntervalTime: 0.05
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const waterPumper: IWaterPumper = makeWaterPumper({
|
||||||
|
pinOne: 37,
|
||||||
|
pinTwo: 35,
|
||||||
|
pumpActiveTimeInSeconds: 1,
|
||||||
|
pumpCoolDownTimeInSeconds: 5
|
||||||
|
})
|
||||||
|
|
||||||
eventManager.listen('onReceiveOffsets', (offsets: any[]) => {
|
eventManager.listen('onReceiveOffsets', (offsets: any[]) => {
|
||||||
if (offsets[0]?.x > 50) {
|
if (offsets[0]?.x > 50) {
|
||||||
xAxisMotorMover.moveCounterClockwise()
|
xAxisMotorMover.moveCounterClockwise()
|
||||||
@ -39,7 +48,10 @@ const main = () => {
|
|||||||
} else {
|
} else {
|
||||||
yAxisMotorMover.stopMovement()
|
yAxisMotorMover.stopMovement()
|
||||||
}
|
}
|
||||||
// console.log(`moving ${xAxisMotorMover.movementState}`)
|
|
||||||
|
if (offsets[0]?.hypotenuse <= 80) {
|
||||||
|
waterPumper.pump()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
|
# command arguments to run process
|
||||||
|
# 1: int pin_one
|
||||||
|
# 2: int pin_two
|
||||||
|
# 3: int motor_active_time
|
||||||
|
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import sys
|
||||||
|
|
||||||
motor_channel = (37, 35)
|
motor_channel = (int(sys.argv[1]), int(sys.argv[2])) # (37, 35)
|
||||||
|
|
||||||
|
motor_active_time = int(sys.argv[3])
|
||||||
|
|
||||||
GPIO.setwarnings(True)
|
GPIO.setwarnings(True)
|
||||||
GPIO.setmode(GPIO.BOARD)
|
GPIO.setmode(GPIO.BOARD)
|
||||||
@ -10,5 +18,5 @@ GPIO.setup(motor_channel, GPIO.OUT)
|
|||||||
GPIO.output(motor_channel, (GPIO.HIGH, GPIO.LOW))
|
GPIO.output(motor_channel, (GPIO.HIGH, GPIO.LOW))
|
||||||
print('Should be on')
|
print('Should be on')
|
||||||
|
|
||||||
sleep(1)
|
sleep(motor_active_time)
|
||||||
GPIO.output(motor_channel, (GPIO.LOW, GPIO.LOW))
|
GPIO.output(motor_channel, (GPIO.LOW, GPIO.LOW))
|
Loading…
x
Reference in New Issue
Block a user