Drive all sensor test and Bugfix
This commit is contained in:
parent
4cadbf9c29
commit
8fa5cae836
@ -6,6 +6,8 @@ import logging
|
||||
import raspy_sensors as Sensors
|
||||
from defines import Topics, SENSORDATA, ALLSENSORDATA
|
||||
|
||||
import time
|
||||
|
||||
def measure_send_data(plantID, actionID, client: mqtt.Client):
|
||||
"""
|
||||
Reads all sensors and publishes data via MQTT in form of SENSORDATA
|
||||
@ -15,7 +17,8 @@ def measure_send_data(plantID, actionID, client: mqtt.Client):
|
||||
actionID (_type_): current ID of driving action
|
||||
client (mqtt.Client): current mqtt client for publishing
|
||||
"""
|
||||
sensorData = SENSORDATA
|
||||
sensordata = {}
|
||||
sensordata |= SENSORDATA
|
||||
|
||||
try:
|
||||
sensorData = Sensors.readSensors()
|
||||
@ -84,12 +87,15 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
|
||||
client (mqtt.Client): current MQTT client
|
||||
"""
|
||||
|
||||
allPlantData = ALLSENSORDATA
|
||||
allPlantData = {
|
||||
"SensorData": [],
|
||||
"ActionID": ""
|
||||
}
|
||||
|
||||
allPlantData["ActionID"] = actionID
|
||||
logging.debug(f"plants {plantIDs}, type {type(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}")
|
||||
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plant}')
|
||||
if errorCode != 0:
|
||||
@ -103,10 +109,16 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
|
||||
# TODO Test error handling
|
||||
logging.info("Measuring Sensors")
|
||||
try:
|
||||
allPlantData["PlantData"].append(Sensors.readSensors())
|
||||
sensordata = {}
|
||||
sensordata |= SENSORDATA
|
||||
sensordata = Sensors.readSensors()
|
||||
sensordata["PlantID"] = plant
|
||||
allPlantData["SensorData"].append(sensordata)
|
||||
except Exception as e:
|
||||
logging.error(str(e))
|
||||
client.publish(Topics["ROBOT_DATA_ERROR"], str(e), qos=1)
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
|
||||
# TODO How to Handle Pictures and PlantID
|
||||
@ -124,6 +136,7 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
|
||||
logging.info("All Plants measured, sending data")
|
||||
client.publish(Topics["ROBOT_DATA_ALL"], json.dumps(allPlantData, indent=4), qos=1)
|
||||
|
||||
|
||||
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:
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 2.4 MiB After Width: | Height: | Size: 2.3 MiB |
@ -104,7 +104,8 @@ def readSensors():
|
||||
Returns:
|
||||
dict: Sensordata
|
||||
"""
|
||||
sensorData = SENSORDATA
|
||||
sensorData = {}
|
||||
sensorData |= SENSORDATA
|
||||
errorMessage = ""
|
||||
|
||||
# read DHT22
|
||||
@ -171,7 +172,7 @@ def readPosition():
|
||||
def main():
|
||||
value = SENSORDATA
|
||||
try:
|
||||
readMCP3008()
|
||||
value |= readSensors()
|
||||
except Exception as e:
|
||||
print(str(e))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user