2018-09-17 18:29:00 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
|
|
import rospy
|
|
|
|
import rospkg
|
|
|
|
|
2018-09-18 20:21:30 +02:00
|
|
|
import math
|
2018-09-25 12:51:23 +02:00
|
|
|
import datetime
|
2018-09-17 18:29:00 +02:00
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
from enums.clutch_state import ClutchState as CS
|
|
|
|
from enums.stop_state import StopState as SS
|
|
|
|
|
2018-09-20 00:00:28 +02:00
|
|
|
from python_qt_binding.QtGui import QPixmap
|
2018-09-25 12:51:23 +02:00
|
|
|
from python_qt_binding.QtWidgets import QMessageBox
|
2018-09-20 00:00:28 +02:00
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
|
2018-09-17 18:29:00 +02:00
|
|
|
class QtWrapper:
|
|
|
|
|
2018-09-17 21:39:35 +02:00
|
|
|
def __init__(self,widget):
|
|
|
|
self.widget = widget
|
2018-09-18 21:37:01 +02:00
|
|
|
self.displayed_robots_id_list = []
|
2018-09-17 18:29:00 +02:00
|
|
|
|
2018-09-20 00:00:28 +02:00
|
|
|
self.clear_robot_info()
|
|
|
|
# self.ok_pixmap = QPixmap('../ui/Ok.jpg')
|
|
|
|
self.ok_pixmap = QPixmap('/home/olek/safetysystemL1.5/src/SafetySystem/safety_user_plugin/ui/Ok.jpg')
|
|
|
|
self.cancel_pixmap = QPixmap('/home/olek/safetysystemL1.5/src/SafetySystem/safety_user_plugin/ui/Cancel.jpg')
|
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
def disconnect_signals(self):
|
|
|
|
self.widget.clutchButton.clicked.disconnect()
|
|
|
|
self.widget.stopButton.clicked.disconnect()
|
|
|
|
self.widget.choiceButton.clicked.disconnect()
|
2018-09-18 19:09:59 +02:00
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
def connect_robot_signals(self):
|
2018-09-18 19:09:59 +02:00
|
|
|
self.widget.clutchButton.clicked.connect(self.handle_clutchButton_clicked_callback)
|
2018-09-25 12:51:23 +02:00
|
|
|
self.widget.stopButton.clicked.connect(self.handle_stopButton_clicked)
|
2018-09-19 21:20:04 +02:00
|
|
|
self.widget.choiceButton.clicked.connect(self.handle_closeButton_clicked)
|
|
|
|
|
|
|
|
def connect_signals(self):
|
|
|
|
self.widget.clutchButton.clicked.connect(self.handle_not_selected_error)
|
|
|
|
self.widget.stopButton.clicked.connect(self.handle_not_selected_error)
|
|
|
|
self.widget.choiceButton.clicked.connect(self.handle_openButton_clicked)
|
|
|
|
|
|
|
|
|
|
|
|
def handle_emitted_signal(self,method_name):
|
|
|
|
exec('self.{0}()'.format(method_name))
|
|
|
|
|
|
|
|
def handle_emitted_signal_with_list_argument(self,method_name,argument):
|
|
|
|
if method_name == 'update_selected_robot_info':
|
|
|
|
self.update_selected_robot_info(argument[0])
|
|
|
|
|
|
|
|
else:
|
|
|
|
method_with_argument = 'self.{0}({1})'.format(method_name,argument[0])
|
|
|
|
exec(method_with_argument)
|
2018-09-18 19:09:59 +02:00
|
|
|
|
2018-09-25 12:51:23 +02:00
|
|
|
def handle_stopButton_clicked(self):
|
|
|
|
if self.robot_state == SS.RUNNING:
|
|
|
|
self.handle_stopButton_clicked_callback()
|
|
|
|
else:
|
|
|
|
reply = QMessageBox.warning(self.widget,"UWAGA","Na pewno chcesz odblokowac robota?",QMessageBox.Yes,QMessageBox.No)
|
|
|
|
|
|
|
|
if reply == QMessageBox.Yes:
|
|
|
|
self.handle_stopButton_clicked_callback()
|
|
|
|
|
|
|
|
|
2018-09-18 19:09:59 +02:00
|
|
|
def get_selected_robot_id(self):
|
2018-09-18 20:21:30 +02:00
|
|
|
current_text = self.widget.robotsList.currentText()
|
|
|
|
|
|
|
|
if 'PIONIER' in current_text:
|
|
|
|
return int(current_text[7:])
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2018-09-20 00:00:28 +02:00
|
|
|
def display_clutch_on(self):
|
|
|
|
self.widget.clutchLabel.setPixmap(self.ok_pixmap.scaled(40,40))
|
2018-09-25 12:51:23 +02:00
|
|
|
self.widget.clutchButton.setStyleSheet("QPushButton { color: black; background-color: green; font: bold 20px}")
|
2018-09-20 00:00:28 +02:00
|
|
|
self.widget.clutchButton.setText('Rozlacz sprzeglo')
|
|
|
|
|
|
|
|
def display_clutch_off(self):
|
|
|
|
self.widget.clutchLabel.setPixmap(self.cancel_pixmap.scaled(40,40))
|
2018-09-25 12:51:23 +02:00
|
|
|
self.widget.clutchButton.setStyleSheet("QPushButton { color: black; background-color: red; font: bold 20px}")
|
2018-09-20 00:00:28 +02:00
|
|
|
self.widget.clutchButton.setText('Polacz sprzeglo')
|
|
|
|
|
|
|
|
def display_state_on(self):
|
|
|
|
self.widget.stateLabel.setPixmap(self.ok_pixmap.scaled(40,40))
|
2018-09-25 12:51:23 +02:00
|
|
|
self.widget.stopButton.setStyleSheet("QPushButton { color: black; background-color: green; font: bold 20px}")
|
2018-09-20 00:00:28 +02:00
|
|
|
self.widget.stopButton.setText('Zatrzymaj robota')
|
2018-09-25 12:51:23 +02:00
|
|
|
self.robot_state = SS.RUNNING
|
2018-09-20 00:00:28 +02:00
|
|
|
|
|
|
|
def display_state_off(self):
|
|
|
|
self.widget.stateLabel.setPixmap(self.cancel_pixmap.scaled(40,40))
|
2018-09-25 12:51:23 +02:00
|
|
|
self.widget.stopButton.setStyleSheet("QPushButton { color: black; background-color: red; font: bold 20px}")
|
2018-09-20 00:00:28 +02:00
|
|
|
self.widget.stopButton.setText('Odblokuj robota')
|
2018-09-25 12:51:23 +02:00
|
|
|
self.robot_state = SS.STOPPED
|
2018-09-20 00:00:28 +02:00
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
def handle_not_selected_error(self):
|
|
|
|
self.log_error('Najpierw wybierz PIONIERA z listy robotow')
|
2018-09-18 19:09:59 +02:00
|
|
|
|
|
|
|
def handle_openButton_clicked(self):
|
|
|
|
selected_robot_id = self.get_selected_robot_id()
|
|
|
|
|
|
|
|
if selected_robot_id != None:
|
|
|
|
self.handle_openButton_clicked_callback(selected_robot_id)
|
|
|
|
else:
|
2018-09-19 21:20:04 +02:00
|
|
|
self.log_error('Najpierw wybierz PIONIERA z listy robotow')
|
|
|
|
|
|
|
|
def handle_closeButton_clicked(self):
|
|
|
|
self.handle_closeButton_clicked_callback()
|
2018-09-18 18:11:39 +02:00
|
|
|
|
|
|
|
def set_robot_selection_callback(self,callback):
|
2018-09-18 19:09:59 +02:00
|
|
|
self.handle_openButton_clicked_callback = callback
|
2018-09-18 18:11:39 +02:00
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
def set_robot_release_callback(self,callback):
|
|
|
|
self.handle_closeButton_clicked_callback = callback
|
|
|
|
|
2018-09-18 18:11:39 +02:00
|
|
|
def set_user_stop_state_updated_callback(self,callback):
|
2018-09-18 19:09:59 +02:00
|
|
|
self.handle_stopButton_clicked_callback = callback
|
2018-09-17 18:29:00 +02:00
|
|
|
|
2018-09-18 18:11:39 +02:00
|
|
|
def set_clutch_switched_callback(self,callback):
|
2018-09-18 19:09:59 +02:00
|
|
|
self.handle_clutchButton_clicked_callback = callback
|
2018-09-18 18:11:39 +02:00
|
|
|
|
2018-09-17 21:39:35 +02:00
|
|
|
def select_robot(self,robot_id):
|
2018-09-19 21:20:04 +02:00
|
|
|
self.disconnect_signals()
|
|
|
|
self.connect_robot_signals()
|
|
|
|
self.log_info('PIONIER' + str(robot_id) + ' wybrany!')
|
|
|
|
self.log_info('Robot zostanie zatrzymany i sprzegniety')
|
|
|
|
|
|
|
|
self.widget.choiceButton.setText('Zwolnij robota')
|
2018-09-17 19:41:31 +02:00
|
|
|
|
2018-09-18 14:56:21 +02:00
|
|
|
def release_robot(self):
|
2018-09-19 21:20:04 +02:00
|
|
|
self.disconnect_signals()
|
|
|
|
self.connect_signals()
|
2018-09-18 20:21:30 +02:00
|
|
|
self.log_info('Odlaczam robota')
|
2018-09-19 21:20:04 +02:00
|
|
|
self.clear_robot_info()
|
2018-09-17 19:41:31 +02:00
|
|
|
|
2018-09-18 14:56:21 +02:00
|
|
|
def update_robots_list_gui(self,robots_id_list):
|
2018-09-18 19:09:59 +02:00
|
|
|
robots_id_list.sort()
|
|
|
|
id_strings_list = (('PIONIER'+str(x)) for x in robots_id_list)
|
2018-09-18 21:37:01 +02:00
|
|
|
|
|
|
|
robots_to_add = []
|
|
|
|
robots_to_remove = []
|
|
|
|
|
|
|
|
for robot_id in robots_id_list:
|
|
|
|
if robot_id not in self.displayed_robots_id_list:
|
|
|
|
robots_to_add.append(robot_id)
|
|
|
|
|
|
|
|
for robot_id in self.displayed_robots_id_list:
|
|
|
|
if robot_id not in robots_id_list:
|
|
|
|
robots_to_remove.append(robot_id)
|
|
|
|
|
|
|
|
for robot_id in robots_to_remove:
|
|
|
|
self.remove_robot_from_list(robot_id)
|
|
|
|
|
|
|
|
for robot_id in robots_to_add:
|
|
|
|
self.add_robot_to_list(robot_id)
|
|
|
|
|
|
|
|
|
|
|
|
def remove_robot_from_list(self,robot_id):
|
|
|
|
count = self.widget.robotsList.count()
|
|
|
|
|
|
|
|
for i in range(count):
|
|
|
|
if str(robot_id) in self.widget.robotsList.itemText(i):
|
|
|
|
self.widget.robotsList.removeItem(i)
|
|
|
|
self.displayed_robots_id_list.remove(robot_id)
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
def add_robot_to_list(self,robot_id):
|
|
|
|
self.widget.robotsList.addItem('PIONIER'+str(robot_id))
|
|
|
|
self.displayed_robots_id_list.append(robot_id)
|
2018-09-18 19:09:59 +02:00
|
|
|
|
2018-09-18 14:56:21 +02:00
|
|
|
|
2018-09-17 21:39:35 +02:00
|
|
|
def update_selected_robot_info(self,robot_info):
|
2018-09-18 20:21:30 +02:00
|
|
|
linear_vel = math.sqrt(robot_info.linear_velocity[0]**2 + robot_info.linear_velocity[1]**2)
|
|
|
|
|
2018-09-18 21:47:49 +02:00
|
|
|
self.widget.idLabel.setText('PIONIER' + str(robot_info.robot_id))
|
2018-09-18 20:21:30 +02:00
|
|
|
self.widget.batteryLabel.setText("{:.2f}".format(robot_info.battery_voltage))
|
|
|
|
self.widget.linearLabel.setText("{:.2f}".format(linear_vel))
|
|
|
|
self.widget.angularLabel.setText("{:.2f}".format(robot_info.angular_velocity[2]))
|
2018-09-19 21:48:09 +02:00
|
|
|
|
|
|
|
# self.log_info(str(robot_info.clutch == CS.ENGAGED))
|
2018-09-18 20:21:30 +02:00
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
if robot_info.clutch == CS.ENGAGED:
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_clutch_on()
|
2018-09-18 20:21:30 +02:00
|
|
|
else:
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_clutch_off()
|
2018-09-18 20:21:30 +02:00
|
|
|
|
2018-09-19 21:20:04 +02:00
|
|
|
if robot_info.state == SS.RUNNING:
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_state_on()
|
2018-09-18 20:21:30 +02:00
|
|
|
else:
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_state_off()
|
2018-09-17 21:39:35 +02:00
|
|
|
|
2018-09-18 01:46:10 +02:00
|
|
|
def master_stopped(self):
|
2018-09-18 20:21:30 +02:00
|
|
|
self.log_info('Przycisk masterSTOP zostal nacisniety. Zatrzymuje roboty')
|
2018-09-17 21:39:35 +02:00
|
|
|
|
2018-09-18 01:46:10 +02:00
|
|
|
def master_started(self):
|
2018-09-18 20:21:30 +02:00
|
|
|
self.log_info('Przycisk masterSTOP odcisniety. Mozesz uruchomic robota')
|
2018-09-17 21:39:35 +02:00
|
|
|
|
2018-09-18 01:46:10 +02:00
|
|
|
def user_stopped(self):
|
2018-09-19 21:20:04 +02:00
|
|
|
self.log_info('Robot zatrzymany')
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_state_off()
|
2018-09-17 21:39:35 +02:00
|
|
|
|
2018-09-18 01:46:10 +02:00
|
|
|
def user_started(self):
|
2018-09-18 20:21:30 +02:00
|
|
|
self.log_info('Robot wystartowal')
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_state_on()
|
2018-09-18 14:56:21 +02:00
|
|
|
|
|
|
|
def disengage_clutch(self):
|
2018-09-19 21:20:04 +02:00
|
|
|
self.log_info('Rozprzegam sprzeglo')
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_clutch_off()
|
2018-09-18 20:21:30 +02:00
|
|
|
|
|
|
|
def engage_clutch(self):
|
2018-09-19 21:20:04 +02:00
|
|
|
self.log_info('Sprzegam sprzeglo')
|
2018-09-20 00:00:28 +02:00
|
|
|
self.display_clutch_on()
|
|
|
|
|
2018-09-18 01:46:10 +02:00
|
|
|
def master_is_stopped_notify(self):
|
2018-09-18 20:21:30 +02:00
|
|
|
self.log_error('Nie mozna wystartowac robota. MasterSTOP wcisniety!')
|
2018-09-18 14:56:21 +02:00
|
|
|
|
|
|
|
def update_restrictions_gui(self,restrictions):
|
2018-09-19 21:48:09 +02:00
|
|
|
self.widget.distanceRestrictionLabel.setText("{:.2f}".format(restrictions.distance))
|
|
|
|
self.widget.linearRestrictionLabel.setText("{:.2f}".format(restrictions.linear_velocity))
|
|
|
|
self.widget.angularRestrictionLabel.setText("{:.2f}".format(restrictions.angular_velocity))
|
2018-09-18 20:21:30 +02:00
|
|
|
|
|
|
|
def log_info(self,info_text):
|
2018-09-25 12:51:23 +02:00
|
|
|
time = datetime.datetime.now().strftime('[%H:%M:%S]')
|
|
|
|
self.widget.logsBrowser.insertHtml('<font color="black">' + str(time) + '. ' + info_text + '</font><br>')
|
2018-09-18 20:21:30 +02:00
|
|
|
self.scroll_to_bottom()
|
|
|
|
# self.widget.logsBrowser.insertHtml(str(self.logger_counter) + '\t[INFO]\t' + info_text)
|
|
|
|
|
|
|
|
def log_warning(self,warning_text):
|
2018-09-25 12:51:23 +02:00
|
|
|
time = datetime.datetime.now().strftime('[%H:%M:%S]')
|
|
|
|
self.widget.logsBrowser.insertHtml('<font color="orange">' + str(time) + '. ' + warning_text + '</font><br> ')
|
2018-09-18 20:21:30 +02:00
|
|
|
self.scroll_to_bottom()
|
|
|
|
# self.widget.logsBrowser.append(str(self.logger_counter) + '\t[WARN]\t' + warning_text)
|
|
|
|
|
|
|
|
def log_error(self,error_text):
|
2018-09-25 12:51:23 +02:00
|
|
|
time = datetime.datetime.now().strftime('[%H:%M:%S]')
|
|
|
|
self.widget.logsBrowser.insertHtml('<font color="red">' + str(time) + '. ' + error_text + '</font><br>')
|
2018-09-18 20:21:30 +02:00
|
|
|
self.scroll_to_bottom()
|
|
|
|
# self.widget.logsBrowser.append(str(self.logger_counter) + '\t[ERROR]\t' + error_text)
|
2018-09-18 14:56:21 +02:00
|
|
|
|
2018-09-18 20:21:30 +02:00
|
|
|
def connection_to_robot_lost(self,lost_robot_id):
|
2018-09-19 21:59:30 +02:00
|
|
|
self.clear_robot_info()
|
|
|
|
self.disconnect_signals()
|
|
|
|
self.connect_signals()
|
2018-09-18 20:21:30 +02:00
|
|
|
self.log_info('Utrata polaczenia z robotem PIONIER' + str(lost_robot_id))
|
2018-09-18 14:56:21 +02:00
|
|
|
|
|
|
|
|
2018-09-18 20:21:30 +02:00
|
|
|
def scroll_to_bottom(self):
|
|
|
|
scrollbar = self.widget.logsBrowser.verticalScrollBar()
|
2018-09-19 21:20:04 +02:00
|
|
|
scrollbar.setValue(scrollbar.maximum())
|
|
|
|
|
|
|
|
|
|
|
|
def clear_robot_info(self):
|
|
|
|
self.widget.idLabel.setText('-')
|
|
|
|
self.widget.batteryLabel.setText('-')
|
|
|
|
self.widget.linearLabel.setText('-')
|
|
|
|
self.widget.angularLabel.setText('-')
|
|
|
|
self.widget.stateLabel.setText('-')
|
|
|
|
self.widget.clutchLabel.setText('-')
|
|
|
|
|
2018-09-20 00:00:28 +02:00
|
|
|
self.widget.choiceButton.setText('Wybierz')
|
|
|
|
|
|
|
|
self.widget.stopButton.setText('-')
|
|
|
|
self.widget.stopButton.setStyleSheet("")
|
|
|
|
|
|
|
|
self.widget.clutchButton.setText('-')
|
|
|
|
self.widget.clutchButton.setStyleSheet("")
|