Пример #1
0
    def __init__(self, parent, label_name,topic_name,topic_type,topic_field,buffer_size):
        
        self.label_name= label_name
        self.topic_type = topic_type
        self.topic_name = topic_name
        self.topic_field = topic_field
        self.buffer_size = buffer_size
        
        self.timer = QTimer()
        self.timer.setInterval(100)
        self.timer.timeout.connect(self.update_figure)
        
        fig = Figure(figsize=(5, 4), dpi=100)
        self.axes = fig.add_subplot(111)
        # We want the axes cleared every time plot() is called
        self.axes.hold(False)

        self.compute_initial_figure()
        self.buffer = collections.deque(maxlen=self.buffer_size)

        
        FigureCanvas.__init__(self, fig)
        self.setParent(parent)

        FigureCanvas.setSizePolicy(self,
                                   QtGui.QSizePolicy.Expanding,
                                   QtGui.QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)
        
        self.subscriber = RosHelper.create_subscriber_from_type(self.topic_name,self.topic_type,self.on_message)
        self.timer.start()
Пример #2
0
    def __init__(self, parent, label_name, topic_name, topic_type, topic_field,
                 buffer_size):

        self.label_name = label_name
        self.topic_type = topic_type
        self.topic_name = topic_name
        self.topic_field = topic_field
        self.buffer_size = buffer_size

        self.timer = QTimer()
        self.timer.setInterval(100)
        self.timer.timeout.connect(self.update_figure)

        fig = Figure(figsize=(5, 4), dpi=100)
        self.axes = fig.add_subplot(111)
        # We want the axes cleared every time plot() is called
        self.axes.hold(False)

        self.compute_initial_figure()
        self.buffer = collections.deque(maxlen=self.buffer_size)

        FigureCanvas.__init__(self, fig)
        self.setParent(parent)

        FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding,
                                   QtGui.QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)

        self.subscriber = RosHelper.create_subscriber_from_type(
            self.topic_name, self.topic_type, self.on_message)
        self.timer.start()
Пример #3
0
 def __init__(self,parent,label_name,topic_name,topic_type,topic_field):
     super(RosLabel,self).__init__(label_name,parent)
     self.label_name = label_name
     self.topic_name = topic_name
     self.topic_type = topic_type
     self.topic_field = topic_field
     self.subscriber = RosHelper.create_subscriber_from_type(self.topic_name,self.topic_type,self.onmsg)
     self.setText("N/A")
Пример #4
0
 def __init__(self,parent,label_name,topic_name,topic_type,topic_field):
     super(RosLabel,self).__init__(label_name,parent)
     self.label_name = label_name
     self.topic_name = topic_name
     self.topic_type = topic_type
     self.topic_field = topic_field
     self.subscriber = RosHelper.create_subscriber_from_type(self.topic_name,self.topic_type,self.onmsg)
     self.setText("N/A")
Пример #5
0
 def __init__(self,parent,name,topic_name,topic_type,topic_fields):
     super(RosMsgView,self).__init__(name,parent)
     self.topic_name = topic_name
     self.topic_type = topic_type
     self.topic_fields = topic_fields
     self.ref_dict = {}
     self.layout = QGridLayout()
     self.__populate_self()
     self.subscriber = RosHelper.create_subscriber_from_type(self.topic_name,self.topic_type,self.onmsg)
Пример #6
0
 def __init__(self,parent,name,topic_name,topic_type,topic_fields):
     super(RosMsgView,self).__init__(name,parent)
     self.topic_name = topic_name
     self.topic_type = topic_type
     self.topic_fields = topic_fields
     self.ref_dict = {}
     self.layout = QGridLayout()
     self.__populate_self()
     self.subscriber = RosHelper.create_subscriber_from_type(self.topic_name,self.topic_type,self.onmsg)
Пример #7
0
    def onval(self, val):
        val = float(val) * self.factor_a + self.factor_b
        #print "value:", val, " a: ", self.factor_a, " b: ",self.factor_b
        msg = RosHelper.create_msg_from_type(self.topic_type)

        #  iterate through msg attributes according to topic field and write value
        r = msg
        fields = self.topic_field.split(".")[1:]
        for subfields in fields[:len(fields) - 1]:
            r = getattr(r, subfields)
        setattr(r, fields[len(fields) - 1], val)
        self.publisher.publish(msg)
Пример #8
0
 def __init__(self,parent,btn_name,topic_name,topic_type,topic_field,toggle_dict):
     super(RosToggleButton,self).__init__(btn_name,parent)
     self.btn_name = btn_name
     self.topic_name = topic_name
     self.topic_type = topic_type
     self.topic_field = topic_field
     self.toggle_dict = toggle_dict
     self.setText("N/A")
     self.publisher = RosHelper.create_publisher_from_type(self.topic_name,self.topic_type)
     self.clicked.connect(self.onclick)
     self.cur_idx = 0
     self.max_idx = len(toggle_dict.keys())-1
