Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set value parameter when toc received and before values are downloaded #475

Open
knmcguire opened this issue Sep 12, 2024 · 0 comments
Open

Comments

@knmcguire
Copy link
Member

We now have a parameter set_value that sets the parameter value on the crazyflie. Currently it is blocked until the crazyflie not only received the full toc but also has downloaded all the values, as it technically doesn't send the parameter directly, but the parameter set that has been downloaded in the cflib.

Technically we could set the parameter after the TOC has been received, as that is faster since TOC can be cached but the values can not. The chance is only that there is a change that the value downloaded on the cflib can be overwritten while it is has been downloaded which could cause issues if not handled properly.

This is the set_value for params:

def set_value(self, complete_name, value):
"""
Set the value for the supplied parameter.
"""
if not self._initialized.isSet():
if self.cf.is_called_by_incoming_handler_thread():
raise Exception('Can not set parameter from callback until fully connected.')
if not self._initialized.wait(timeout=60):
raise Exception('Connection timed out')
element = self.toc.get_element_by_complete_name(complete_name)
if not element:
logger.warning("Cannot set value for [%s], it's not in the TOC!",
complete_name)
raise KeyError('{} not in param TOC'.format(complete_name))
elif element.access == ParamTocElement.RO_ACCESS:
logger.debug('[%s] is read only, no trying to set value',
complete_name)
raise AttributeError('{} is read-only!'.format(complete_name))
else:
varid = element.ident
pk = CRTPPacket()
pk.set_header(CRTPPort.PARAM, WRITE_CHANNEL)
if self._useV2:
pk.data = struct.pack('<H', varid)
else:
pk.data = struct.pack('<B', varid)
if element.pytype == '<f' or element.pytype == '<d':
value_nr = float(value)
else:
value_nr = int(value)
pk.data += struct.pack(element.pytype, value_nr)
self.param_updater.request_param_setvalue(pk)

Either two ways we can solve this:

  1. Have a block of the set_value, that checks if the setting is happening simultaneously or if it has been set by the cflib upon startup (such that it ignores the value of the crazyflie and sets the cflib one, or whoever we think has higher authorization)
  2. Have a function that is between set_value and set_value_raw, which is basically set_value_raw but it wait until the toc such that you don't have assume the type.

This might improve the appeared connection speed for swarms significantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant