Welcome to the Robolink Community forum!
HELP RE Python in Blockly and PyCharm
-
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 MikeBLOCKLY 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 syntaxProcess finished with exit code 1
-
@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/