MCPcopy Create free account
hub / github.com/bitcraze/crazyflie-lib-python / _connected

Method _connected

examples/basiclog.py:67–97  ·  view source on GitHub ↗

This callback is called form the Crazyflie API when a Crazyflie has been connected and the TOCs have been downloaded.

(self, link_uri)

Source from the content-addressed store, hash-verified

65 self.is_connected = True
66
67 def _connected(self, link_uri):
68 """ This callback is called form the Crazyflie API when a Crazyflie
69 has been connected and the TOCs have been downloaded."""
70 print('Connected to %s' % link_uri)
71
72 # The definition of the logconfig can be made before connecting
73 self._lg_stab = LogConfig(name='Stabilizer', period_in_ms=10)
74 self._lg_stab.add_variable('stabilizer.roll', 'float')
75 self._lg_stab.add_variable('stabilizer.pitch', 'float')
76 self._lg_stab.add_variable('stabilizer.yaw', 'float')
77
78 # Adding the configuration cannot be done until a Crazyflie is
79 # connected, since we need to check that the variables we
80 # would like to log are in the TOC.
81 try:
82 self._cf.log.add_config(self._lg_stab)
83 # This callback will receive the data
84 self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
85 # This callback will be called on errors
86 self._lg_stab.error_cb.add_callback(self._stab_log_error)
87 # Start the logging
88 self._lg_stab.start()
89 except KeyError as e:
90 print('Could not start log configuration,'
91 '{} not found in TOC'.format(str(e)))
92 except AttributeError:
93 print('Could not add Stabilizer log config, bad configuration.')
94
95 # Start a timer to disconnect in 10s
96 t = Timer(5, self._cf.close_link)
97 t.start()
98
99 def _stab_log_error(self, logconf, msg):
100 """Callback from the log API when an error occurs"""

Callers

nothing calls this directly

Calls 5

LogConfigClass · 0.90
add_variableMethod · 0.80
add_configMethod · 0.80
add_callbackMethod · 0.80
startMethod · 0.45

Tested by

no test coverage detected