Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Wipy 2.0 and save data on my pc, not in flash memory

    Scheduled Pinned Locked Moved WiPy 2&3
    wipy2.0i2cpycompythonsaving data
    100 Posts 2 Posters 25.6k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V Offline
      VFlorio94 @robert-hh
      last edited by

      @robert-hh
      The intention of calcolo_position(sec) is which you have write. The function collect 2 values each second, calculate mean and re-use this value in the next function "acquisizione_interval_pitch", to generate the output.
      I need to mantain this time of acquisition because i work on subject and I want to extract data about their trunk posture in real time. I want to give them some feedback in real time.

      lib_imu is a simple library create to extract by I2c BNO055.
      lib_imu.get_euler return the Euler Angle of pitch, roll and yaw.

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @VFlorio94
        last edited by

        @vflorio94 said in Wipy 2.0 and save data on my pc, not in flash memory:

        lib_imu.get_euler return the Euler Angle of pitch, roll and yaw.

        I am asking about the data type: Does it return a tuple with three float values?

        V 1 Reply Last reply Reply Quote 0
        • V Offline
          VFlorio94 @robert-hh
          last edited by

          @robert-hh Sorry, I didn't understand your question before.
          it returns TUPLE
          thank you for your help and your patience

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @VFlorio94
            last edited by

            @vflorio94 In the first step, i changed two functions, media and calcolo_position. I simplified calcolo_position and reordered some lines. The major problem as I guess was a termination problem. It simply never hit the 0.5 second window for termination. It still is not perfect in matters of memory allocation, because it would better preallocate the "lists" as arrays. But that is a bigger change.
            I changed media(), because the way it is it would implicitely allocate a list. The way it is now it's a little bit slower.

            def calcolo_position(secondi):
            # function to calculate the position each second, the number of second is assigned
                gc.collect()
                # Configure I2C to extract euler angle
                lib_imu.set_configmode()
                time.sleep(0.03)
                # set unit
                lib_imu.set_units()
                time.sleep(0.03)
                # set mode
                lib_imu.set_mode('ndof')
                # create 3 lists 
                lista_heading = []
                lista_roll = []
                lista_pitch = []
                t = Timer.Chrono()
                t.start()
                time.sleep(0.1)
                while 1: 
                    t_now = t.read() 
                    if  t_now <= secondi:
                        eul = lib_imu.get_euler()
                        lista_heading.append(eul[0])
                        lista_roll.append(eul[1])
                        lista_pitch.append(eul[2])
                        time.sleep(0.5) 
                        if t_now > (secondi - 0.5):
                        # Calculate mean and standard deviation
                            print(lista_heading)
                            print(lista_roll)
                            print(lista_pitch)
                            print("Calcolo media")
                            mean_pos = (media(lista_pitch), 
                                        media(lista_pitch),
                                        media(lista_heading))
                            # Calcolo deviazione standard
                            devstd_pos = (dev_std(lista_heading), 
                                          dev_std(lista_roll), 
                                          dev_std(lista_pitch))
                            return mean_pos, devstd_pos
                    else:
                        t.stop()
                        del lista_heading
                        del lista_pitch
                        del lista_roll
                        gc.collect()
                        print("Acquisizione terminata")
                        break
            
            def media(sequenza):
                # calculate mean
                mean = 0.0
                for _ in range (1, len(sequenza)):
                    mean += sequenza[_]
                return mean / (len(sequenza)-1)
            
            V 1 Reply Last reply Reply Quote 0
            • V Offline
              VFlorio94 @robert-hh
              last edited by

              @robert-hh thank you for your help, but also after the changes that you suggest the error stay.
              i think that I need to preallocate the list as arrays, but I don't know i can do. i've never programming with python before.
              Could you help me please?

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @VFlorio94
                last edited by

                @vflorio94 I simplified calcoco_position() slightly more and added a print statement. can you tell me how far that progresses, and what is the argument you call calcoso:position(9 with?

                def calcolo_position(secondi):
                # function to calculate the position each second, the number of second is assigned
                    gc.collect()
                    # Configure I2C to extract euler angle
                    lib_imu.set_configmode()
                    time.sleep(0.03)
                    # set unit
                    lib_imu.set_units()
                    time.sleep(0.03)
                    # set mode
                    lib_imu.set_mode('ndof')
                    # create 3 lists 
                    lista_heading = []
                    lista_roll = []
                    lista_pitch = []
                    t = Timer.Chrono()
                    t.start()
                    time.sleep(0.1)
                    while 1: 
                        t_now = t.read() 
                        if  t_now <= secondi:
                            print("t-now = ", t_now)
                            eul = lib_imu.get_euler()
                            lista_heading.append(eul[0])
                            lista_roll.append(eul[1])
                            lista_pitch.append(eul[2])
                            time.sleep(0.5) 
                        else:
                            t.stop()
                            print(lista_heading)
                            print(lista_roll)
                            print(lista_pitch)
                            print("Calcolo media")
                            mean_pos = (media(lista_pitch), 
                                        media(lista_pitch),
                                        media(lista_heading))
                            # Calcolo deviazione standard
                            devstd_pos = (dev_std(lista_heading), 
                                          dev_std(lista_roll), 
                                          dev_std(lista_pitch))
                            print("Acquisizione terminata")
                            return mean_pos, devstd_pos
                
                1 Reply Last reply Reply Quote 0
                • V Offline
                  VFlorio94
                  last edited by VFlorio94

                  when i call calcolo_position I pass to it calcolo_position(1). But i call the function more than one time.
                  i change another time the code but the same is the same.
                  this is my 'main'
                  and few comment before you can find the other function that use inside the function 'calcolo_position(1)'

                  print("START ACQUISITION")
                  print("Rilevazione posizione corretta")
                  time.sleep(1)
                  position_ok = []
                  position_ok = calcolo_position(6)
                  mean_pos_ok = position_ok[0]
                  print("media posizione corretta", mean_pos_ok[2])
                  dev_std_ok = position_ok[1]
                  gc.collect()
                  print("END FIRST ACQUISITION")
                  time.sleep(2)
                  print("SECOND AQUISITION ")
                  time.sleep(1)
                  position_no =[]
                  position_no = calcolo_position(6)
                  mean_pos_no = position_no[0]
                  dev_std_no = position_no[1]
                  gc.collect()
                  print("END SECOND AQUISITION")
                  time.sleep(1)
                  print("START test pitch")
                  time.sleep(1)
                  acquisizione_interval_pitch(20, 1,  mean_pos_ok, mean_pos_no, dev_std_no )`
                  robert-hhR 1 Reply Last reply Reply Quote 1
                  • robert-hhR Offline
                    robert-hh @VFlorio94
                    last edited by

                    @vflorio94 said in Wipy 2.0 and save data on my pc, not in flash memory:

                    position_ok = calcolo_position(6)

                    If you run that line, will it ever return or just give the error?

                    robert-hhR 2 Replies Last reply Reply Quote 0
                    • robert-hhR Offline
                      robert-hh @robert-hh
                      last edited by

                      @robert-hh And if in calcolo_posuition you add a print before the while 1: loop, will that be printed?

                      V 1 Reply Last reply Reply Quote 0
                      • robert-hhR Offline
                        robert-hh @robert-hh
                        last edited by robert-hh

                        @robert-hh I understand. It is the calcolo_position(1) which crashes. That could be another problem in the function media() (division by zero).
                        Edit: Just to be sure: can you show how the code for calcolo_position() looks now?

                        V 1 Reply Last reply Reply Quote 0
                        • V Offline
                          VFlorio94 @robert-hh
                          last edited by

                          @robert-hh if i add a print before 'while 1:' each time that the function is call inside the the other function 'acquisizione_interval_pitch()' I have the print that I write. So during the first time that i run the code it works. Then, if I try to run the same file for the second time it crashes.
                          The problem is the function 'calcolo_position(1)'.

                          Calcolo Position before while
                          t-now =  0.1012856
                          funzione get euler
                          t-now =  0.6119527
                          funzione get euler
                          [359.25, 359.0]
                          [-0.875, -0.5]
                          [82.5, 70.9375]
                          Calcolo media
                          Acquisizione terminata```
                          robert-hhR 1 Reply Last reply Reply Quote 1
                          • robert-hhR Offline
                            robert-hh @VFlorio94
                            last edited by

                            @vflorio94 But when the program terminates with the call to 'calcolo_position(1)', what is the error message?

                            V 2 Replies Last reply Reply Quote 0
                            • V Offline
                              VFlorio94 @robert-hh
                              last edited by

                              @robert-hh
                              yes, the problem is the function 'calcolo_position(1)'. But after I call this function and I acquire data during 1 second, in the next call of the function the data collected before are not important.
                              So, I think that I need to refresh/ release this memory allocation after the call to the function but I don't know how.
                              Can you help me? thank you a lot.

                              1 Reply Last reply Reply Quote 0
                              • V Offline
                                VFlorio94 @robert-hh
                                last edited by VFlorio94

                                @robert-hh The first time the program terminates without error.
                                if I run for the second time the same main program don't go on and give me the message 'memory allocation...'

                                1 Reply Last reply Reply Quote 0
                                • V Offline
                                  VFlorio94 @robert-hh
                                  last edited by

                                  @robert-hh I suppose that the problem can be the function 'calcolo_position', but i'm not sure, beacuse the message is only which I copy before.
                                  the first time the program terminates in the right way, with no error and everything it's ok.
                                  then I run the program newly and it don't work.
                                  In my opinion, for my experience with c++ for example , I have to search to release the memory allocation and restart with the allocation from the begging each time that i call the function 'calcolo_position(1). but i don't know how. can you help me?
                                  thank you for your help

                                  robert-hhR 1 Reply Last reply Reply Quote 1
                                  • robert-hhR Offline
                                    robert-hh @VFlorio94
                                    last edited by

                                    @vflorio94 said in Wipy 2.0 and save data on my pc, not in flash memory:

                                    hen I run the program newly and it don't work.

                                    How do you restart the program?
                                    Normally, when objects are not used any more, they are released and garbage collection will reclaim the space. You can fore garbage collection with the call to gc.collect().

                                    V 1 Reply Last reply Reply Quote 0
                                    • V Offline
                                      VFlorio94 @robert-hh
                                      last edited by

                                      @robert-hh to restart the program I mantain the program open and I reuse the command run.
                                      I put gc.collect() in the code, you can see where in the code that I copy to you before, but the error stay.

                                      robert-hhR 1 Reply Last reply Reply Quote 0
                                      • robert-hhR Offline
                                        robert-hh @VFlorio94
                                        last edited by

                                        @vflorio94 Can you try to start and run the program from a simple terminal emulator like putty or screen. Using the intgrated environments of Atom or VSC may hide or create problems.

                                        V 1 Reply Last reply Reply Quote 0
                                        • V Offline
                                          VFlorio94 @robert-hh
                                          last edited by

                                          @robert-hh Is IDLE Python GUI good?
                                          now I need to implement code with more lines, to compare the other data that calcolo_position(1) return in the same function 'acquisizione_interval_pitch()'.
                                          I'm afraid about this, because I think that the error can be show before the end of the acquisition.

                                          And more I have to use an interval of acquisition more longer than 20 second, like 120 second.

                                          robert-hhR 1 Reply Last reply Reply Quote 1
                                          • robert-hhR Offline
                                            robert-hh @VFlorio94
                                            last edited by

                                            @vflorio94 You can use any editor you like for writing the code on you PC. The PyCom plugin for upload and run is what may create unexpected result. To sort that out, upload your code with ftp (Filezilla) and use a simple serial terminal to run the code.

                                            V 2 Replies Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 5
                                            • 3 / 5
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom