some code question

Discussions about all things Bitcraze
arix
Member
Posts: 40
Joined: Fri Sep 01, 2017 1:45 am

Re: some code question

Post by arix » Wed Apr 18, 2018 8:55 am

arnaud wrote:
Mon Apr 16, 2018 7:52 am
Hi,

1. I think the USBlink is a good example, if you do things that way you will be able to enable the serial link using a UART message. Though, as a first approach, I would just create something like serialGetLink and modify comm.c to use it by default instead of the radioLink. I think DMA will eventually be required, but it should work without. So I would see that as a separate things: you can implement the link without DMA and add DMA support after to gain more performance. As a side note: just implementing the UART with interrupt will already help a lot and is much simpler than using DMA.
2. I am not sure to fully understand the questions. The lib has API that uses callbacks and that should allow you to log and control the crazyflie in real time.
3. It depends what you want to do exactly. Do you want to be able to send raw packet to your code or do you want to make a new setpoint packet?
can you give me a code example to log and control the crazyflie in real time? I have try to change basiclog.py but i can't achieve it .



arnaud
Bitcraze
Posts: 2226
Joined: Tue Feb 06, 2007 12:36 pm

Re: some code question

Post by arnaud » Wed Apr 18, 2018 9:02 am

If you un-comment this function call in the autonomous sequence example: https://github.com/bitcraze/crazyflie-l ... ce.py#L151, a log block is created and activated. This is using the same api as in basiclog.

arix
Member
Posts: 40
Joined: Fri Sep 01, 2017 1:45 am

Re: some code question

Post by arix » Wed Apr 18, 2018 10:09 am

arnaud wrote:
Wed Apr 18, 2018 9:02 am
If you un-comment this function call in the autonomous sequence example: https://github.com/bitcraze/crazyflie-l ... ce.py#L151, a log block is created and activated. This is using the same api as in basiclog.
Thank you ! i have understand the callback and i have used basiclog to achieve it.

Code: Select all

 def _connected(self, link_uri):
        """ This callback is called form the Crazyflie API when a Crazyflie
        has been connected and the TOCs have been downloaded."""
        print('Connected to %s' % link_uri)

        # The definition of the logconfig can be made before connecting
        self._lg_stab = LogConfig(name='zdistance ', period_in_ms=10)
        self._lg_stab.add_variable('range.zrange', 'uint16_t')


        # Adding the configuration cannot be done until a Crazyflie is
        # connected, since we need to check that the variables we
        # would like to log are in the TOC.
        try:
            self._cf.log.add_config(self._lg_stab)
            # This callback will receive the data
            self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
            # This callback will be called on errors
            self._lg_stab.error_cb.add_callback(self._stab_log_error)
            # Start the logging
            self._lg_stab.start()
        except KeyError as e:
            print('Could not start log configuration,'
                  '{} not found in TOC'.format(str(e)))
        except AttributeError:
            print('Could not add Stabilizer log config, bad configuration.')

        # Start a timer to disconnect in 10s
        t = Timer(5, self.commanderr)
        t.start()

Code: Select all

def commanderr(self):
	
        self._cf.commander.send_setpoint(0, 0, 0, 0)
        while(1):
                 for i in range (10): 
                          self._cf.commander.send_setpoint(0,0,0,36000)
                          time.sleep(0.1)
But i have some problem.
if i ctrl+c problem ,the crazyflie will reboot when i use usb connecte.
According to my code, the crazyflie don't work well. It will can't work when i running code ,but after some time it running or always don't work. And the time is so long over 5s
.

arix
Member
Posts: 40
Joined: Fri Sep 01, 2017 1:45 am

Re: some code question

Post by arix » Sat Apr 21, 2018 12:24 pm

arix wrote:
Wed Apr 18, 2018 10:09 am
arnaud wrote:
Wed Apr 18, 2018 9:02 am
If you un-comment this function call in the autonomous sequence example: https://github.com/bitcraze/crazyflie-l ... ce.py#L151, a log block is created and activated. This is using the same api as in basiclog.
Thank you ! i have understand the callback and i have used basiclog to achieve it.

Code: Select all

 def _connected(self, link_uri):
        """ This callback is called form the Crazyflie API when a Crazyflie
        has been connected and the TOCs have been downloaded."""
        print('Connected to %s' % link_uri)

        # The definition of the logconfig can be made before connecting
        self._lg_stab = LogConfig(name='zdistance ', period_in_ms=10)
        self._lg_stab.add_variable('range.zrange', 'uint16_t')


        # Adding the configuration cannot be done until a Crazyflie is
        # connected, since we need to check that the variables we
        # would like to log are in the TOC.
        try:
            self._cf.log.add_config(self._lg_stab)
            # This callback will receive the data
            self._lg_stab.data_received_cb.add_callback(self._stab_log_data)
            # This callback will be called on errors
            self._lg_stab.error_cb.add_callback(self._stab_log_error)
            # Start the logging
            self._lg_stab.start()
        except KeyError as e:
            print('Could not start log configuration,'
                  '{} not found in TOC'.format(str(e)))
        except AttributeError:
            print('Could not add Stabilizer log config, bad configuration.')

        # Start a timer to disconnect in 10s
        t = Timer(5, self.commanderr)
        t.start()

Code: Select all

def commanderr(self):
	
        self._cf.commander.send_setpoint(0, 0, 0, 0)
        while(1):
                 for i in range (10): 
                          self._cf.commander.send_setpoint(0,0,0,36000)
                          time.sleep(0.1)
Thank you I have solve it .

Post Reply