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

"ActionID": "" "ActionID": ""
} }


# TODO When sensor is available
POSITION = { POSITION = {
"Position": "" "Position": ""
} }
PLANTDATA PLANTDATA
] ]


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

+ 19
- 10
software/roboter/raspy/functions.py View File

""" """
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


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"
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
logging.info("Taking Picture")
sendPicture(client)
# Taking Picture not fully implemented
# logging.info("Taking Picture")
# 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"
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"
allPlantData["SensorData"].append(sensordata) 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}') 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"




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:
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
""" """
logging.info("Received position request") logging.info("Received position request")


# TODO Write GPS Sensor Function
position = { position = {
"Position": "" "Position": ""
} }
""" """
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%

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



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',

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

""" """
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
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


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
try: try:
camera = PiCamera() camera = PiCamera()
except: except:
# raise Exception("Camera not connected")
pass
raise Exception("Camera not connected")
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

Loading…
Cancel
Save