Example #1
0
 def callback_Triggered(self, data):
     topic = self.param_out_topic
     if topic[0] == '/':
         topic = topic[1:len(topic)]
     self.time_triggered = time.time()
     self.triggered = True
     obs_msg = []
     if self.triggering:
         self.triggering = False
         diff_t = self.time_triggered - self.time_triggering
         if diff_t <= self.req_delta_t:
             obs_msg.append('ok(' + topic + '_Triggered)')
             print "\nIn Time Triggered after seconds : ", diff_t
             print 'ok(' + topic + '_Triggered)'
             self.pub.publish(Observations(time.time(), obs_msg))
         else:
             obs_msg.append('~ok(' + topic + '_Triggered)')
             self.pub.publish(Observations(time.time(), obs_msg))
             print "Late Triggered after seconds : ", diff_t
             print '~ok(' + topic + '_Triggered)'
         self.triggered = True
     else:
         print '~ok(' + topic + '_Triggered)'
         obs_msg.append('~ok(' + topic + '_Triggered)')
         self.pub.publish(Observations(time.time(), obs_msg))
Example #2
0
 def start(self):
     print "NObs is up...."
     if self.param_node_name[0] != '/':
         self.param_node_name = "/%s" % (self.param_node_name)
     r = rospy.Rate(10)  # 10hz
     while not rospy.is_shutdown():
         found = False
         code, statusMessage, sysState = self.m.getSystemState(
             self.caller_id)
         for lst in sysState:
             for row in lst:
                 for node in row[1]:
                     if node == self.param_node_name:
                         found = True
                         break
         obs_msg = []
         if found == True:
             self.msg = 'running(' + self.param_node_name[
                 1:len(self.param_node_name)] + ')'
             rospy.loginfo(
                 'running(' +
                 self.param_node_name[1:len(self.param_node_name)] + ')')
             obs_msg.append(self.msg)
             self.pub.publish(Observations(time.time(), obs_msg))
         else:
             self.msg = '~running(' + self.param_node_name[
                 1:len(self.param_node_name)] + ')'
             rospy.loginfo(
                 '~running(' +
                 self.param_node_name[1:len(self.param_node_name)] + ')')
             obs_msg.append(self.msg)
             self.pub.publish(Observations(time.time(), obs_msg))
         r.sleep()
Example #3
0
 def access_data(self, data):
     temp_data = data
     for f in temp_data.__slots__:
         if f == "status":
             a = getattr(temp_data, f)
             i = 0
             print "\n"
             while (i < len(a)):
                 obs_msg = []
                 if self.param_dev_node in a[i].name:
                     if a[i].level == 0:
                         print "Name:", a[i].name, "OK"
                         obs_msg.append('ok(' + self.param_dev_node + ')')
                         self.pub.publish(Observations(
                             time.time(), obs_msg))
                     elif a[i].level == 1:
                         print "Name:", a[i].name, "WARNINNG"
                         obs_msg.append('n_ok(' + self.param_dev_node + ')')
                         self.pub.publish(Observations(
                             time.time(), obs_msg))
                     else:
                         print "Name:", a[i].name, "ERROR"
                         obs_msg.append('n_ok(' + self.param_dev_node + ')')
                         self.pub.publish(Observations(
                             time.time(), obs_msg))
                 else:
                     print self.param_dev_node + " not found."
                 i = i + 1
 def check_topic(self, string, sleeptime, *args):
     try:
         while not rospy.is_shutdown():
             t = 0
             m = xmlrpclib.ServerProxy(os.environ['ROS_MASTER_URI'])
             pubcode, statusMessage, topicList = m.getPublishedTopics(
                 self.caller_id, "")
             for item in topicList:
                 if item[0] == string:
                     t = 1
                     if time.time() - self.prev_t > 2:
                         rospy.loginfo('~ok(' + self.topic_name + ')')
                         self.pub.publish(
                             Observations(time.time(),
                                          ['~ok(' + self.topic_name + ')']))
                     break
             if t == 0:
                 t = 1
                 self.msg = '~ok(' + self.topic_name + ')'
                 rospy.loginfo('~ok(' + self.topic_name + ')')
                 self.pub.publish(Observations(time.time(), [self.msg]))
             time.sleep(sleeptime)  #sleep for a specified amount of time.
     except:
         print "An unhandled exception occured, here's the traceback!"
         traceback.print_exc()
		def publish_output(self,obtained_val):
					obs_msg = []
					if (float(obtained_val) >= float(self.th) - float(self.dev)) | (float(obtained_val) <= float(self.th) + float(self.dev))  :
							print 'ok('+self.property+','+self.node+')'
							obs_msg.append('ok('+self.property+','+self.node+')')
							self.pub.publish(Observations(time.time(),obs_msg))
					else:
							print '~ok('+self.property+','+self.node+')'
							obs_msg.append('~ok('+self.property+','+self.node+')')
							self.pub.publish(Observations(time.time(),obs_msg))
 def make_output(self, diff_freq):
     if self.param_topic[0] == '/':
         self.param_topic = self.param_topic[1:len(self.param_topic)]
     obs_msg = []
     if self.param_dev > diff_freq:
         self.msg = 'ok(' + self.topic_name + ')'
         rospy.loginfo('ok(' + self.topic_name + ')')
         obs_msg.append(self.msg)
         self.pub.publish(Observations(time.time(), obs_msg))
     else:
         self.msg = '~ok(' + self.topic_name + ')'
         rospy.loginfo('~ok(' + self.topic_name + ')')
         obs_msg.append(self.msg)
         self.pub.publish(Observations(time.time(), obs_msg))
