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



  • @robert-hh yes , when I run rhe code in Visual Studio code with this main I have this output :

    Calcolo media
    Acquisizione terminata
    fine prova
    ā•ā•>
    

    the program end correctly. And the REPL prompt is not avaiable any more.
    Now i don't have anymore the message of error with memory allocation.
    but now I try to complete the code with more lines and more implementation



  • @vflorio94 Using a serial terminal is not at all in conflict with "import machine". What you might see is, that once you runa program on your device, the REPL prompt is not available any more.



  • @robert-hh I have some difficult to use a serial terminal to run the code, because I have 'import machine' in main, so I have to use socket, but I don't understand how.
    Can you hel me?

    #Sending
    import socket
    
    DEST_IP = "192.168.4.255"
    UDP_PORT = 15005
    sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    
    def sending(msg):
        sock.sendto(msg, (DEST_IP, UDP_PORT))
    
    #main
    import machine 
    import pycom
    import time
    import lib_imu
    import gc
    import interval_position
    import sending
    #rilevazione posizione centrale corretta
    print("INIZIO ACQUISIONE")
    print("Rilevazione posizione corretta")
    time.sleep(1)
    position_ok = []
    position_ok = interval_position.calcolo_position(6, 1)
    mean_pos_ok = position_ok[0]
    print("media posizione corretta", mean_pos_ok[2])
    dev_std_ok = position_ok[1]
    gc.collect()
    print("FINE Rilevazione posizione corretta")
    time.sleep(2)
    print("Rilevazione posizione errata")
    time.sleep(1)
    position_no =[]
    position_no = interval_position.calcolo_position(6, 2)
    mean_pos_no = position_no[0]
    dev_std_no = position_no[1]
    gc.collect()
    print("FINE Rilevazione posizione errata")
    time.sleep(1)
    print("Inizio test pitch")
    time.sleep(1)
    # the function below return 1 if the test is completed correctly
    p = interval_position.acquisizione_interval_pitch(20, 1,  mean_pos_ok, mean_pos_no, dev_std_no, 3)
    del position_ok
    del position_no
    if p == 1:
        stringa = "Acquisizione terminata"
        sending.sending(stringa)
    


  • @robert-hh yes, I'll try to use GUI Idle python , but I have some problem with socket



  • @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.



  • @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.



  • @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.



  • @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.



  • @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().



  • @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-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...'



  • @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.



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



  • @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-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?



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



  • @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?



  • 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 )`


  • @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
    


  • @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?



Pycom on Twitter