|
|
@@ -6,7 +6,6 @@ import logging |
|
|
|
import raspy_sensors as Sensors |
|
|
|
from defines import Topics, SENSORDATA, ALLSENSORDATA |
|
|
|
|
|
|
|
import time |
|
|
|
|
|
|
|
def measure_send_data(plantID, actionID, client: mqtt.Client): |
|
|
|
""" |
|
|
@@ -47,9 +46,13 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): |
|
|
|
# errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plantID}') |
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
return |
|
|
@@ -65,9 +68,13 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): |
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') |
|
|
|
|
|
|
|
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) |
|
|
|
return |
|
|
|
|
|
|
@@ -98,10 +105,15 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): |
|
|
|
# FIXME Only possible with color codes |
|
|
|
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}') |
|
|
|
|
|
|
|
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) |
|
|
|
return |
|
|
|
|
|
|
@@ -125,9 +137,13 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): |
|
|
|
|
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_arm.py {plant}') |
|
|
|
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) |
|
|
|
return |
|
|
|
|
|
|
@@ -138,9 +154,13 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): |
|
|
|
logging.info("Robot driving home") |
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back_straight.py') |
|
|
|
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) |
|
|
|
return |
|
|
|
|
|
|
@@ -231,7 +251,7 @@ def get_batteryStatus(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
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()) |
|
|
|
except: |
|
|
|
logging.error("Robot not connected") |
|
|
|
logging.error("EV3 not connected") |
|
|
|
client.publish(Topics["ROBOT_DATA_ERROR"], "Robot not connected", qos=1) |
|
|
|
return |
|
|
|
|