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.

    Python Code Problem between Blockly and PyCharm

    CoDrone Lite/Pro
    2
    2
    387
    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
      Need help. I have set up both Blockly and PyCharm to code to our CoDrone Pros at our school. To we have found that the Python code seen in Blockly when copied and pasted into PyCharm does not want to recognise Python commands. See the Blckly generated code here...

      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()
      })

      Not anything exciting but keyboard controls.

      When pasted into a new CoDrone snip in PyCharm it does not work.
      Here is the response...

      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