Page 1 of 1

Getting values of parameters using TOC [Python]

Posted: Tue Jun 19, 2018 8:54 am
by aesreal
Hi all,

So I've been trying to get values of specific parameters of the crazyflies using toc.

I first looked under ParamTab of cfclient to see how the parameters are populated.
Under line 255, I found "" ...

Which sure enough, printed out the objects for each parameter. Still had no idea how to get the values out, I tried dir([some_group][some_parameter]) and got these

Code: Select all

['RO_ACCESS', 'RW_ACCESS', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'access', 'ctype', 'get_readable_access', 'group', 'ident', 'name', 'pytype', 'types']
Which corresponds to the ParamTocElement Object here: ... y#L73-L124

But with all said, I still don't have any clue how to get the value, which is as listed in cfclient, of any specific paramter using toc.

Does anyone have a solution to this? From what I see, it doesn't seem to be implemented yet? There isn't really anything under ParamBlockModel in that says anything about populating the value: ... #L114-L123

I've also read this: viewtopic.php?f=6&t=1198&p=6487&hilit=param#p6487
But what it describes seems to be the need for a callback in order to get the values of the parameters, instead of a direct way to obtaining the values.

Re: Getting values of parameters using TOC [Python]

Posted: Tue Jun 19, 2018 12:39 pm
by aesreal
Been playing around, so the current way of doing this is to first add "add_update_callback" method to cf.param, something like this:

Code: Select all,, cb=self._param_callback)

def _param_callback(self, name, value):
	"""Generic callback registered for all the groups"""
	print('{0}: {1}'.format(name, value))
where is the group that the parameter belong to (eg. ring, cpu, firmware) and is the actual parameter itself (eg. headlightEnable, flash, pitch_kd)

In _param_callback, name is the FULLPATH of the parameter (aka or ring.headlightEnable or cpu.flash or pid_attitude.pitch_kd) and value is what you would want.

Afterwards, you can just save the value into a variable and do whatever you want with it.
This method is actually already described in the, but it is still a roundabout way of getting values. Not only do you have to code something to wait for the callback, you can't directly access it with just a single line such as

Code: Select all

value =['some.path']
And it is not intuitive to do a comparison such as

Code: Select all

if['some']['param'] == something
I'm going to play around with this somemore, possible editing the ParamTocElement to include the value in, if I know how