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

#!/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

import raspy_sensors as Sensors import raspy_sensors as Sensors
from defines import Topics, SENSORDATA, ALLSENSORDATA from defines import Topics, SENSORDATA, ALLSENSORDATA


import time


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


if errorCode != 0: 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) client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)


return return
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}')


if errorCode != 0: 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) client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return return


# FIXME Only possible with color codes # FIXME Only possible with color codes
logging.info(f"Robot Driving to plant {plant}") 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}') errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_plant.py {plant}')

if errorCode != 0: 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) client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return return


errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_arm.py {plant}') errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_arm.py {plant}')
if errorCode != 0: 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) client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return return


logging.info("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_straight.py') errorCode = os.system(f'sshpass -p maker ssh robot@ev3dev.local python3 /home/robot/Programme/drive_back_straight.py')
if errorCode != 0: 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) client.publish(Topics["ROBOT_DATA_ROBOTREADY"], "True", qos=1)
return return


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:
logging.error("Robot not connected")
logging.error("EV3 not connected")
client.publish(Topics["ROBOT_DATA_ERROR"], "Robot not connected", qos=1) client.publish(Topics["ROBOT_DATA_ERROR"], "Robot not connected", qos=1)
return return



Loading…
Cancel
Save