from servo import ServoMotor from ultrasonic import UltrsonicSensor if __name__ == "__main__": config = {} with open('config.json') as f: config = json.load(f) motionControl = MotionControl(config['MultiStepperController']) motionControl.setSpeed(1.5) motionsensor = MotionSensor() ultrasonicSensorFront = UltrsonicSensor(config["FrontUltrsonicSensor"]) ultrasonicSensorBack = UltrsonicSensor(config["BackUltrsonicSensor"]) servo = ServoMotor(config['HeadMountServo']) servoAngle = 90 servo.rotate(servoAngle) try: while 1: events = get_gamepad() for event in events: # print(event.ev_type, event.code, event.state) if event.ev_type == 'Key' and event.code == 'BTN_NORTH' and event.state == 0: print('Moving forward') motionControl.move(0.1) elif event.ev_type == 'Key' and event.code == 'BTN_EAST' and event.state == 0: print('Moving backward') motionControl.move(-0.1) elif event.ev_type == 'Key' and event.code == 'BTN_Z' and event.state == 0: print('Rotating') motionControl.rotate(10)
import sys import json from servo import ServoMotor from ultrasonic import UltrsonicSensor from motioncontrol import MotionControl from motionsensor import MotionSensor config = {} with open('config.json') as f: config = json.load(f) ultrasonicSensorFront = UltrsonicSensor(config["FrontUltrsonicSensor"]) motionControl = MotionControl(config['MultiStepperController']) servo = ServoMotor(config['HeadMountServo']) servo.rotate(0) motionSensor = MotionSensor() def calibrateMovement(dist: float): startAvg = 0 for i in range(10): distance = ultrasonicSensorFront.getDistance() time.sleep(0.1) startAvg += distance startAvg /= 10 motionControl.move(dist) time.sleep(1) endAvg = 0