def move(d): # this is called from comms when a cmd is received if (d == "F") or (d == "W"): forwards() comms.sendToUI("Received Forwards") print colored("Received Forwards", 'yellow') if (d == "B") or (d == "X"): backwards() comms.sendToUI("Received Backwards") print colored("Received Backwards", 'yellow') if (d == "L") or (d == "A"): left() comms.sendToUI("Received Left") print colored("Received Left", 'yellow') if (d == "R") or (d == "D"): right() comms.sendToUI("Received Right") print colored("Received Right", 'yellow') if (d == "Stop") or (d == "S"): stop() comms.sendToUI("Received Stop") print colored("Received Stop", 'yellow')
def camera(status): if status == "CamOn": print colored("Starting camera stream", 'yellow') os.system('./startstream.sh &> /dev/null') if status == "CamOff": print colored("Stopping camera stream", 'yellow') os.system('sudo killall raspistill') if status == "HL": print colored("Switching off headlights", 'yellow') GPIO.output(headlights, False) comms.sendToUI("Headlights off") if status == "HH": print colored("Switching on headlights", 'yellow') GPIO.output(headlights, True) comms.sendToUI("Headlights on")
def servo(msg): global pan_var global tilt_var if msg == "pan_left": pan_var = pan_var + 100 if pan_var < 2500 and pan_var > 500: print colored("Panning left " + str(pan_var), 'yellow') servo_mv(pan, pan_var) # pan left a bit comms.sendToUI("Panning left") else: # to stop trying to pan too far pan_var = pan_var - 100 if msg == "pan_right": pan_var = pan_var - 100 if pan_var < 2500 and pan_var > 500: print colored("Panning right " + str(pan_var), 'yellow') servo_mv(pan, pan_var) # pan right a bit comms.sendToUI("Panning right") else: # to stop trying to pan too far pan_var = pan_var + 100 if msg == "tilt_backwards": tilt_var = tilt_var + 100 if tilt_var < 2500 and tilt_var > 500: print colored("Tilting backwards " + str(tilt_var), 'yellow') servo_mv(tilt, tilt_var) # tilt backwards a bit comms.sendToUI("Tilting backwards") else: # to stop tilting too far tilt_var = tilt_var + 100 if msg == "tilt_forwards": tilt_var = tilt_var - 100 if tilt_var < 2500 and tilt_var > 500: print colored("Tilting forwards " + str(tilt_var), 'yellow') servo_mv(tilt, tilt_var) # tilt forwards a bit comms.sendToUI("Tilting forwards") else: tilt_var = tilt_var + 100
def servo(direction): if direction == "pan_left": print colored("Panning left", 'yellow') comms.sendToUI("Panning left") pan.ChangeDutyCycle(servoLeft) if direction == "pan_right": print colored("Panning right", 'yellow') comms.sendToUI("Panning right") pan.ChangeDutyCycle(servoRight) if direction == "pan_center": print colored("Panning to center", 'yellow') comms.sendToUI("Panning to center") pan.ChangeDutyCycle(servoNeutral) if direction == "tilt_forwards": print colored("Tilting forwards", 'yellow') comms.sendToUI("Tiliting forwards") tilt.ChangeDutyCycle(servoForwards) if direction == "tilt_backwards": print colored("Tilting backwards", 'yellow') comms.sendToUI("Tiliting backwards") tilt.ChangeDutyCycle(servoBackwards) if direction == "tilt_up": print colored("Tilting to center", 'yellow') comms.sendToUI("Tiliting to center") tilt.ChangeDutyCycle(servoNeutral)