|
|
@@ -18,6 +18,8 @@ def measure_send_data(plantID, actionID, client: mqtt.Client): |
|
|
|
""" |
|
|
|
Reads all sensors and publishes data via MQTT in form of SENSORDATA |
|
|
|
|
|
|
|
***Function is only neccessary for driving without color codes*** |
|
|
|
|
|
|
|
Args: |
|
|
|
plantID (_type_): plant to measure |
|
|
|
actionID (_type_): current ID of driving action |
|
|
@@ -58,6 +60,8 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): |
|
|
|
|
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/plant_{plantID}.py') |
|
|
|
|
|
|
|
# Error handling for drive operation |
|
|
|
# Abort when drive operation at start when error occurs |
|
|
|
if errorCode != 0: |
|
|
|
if errorCode == 65280: |
|
|
|
errorMessage = "EV3 not connected" |
|
|
@@ -67,19 +71,20 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client): |
|
|
|
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 |
|
|
|
|
|
|
|
logging.info("Measuring Sensors") |
|
|
|
measure_send_data(plantID, actionID, client) |
|
|
|
|
|
|
|
# TODO How to Handle Pictures and PlantID |
|
|
|
logging.info("Taking Picture") |
|
|
|
sendPicture(client) |
|
|
|
# Taking Picture not fully implemented |
|
|
|
# logging.info("Taking Picture") |
|
|
|
# sendPicture(client) |
|
|
|
|
|
|
|
logging.info("Robot driving home") |
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}') |
|
|
|
|
|
|
|
# Error handling for drive operation |
|
|
|
# Abort when drive operation at start when error occurs |
|
|
|
if errorCode != 0: |
|
|
|
if errorCode == 65280: |
|
|
|
errorMessage = "EV3 not connected" |
|
|
@@ -119,10 +124,11 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): |
|
|
|
allPlantData["ActionID"] = actionID |
|
|
|
|
|
|
|
for plant in plantIDs: |
|
|
|
# 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}') |
|
|
|
|
|
|
|
# Error handling for drive operation |
|
|
|
# Abort when drive operation at start when error occurs |
|
|
|
if errorCode != 0: |
|
|
|
if errorCode == 65280: |
|
|
|
errorMessage = "EV3 not connected" |
|
|
@@ -149,11 +155,13 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): |
|
|
|
allPlantData["SensorData"].append(sensordata) |
|
|
|
|
|
|
|
|
|
|
|
# TODO How to Handle Pictures and PlantID |
|
|
|
logging.info("Taking Picture") |
|
|
|
sendPicture(client) |
|
|
|
# Taking Picture not fully implemented |
|
|
|
# logging.info("Taking Picture") |
|
|
|
# sendPicture(client) |
|
|
|
|
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_arm.py {plant}') |
|
|
|
# Error handling for drive operation |
|
|
|
# Abort when drive operation at start when error occurs |
|
|
|
if errorCode != 0: |
|
|
|
if errorCode == 65280: |
|
|
|
errorMessage = "EV3 not connected" |
|
|
@@ -170,6 +178,8 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client): |
|
|
|
|
|
|
|
|
|
|
|
logging.info("Robot driving home") |
|
|
|
# Error handling for drive operation |
|
|
|
# Abort when drive operation at start when error occurs |
|
|
|
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back_straight.py') |
|
|
|
if errorCode != 0: |
|
|
|
if errorCode == 65280: |
|
|
@@ -215,7 +225,6 @@ def drive_plant(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
thread.start() |
|
|
|
|
|
|
|
|
|
|
|
# FIXME Only possible with color codes |
|
|
|
def drive_plant_all(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
""" |
|
|
|
Function to drive to plants according to request |
|
|
@@ -254,7 +263,6 @@ def get_position(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
""" |
|
|
|
logging.info("Received position request") |
|
|
|
|
|
|
|
# TODO Write GPS Sensor Function |
|
|
|
position = { |
|
|
|
"Position": "" |
|
|
|
} |
|
|
@@ -266,6 +274,7 @@ def get_batteryStatus(client: mqtt.Client, userdata, message: mqtt.MQTTMessage): |
|
|
|
""" |
|
|
|
Callback function for battery status request |
|
|
|
Function to read battery status from EV3 and send via MQTT in form of BATTERY |
|
|
|
Current battery level is stored in "voltage_now" file |
|
|
|
Reading battery level via SSH script execution |
|
|
|
Battery level shown in Volts: |
|
|
|
8,5V -> 100% |