OpenViBE forum

The OpenViBE community
It is currently Tue Jul 16, 2019 10:51 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Jan 09, 2019 4:45 pm 
Offline

Joined: Wed Nov 14, 2018 6:10 pm
Posts: 27
I have a python script that sends commands over serial protocol to an external device after certain conditions have been fulfilled. The commands are sent over a period of 10 seconds at particular times. Naturally, the python code would not stop and rather run on every chunk received, making the task difficult to implement.
To give an idea of the scenario I am implementing, I receive data:
Quote:
12 0 1
12.5 1 1
13 2 1
13.5 3 1
14 4 0
14.5 5 1
15 6 1
15.5 7 1
16 8 1
16.5 9 0
17 10 1
17.5 11 0
18 12 1
18.5 13 1
19 14 1
19.5 15 1
20 16 0
20.5 17 0
21 18 0
21.5 19 1
22 20 1
22.5 21 1
23 22 1
23.5 23 1
24 24 1
24.5 25 1
25 26 1
25.5 27 1
26 28 1
26.5 29 1
44 30 0
44.5 31 1
45 32 1
45.5 33 1
46 34 0
46.5 35 0
47 36 1
47.5 37 1
48 38 1
48.5 39 0
49 40 1
49.5 41 1
50 42 1
50.5 43 1
51 44 0
51.5 45 1
52 46 0
52.5 47 1
53 48 0
53.5 49 1
54 50 1
54.5 51 1
55 52 1
55.5 53 0
56 54 0
56.5 55 0
57 56 1
57.5 57 1
58 58 0
58.5 59 0

How my code works is, for the first trial( 12 to 26.5 seconds), On finding two consecutive 1's ( in 3rd column) , I would activate the device and send instructions at specific times in 10 seconds. At the same time I output a buffer with the activation state. Similarly for 2nd trial(44 to 58.5).
Is there a workaround that I get sufficient time for executing the byte sequences ?


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 10, 2019 8:36 am 
Offline

Joined: Wed Oct 31, 2018 9:14 am
Posts: 91
Hi,

I'm not sure I understood
your problem is that your script is too slow and lags behind as you go?
or the problem is that you do not get the instructions at the exact second?
Or does your script start with each chunk?

Thibaut


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 10, 2019 10:08 am 
Offline

Joined: Wed Nov 14, 2018 6:10 pm
Posts: 27
Hi
My problem is I cannot send the instructions at the time specified because it takes 10 seconds to run the whole sequence, but chunks are coming in so before these set of commands get executed, the script would run again as chunks keep coming.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 10, 2019 10:14 am 
Offline

Joined: Wed Nov 14, 2018 6:10 pm
Posts: 27
To clarify my problem more, here is my process function:
Code:
def process(self):

        for chunkIndex in range( len(self.input[0]) ):
            #print 'chunk Index' , chunkIndex
            if ( (len(self.store) % 30) == 1  or len(self.store)==0):
                    self.active=0
            if(type(self.input[0][chunkIndex]) == OVSignalHeader):
                #print 'type 1'
                self.signalHeader = self.input[0].pop()
                outputHeader = OVSignalHeader(
                self.signalHeader.startTime,
                self.signalHeader.endTime,
                [1, self.signalHeader.dimensionSizes[1]],
                ['Active']+self.signalHeader.dimensionSizes[1]*[''],
                self.signalHeader.samplingRate)
               
                self.output[0].append(outputHeader)
               
            elif(type(self.input[0][chunkIndex]) == OVSignalBuffer):
                #print 'type2'
                #print 'size of chunk', len(self.input[0][chunkIndex])
                chunk=self.input[0].pop()
                self.store.append(chunk[0])
               
       
                #print 'Store', self.store
                if (len(self.store)>=2):
                    if (int(chunk[0])==1) and (int(self.store[len(self.store)-1])==1) and (self.active==0):
                        self.active=1
                        #command flag
                        cf=0
                        print 'Activated FES'
                        currTime=self.timeInMS()
                        print 'Current Time:',currTime
                        uqt = [whatever+currTime for whatever in self.uniqueTimes]
                        print 'Modified times according to currrent time: ',uqt
                        while (cf<len(self.updateCommands)):
                                pt=self.timeInMS()
                                if (pt==uqt[cf]):
                                     self.sendByteList(self.updateCommands[cf])
                                     print 'Command Sent at time:',pt
                                     cf=cf+1
                           
                npBuffer = np.array(chunk).reshape(tuple(self.signalHeader.dimensionSizes))
                npBuffer = npBuffer.mean(axis=0)
                chunk = OVSignalBuffer(chunk.startTime, chunk.endTime, npBuffer.tolist())
                self.output[0].append(chunk)
               
            elif(type(self.input[0][chunkIndex]) == OVSignalEnd):
                #print 'type 3'
                self.output[0].append(self.input[0].pop())
                self.hasomed.close()


self.hasomed is my device, self.UpdateCommands is a list of list of bytes that are sent using self.SendByteList, self.UniqueTimes are times at which I need to send commands, number of commands in self.UpdateCommands is equal to number of times, self.timeInMS gives the current time in mili-seconds


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 11, 2019 9:21 am 
Offline

Joined: Wed Oct 31, 2018 9:14 am
Posts: 91
Hi,
I'm not sure, I read your script "in diagonal". The fact that it takes 10s is that you need 10s of information not that it is slow.
In this case you can simply use additional variables in your python script. You have an available initialize function and a __init__. the process will just have to fill an array (a stack) taking the last ten seconds if your window of 10s is moving. Or you can fill a fix array of 10s data and clean it every 10s. And you send the order when it is necessary.
http://openvibe.inria.fr/tutorial-using ... -openvibe/
Thibaut


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Americanized by Maƫl Soucaze.