Browse Source

Drive all sensor test and Bugfix

master
Luis Waldhauser 1 year ago
parent
commit
8fa5cae836

+ 18
- 5
software/roboter/raspy/functions.py View File

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):
""" """
Reads all sensors and publishes data via MQTT in form of SENSORDATA Reads all sensors and publishes data via MQTT in form of SENSORDATA
actionID (_type_): current ID of driving action actionID (_type_): current ID of driving action
client (mqtt.Client): current mqtt client for publishing client (mqtt.Client): current mqtt client for publishing
""" """
sensorData = SENSORDATA
sensordata = {}
sensordata |= SENSORDATA


try: try:
sensorData = Sensors.readSensors() sensorData = Sensors.readSensors()
client (mqtt.Client): current MQTT client client (mqtt.Client): current MQTT client
""" """


allPlantData = ALLSENSORDATA
allPlantData = {
"SensorData": [],
"ActionID": ""
}
allPlantData["ActionID"] = actionID allPlantData["ActionID"] = actionID
logging.debug(f"plants {plantIDs}, type {type(plantIDs)}")


for plant in plantIDs: for plant in plantIDs:
# 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:
# TODO Test error handling # TODO Test error handling
logging.info("Measuring Sensors") logging.info("Measuring Sensors")
try: try:
allPlantData["PlantData"].append(Sensors.readSensors())
sensordata = {}
sensordata |= SENSORDATA
sensordata = Sensors.readSensors()
sensordata["PlantID"] = plant
allPlantData["SensorData"].append(sensordata)
except Exception as e: except Exception as e:
logging.error(str(e)) logging.error(str(e))
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1) client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1)

time.sleep(3)


# TODO How to Handle Pictures and PlantID # TODO How to Handle Pictures and PlantID
logging.info("All Plants measured, sending data") logging.info("All Plants measured, sending data")
client.publish(Topics["ROBOT_DATA_ALL"], json.dumps(allPlantData, indent=4), qos=1) client.publish(Topics["ROBOT_DATA_ALL"], json.dumps(allPlantData, indent=4), qos=1)



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:

BIN
software/roboter/raspy/picture.png View File


+ 3
- 2
software/roboter/raspy/raspy_sensors.py View File

Returns: Returns:
dict: Sensordata dict: Sensordata
""" """
sensorData = SENSORDATA
sensorData = {}
sensorData |= SENSORDATA
errorMessage = "" errorMessage = ""


# read DHT22 # read DHT22
def main(): def main():
value = SENSORDATA value = SENSORDATA
try: try:
readMCP3008()
value |= readSensors()
except Exception as e: except Exception as e:
print(str(e)) print(str(e))



Loading…
Cancel
Save