Robot comments extended, Docu updated

This commit is contained in:
waldluis 2023-06-09 10:08:27 +02:00
parent e975585f57
commit d9ad3bce0c
5 changed files with 25 additions and 19 deletions

Binary file not shown.

View File

@ -65,7 +65,6 @@ ALLSENSORDATA = {
"ActionID": "" "ActionID": ""
} }
# TODO When sensor is available
POSITION = { POSITION = {
"Position": "" "Position": ""
} }
@ -115,7 +114,6 @@ ALLPLANTDATA = [
PLANTDATA PLANTDATA
] ]
# TODO When sensor is available
POSITION = { POSITION = {
"Position": "", "Position": "",
"Timestamp": "" "Timestamp": ""

View File

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

View File

@ -45,7 +45,7 @@ def on_connect(client: mqtt.Client, userdata, flags, rc):
def main(): def main():
""" """
Initialises MQTT and Sensors Initialises MQTT
Runs forever and controlls all robot functions Runs forever and controlls all robot functions
""" """
logging.basicConfig(filename="robot.log", filemode="a", encoding="utf-8", level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s %(message)s', logging.basicConfig(filename="robot.log", filemode="a", encoding="utf-8", level=logging.DEBUG, format='%(asctime)s %(name)s %(levelname)s %(message)s',

View File

@ -99,6 +99,7 @@ def readSensors(sensorData):
""" """
Read DHT22, TSL2561 and Humidity Sensor Read DHT22, TSL2561 and Humidity Sensor
Dictionary is passed to ensure that values are available when errors occur Dictionary is passed to ensure that values are available when errors occur
When error occurs during reading of sensor, affected values are set to 0
Args: Args:
sensorData (dictionary): Dictionary of type SENSORDATA sensorData (dictionary): Dictionary of type SENSORDATA
@ -114,7 +115,7 @@ def readSensors(sensorData):
try: try:
sensorData["AirTemperature"], sensorData["AirHumidity"] = readDHT22() sensorData["AirTemperature"], sensorData["AirHumidity"] = readDHT22()
except Exception as e: except Exception as e:
sensorData["AirHumidity"] = 0 # No value returend if error occurs -> setting dummy value sensorData["AirHumidity"] = 0 # No value returend if error occurs -> setting safe values
sensorData["AirTemperature"] = 0 sensorData["AirTemperature"] = 0
errorMessage = str(e) + "\n" # Appending received error message to later forward all occured errors errorMessage = str(e) + "\n" # Appending received error message to later forward all occured errors
@ -122,14 +123,14 @@ def readSensors(sensorData):
try: try:
sensorData["Brightness"] = readTSL2561() sensorData["Brightness"] = readTSL2561()
except Exception as e: except Exception as e:
sensorData["Brightness"] = 0 # No value returend if error occurs -> setting dummy value sensorData["Brightness"] = 0 # No value returend if error occurs -> setting safe value
errorMessage = errorMessage + str(e) + "\n" # Appending received error message to later forward all occured errors errorMessage = errorMessage + str(e) + "\n" # Appending received error message to later forward all occured errors
# read YL-69 # read YL-69
try: try:
sensorData["SoilMoisture"] = readMCP3008() sensorData["SoilMoisture"] = readMCP3008()
except Exception as e: except Exception as e:
sensorData["SoilMoisture"] = 0 # No value returend if error occurs -> setting dummy value sensorData["SoilMoisture"] = 0 # No value returend if error occurs -> setting safe value
errorMessage = errorMessage + str(e) + "\n" # Appending received error message to later forward all occured errors errorMessage = errorMessage + str(e) + "\n" # Appending received error message to later forward all occured errors
# raise combined error message # raise combined error message
@ -146,15 +147,13 @@ def takePicture():
try: try:
camera = PiCamera() camera = PiCamera()
except: except:
# raise Exception("Camera not connected") raise Exception("Camera not connected")
pass
camera.start_preview() camera.start_preview()
camera.capture("picture.png") camera.capture("picture.png")
camera.stop_preview() camera.stop_preview()
# TODO - read position with sensor
def readPosition(): def readPosition():
""" """
Read and return Position Read and return Position