Robot logging added
This commit is contained in:
parent
c35028f354
commit
0385aa7792
@ -2,6 +2,7 @@ import paho.mqtt.client as mqtt
|
|||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
import raspy_sensors as Sensors
|
import raspy_sensors as Sensors
|
||||||
from defines import Topics, SENSORDATA
|
from defines import Topics, SENSORDATA
|
||||||
|
|
||||||
@ -44,23 +45,23 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client):
|
|||||||
|
|
||||||
# TODO Error Message
|
# TODO Error Message
|
||||||
if errorCode != 0:
|
if errorCode != 0:
|
||||||
print(f"Robot Error {errorCode} occurred")
|
logging.error(f"Robot Error {errorCode} occurred")
|
||||||
print("Drive Plant aborted, Robot at starting position")
|
logging.error("Drive Plant aborted, Robot at starting position")
|
||||||
return
|
return
|
||||||
|
|
||||||
print("Measuring Sensors")
|
logging.info("Measuring Sensors")
|
||||||
measure_send_data(plantID, actionID, client)
|
measure_send_data(plantID, actionID, client)
|
||||||
|
|
||||||
print("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}')
|
||||||
|
|
||||||
# TODO Error Message
|
# TODO Error Message
|
||||||
if errorCode != 0:
|
if errorCode != 0:
|
||||||
print(f"Robot Error {errorCode} occurred")
|
logging.error(f"Robot Error {errorCode} occurred")
|
||||||
print(f"Drive Home aborted, Robot at plant {plantID}")
|
logging.error(f"Drive Home aborted, Robot at plant {plantID}")
|
||||||
return
|
return
|
||||||
|
|
||||||
print("Robot home")
|
logging.info("Robot home")
|
||||||
|
|
||||||
#TODO decide about robot occupied message
|
#TODO decide about robot occupied message
|
||||||
#client.publish("ROBOT/DATA/OCCUPIED", "false")
|
#client.publish("ROBOT/DATA/OCCUPIED", "false")
|
||||||
@ -82,7 +83,7 @@ def drive_plant(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage):
|
|||||||
plantID = dictMessage["PlantID"]
|
plantID = dictMessage["PlantID"]
|
||||||
actionID = dictMessage["ActionID"]
|
actionID = dictMessage["ActionID"]
|
||||||
|
|
||||||
print(f"Received Drive-request to plant {plantID}, ActionID: {actionID}")
|
logging.info(f"Received Drive-request to plant {plantID}, ActionID: {actionID}")
|
||||||
|
|
||||||
thread = threading.Thread(target= drive_plant_thread, args=(plantID, actionID, clients), daemon=True)
|
thread = threading.Thread(target= drive_plant_thread, args=(plantID, actionID, clients), daemon=True)
|
||||||
thread.start()
|
thread.start()
|
||||||
@ -118,12 +119,12 @@ def get_BatteryStatus(clients: mqtt.Client, userdata, message: mqtt.MQTTMessage)
|
|||||||
userdata (_type_): _description_
|
userdata (_type_): _description_
|
||||||
message (mqtt.MQTTMessage): received message
|
message (mqtt.MQTTMessage): received message
|
||||||
"""
|
"""
|
||||||
print("Received battery status request")
|
logging.info("Received battery status request")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
batteryLevel = int(os.popen('sshpass -p maker ssh robot@ev3dev.local cat /sys/devices/platform/battery/power_supply/lego-ev3-battery/voltage_now').read())
|
batteryLevel = int(os.popen('sshpass -p maker ssh robot@ev3dev.local cat /sys/devices/platform/battery/power_supply/lego-ev3-battery/voltage_now').read())
|
||||||
except:
|
except:
|
||||||
print("Robot not connected")
|
logging.error("Robot not connected")
|
||||||
#TODO Error Message
|
#TODO Error Message
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ Interaction with the EV3 via SSH
|
|||||||
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import functions
|
import functions
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL
|
from defines import Topics, RASPI_CLIENT_ID, MQTT_BROKER_GLOBAL
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ def on_connect(client: mqtt.Client, userdata, flags, rc):
|
|||||||
client.subscribe(Topics["ROBOT_ACTION_GETPOSITION"])
|
client.subscribe(Topics["ROBOT_ACTION_GETPOSITION"])
|
||||||
client.subscribe(Topics["ROBOT_ACTION_GETBATTERY"])
|
client.subscribe(Topics["ROBOT_ACTION_GETBATTERY"])
|
||||||
|
|
||||||
print("MQTT initialized")
|
logging.info("MQTT initialized")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -44,6 +46,10 @@ def main():
|
|||||||
Initialises MQTT and Sensors
|
Initialises MQTT and Sensors
|
||||||
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',
|
||||||
|
datefmt="%d-%m-%Y %H:%M:%S")
|
||||||
|
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
|
||||||
|
|
||||||
client = mqtt.Client(RASPI_CLIENT_ID)
|
client = mqtt.Client(RASPI_CLIENT_ID)
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
client.connect(MQTT_BROKER_GLOBAL)
|
client.connect(MQTT_BROKER_GLOBAL)
|
||||||
@ -51,7 +57,7 @@ def main():
|
|||||||
# CHECK forever or start
|
# CHECK forever or start
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
|
|
||||||
print("Starting Loop")
|
logging.info("Starting Loop")
|
||||||
while True:
|
while True:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user