Welcome to the Robolink Community forum!
Python Code Problem between Blockly and PyCharm
-
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... -
@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/