Example #7
0
    def check_topic(self, string, sleeptime, *args):
        while True:
            t1 = 0
            t2 = 0
            pubcode, statusMessage, topicList = self.m.getPublishedTopics(
                self.caller_id, "")
            for item in topicList:
                if item[0] == self.param_in_topic:
                    t1 = 1
                if item[0] == self.param_out_topic:
                    t2 = 1

            if t1 == 0:
                t1 = 1
                print "Topic:[" + self.param_in_topic + "] does not exist."
            if t2 == 0:
                t2 = 1
                print "Topic:[" + self.param_out_topic + "] does not exist."
                self.pub.publish(
                    Observations(time.time(), [
                        '~Ok(' +
                        self.param_out_topic[1:len(self.param_out_topic)] +
                        '_Triggered)'
                    ]))
            time.sleep(sleeptime)  #sleep for a specified amount of time.
 def start(self):
     if self.param_topic[0] != '/':
         self.param_topic = "/%s" % (self.param_topic)
     self.topic_name = self.param_topic[1:len(self.param_topic)]
     #print self.param_topic, self.param_frq, self.param_dev, self.param_ws
     topic_found = False
     firstcheck = True
     while firstcheck:
         pubcode, statusMessage, topicList = self.m.getPublishedTopics(
             self.caller_id, "")
         for item in topicList:
             if item[0] == self.param_topic:
                 self.param_topic = item[0]
                 self.topic_type = item[1]
                 topic_found = True
         if topic_found == True:
             firstcheck = False
             msg_class = roslib.message.get_message_class(self.topic_type)
             rospy.Subscriber(self.param_topic, msg_class, self.callback)
             rospy.spin()
         else:
             self.msg = '~ok(' + self.topic_name + ')'
             rospy.loginfo('Observer=' + rospy.get_name() + ',Topic=\\' +
                           self.topic_name + ',' + self.msg)
             self.pub.publish(Observations(time.time(), [self.msg]))
         time.sleep(1)
