CrazyFlie Connecting but motors not starting

Post here to get support
Post Reply
abhinav90
Beginner
Posts: 3
Joined: Tue Jul 16, 2013 3:30 pm

CrazyFlie Connecting but motors not starting

Post by abhinav90 »

Hi,

I am trying to connect to the CrazyFlie via the Python API and make the motors work by giving a thrust value. The connection happens. Even the green led comes on and flickers a bit continuosly remains on showing thats its connected with the crazyRadio. However, the motors don't move.

This is the response I get from the command line code: The last line "sending data" is a print set by me once the infinite loop kicks in to keep pinging the copter after every 0.1 seconds.

Code: Select all


C:\Users\raghav\Documents\QuadCopter\cfclient-2013.4.2\lib>C:\Pytho
n27-32bit\python.exe sample.py


DEBUG:cflib.crazyflie:Adding callback on port [5] to [<bound method Log._new_pac
ket_cb of <cflib.crazyflie.log.Log instance at 0x0260F648>>]
DEBUG:cflib.crazyflie:Adding callback on port [0] to [<bound method Console.inco
ming of <cflib.crazyflie.console.Console instance at 0x0260F6E8>>]
DEBUG:cflib.crazyflie:Adding callback on port [2] to [<bound method _ParamUpdate
r._new_packet_cb of <_ParamUpdater(Thread-2, initial daemon)>>]
before open link
INFO:cflib.crazyflie:Callback->Connection initialized[radio://0/10/250K]
INFO:cflib.crazyflie:We are connected[radio://0/10/250K], request connection set
up
DEBUG:cflib.crazyflie.toc:[5]: Start fetching...
DEBUG:cflib.crazyflie:Adding callback on port [5] to [<bound method TocFetcher._
new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x0266C300>>]
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
after link is opened
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while sche
duling new one on [5]
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while sche
duling new one on [5]
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while sche
duling new one on [5]
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while sche
duling new one on [5]
INFO:cflib.crazyflie:Callback->Connected to [radio://0/10/250K]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
ERROR:cflib.crazyflie.toc:Got packet that was not on TOC channel, TOC fetch will
 probably not succeed
DEBUG:cflib.crazyflie.toc:[5]: Got TOC CRC, 9 items and crc=0x6F098296
DEBUG:cflib.crazyflie.toc:Requesting index 0 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
DEBUG:cflib.crazyflie.toc:Added element [0]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 1
DEBUG:cflib.crazyflie.toc:Requesting index 1 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: No answer on [5], do retry
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while sche
duling new one on [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [1]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 2
DEBUG:cflib.crazyflie.toc:Requesting index 2 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [2]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 3
DEBUG:cflib.crazyflie.toc:Requesting index 3 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [3]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 4
DEBUG:cflib.crazyflie.toc:Requesting index 4 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [4]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 5
DEBUG:cflib.crazyflie.toc:Requesting index 5 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [5]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 6
DEBUG:cflib.crazyflie.toc:Requesting index 6 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [6]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 7
DEBUG:cflib.crazyflie.toc:Requesting index 7 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [7]
DEBUG:cflib.crazyflie.toc:[5]: More variables, requesting index 8
DEBUG:cflib.crazyflie.toc:Requesting index 8 on port 5
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [5]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [5], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [8]
WARNING:cflib.crazyflie.toccache:Could not save cache, no writable directory
DEBUG:cflib.crazyflie:Removing callback on port [5] to [<bound method TocFetcher
._new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x0266C300>>]
DEBUG:cflib.crazyflie.toc:[5]: Done!
INFO:cflib.crazyflie:Log TOC finished updating
DEBUG:cflib.crazyflie.toc:[2]: Start fetching...
DEBUG:cflib.crazyflie:Adding callback on port [2] to [<bound method TocFetcher._
new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x0266CCB0>>]
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:[2]: Got TOC CRC, 23 items and crc=0xCE379F23
DEBUG:cflib.crazyflie.toc:Requesting index 0 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [0]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 1
DEBUG:cflib.crazyflie.toc:Requesting index 1 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [1]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 2
DEBUG:cflib.crazyflie.toc:Requesting index 2 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [2]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 3
DEBUG:cflib.crazyflie.toc:Requesting index 3 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [3]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 4
DEBUG:cflib.crazyflie.toc:Requesting index 4 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [4]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 5
DEBUG:cflib.crazyflie.toc:Requesting index 5 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [5]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 6
DEBUG:cflib.crazyflie.toc:Requesting index 6 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [6]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 7
DEBUG:cflib.crazyflie.toc:Requesting index 7 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [7]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 8
DEBUG:cflib.crazyflie.toc:Requesting index 8 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [8]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 9
DEBUG:cflib.crazyflie.toc:Requesting index 9 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [9]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 10
DEBUG:cflib.crazyflie.toc:Requesting index 10 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [10]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 11
DEBUG:cflib.crazyflie.toc:Requesting index 11 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [11]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 12
DEBUG:cflib.crazyflie.toc:Requesting index 12 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [12]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 13
DEBUG:cflib.crazyflie.toc:Requesting index 13 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [13]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 14
DEBUG:cflib.crazyflie.toc:Requesting index 14 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [14]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 15
DEBUG:cflib.crazyflie.toc:Requesting index 15 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [15]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 16
DEBUG:cflib.crazyflie.toc:Requesting index 16 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [16]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 17
DEBUG:cflib.crazyflie.toc:Requesting index 17 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [17]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 18
DEBUG:cflib.crazyflie.toc:Requesting index 18 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [18]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 19
DEBUG:cflib.crazyflie.toc:Requesting index 19 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [19]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 20
DEBUG:cflib.crazyflie.toc:Requesting index 20 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [20]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 21
DEBUG:cflib.crazyflie.toc:Requesting index 21 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [21]
DEBUG:cflib.crazyflie.toc:[2]: More variables, requesting index 22
DEBUG:cflib.crazyflie.toc:Requesting index 22 on port 2
DEBUG:cflib.crazyflie:ExpectAnswer: Will expect answer on port [2]
DEBUG:cflib.crazyflie:ExpectAnswer: Got answer back on port [2], cancelling time
r
DEBUG:cflib.crazyflie.toc:Added element [22]
WARNING:cflib.crazyflie.toccache:Could not save cache, no writable directory
DEBUG:cflib.crazyflie:Removing callback on port [2] to [<bound method TocFetcher
._new_packet_cb of <cflib.crazyflie.toc.TocFetcher instance at 0x0266CCB0>>]
DEBUG:cflib.crazyflie.toc:[2]: Done!
INFO:cflib.crazyflie:Param TOC finished updating
INFO:cflib.crazyflie:Callback->Connection setup finished [radio://0/10/250K]
sending data


Below is my file sample.py. I have used several different variations of the below code but can't resolve the issue as to why the motors don't start up. When I switch on the crazyflie, the motors do their test spin properly signifying that the soldering and connections to the motors are proper. Just can't get the program to work! Any help is appreciated.

Code: Select all


import logging
import time 
import cflib.crtp
from cfclient.utils.logconfigreader import LogConfig
from cfclient.utils.logconfigreader import LogVariable
from cflib.crazyflie import Crazyflie
 
logging.basicConfig(level=logging.DEBUG)
 
 
class Main:

    def __init__(self):


        self.crazyflie = Crazyflie()
        cflib.crtp.init_drivers()
 
        self.crazyflie.connectSetupFinished.add_callback(self.connectSetupFinished)

        print("before open link")
        self.crazyflie.open_link("radio://0/10/250K")
 
        print("after link is opened")

    def connectSetupFinished(self, linkURI):
             
        roll    = 0.0
        pitch   = 0.0
        yawrate = 0
        thrust  = 20000
        
        print("sending data")

        result = self.crazyflie.commander.send_setpoint(roll, pitch, yawrate, thrust)
        while(True):
            result = self.crazyflie.commander.send_setpoint(roll, pitch, yawrate, thrust)
            time.sleep(0.1)

 
    def log_accel_data(self, data):
        logging.info("Accelerometer: x=%.2f, y=%.2f, z=%.2f" %
                        (data["acc.x"], data["acc.y"], data["acc.z"]))
 
Main()

marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: CrazyFlie Connecting but motors not starting

Post by marcus »

Hi,

It might cause a problem that you are hijacking the callback thread, you shouldn't do this. connectSetupFinished should return quickly so you have to start a new thread to send the control setpoint. Otherwise it looks ok. You have to send a value that is above 10000 and you have to send it at least every 500 ms I think.

/Marcus
abhinav90
Beginner
Posts: 3
Joined: Tue Jul 16, 2013 3:30 pm

Re: CrazyFlie Connecting but motors not starting

Post by abhinav90 »

Hi Marcus,

Thanks for the suggestion, but I tried it out with threading and still had the same issue. Here is one variant of the threading that I tried and the result that I got. (Please note, the result this time is much cleaner as I removed the unwanted logger functions from the code), I also tried with cfclient 4 instead of 4.2 to see if that helps, but still no luck in getting the motors to move.

Output:

Code: Select all

C:\Users\raghav\Documents\QuadCopter\cfclient-2013.4\lib>C:\Python2
7-32bit\python.exe sample.py
before open link
No handlers could be found for logger "cflib.crazyflie"
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:root:[5]: Was expecting 0 but got 9
WARNING:cflib.crazyflie:ExpectAnswer: ERROR! Older timer whas running while sche
duling new one on [2]

sending dataafter link is opened

My new Threaded Code: (The 10 second sleep was just put later on to see if that helps, have tried without it as well with no luck. Have also tried putting the thread start call in the callback function connectSetupFinished but that didnt help either)

Code: Select all

import logging
import time 
import cflib.crtp
import threading
from cflib.crazyflie import Crazyflie

 
class Main:

    def __init__(self):


        self.crazyflie = Crazyflie()
        cflib.crtp.init_drivers()
 
        print("before open link")
        self.crazyflie.open_link("radio://0/10/250K")
 
        self.crazyflie.connectSetupFinished.add_callback(self.connectSetupFinished)
        
        time.sleep(10)
    
        t1 = threading.Thread(target=self.MyThread1)
        t1.start()    
        
        print("after link is opened")       
    
    def MyThread1(self):             
        roll    = 0.0
        pitch   = 0.0
        yawrate = 0
        thrust  = 20000
        
        print("sending data")
        
        while(True):
            result = self.crazyflie.commander.send_setpoint(roll, pitch, yawrate, thrust)
            time.sleep(0.1)


    def connectSetupFinished(self, linkURI):
        """
        Called once connection is done
        """ 
Main()



Any other ideas?
marcus
Bitcraze
Posts: 659
Joined: Mon Jan 28, 2013 7:02 pm
Location: Sweden
Contact:

Re: CrazyFlie Connecting but motors not starting

Post by marcus »

I tested the code and it's working. Do you have your Crazyflie connected to the USB? When it's charging the motors will not spin.
abhinav90
Beginner
Posts: 3
Joined: Tue Jul 16, 2013 3:30 pm

Re: CrazyFlie Connecting but motors not starting

Post by abhinav90 »

No the crazyflie is not connected to the USB. I am using cfclient 4.2. Is there anyway to diagnose this issue, and see whether its a software issue or hardware issue. Is there some test packets I can send or any other way to find out where the issue lies in my case. Thanks.
Post Reply