Browse Source

Autostart added, EV3 error handling improved

master
Luis Waldhauser 1 year ago
parent
commit
5e21e4b2c5
2 changed files with 46 additions and 17 deletions
  1. 9
    0
      software/roboter/raspy/autostart.sh
  2. 37
    17
      software/roboter/raspy/functions.py

+ 9
- 0
software/roboter/raspy/autostart.sh View File

@@ -0,0 +1,9 @@
#!/bin/bash

# Script to automatically start the robot operating programm
# Has to be included to autostart of the RaspberryPi

cd ~/Documents/GIT/projektarbeit_duelger_waldhauser_caliskan/
source .venv/bin/activate
cd software/roboter/raspy
python3 mainProg.py

+ 37
- 17
software/roboter/raspy/functions.py View File

@@ -6,7 +6,6 @@ import logging
import raspy_sensors as Sensors
from defines import Topics, SENSORDATA, ALLSENSORDATA

import time

def measure_send_data(plantID, actionID, client: mqtt.Client):
"""
@@ -47,9 +46,13 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client):
# errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plantID}')

if errorCode != 0:
logging.error(f"Robot Error {errorCode} occurred")
logging.info("Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], "Drive Plant aborted, Robot at starting position", qos=1)
if errorCode == 65280:
errorMessage = "EV3 not connected"
else:
errorMessage = "Motor or Sensor unplugged"
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at starting position", qos=1)
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)

return
@@ -65,9 +68,13 @@ def drive_plant_thread(plantID, actionID, client: mqtt.Client):
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back.py {plantID}')

if errorCode != 0:
logging.error(f"Robot Error {errorCode} occurred")
logging.info(f"Drive Home aborted, Robot at plant {plantID}")
client.publish(Topics["ROBOT_DATA_ERROR"], f"Drive Home aborted, Robot at plant {plantID}", qos=1)
if errorCode == 65280:
errorMessage = "EV3 not connected"
else:
errorMessage = "Motor or Sensor unplugged"
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at plant {plantID}", qos=1)
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return

@@ -98,10 +105,15 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
# FIXME Only possible with color codes
logging.info(f"Robot Driving to plant {plant}")
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plant}')

if errorCode != 0:
logging.error(f"Robot Error {errorCode} occurred")
logging.info("Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], "Drive Plant aborted, Robot at starting position", qos=1)
if errorCode == 65280:
errorMessage = "EV3 not connected"
else:
errorMessage = "Motor or Sensor unplugged"
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at starting position", qos=1)
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return
@@ -125,9 +137,13 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):

errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_arm.py {plant}')
if errorCode != 0:
logging.error(f"Robot Error {errorCode} occurred")
logging.info("Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], f"Rotate arm aborted, Robot at plant {plant}", qos=1)
if errorCode == 65280:
errorMessage = "EV3 not connected"
else:
errorMessage = "Motor or Sensor unplugged"
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at plant {plant}", qos=1)
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return

@@ -138,9 +154,13 @@ def drive_plant_all_thread(plantIDs: list, actionID, client: mqtt.Client):
logging.info("Robot driving home")
errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back_straight.py')
if errorCode != 0:
logging.error(f"Robot Error {errorCode} occurred")
logging.info(f"Drive Home aborted, Robot at plant {plant}")
client.publish(Topics["ROBOT_DATA_ERROR"], f"Drive Home aborted, Robot at plant {plant}", qos=1)
if errorCode == 65280:
errorMessage = "EV3 not connected"
else:
errorMessage = "Motor or Sensor unplugged"
logging.info(f"{errorMessage}, Drive Plant aborted, Robot at starting position")
client.publish(Topics["ROBOT_DATA_ERROR"], f"{errorMessage}, Drive Plant aborted, Robot at plant {plant}", qos=1)
client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return

@@ -231,7 +251,7 @@ def get_batteryStatus(client: mqtt.Client, userdata, message: mqtt.MQTTMessage):
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())
except:
logging.error("Robot not connected")
logging.error("EV3 not connected")
client.publish(Topics["ROBOT_DATA_ERROR"], "Robot not connected", qos=1)
return


Loading…
Cancel
Save