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



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


sensorData = { sensorData = {
"Air Temperature [°C]" : 0, "Air Temperature [°C]" : 0,


#endregion #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''' '''Measure data for one plant via sensor class and send via MQTT'''
sensorData = sensors.readSensors() sensorData = sensors.readSensors()
sensorData["Plant_ID"] = plantID sensorData["Plant_ID"] = plantID
sensorData["Action_ID"] = actionID sensorData["Action_ID"] = actionID
client.publish("Robot/Data/SensorData", json.dumps(sensorData, indent=4)) 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 #endregion


#[ ]TODO Start drive forward -> Thread #[ ]TODO Start drive forward -> Thread


print(f"Measuring data at Plant {message}") 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") print("Driving back to start position")
#[ ]TODO Start Drive Back Function in Thread #[ ]TODO Start Drive Back Function in Thread


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


def get_position(clients, userdata, message): def get_position(clients, userdata, message):
client.publish("Robot/Data/Position", json.dumps(gpsPosition, indent=4)) client.publish("Robot/Data/Position", json.dumps(gpsPosition, indent=4))





def get_BatteryStatus(clients, userdata, message): def get_BatteryStatus(clients, userdata, message):

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


#endregion #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