Navigation

    Robolink logo
    • Register
    • Login
    • Search
    • [[global:header.categories]]
    • [[global:header.recent]]
    • [[global:header.tags]]
    • [[global:header.popular]]
    • [[global:header.users]]
    • [[global:header.groups]]
    As of September 2021, we have moved technical support to Robolink Help

    Welcome to the Robolink Community forum!

    You can post here to interact with others in the Robolink community. We're checking it weekly, and we'll respond to some messages. If you're looking for technical support, head over to Robolink Help.

    HELP RE Python in Blockly and PyCharm

    CoDrone Lite/Pro
    2
    2
    104
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      stemkids last edited by

      Hi I am having a confusion moment so any help welcomed.
      We have set up PyCharm to connect to out set of CoDrone pros and can do flights. However to help out students we also have Blockly running. When I produce a program in Blockly and see the Python generated code ( see code to just fly by keyboard attached below ) I then copied this into a PyCharm program with the CoDrone addition and it did not run and gave the error syntax code ( see below at the end ).

      Does Blockly Python not = Python in PyCharm ???? Is there a manual for syntax commands I can print for my students and not the interactive text syntax inside of PyCharm ???
      Thanks for any help Mike

      BLOCKLY CODE :

      import CoDrone

      drone = CoDrone.CoDrone()
      drone.pair(drone.Nearest)

      addEvent('whenKeyPress', function (Keyboard.SPACEBAR){
      drone.takeoff()
      while drone.is_code_running():
      if Key.KEY_PRESSED == Keyboard.z:
      drone.move(1,0,0,0,50)
      if Key.KEY_PRESSED == Keyboard.x:
      drone.move(1,0,0,0,-20)
      if Key.KEY_PRESSED == Keyboard.UP:
      drone.move(1,0,50,0,0)
      if Key.KEY_PRESSED == Keyboard.DOWN:
      drone.move(1,0,-50,0,0)
      if Key.KEY_PRESSED == Keyboard.LEFT:
      drone.move(1,0,0,-50,0)
      if Key.KEY_PRESSED == Keyboard.RIGHT:
      drone.move(1,0,0,50,0)
      if Key.KEY_PRESSED == Keyboard.q:
      drone.land()
      })

      ERROR in PyCharm

      File "C:/Users/mjones/PycharmProjects/pythonProject2/basic take off.py", line 6
      addEvent('whenKeyPress', function (Keyboard.SPACEBAR){
      ^
      SyntaxError: invalid syntax

      Process finished with exit code 1

      admin 1 Reply Last reply Reply Quote 0
      • admin
        admin @stemkids last edited by

        @stemkids For most of the projects you make in Blockly, the generated Python code does carry over to PyCharm. With controlling the drone using arrow keys, we have a separate Python lesson on how to do it. It will not behave exactly the same as the Blockly one because Blockly uses Javascript and can continuously read keyboard commands. In Python, you will be writing code to request one input at a time. It is possible to write a program in Python that works just like the Blockly program but it is more advanced and is not included in our lessons.

        Here are some lessons that can help!
        CoDrone Mini lesson on user input and making a remote - https://learn.robolink.com/lesson/user-input/
        CoDrone Pro/Lite lesson on remote control - https://learn.robolink.com/lesson/codrone-python-user-input/

        1 Reply Last reply Reply Quote 0
        • First post
          Last post