Using SyncLogger with passed in arguments.[solved]

Firmware/software/electronics/mechanics
Post Reply
cafeciaojoe
Member
Posts: 81
Joined: Mon Jun 18, 2018 2:37 am

Using SyncLogger with passed in arguments.[solved]

Post by cafeciaojoe »

Hi,

I have a class attribute called self.cf_pos.

I passed it into a function:

Code: Select all

def flight_logger(self, cf, uri,cf_pos)
Which then passes it to another function in the same class:

Code: Select all

def sync_logger(scf, cf_pos,log_angle,log_position)
the sync logger function takes a cf instance, the class attribute cf_pos and a couple of log configurations. problem is, the cf_pos in the code below is not updating, my IDE is telling me it is a parameter of SyncLogger. Is this a SyncLogger problem or a python problem?

Thanks all.

code below:

Code: Select all

    def sync_logger(self,cf,[b]cf_pos[/b],log_angle,log_position):

        rawAngle0x = [0, 0]
        rawAngle0y = [0, 0]
        rawAngle1x = [0, 0]
        rawAngle1y = [0, 0]

        state_estimate = [0, 0, 0]

        with SyncLogger(cf, [log_angle,log_position]) as log:
            # TODO add roll and yaw.
            for log_entry in log:
                if 'lighthouse.rawAngle0x' in log_entry[1]:
                    data_1 = log_entry[1]
                    rawAngle0x.append(data_1['lighthouse.rawAngle0x'])
                    rawAngle0x.pop(0)
                    rawAngle1x.append(data_1['lighthouse.rawAngle1x'])
                    rawAngle1x.pop(0)
 
                    if rawAngle0x[0] == rawAngle0x[1] and rawAngle1x[0] == rawAngle1x[1]:
                        [b]cf_pos[/b] = Position(float('nan'), float('nan'), float('nan'))
                        # print(self.cf_pos.x, self.cf_pos.y, self.cf_pos.z)

                if 'stateEstimate.x' in log_entry[1]:
                    if rawAngle0x[0] != rawAngle0x[1] or rawAngle1x[0] != rawAngle1x[1]:
                        data_2 = log_entry[1]
                        state_estimate[0] = data_2['stateEstimate.x']
                        state_estimate[1] = data_2['stateEstimate.y']
                        state_estimate[2] = data_2['stateEstimate.z']
                        [b]cf_pos[/b] = Position(state_estimate[0], state_estimate[1], state_estimate[2])
                        # print('updating state estimate to {}'.format(self.cf_pos))
Last edited by cafeciaojoe on Fri Jan 22, 2021 12:44 am, edited 1 time in total.
PhD Student
RMIT University
School of Design
http://www.cafeciaojoe.com
Image
kristoffer
Bitcraze
Posts: 479
Joined: Tue Jun 30, 2015 7:47 am

Re: Using SyncLogger with passed in arguments.

Post by kristoffer »

I'm not completely sure what you are trying to do, but my guess is that you want

Code: Select all

self.cf_pos
to be updated in the background by calling

Code: Select all

 flight_logger
. Correct?
This does not work since the for loop in the SyncLogger context will never return, it will simply run the for loop forever (unless I missed something). If you add some sort of

Code: Select all

break
condition to leave the for loop,

Code: Select all

self.cf_pos
should have been updated as python is passing arguments by reference.
What you see is most likely a python problem, you can convince your self by printing the contents of the local

Code: Select all

log
object that hopefully contains the correct data.
cafeciaojoe
Member
Posts: 81
Joined: Mon Jun 18, 2018 2:37 am

Re: Using SyncLogger with passed in arguments.

Post by cafeciaojoe »

Thanks for the help! this makes sense
PhD Student
RMIT University
School of Design
http://www.cafeciaojoe.com
Image
Post Reply