Browse Source

Robot logging added

master
Luis Waldhauser 1 year ago
parent
commit
0385aa7792
2 changed files with 19 additions and 12 deletions
  1. 11
    10
      software/roboter/raspy/functions.py
  2. 8
    2
      software/roboter/raspy/mainProg.py

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

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




# TODO Error Message # TODO Error Message
if errorCode != 0: if errorCode != 0:
print(f"Robot Error {errorCode} occurred")
print("Drive Plant aborted, Robot at starting position")
logging.error(f"Robot Error {errorCode} occurred")
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")
print(f"Drive Home aborted, Robot at plant {plantID}")
logging.error(f"Robot Error {errorCode} occurred")
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")
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()
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



+ 8
- 2
software/roboter/raspy/mainProg.py View File



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




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




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)
# 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…
Cancel
Save