Browse Source

Robot Docu extended and main to mainProg added

master
waldluis 1 year ago
parent
commit
f29e567f07
2 changed files with 37 additions and 21 deletions
  1. BIN
      documentation/Robot.docx
  2. 37
    21
      software/roboter/raspy/mainProg.py

BIN
documentation/Robot.docx View File


+ 37
- 21
software/roboter/raspy/mainProg.py View File

@@ -4,6 +4,7 @@ from raspySensors import RaspySensors

#region global Varaibles
sensors = RaspySensors()
client = mqtt.Client()

sensorData = {
"Air Temperature [°C]" : 0,
@@ -27,15 +28,35 @@ batteryStatus = {

#endregion

#region
#region global functions

def measureSendData(plantID, actionID):
def measure_send_data(plantID, actionID):
'''Measure data for one plant via sensor class and send via MQTT'''
sensorData = sensors.readSensors()
sensorData["Plant_ID"] = plantID
sensorData["Action_ID"] = actionID
client.publish("Robot/Data/SensorData", json.dumps(sensorData, indent=4))


def init_mqtt():
'''Initialise MQTT client'''
mqttBroker = "mqtt.eclipseprojects.io"
client = mqtt.Client("Robot")

#Add callbacks
client.message_callback_add("Robot/Data", send_data_json) #Testing
client.message_callback_add("Robot/Action/Drive", drive_plant)
client.message_callback_add("Robot/Action/GetPosition", get_position)
client.message_callback_add("Robot/Action/GetBattery", get_BatteryStatus)

#Subscribe to topics
client.subscribe("Robot/Data") #Testing
client.subscribe("Robot/Action/Drive")
client.subscribe("Robot/Action/GetPosition")
client.subscribe("Robot/Action/GetBattery")

client.connect(mqttBroker)


#endregion

@@ -56,12 +77,12 @@ def drive_plant(clients, userdata, message):
#[ ]TODO Start drive forward -> Thread

print(f"Measuring data at Plant {message}")
measureSendData() # With threads not here
measure_send_data() # With Signal not here

print("Driving back to start position")
#[ ]TODO Start Drive Back Function in Thread

print("Back at starting Position")
print("Back at starting Position") #Signal

def get_position(clients, userdata, message):
@@ -74,8 +95,8 @@ def get_position(clients, userdata, message):
client.publish("Robot/Data/Position", json.dumps(gpsPosition, indent=4))



def get_BatteryStatus(clients, userdata, message):

'''Callback function for battery status request
Function to read battery status from ev3 and send via MQTT'''

@@ -91,23 +112,18 @@ def get_BatteryStatus(clients, userdata, message):
#endregion


mqttBroker = "mqtt.eclipseprojects.io"
client = mqtt.Client("Robot")

dataDict = {} #Testing
def main():
init_mqtt()
dataDict = {} #Testing

client.loop_start()

while True:
pass

#Add callbacks
client.message_callback_add("Robot/Data", send_data_json) #Testing
client.message_callback_add("Robot/Action/Drive", drive_plant)
client.message_callback_add("Robot/Action/GetPosition", get_position)
client.message_callback_add("Robot/Action/GetBattery", get_BatteryStatus)

client.connect(mqttBroker)

#Subscribe to topics
client.subscribe("Robot/Data") #Testing
client.subscribe("Robot/Action/Drive")
client.subscribe("Robot/Action/GetPosition")
client.subscribe("Robot/Action/GetBattery")

client.loop_forever()
if __name__ == "__main__":
main()

Loading…
Cancel
Save