Пример #9
0
    def onval(self,val):
        val = float(val) * self.factor_a + self.factor_b
        #print "value:", val, " a: ", self.factor_a, " b: ",self.factor_b
        msg = RosHelper.create_msg_from_type(self.topic_type)

        #  iterate through msg attributes according to topic field and write value
        r = msg
        fields =self.topic_field.split(".")[1:]
        for subfields in fields[:len(fields)-1]:
            r = getattr(r,subfields) 
        setattr(r, fields[len(fields)-1], val)
        self.publisher.publish(msg)
Пример #10
0
 def __populate_self(self):
     i = 1
     if len(self.topic_fields) == 0:
         fields = RosHelper.get_all_msg_fields(self.topic_type)
     else:  
         fields = self.topic_fields
         
     for field in fields:
         self.ref_dict[field] = QLabel("None",self)
         self.layout.addWidget(QLabel(field,self),i,1)
         self.layout.addWidget(self.ref_dict[field],i,2)
         i+=1
     self.setLayout(self.layout)
Пример #11
0
    def __populate_self(self):
        i = 1
        if len(self.topic_fields) == 0:
            fields = RosHelper.get_all_msg_fields(self.topic_type)
        else:
            fields = self.topic_fields

        for field in fields:
            self.ref_dict[field] = QLabel("None", self)
            self.layout.addWidget(QLabel(field, self), i, 1)
            self.layout.addWidget(self.ref_dict[field], i, 2)
            i += 1
        self.setLayout(self.layout)
Пример #12
0
 def __init__(self, parent, btn_name, topic_name, topic_type, topic_field,
              toggle_dict):
     super(RosToggleButton, self).__init__(btn_name, parent)
     self.btn_name = btn_name
     self.topic_name = topic_name
     self.topic_type = topic_type
     self.topic_field = topic_field
     self.toggle_dict = toggle_dict
     self.setText("N/A")
     self.publisher = RosHelper.create_publisher_from_type(
         self.topic_name, self.topic_type)
     self.clicked.connect(self.onclick)
     self.cur_idx = 0
     self.max_idx = len(toggle_dict.keys()) - 1
Пример #13
0
    def onclick(self, msg):

        key = self.toggle_dict.keys()[self.cur_idx]
        val = self.toggle_dict[key]

        self.setText(str(key))
        msg = RosHelper.create_msg_from_type(self.topic_type)

        #  iterate through msg attributes according to topic field and write value
        r = msg
        fields = self.topic_field.split(".")[1:]
        for subfields in fields[:len(fields) - 1]:
            r = getattr(r, subfields)
        setattr(r, fields[len(fields) - 1], val)
        self.publisher.publish(msg)

        if self.cur_idx < self.max_idx:
            self.cur_idx += 1
        else:
            self.cur_idx = 0
Пример #14
0
    def onclick(self,msg):

        key = self.toggle_dict.keys()[self.cur_idx]
        val = self.toggle_dict[key]
        
        self.setText(str(key))
        msg = RosHelper.create_msg_from_type(self.topic_type)

        #  iterate through msg attributes according to topic field and write value
        r = msg
        fields =self.topic_field.split(".")[1:]
        for subfields in fields[:len(fields)-1]:
            r = getattr(r,subfields) 
        setattr(r, fields[len(fields)-1], val)
        self.publisher.publish(msg)
        
        if self.cur_idx < self.max_idx:
            self.cur_idx += 1
        else:
            self.cur_idx = 0
Пример #15
0
 def __init__(self,parent,label_name,topic_name,topic_type,topic_field,min_max_tuple,default):
     super(RosSlider,self).__init__(QtCore.Qt.Horizontal,parent)
     self.label_name = label_name
     self.topic_name = topic_name
     self.topic_type = topic_type
     self.topic_field = topic_field
     self.setMinimum(0)
     self.setMaximum(100)
     self.min = min_max_tuple[0]
     self.max = min_max_tuple[1]
     self.factor_a =  (self.max - self.min) / 100.0
     self.factor_b = self.max  - self.factor_a*100.0
     self.default = int(( default - self.factor_b ) / self.factor_a) 
     
     if self.default is not None:
         print "setting default to:", self.default, "%"
         self.setValue(self.default )
     
     self.publisher = RosHelper.create_publisher_from_type(self.topic_name,self.topic_type)
     self.valueChanged.connect(self.onval)
     
     self.onval(self.default)