def Run(self, duration, newPosition, speed, direction): #TODO https://www.google.com/search?q=pass+object+to+python+function&rlz=1C1GCEA_enUS892US892&oq=pass+object+to+python+function&aqs=chrome..69i57.5686j0j7&sourceid=chrome&ie=UTF-8 #TODO https://stackoverflow.com/questions/20725699/how-do-i-pass-instance-of-an-object-as-an-argument-in-a-function-in-python """ Run an actuator for a given number of milliseconds to a given position at percentage of max speed in FORWARD or BACKWARDS direction Key arguments: duration - Time actuator is in motion, for Servo() objects this can be used to control speed of movement newPosition - New position between -1 and 1 that actuator should move to speed - Speed at which actuator moves at, for Servo() objects this parameter is NOT used direction - Set counter-clockwise (CCW or LINEAR_IN) or clockwise (CW or LINEAR_OUT) as the forward direction Return Value: NOTHING """ print("Actuator.py Run() function started!") if(type == "S"): currentPosition = self.actuatorObject.value() if(currentPosition < (newPosition - Actuator.SERVO_SLACK)): self.actuatorObject.max() #TODO THIS MAY NOT STOP AND GO ALL THE WAY TO MAX POS elif(currentPosition > (newPosition - Actuator.SERVO_SLACK)): self.actuatorObject.min() #TODO THIS MAY NOT STOP AND GO ALL THE WAY TO MIN POS else: # NEAR to new position DO NOTHING self.actuatotObject.dettach() elif(type == "M"): #TODO Write motor control code Motor.enable() #TODO CHANGE TO self.acutatorObject currentPosition = actuatorObject.value while(currentPosition != newPosition): if(actuatorObject.forwardDirection == Actuator.CW): Motor.forward(speed) else: Motor.reverse(speed) currentPosition = self.actuatorObject.value sleep(duration) #TODO signal.pause(duration) Motor.disable() elif(type == "R"): relay.on() sleep(duration) #TODO signal.pause(duration) relay.off() else: self.DebugObect.Dprint("INVALID Actutator Type sent to Run method, please use S, M, R as first parameter to Actuator() Object") self.DebugObject.Dprint("Run function completed!")
def main(): parser = argparse.ArgumentParser() parser.add_argument('--model_name', default='test_model', help='Model identifier.') parser.add_argument('--model_path', required=True, help='Path to model file.') parser.add_argument('--speed', default=0.5, type=float, help='Reduction factor on speed') args = parser.parse_args() model = ModelDescriptor(name=args.model_name, input_shape=(1, 192, 192, 3), input_normalizer=(0, 1), compute_graph=utils.load_compute_graph( args.model_path)) left = Motor(PIN_A, PIN_B) right = Motor(PIN_C, PIN_D) print('spinning') try: with PiCamera(sensor_mode=4, framerate=30): with CameraInference(model) as inference: for result in inference.run(): data = [ tensor.data for _, tensor in result.tensors.items() ] lspeed, rspeed = data[0] print('#%05d (%5.2f fps): %1.2f/%1.2f' % (inference.count, inference.rate, lspeed, rspeed)) if lspeed < 0: left.reverse(-max(-1, lspeed) * args.speed) else: left.forward(min(1, lspeed) * args.speed) if rspeed < 0: right.reverse(-max(-1, rspeed) * args.speed) else: right.forward(min(1, rspeed) * args.speed) except Exception as e: left.stop() right.stop() print(e)
motor2.forwards() motor3.forwards() motor4.forwards() elif (rightSide == -100 and leftSide == -100 ): #full steam backwards motor1.backwards() motor2.backwards() motor3.backwards() motor4.backwards() elif (rightSide == -150 and leftSide == -100 ): #Turn Half Right Backwards motor1.stop() motor2.stop() motor3.reverse() motor4.reverse() elif (rightSide == -100 and leftSide == -150 ): #Turn Half Left Backwards motor1.stop() motor2.stop() motor3.reverse() motor4.reverse() else: #motors off motor1.stop() motor2.stop() motor3.stop() motor4.stop()