Example #9
0
    def make_output(self, Trend):
				if self.topic[0] == '/':
							self.topic = self.topic[1:len(self.topic)]
				obs_msg = []
				if Trend == +1 :
						rospy.loginfo('1');
						obs_msg.append('inc('+self.topic+'_'+self.param_field+')')
						self.pub.publish(Observations(time.time(),obs_msg))
						
				elif Trend == -1 :
						rospy.loginfo('-1');
						obs_msg.append('dec('+self.topic+'_'+self.param_field+')')
						self.pub.publish(Observations(time.time(),obs_msg))
				else:
						rospy.loginfo('0');
						obs_msg.append('con('+self.topic+'_'+self.param_field+')')
						self.pub.publish(Observations(time.time(),obs_msg))	
    def BQObs_thread(self, topic1, topic2, sleeptime, *args):
        while True:
            t1 = 0
            t2 = 0
            pubcode, statusMessage, topicList = self.m.getPublishedTopics(
                self.caller_id, "")
            for item in topicList:
                if item[0] == topic1:
                    t1 = 1
                if item[0] == topic2:
                    t2 = 1

            if t1 == 0:
                t1 = 1
                self.pub.publish(
                    Observations(time.time(), [
                        '~matched(' + topic1[1:len(topic1)] + ',' +
                        topic2[1:len(topic2)] + ')'
                    ]))
            if t2 == 0:
                t2 = 1
                self.pub.publish(
                    Observations(time.time(), [
                        '~matched(' + topic1[1:len(topic1)] + ',' +
                        topic2[1:len(topic2)] + ')'
                    ]))
            print('Num1=' + str(self.num1) + ',Num2' + str(self.num2))
            if (self.num1 != 0) & (self.num2 != 0):
                data1 = self.sum1 / self.num1
                data2 = self.sum2 / self.num2
                self.Trend1 = self.regression1.find(data1, self.curr_t1,
                                                    self.r11)
                self.Trend2 = self.regression2.find(data2, self.curr_t2,
                                                    self.r12)
                rospy.loginfo(self.topic1 + '_avg_data=' + str(data1) + ',' +
                              self.topic1 + 'Trend=' + str(self.Trend1) + ',' +
                              self.topic2 + 'Trend=' + str(self.Trend2) + ',' +
                              self.topic2 + '_avg_data=' + str(data2))
                self.num1 = 0
                self.num2 = 0
                self.sum1 = 0.0
                self.sum2 = 0.0
            self.publish_output()
            time.sleep(sleeptime)  #sleep for a specified amount of time.
    def publish_output(self):
        if self.topic1[0] == '/':
            self.topic1 = self.topic1[1:len(self.topic1)]
        if self.topic2[0] == '/':
            self.topic2 = self.topic2[1:len(self.topic2)]
        obs_msg = []
        if self.Trend1 == self.Trend2:
            if self.mismatch != 0:
                self.mismatch = self.mismatch - 1
        else:
            self.mismatch = self.mismatch + 1

        rospy.loginfo('mismatch=' + str(self.mismatch) + ',thr=' +
                      str(self.mismatch_thr))
        if self.mismatch <= self.mismatch_thr:
            rospy.loginfo('matched(' + self.topic1 + ',' + self.topic2 + ')')
            obs_msg.append('matched(' + self.topic1 + ',' + self.topic2 + ')')
            self.pub.publish(Observations(time.time(), obs_msg))
        else:
            rospy.loginfo('~matched(' + self.topic1 + ',' + self.topic2 + ')')
            obs_msg.append('~matched(' + self.topic1 + ',' + self.topic2 + ')')
            self.pub.publish(Observations(time.time(), obs_msg))
 def access_data(self, data):
     temp_data = data
     for f in temp_data.__slots__:
         if f == "channel":
             att = getattr(temp_data, f)
             j = 0
             obs_msg = []
             while (j < len(att)):
                 if att[j].status == 1:
                     obs_msg.append('on(' + att[j].dev_connected + ')')
                 else:
                     obs_msg.append('~on(' + att[j].dev_connected + ')')
                 j = j + 1
             self.pub.publish(Observations(time.time(), obs_msg))
Example #13
0
 def check_topic(self, top, sleeptime, *args):
     while True:
         t = 0
         m = xmlrpclib.ServerProxy(os.environ['ROS_MASTER_URI'])
         pubcode, statusMessage, topicList = m.getPublishedTopics(
             self.caller_id, "")
         for item in topicList:
             if item[0] == top:
                 self.Topic = True
                 t = 1
                 break
         if t == 0:
             t = 1
             print "Topic:[" + top + "] does not exist."
             self.pub.publish(
                 Observations(time.time(),
                              ['~ok(' + self.param_dev_node + ')']))
         time.sleep(sleeptime)  #sleep for a specified amount of time.
 def check_thread(self, topic1, topic2, sleeptime, *args):
     try:
         while not rospy.is_shutdown():
             t1 = 0
             t2 = 0
             m = xmlrpclib.ServerProxy(os.environ['ROS_MASTER_URI'])
             pubcode, statusMessage, topicList = m.getPublishedTopics(
                 self.caller_id, "")
             for item in topicList:
                 if item[0] == topic1:
                     t1 = 1
                 if item[0] == topic2:
                     t2 = 1
             if t1 == 0 | t2 == 0:
                 t1 = 1
                 self.pub.publish(
                     Observations(time.time(), [
                         '~matched(' + topic1[1:len(topic1)] + ',' +
                         topic2[1:len(topic2)] + ')'
                     ]))
             time.sleep(sleeptime)  #sleep for a specified amount of time.
     except:
         print "An unhandled exception occured, here's the traceback!"
         traceback.print_exc()