Trouble getting real time feedback form sensors



  • Re: please teach us available sensor data

    Hi guys, I'm building AI on top of the Codrone library and am a bit of nb in python. I've tried to implement the code presented in this topic: https://forum.robolink.com/topic/49/please-teach-us-available-sensor-data/5

    I'm getting a DataType error and any help would be great. Need feedback from sensors while flying to teach him to fly by himself 🙂

    Port : [COM3]
    Drone : [9519]
    Battery : [57]


    NameError Traceback (most recent call last)
    <ipython-input-9-d219565f103e> in <module>()
    18
    19 #set the event handler
    ---> 20 drone.setEventHandler(DataType.Imu, eventUpdateAttitude)
    21
    22
    NameError: name 'DataType' is not defined

    Code implemented here:

    #create these to store variables globally
    rollAngle =0
    yawAngle =0
    pitchAngle =0
    import time

    def eventUpdateAttitude(data):
    global rollAngle, pitchAngle, yawAngle

    rollAngle =data.roll
    pitchAngle = data.pitch
    yawAngle = data.yaw
    

    #creates drone object
    drone = CoDrone.CoDrone(True, False, False, False, False)
    drone.connect()

    #set the event handler
    drone.setEventHandler(DataType.Imu, eventUpdateAttitude)

    while(drone.isConnected()):
    #request for the angle data
    drone.sendRequest(DataType.Imu)
    time.sleep(0.05)#make sure to have a delay
    print("Roll:",rollAngle, " Yaw:", yawAngle," Pitch:",pitchAngle)


  • administrators

    Hello @beraug Are you using our latest library with the most updated functions we have recently created? Check out this link it has sample code we have created for our library https://support.robolink.com/ Let me know if you have any other questions.



  • As @robolink_arnold mentioned, looks like the code you're running is using the old library. If you check out the URL he linked, you'll be able to use a newer set of functions that hopefully are easier to use and understand.

    Let us know if you have any other questions or have trouble getting it to work!



  • HI Arnold and Wes, Thanks very much for replying my question.

    I've actually had a bit of trouble finding the latest library that actually works with the functions in the link sent. Not sure but when I've installed CoDrone using pip it gave me a different version from the latest.

    I'm getting the files from here: https://github.com/RobolinkInc/CoDrone and have also tried to just replace the files in the installed directory to update them to the latest revision but does not look like it is working. I'm getting the same error:

    ***NameError Traceback (most recent call last)
    <ipython-input-8-d219565f103e> in <module>()
    18
    19 #set the event handler
    ---> 20 drone.setEventHandler(DataType.Imu, eventUpdateAttitude)
    21
    22

    NameError: name 'DataType' is not defined***

    Could you please share the repository of the latest code?

    Cheers.



  • @beraug Let me check with @robolink_whoseop to make sure you're getting the proper version and library.

    Quick question before I get back with Whoseop's help, are you running in PyCharm or just purely command line?


  • administrators

    Hello @beraug are you using pycharm?



  • Hi guys, sorry for my late reply, I’m in Australia so a bit of lag on my answers.

    I’m using the command lines directly from Jupiter notebook. Cheers.



  • @beraug Ohhh, I see, Jupyter notebook. We haven't yet tested running CoDrone using a Jupyter Notebook yet, unfortunately. That explains why you're running into errors. At the moment, I would recommend following the PyCharm setup to use Python with CoDrone, since that's what we've supported so far. It can be a bit cumbersome and technical, which we're currently trying to improve on. That said, here is the tutorial on how to set that up.

    Our team is currently exploring Jupyter notebook for a different project, but we haven't used it with CoDrone yet. @robolink_arnold Are you familiar with what the error might mean, and whether we even have access to the latest CoDrone library via Jupyter notebook?



  • Thanks guys, will have a look.

    The link to download the lates library would also be highly regarded.

    I've actually manage to get the code running with this code, although when the drone is flying it don't send the data. He can only send when has finished the flight command. I wonder how to make then work in parallel?

    import time

    def eventUpdateAttitude(data):
    global height, horizontal_position_X, horizontal_position_Y

    height = getHeight()
    horizontal_position_X = horizontal_position.X
    horizontal_position_Y = horizontal_position.Y

    #set the event handler

    drone = CoDrone.CoDrone(True, False, False, False, False)
    drone.connect()
    drone.setEventHandler([drone.getHeight(),drone.getOptFlowPosition()], eventUpdateAttitude)

    horizontal_position = drone.getOptFlowPosition()
    height = drone.getHeight()

    drone.takeoff()

    while(drone.isConnected()):
    #request for the angle data
    drone.sendRequest([drone.getHeight(),drone.getOptFlowPosition()])
    time.sleep(0.05)#make sure to have a delay
    print(horizontal_position.X, horizontal_position.Y,height)



  • @robolink_arnold Can you take a look at this?


  • administrators

    @beraug Can you try running this code instead to verify everything works https://support.robolink.com/codrone-library/getgyroangles let me know what results you get.


Log in to reply
 

Looks like your connection to Robolink community was lost, please wait while we try to reconnect.