Getting values of parameters using TOC [Python]

Post here to get support
Post Reply
aesreal
Beginner
Posts: 22
Joined: Thu Mar 08, 2018 6:34 am

Getting values of parameters using TOC [Python]

Post by aesreal » Tue Jun 19, 2018 8:54 am

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 "self.cf.param.toc.toc"
https://github.com/bitcraze/crazyflie-c ... ab.py#L255

Which sure enough, printed out the objects for each parameter. Still had no idea how to get the values out, I tried dir(self.cf.param.toc.toc[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:
https://github.com/bitcraze/crazyflie-l ... 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 ParamTab.py that says anything about populating the value: https://github.com/bitcraze/crazyflie-c ... #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.



aesreal
Beginner
Posts: 22
Joined: Thu Mar 08, 2018 6:34 am

Re: Getting values of parameters using TOC [Python]

Post by aesreal » Tue Jun 19, 2018 12:39 pm

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

self.cf.param.add_update_callback(group=self.group, name=self.name, cb=self._param_callback)

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

In _param_callback, name is the FULLPATH of the parameter (aka self.group+self.name 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 https://wiki.bitcraze.io/doc:crazyflie:api:python:index, 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 = self.cf.param.get_some_value['some.path']
And it is not intuitive to do a comparison such as

Code: Select all

if self.cf.param.toc.toc['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

Post Reply