def onExecute(self, ec_id):
        print("\n")
        print("Command list: ")
        print(" echo [msg]       : echo message.")
        print(" set_value [value]: set value.")
        print(" get_value        : get current value.")
        print(" get_echo_history : get input messsage history.")
        print(" get_value_history: get input value history.")
        print("> ", end="")
        args = str(sys.stdin.readline())

        argv = str.split(args)
        argv[-1] = argv[-1].rstrip("\n")

        if self._async_echo and self._async_echo.finished():
            print("echo() finished: ", self._result[0])
            self._async_echo = None

        if argv[0] == "echo" and len(argv) > 1:
            if not self._async_echo:
                retmsg = ""
                func = echo_functor(argv[1], self._result)
                self._async_echo = OpenRTM_aist.Async_tInvoker(
                    self._myservice0._ptr(), func)
                self._async_echo.invoke()
            else:
                print("echo() still invoking")

            return RTC.RTC_OK

        if argv[0] == "set_value" and len(argv) > 1:
            val = float(argv[1])
            self._myservice0._ptr().set_value(val)
            print("Set remote value: ", val)
            return RTC.RTC_OK

        if argv[0] == "get_value":
            retval = self._myservice0._ptr().get_value()
            print("Current remote value: ", retval)
            return RTC.RTC_OK

        if argv[0] == "get_echo_history":
            OpenRTM_aist.CORBA_SeqUtil.for_each(
                self._myservice0._ptr().get_echo_history(), self.seq_print())
            return RTC.RTC_OK

        if argv[0] == "get_value_history":
            OpenRTM_aist.CORBA_SeqUtil.for_each(
                self._myservice0._ptr().get_value_history(), self.seq_print())
            return RTC.RTC_OK

        print("Invalid command or argument(s).")

        return RTC.RTC_OK
Ejemplo n.º 2
0
    def onDeactivated(self, ec_id):
        if self._fs:
            self._fs.close()
            self._fs = None
        self._datasize = 1
        self.setDataSize(self._datasize)
        self._sendcount = 0
        self._logmulcnt = 0

        if self.getInPortConnectorSize() == 0:
            async_ = OpenRTM_aist.Async_tInvoker(self, Throughput_py.exit)
            async_.invoke()
        return RTC.RTC_OK
Ejemplo n.º 3
0
    def receiveData(self, tm, seq_length):
        received_time = OpenRTM_aist.Time().getTime()
        if self._size == 0:
            self._size = seq_length
        record_num = len(self._record)
        record_ptr = record_num
        if self._size != seq_length and record_num != 0:

            max_latency = 0.0
            min_latency = 0.0
            mean_latency = 0.0
            variance = 0.0
            stddev = 0.0
            throughput = 0.0
            sum = 0.0
            sq_sum = 0.0
            record_len = len(self._record)

            #print record_len

            for d in self._record:
                tmp = d
                sum += tmp
                sq_sum += tmp * tmp
                if tmp > max_latency:
                    max_latency = tmp
                elif tmp < min_latency:
                    min_latency = tmp

            mean_latency = sum / record_len
            variance = (sq_sum / record_len) - (mean_latency * mean_latency)
            stddev = math.sqrt(variance)
            throughput = ((((self._size * self._varsize) + 8) * 8) /
                          mean_latency) / (1024 * 1024)

            self._fs.write(str(self._size) + "\t")
            self._fs.write(str(min_latency) + "\t" + str(max_latency) + "\t")
            self._fs.write(str(mean_latency) + "\t" + str(stddev) + "\t")
            self._fs.write(str(throughput) + "\n")
            self._record = []

            if seq_length < self._size:

                async = OpenRTM_aist.Async_tInvoker(self, Throughput_py.exit)
                async .invoke()
                return
        send_time = OpenRTM_aist.TimeValue(tm.sec, tm.nsec / 1000)
        if record_ptr == self._maxsample[0]:
            self._record.pop(0)
        self._record.append((received_time - send_time).toDouble())
        self._size = seq_length
Ejemplo n.º 4
0
 def callServiceAsync(self, name, func):
     async_call = OpenRTM_aist.Async_tInvoker(self.getServicePtr(name),
                                              func)
     async_call.invoke()
     return async_call