Browse Source

Robot comments extended, Docu updated

master
waldluis 1 year ago
parent
commit
d9ad3bce0c

BIN
documentation/Robot.docx View File


+ 0
- 2
software/roboter/raspy/defines.py View File

@@ -65,7 +65,6 @@ ALLSENSORDATA = {
"ActionID": ""
}

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

# TODO When sensor is available
POSITION = {
"Position": "",
"Timestamp": ""

+ 19
- 10
software/roboter/raspy/functions.py 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

***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%

+ 1
- 1
software/roboter/raspy/mainProg.py View File

@@ -45,7 +45,7 @@ def on_connect(client: mqtt.Client, userdata, flags, rc):

def main():
"""
Initialises MQTT and Sensors
Initialises MQTT
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',

+ 5
- 6
software/roboter/raspy/raspy_sensors.py View File

@@ -99,6 +99,7 @@ def readSensors(sensorData):
"""
Read DHT22, TSL2561 and Humidity Sensor
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:
sensorData (dictionary): Dictionary of type SENSORDATA
@@ -114,7 +115,7 @@ def readSensors(sensorData):
try:
sensorData["AirTemperature"], sensorData["AirHumidity"] = readDHT22()
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
errorMessage = str(e) + "\n" # Appending received error message to later forward all occured errors

@@ -122,14 +123,14 @@ def readSensors(sensorData):
try:
sensorData["Brightness"] = readTSL2561()
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

# read YL-69
try:
sensorData["SoilMoisture"] = readMCP3008()
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

# raise combined error message
@@ -146,15 +147,13 @@ def takePicture():
try:
camera = PiCamera()
except:
# raise Exception("Camera not connected")
pass
raise Exception("Camera not connected")
camera.start_preview()
camera.capture("picture.png")
camera.stop_preview()


# TODO - read position with sensor
def readPosition():
"""
Read and return Position

Loading…
Cancel
Save