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
|
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
|
||||||
@ -15,7 +17,8 @@ def measure_send_data(plantID, actionID, client: mqtt.Client):
|
|||||||
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()
|
||||||
@ -84,12 +87,15 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
|
|||||||
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:
|
||||||
@ -103,11 +109,17 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
|
|||||||
# 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("Taking Picture")
|
logging.info("Taking Picture")
|
||||||
@ -124,6 +136,7 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
|
|||||||
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:
|
||||||
|
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:
|
Returns:
|
||||||
dict: Sensordata
|
dict: Sensordata
|
||||||
"""
|
"""
|
||||||
sensorData = SENSORDATA
|
sensorData = {}
|
||||||
|
sensorData |= SENSORDATA
|
||||||
errorMessage = ""
|
errorMessage = ""
|
||||||
|
|
||||||
# read DHT22
|
# read DHT22
|
||||||
@ -171,7 +172,7 @@ def readPosition():
|
|||||||
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…
x
Reference in New Issue
Block a user