|
|
|
|
|
|
|
|
import raspy_sensors as Sensors |
|
|
import raspy_sensors as Sensors |
|
|
from defines import Topics, SENSORDATA, ALLSENSORDATA |
|
|
from defines import Topics, SENSORDATA, ALLSENSORDATA |
|
|
|
|
|
|
|
|
import time |
|
|
|
|
|
|
|
|
|
|
|
def measure_send_data(plantID, actionID, client: mqtt.Client): |
|
|
def measure_send_data(plantID, actionID, client: mqtt.Client): |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
# errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plantID}') |
|
|
# errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plantID}') |
|
|
|
|
|
|
|
|
if errorCode != 0: |
|
|
if errorCode != 0: |
|
|
logging.error(f"Robot Error {errorCode} occurred") |
|
|
|
|
|
logging.info("Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], "Drive Plant aborted, Robot at starting position", qos=1) |
|
|
|
|
|
|
|
|
if errorCode == 65280: |
|
|
|
|
|
errorMessage = "EV3 not connected" |
|
|
|
|
|
else: |
|
|
|
|
|
errorMessage = "Motor or Sensor unplugged" |
|
|
|
|
|
|
|
|
|
|
|
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at starting position", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') |
|
|
|
|
|
|
|
|
if errorCode != 0: |
|
|
if errorCode != 0: |
|
|
logging.error(f"Robot Error {errorCode} occurred") |
|
|
|
|
|
logging.info(f"Drive Home aborted, Robot at plant {plantID}") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"Drive Home aborted, Robot at plant {plantID}", qos=1) |
|
|
|
|
|
|
|
|
if errorCode == 65280: |
|
|
|
|
|
errorMessage = "EV3 not connected" |
|
|
|
|
|
else: |
|
|
|
|
|
errorMessage = "Motor or Sensor unplugged" |
|
|
|
|
|
|
|
|
|
|
|
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at plant {plantID}", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# FIXME Only possible with color codes |
|
|
# FIXME Only possible with color codes |
|
|
logging.info(f"Robot Driving to plant {plant}") |
|
|
logging.info(f"Robot Driving to plant {plant}") |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plant}') |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plant}') |
|
|
|
|
|
|
|
|
if errorCode != 0: |
|
|
if errorCode != 0: |
|
|
logging.error(f"Robot Error {errorCode} occurred") |
|
|
|
|
|
logging.info("Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], "Drive Plant aborted, Robot at starting position", qos=1) |
|
|
|
|
|
|
|
|
if errorCode == 65280: |
|
|
|
|
|
errorMessage = "EV3 not connected" |
|
|
|
|
|
else: |
|
|
|
|
|
errorMessage = "Motor or Sensor unplugged" |
|
|
|
|
|
|
|
|
|
|
|
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at starting position", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_arm.py {plant}') |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_arm.py {plant}') |
|
|
if errorCode != 0: |
|
|
if errorCode != 0: |
|
|
logging.error(f"Robot Error {errorCode} occurred") |
|
|
|
|
|
logging.info("Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"Rotate arm aborted, Robot at plant {plant}", qos=1) |
|
|
|
|
|
|
|
|
if errorCode == 65280: |
|
|
|
|
|
errorMessage = "EV3 not connected" |
|
|
|
|
|
else: |
|
|
|
|
|
errorMessage = "Motor or Sensor unplugged" |
|
|
|
|
|
|
|
|
|
|
|
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at plant {plant}", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logging.info("Robot driving home") |
|
|
logging.info("Robot driving home") |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back_straight.py') |
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back_straight.py') |
|
|
if errorCode != 0: |
|
|
if errorCode != 0: |
|
|
logging.error(f"Robot Error {errorCode} occurred") |
|
|
|
|
|
logging.info(f"Drive Home aborted, Robot at plant {plant}") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"Drive Home aborted, Robot at plant {plant}", qos=1) |
|
|
|
|
|
|
|
|
if errorCode == 65280: |
|
|
|
|
|
errorMessage = "EV3 not connected" |
|
|
|
|
|
else: |
|
|
|
|
|
errorMessage = "Motor or Sensor unplugged" |
|
|
|
|
|
|
|
|
|
|
|
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position") |
|
|
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at plant {plant}", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
batteryLevel = int(os.popen('sshpass -p maker ssh robot@ev3dev.local cat /sys/devices/platform/battery/power_supply/lego-ev3-battery/voltage_now').read()) |
|
|
batteryLevel = int(os.popen('sshpass -p maker ssh robot@ev3dev.local cat /sys/devices/platform/battery/power_supply/lego-ev3-battery/voltage_now').read()) |
|
|
except: |
|
|
except: |
|
|
logging.error("Robot not connected") |
|
|
|
|
|
|
|
|
logging.error("EV3 not connected") |
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], "Robot not connected", qos=1) |
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], "Robot not connected", qos=1) |
|
|
return |
|
|
return |
|
|
|
|
|
|