Displaying list of robot works for master plugin

This commit is contained in:
Olek Bojda 2018-09-26 23:01:04 +02:00
parent 09d9f6b653
commit 62e7d10641
4 changed files with 110 additions and 67 deletions

View File

@ -85,21 +85,14 @@ class MasterPlugin(Plugin):
self._master_info.robots_id_list = robots_id_list
def new_robot_registered(self,robot_id):
# raise NotImplementedError
self._ros_wrapper.add_robot_subscriber(robot_id)
self.cbhandler.add_robot_signal.emit(robot_id)
# self._qt_wrapper.add_robot(robot_id)
def robot_unregistered(self,robot_id):
# raise NotImplementedError
self._ros_wrapper.remove_robot_subscriber(robot_id)
self.cbhandler.remove_robot_signal.emit(robot_id)
# self._qt_wrapper.remove_robot(robot_id)
def update_robot_info(self,robot_info):
# TODO emit signal to qt_wrapper where it will update info about one of robots
# self._qt_wrapper.update_robot_info(self,robot_info)
# raise NotImplementedError
self.cbhandler.robot_info_signal.emit(robot_info)
def master_started(self):

View File

@ -13,7 +13,13 @@ from master_restrictions import Restrictions
from python_qt_binding.QtGui import QPixmap
from python_qt_binding.QtGui import QTextCursor
from python_qt_binding.QtGui import QStandardItem
from python_qt_binding.QtGui import QStandardItemModel
from python_qt_binding.QtGui import QBrush
from python_qt_binding.QtWidgets import QMessageBox
from python_qt_binding.QtWidgets import QHeaderView
from python_qt_binding.QtWidgets import QAbstractItemView
from python_qt_binding.QtCore import Qt
class QtWrapper:
@ -23,6 +29,7 @@ class QtWrapper:
self.displayed_robots_id_list = []
self.master_stop_state = None
self.init_robots_list()
# self.disable_sliders_tracking()
@ -38,6 +45,28 @@ class QtWrapper:
self.widget.angularSlider.setValue(100)
self.widget.linearSlider.setValue(100)
def init_robots_list(self):
self.stdItemModel = QStandardItemModel( 0, 6, self.widget.robotsList)
self.stdItemModel.setHeaderData( 0, Qt.Horizontal, 'Robot' )
self.stdItemModel.setHeaderData( 1, Qt.Horizontal, 'Stan baterii' )
self.stdItemModel.setHeaderData( 2, Qt.Horizontal, 'Stan robota' )
self.stdItemModel.setHeaderData( 3, Qt.Horizontal, 'Stan sprzegla' )
self.stdItemModel.setHeaderData( 4, Qt.Horizontal, 'Predk. lin.' )
self.stdItemModel.setHeaderData( 5, Qt.Horizontal, 'Predk. obr.' )
self.widget.robotsList.setModel(self.stdItemModel)
self.widget.robotsList.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
self.widget.robotsList.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
self.widget.robotsList.horizontalHeader().setSectionResizeMode(2, QHeaderView.Stretch)
self.widget.robotsList.horizontalHeader().setSectionResizeMode(3, QHeaderView.Stretch)
self.widget.robotsList.horizontalHeader().setSectionResizeMode(4, QHeaderView.Stretch)
self.widget.robotsList.horizontalHeader().setSectionResizeMode(5, QHeaderView.Stretch)
self.widget.robotsList.horizontalHeader().setSectionsMovable(False)
# self.widget.robotsList.setSelectionBehavior(QAbstractItemView.SelectRows)
self.widget.robotsList.setSelectionMode(QAbstractItemView.NoSelection)
def disable_sliders_tracking(self):
self.widget.distanceSlider.setTracking(False)
@ -73,17 +102,6 @@ class QtWrapper:
self.set_sliders_to_initial_values()
# 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)
def handle_masterstopButton_clicked(self):
if self.master_stop_state == SS.RUNNING:
self.master_stop_state_updated_callback()
@ -93,7 +111,6 @@ class QtWrapper:
if reply == QMessageBox.Yes:
self.master_stop_state_updated_callback()
def display_master_stop_on(self):
self.widget.masterstopButton.setStyleSheet("QPushButton { color: black; background-color: green; font: bold 20px}")
self.widget.masterstopButton.setText('Zatrzymaj roboty')
@ -103,47 +120,61 @@ class QtWrapper:
self.widget.masterstopButton.setText('Odblokuj roboty')
def update_robots_list_gui(self,robots_id_list):
robots_id_list.sort()
id_strings_list = (('PIONIER'+str(x)) for x in robots_id_list)
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 update_robot_info(self,robot_info):
self.log_info(str(robot_info.robot_id))
items_to_add = []
items_to_add.append(QStandardItem('PIONIER{}'.format(robot_info.robot_id)))
items_to_add.append(QStandardItem('{:.2f}'.format(robot_info.battery_voltage)))
if robot_info.state == SS.RUNNING:
item = QStandardItem('Dziala')
item.setBackground(QBrush(Qt.green))
items_to_add.append(item)
elif robot_info.state == SS.STOPPED:
item = QStandardItem('Zatrzymany')
item.setBackground(QBrush(Qt.red))
items_to_add.append(item)
else:
raise ValueError('Undefined value of robot_info.robot_state')
if robot_info.clutch == CS.ENGAGED:
item = QStandardItem('Sprzegniete')
item.setBackground(QBrush(Qt.green))
items_to_add.append(item)
elif robot_info.clutch == CS.DISENGAGED:
item = QStandardItem('Rozprzegniete')
item.setBackground(QBrush(Qt.red))
items_to_add.append(item)
else:
raise ValueError('Undefined value of robot_info.clutch_state')
linear_vel = math.sqrt(robot_info.linear_velocity[0]**2 + robot_info.linear_velocity[1]**2)
items_to_add.append(QStandardItem('{:.2f}'.format(linear_vel)))
items_to_add.append(QStandardItem('{:.2f}'.format(robot_info.angular_velocity[2])))
items_list = self.stdItemModel.findItems('PIONIER{0}'.format(robot_info.robot_id),Qt.MatchExactly)
if len(items_list) > 0:
for item in items_list:
row_number = item.row()
else:
row_number = self.stdItemModel.rowCount()
for i,item in enumerate(items_to_add):
item.setTextAlignment(Qt.AlignCenter)
item.setEditable(0)
self.stdItemModel.setItem(row_number,i,item)
# new_robot_info2=QStandardItem('PIONIER'+str(robot_id))
# new_robot_info3=QStandardItem('PIONIER'+str(robot_id))
# new_robot_info4=QStandardItem('PIONIER'+str(robot_id))
# new_robot_info5=QStandardItem('PIONIER'+str(robot_id))
# new_robot_info6=QStandardItem('PIONIER'+str(robot_id))
# items_list = [new_robot_info,new_robot_info2,new_robot_info3,new_robot_info4,new_robot_info5,new_robot_info6]
# self.stdItemModel.insertRow(self.stdItemModel.rowCount(),items_list)
# raise NotImplementedError
# 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)
def master_stopped(self):
self.master_stop_state = SS.STOPPED
self.display_master_stop_off()
@ -156,14 +187,30 @@ class QtWrapper:
def add_robot(self,robot_id):
self.log_info('PIONIER{0} polaczony'.format(robot_id))
if robot_id not in self.displayed_robots_id_list:
new_robot_info=QStandardItem('PIONIER{}'.format(robot_id))
new_robot_info.setTextAlignment(Qt.AlignCenter)
new_robot_info.setEditable(0)
# new_robot_info.setBackground(QBrush(Qt.white))
self.stdItemModel.setItem(self.stdItemModel.rowCount(),0,new_robot_info)
self.displayed_robots_id_list.append(robot_id)
self.log_info('PIONIER{0} polaczony'.format(robot_id))
else:
raise RuntimeError('Adding robot, which is already in master GUI')
def remove_robot(self,robot_id):
items_list = self.stdItemModel.findItems('PIONIER{0}'.format(robot_id),Qt.MatchExactly)
if len(items_list) > 0:
for item in items_list:
row_number = item.row()
self.stdItemModel.removeRow(row_number)
self.log_info('PIONIER{0} rozlaczony'.format(robot_id))
self.displayed_robots_id_list.remove(robot_id)
def log_info(self,info_text):
time = datetime.datetime.now().strftime('[%H:%M:%S]')
@ -172,7 +219,6 @@ class QtWrapper:
self.widget.logsBrowser.setTextCursor(cursor)
self.widget.logsBrowser.insertHtml('<font color="black">' + str(time) + '. ' + info_text + '</font><br>')
self.scroll_to_bottom()
# self.widget.logsBrowser.insertHtml(str(self.logger_counter) + '\t[INFO]\t' + info_text)
def log_warning(self,warning_text):
time = datetime.datetime.now().strftime('[%H:%M:%S]')
@ -183,7 +229,6 @@ class QtWrapper:
self.widget.logsBrowser.textCursor().movePosition(QTextCursor.End)
self.widget.logsBrowser.insertHtml('<font color="orange">' + str(time) + '. ' + warning_text + '</font><br> ')
self.scroll_to_bottom()
# self.widget.logsBrowser.append(str(self.logger_counter) + '\t[WARN]\t' + warning_text)
def log_error(self,error_text):
time = datetime.datetime.now().strftime('[%H:%M:%S]')
@ -194,7 +239,6 @@ class QtWrapper:
self.widget.logsBrowser.textCursor().movePosition(QTextCursor.End)
self.widget.logsBrowser.insertHtml('<font color="red">' + str(time) + '. ' + error_text + '</font><br>')
self.scroll_to_bottom()
# self.widget.logsBrowser.append(str(self.logger_counter) + '\t[ERROR]\t' + error_text)
def scroll_to_bottom(self):
scrollbar = self.widget.logsBrowser.verticalScrollBar()

View File

@ -25,8 +25,7 @@ class ROSWrapper:
self.periodic_timer = None
self.setup_subscribers_and_publishers()
# def setup_node(self):
# rospy.init_node('safety_user_plugin', anonymous=True)
def setup_subscribers_and_publishers(self):
self.master_stop_publisher = rospy.Publisher('/RosAria/master_stop',Bool,queue_size = 1)

View File

@ -13,9 +13,16 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="2,0,2,0,1">
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0,0,2,0,1">
<item>
<widget class="QListView" name="robotsList"/>
<widget class="QTableView" name="robotsList">
<property name="textElideMode">
<enum>Qt::ElideMiddle</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">