Docu small changes and MQTT topics added to robot
This commit is contained in:
parent
9b32acdc68
commit
6e66611e06
Binary file not shown.
@ -3504,7 +3504,8 @@
|
|||||||
"_parent": {
|
"_parent": {
|
||||||
"$ref": "AAAAAAGHMigXUpG7rpw="
|
"$ref": "AAAAAAGHMigXUpG7rpw="
|
||||||
},
|
},
|
||||||
"name": "Role1"
|
"name": "Role1",
|
||||||
|
"type": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_type": "UMLAttribute",
|
"_type": "UMLAttribute",
|
||||||
@ -3512,7 +3513,8 @@
|
|||||||
"_parent": {
|
"_parent": {
|
||||||
"$ref": "AAAAAAGHMigXUpG7rpw="
|
"$ref": "AAAAAAGHMigXUpG7rpw="
|
||||||
},
|
},
|
||||||
"name": "Role2"
|
"name": "Role2",
|
||||||
|
"type": ""
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_type": "UMLAttribute",
|
"_type": "UMLAttribute",
|
||||||
@ -3520,7 +3522,242 @@
|
|||||||
"_parent": {
|
"_parent": {
|
||||||
"$ref": "AAAAAAGHMigXUpG7rpw="
|
"$ref": "AAAAAAGHMigXUpG7rpw="
|
||||||
},
|
},
|
||||||
"name": "Role3"
|
"name": "Role3",
|
||||||
|
"type": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "UMLModel",
|
||||||
|
"_id": "AAAAAAGHSvOnT6lLzLI=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAFF+h6SjaM2Hec="
|
||||||
|
},
|
||||||
|
"name": "Model1",
|
||||||
|
"ownedElements": [
|
||||||
|
{
|
||||||
|
"_type": "UMLClassDiagram",
|
||||||
|
"_id": "AAAAAAGHSvOnUKlMd1M=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvOnT6lLzLI="
|
||||||
|
},
|
||||||
|
"name": "ClassDiagram1",
|
||||||
|
"ownedViews": [
|
||||||
|
{
|
||||||
|
"_type": "UMLClassView",
|
||||||
|
"_id": "AAAAAAGHSvO0JalSVe0=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvOnUKlMd1M="
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalQDB0="
|
||||||
|
},
|
||||||
|
"subViews": [
|
||||||
|
{
|
||||||
|
"_type": "UMLNameCompartmentView",
|
||||||
|
"_id": "AAAAAAGHSvO0JalTHAU=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalSVe0="
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalQDB0="
|
||||||
|
},
|
||||||
|
"subViews": [
|
||||||
|
{
|
||||||
|
"_type": "LabelView",
|
||||||
|
"_id": "AAAAAAGHSvO0JalU/Lk=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalTHAU="
|
||||||
|
},
|
||||||
|
"visible": false,
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"height": 13
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "LabelView",
|
||||||
|
"_id": "AAAAAAGHSvO0JalVXXc=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalTHAU="
|
||||||
|
},
|
||||||
|
"font": "Arial;13;1",
|
||||||
|
"left": 637,
|
||||||
|
"top": 119,
|
||||||
|
"width": 190,
|
||||||
|
"height": 13,
|
||||||
|
"text": "RaspySensors"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "LabelView",
|
||||||
|
"_id": "AAAAAAGHSvO0JalW0mo=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalTHAU="
|
||||||
|
},
|
||||||
|
"visible": false,
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"width": 80.9072265625,
|
||||||
|
"height": 13,
|
||||||
|
"text": "(from Model1)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "LabelView",
|
||||||
|
"_id": "AAAAAAGHSvO0JalXjv8=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalTHAU="
|
||||||
|
},
|
||||||
|
"visible": false,
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"height": 13,
|
||||||
|
"horizontalAlignment": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"left": 632,
|
||||||
|
"top": 112,
|
||||||
|
"width": 200,
|
||||||
|
"height": 25,
|
||||||
|
"stereotypeLabel": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalU/Lk="
|
||||||
|
},
|
||||||
|
"nameLabel": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalVXXc="
|
||||||
|
},
|
||||||
|
"namespaceLabel": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalW0mo="
|
||||||
|
},
|
||||||
|
"propertyLabel": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalXjv8="
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "UMLAttributeCompartmentView",
|
||||||
|
"_id": "AAAAAAGHSvO0JqlYsbg=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalSVe0="
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalQDB0="
|
||||||
|
},
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"left": 632,
|
||||||
|
"top": 137,
|
||||||
|
"width": 200,
|
||||||
|
"height": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "UMLOperationCompartmentView",
|
||||||
|
"_id": "AAAAAAGHSvO0JqlZXW4=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalSVe0="
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalQDB0="
|
||||||
|
},
|
||||||
|
"subViews": [
|
||||||
|
{
|
||||||
|
"_type": "UMLOperationView",
|
||||||
|
"_id": "AAAAAAGHSvPxiKl9u9A=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JqlZXW4="
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"$ref": "AAAAAAGHSvPxg6l6DOE="
|
||||||
|
},
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"left": 637,
|
||||||
|
"top": 152,
|
||||||
|
"width": 190,
|
||||||
|
"height": 13,
|
||||||
|
"text": "+measureAll(): Dictionary",
|
||||||
|
"horizontalAlignment": 0
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"left": 632,
|
||||||
|
"top": 147,
|
||||||
|
"width": 200,
|
||||||
|
"height": 23
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "UMLReceptionCompartmentView",
|
||||||
|
"_id": "AAAAAAGHSvO0JqlauSU=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalSVe0="
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalQDB0="
|
||||||
|
},
|
||||||
|
"visible": false,
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"width": 10,
|
||||||
|
"height": 10
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "UMLTemplateParameterCompartmentView",
|
||||||
|
"_id": "AAAAAAGHSvO0Jqlbl7Q=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalSVe0="
|
||||||
|
},
|
||||||
|
"model": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalQDB0="
|
||||||
|
},
|
||||||
|
"visible": false,
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"width": 10,
|
||||||
|
"height": 10
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"font": "Arial;13;0",
|
||||||
|
"containerChangeable": true,
|
||||||
|
"left": 632,
|
||||||
|
"top": 112,
|
||||||
|
"width": 200,
|
||||||
|
"height": 280,
|
||||||
|
"nameCompartment": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalTHAU="
|
||||||
|
},
|
||||||
|
"attributeCompartment": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JqlYsbg="
|
||||||
|
},
|
||||||
|
"operationCompartment": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JqlZXW4="
|
||||||
|
},
|
||||||
|
"receptionCompartment": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JqlauSU="
|
||||||
|
},
|
||||||
|
"templateParameterCompartment": {
|
||||||
|
"$ref": "AAAAAAGHSvO0Jqlbl7Q="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_type": "UMLClass",
|
||||||
|
"_id": "AAAAAAGHSvO0JalQDB0=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvOnT6lLzLI="
|
||||||
|
},
|
||||||
|
"name": "RaspySensors",
|
||||||
|
"operations": [
|
||||||
|
{
|
||||||
|
"_type": "UMLOperation",
|
||||||
|
"_id": "AAAAAAGHSvPxg6l6DOE=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvO0JalQDB0="
|
||||||
|
},
|
||||||
|
"name": "measureAll",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"_type": "UMLParameter",
|
||||||
|
"_id": "AAAAAAGHSvSoBamCDuA=",
|
||||||
|
"_parent": {
|
||||||
|
"$ref": "AAAAAAGHSvPxg6l6DOE="
|
||||||
|
},
|
||||||
|
"type": "Dictionary",
|
||||||
|
"direction": "return"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,31 +5,86 @@ from raspySensors import RaspySensors
|
|||||||
#region global Varaibles
|
#region global Varaibles
|
||||||
sensors = RaspySensors()
|
sensors = RaspySensors()
|
||||||
|
|
||||||
|
sensorData = {
|
||||||
|
"Air Temperature [°C]" : 0,
|
||||||
|
"Air Humidity [%]" : 0,
|
||||||
|
"Earth Humidity [%]" : 0,
|
||||||
|
"Brightness [Lux]" : 0,
|
||||||
|
"Plant ID": 0,
|
||||||
|
"Action ID": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
gpsPosition = {
|
||||||
|
"Position": 0,
|
||||||
|
"Action ID": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
batteryStatus = {
|
||||||
|
"Battery": 0,
|
||||||
|
"Action ID": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region
|
#region
|
||||||
|
|
||||||
def measureSendData():
|
def measureSendData(plantID, actionID):
|
||||||
'''Measure Data 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()
|
||||||
client.publish("Robot/Data", json.dumps(sensorData, indent=4))
|
sensorData["Plant_ID"] = plantID
|
||||||
|
sensorData["Action_ID"] = actionID
|
||||||
|
client.publish("Robot/Data/SensorData", json.dumps(sensorData, indent=4))
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region MQTT callbacks
|
#region MQTT callbacks
|
||||||
|
|
||||||
|
#Testing
|
||||||
def send_data_json(client, userdata, message):
|
def send_data_json(client, userdata, message):
|
||||||
strIn = str(message.payload.decode("UTF-8"))
|
strIn = str(message.payload.decode("UTF-8"))
|
||||||
dataDict = json.loads(strIn)
|
dataDict = json.loads(strIn)
|
||||||
print("Received data: ", json.dumps(dataDict))
|
print("Received data: ", json.dumps(dataDict))
|
||||||
|
|
||||||
#Function for all Plants or one which changes according to request
|
|
||||||
def drive_plant_1(clients, userdata, message):
|
def drive_plant(clients, userdata, message):
|
||||||
#TODO Start drive forward
|
'''Function to drive to plant according to request'''
|
||||||
print("Driving to plant 1")
|
|
||||||
measureSendData()
|
#[ ]TODO handle MQTT message
|
||||||
#TODO Start Drive Back Function
|
print(f"Driving to plant {message}")
|
||||||
|
#[ ]TODO Start drive forward -> Thread
|
||||||
|
|
||||||
|
print(f"Measuring data at Plant {message}")
|
||||||
|
measureSendData() # With threads not here
|
||||||
|
|
||||||
print("Driving back to start position")
|
print("Driving back to start position")
|
||||||
|
#[ ]TODO Start Drive Back Function in Thread
|
||||||
|
|
||||||
|
print("Back at starting Position")
|
||||||
|
|
||||||
|
|
||||||
|
def get_position(clients, userdata, message):
|
||||||
|
'''Callback function for GPS position request
|
||||||
|
Function to send actual GPS position via MQTT'''
|
||||||
|
|
||||||
|
#[ ]TODO handle MQTT message
|
||||||
|
gpsPosition["Position"] = sensors.readPosition()
|
||||||
|
gpsPosition["Action_ID"] = 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'''
|
||||||
|
|
||||||
|
#[ ]TODO handle MQTT message
|
||||||
|
batteryStatus["Battery"] = sensors.readBattery()
|
||||||
|
batteryStatus["Action ID"] = message
|
||||||
|
client.publish("Robot/Data/Battery", json.dumps(batteryStatus, indent=4))
|
||||||
|
|
||||||
|
batteryStatus()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -37,15 +92,22 @@ def drive_plant_1(clients, userdata, message):
|
|||||||
|
|
||||||
|
|
||||||
mqttBroker = "mqtt.eclipseprojects.io"
|
mqttBroker = "mqtt.eclipseprojects.io"
|
||||||
client = mqtt.Client("Smartphone_temp")
|
client = mqtt.Client("Robot")
|
||||||
|
|
||||||
dataDict = {}
|
dataDict = {} #Testing
|
||||||
|
|
||||||
client.message_callback_add("Robot/Data", send_data_json)
|
#Add callbacks
|
||||||
client.message_callback_add("Robot/Plant/1", drive_plant_1)
|
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)
|
client.connect(mqttBroker)
|
||||||
client.subscribe("Robot/Data")
|
|
||||||
client.subscribe("Robot/Plant/1")
|
#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()
|
client.loop_forever()
|
@ -6,9 +6,10 @@ import json
|
|||||||
|
|
||||||
class RaspySensors:
|
class RaspySensors:
|
||||||
'''Class to handle all sensors'''
|
'''Class to handle all sensors'''
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
'''Init all Sensors'''
|
'''Init all Sensors'''
|
||||||
#Message if Error
|
#[ ]TODO Message if Error
|
||||||
|
|
||||||
|
|
||||||
#Air Temperature & Humidity
|
#Air Temperature & Humidity
|
||||||
@ -22,7 +23,9 @@ class RaspySensors:
|
|||||||
"Air Temperature [°C]" : 0,
|
"Air Temperature [°C]" : 0,
|
||||||
"Air Humidity [%]" : 0,
|
"Air Humidity [%]" : 0,
|
||||||
"Earth Humidity [%]" : 0,
|
"Earth Humidity [%]" : 0,
|
||||||
"Brightness [Lux]" : 0
|
"Brightness [Lux]" : 0,
|
||||||
|
"Plant ID": 0,
|
||||||
|
"Action ID": 0
|
||||||
}
|
}
|
||||||
|
|
||||||
def readSensors(self):
|
def readSensors(self):
|
||||||
@ -44,13 +47,21 @@ class RaspySensors:
|
|||||||
|
|
||||||
return self.sensorData
|
return self.sensorData
|
||||||
|
|
||||||
|
#[ ]TODO - take picture function
|
||||||
def takePicture(self):
|
def takePicture(self):
|
||||||
'''Take picture and return image'''
|
'''Take picture and return image'''
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
|
#[ ]TODO
|
||||||
def readPosition(self):
|
def readPosition(self):
|
||||||
'''Read and return Position'''
|
'''Read and return Position'''
|
||||||
return self.position
|
return self.position
|
||||||
|
|
||||||
|
#[ ]TODO
|
||||||
|
def readBattery(self):
|
||||||
|
'''Read and return battery of ev3'''
|
||||||
|
return self.battery
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#for Testing only
|
#for Testing only
|
||||||
|
Loading…
x
Reference in New Issue
Block a user