diff --git a/src/tools/scratch2jderobot/.gitignore b/src/tools/scratch2jderobot/.gitignore deleted file mode 100644 index 78077cb84..000000000 --- a/src/tools/scratch2jderobot/.gitignore +++ /dev/null @@ -1,57 +0,0 @@ -# Compiled Object files -*.slo -*.lo -*.o -*.obj -*.pyc - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app - -# Autosaved files -*~ - -# IDEs -CMakeLists.txt.user -.project -.cproject -.settings -.pydevproject - -# ROS -bin -build -lib -msg_gen -srv_gen -Makefile -CMakeCache.txt -cmake -cmake_install.cmake -gtest -catkin_generated -devel -test_results -CTestTestfile.cmake -CMakeFiles -catkin diff --git a/src/tools/scratch2jderobot/CMakeLists.txt b/src/tools/scratch2jderobot/CMakeLists.txt deleted file mode 100644 index e014b8647..000000000 --- a/src/tools/scratch2jderobot/CMakeLists.txt +++ /dev/null @@ -1,85 +0,0 @@ -IF (ENABLE_ROS) - project(scratch2jderobot) - ## Find catkin macros and libraries - find_package(catkin REQUIRED COMPONENTS - rospy - ) - - ## Uncomment this if the package has a setup.py. This macro ensures - ## modules and global scripts declared therein get installed - ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html - catkin_python_setup() - - ################################################ - ## Declare ROS messages, services and actions ## - ################################################ - - ## Generate messages in the 'msg' folder - #add_message_files( - #DIRECTORY msg - #FILES - #Example.msg - #) - - ## Generate services in the 'srv' folder - #add_service_files( - #DIRECTORY srv - #FILES - #Example.srv - #) - - ## Generate added messages and services with any dependencies listed here - #generate_messages() - - ################################### - ## catkin specific configuration ## - ################################### - - ## Declare things to be passed to dependent projects - catkin_package( - INCLUDE_DIRS src - CATKIN_DEPENDS rospy - DEPENDS - ) - - ########### - ## Build ## - ########### - - ## Specify additional locations of header files - ## Your package locations should be listed before other locations - include_directories( - include src - ${catkin_INCLUDE_DIRS} - ) - - ############# - ## Testing ## - ############# - - ## Add folders to be run by python nosetests - #catkin_add_nosetests(src/node/test.py) - - #if(CATKIN_ENABLE_TESTING) - # find_package(rostest REQUIRED) - # add_rostest(test/.test) - #endif() - - ############# - ## INSTALL ## - ############# - - - #INSTALL (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cfg/robot.yml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/conf COMPONENT scratch2jderobot) - - #INSTALL (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cfg/drone.yml DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/conf COMPONENT scratch2jderobot) - - INSTALL (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/python/scratch2jderobot/ COMPONENT scratch2jderobot) - INSTALL (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/python/scratch2jderobot/ COMPONENT scratch2jderobot) - INSTALL (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/extension DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/python/scratch2jderobot/ COMPONENT scratch2jderobot) - INSTALL (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/kurt DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/python/scratch2jderobot/ COMPONENT scratch2jderobot) - INSTALL (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/scripts DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/python/scratch2jderobot/ COMPONENT scratch2jderobot) - INSTALL (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cfg DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/python/scratch2jderobot/ COMPONENT scratch2jderobot) - #INSTALL (FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/scratch2python.py DESTINATION ${CMAKE_INSTALL_PREFIX}/share/jderobot/python/scratch2jderobot/ COMPONENT scratch2jderobot) - -ENDIF() diff --git a/src/tools/scratch2jderobot/README.md b/src/tools/scratch2jderobot/README.md deleted file mode 100644 index 92560f064..000000000 --- a/src/tools/scratch2jderobot/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Collaboration project for the Google Summer of Code 2017 - -## Author: [Raúl Pérula-Martínez](http://raulperula.github.io/) - -This project is focused on to develop a translator for programs in Scratch 2.0 to Python, including new blocks for developing robotics programs in ROS and ICE middlewares. - -More info: http://jderobot.org/Raulperula-colab - -# Installation requirements - - pip install -r requirements.txt diff --git a/src/tools/scratch2jderobot/cfg/drone.yml b/src/tools/scratch2jderobot/cfg/drone.yml deleted file mode 100644 index 6784a6743..000000000 --- a/src/tools/scratch2jderobot/cfg/drone.yml +++ /dev/null @@ -1,47 +0,0 @@ -drone: - Motors: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Motors:default -h localhost -p 9000" - Topic: "/cmd_vel_mux/input/teleop" - Name: Motors - maxV: 3 - maxW: 0.7 - - Camera1: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Camera:default -h localhost -p 9000" - Format: RGB8 - Topic: "/camera/rgb/image_raw" - Name: Camera1 - - Pose3D: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Pose3D:default -h localhost -p 9000" - Topic: "/odom" - Name: Pose3d - - Laser: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Laser:default -h localhost -p 9000" - Topic: "/scan" - Name: Laser - - CMDVel: - Server: Ice # Deactivate, Ice , ROS - Proxy: "CMDVel:default -h localhost -p 9000" - Name: CMDVel - - Navdata: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Navdata:default -h localhost -p 9000" - Name: Navdata - - Extra: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Extra:default -h localhost -p 9000" - Name: Extra - - Vmax: 3 - Wmax: 0.7 - - NodeName: drone diff --git a/src/tools/scratch2jderobot/cfg/robot.yml b/src/tools/scratch2jderobot/cfg/robot.yml deleted file mode 100644 index 28f8730e4..000000000 --- a/src/tools/scratch2jderobot/cfg/robot.yml +++ /dev/null @@ -1,29 +0,0 @@ -robot: - Motors: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Motors:default -h localhost -p 9001" - Topic: "/mobile_base/commands/velocity" - Name: robotMotors - maxW: 0.7 - maxV: 4 - - Laser: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Laser:tcp -h localhost -p 9001" - Topic: "/scan" - Name: robotLaser - - Pose3D: - Server: Ice # Deactivate, Ice , ROS - Proxy: "Pose3D:default -h localhost -p 9001" - Topic: "/odom" - Name: robotPose3d - - Camera1: - Server: Ice # Deactivate, Ice , ROS - Proxy: "CameraL:default -h localhost -p 9001" - Format: RGB8 - Topic: "/cameraL/image_raw" - Name: robotCamera1 - - NodeName: robot diff --git a/src/tools/scratch2jderobot/data/test_cat_mouse_1.sb2 b/src/tools/scratch2jderobot/data/test_cat_mouse_1.sb2 deleted file mode 100644 index ae2a1d6ec..000000000 Binary files a/src/tools/scratch2jderobot/data/test_cat_mouse_1.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_drone_blocks_1.sb2 b/src/tools/scratch2jderobot/data/test_drone_blocks_1.sb2 deleted file mode 100644 index c9a97713d..000000000 Binary files a/src/tools/scratch2jderobot/data/test_drone_blocks_1.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_drone_blocks_2.sb2 b/src/tools/scratch2jderobot/data/test_drone_blocks_2.sb2 deleted file mode 100644 index 60630decb..000000000 Binary files a/src/tools/scratch2jderobot/data/test_drone_blocks_2.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_drone_blocks_3.sb2 b/src/tools/scratch2jderobot/data/test_drone_blocks_3.sb2 deleted file mode 100644 index fd7351508..000000000 Binary files a/src/tools/scratch2jderobot/data/test_drone_blocks_3.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_general_blocks.sb2 b/src/tools/scratch2jderobot/data/test_general_blocks.sb2 deleted file mode 100644 index 88c035e34..000000000 Binary files a/src/tools/scratch2jderobot/data/test_general_blocks.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_math_blocks_1.sb2 b/src/tools/scratch2jderobot/data/test_math_blocks_1.sb2 deleted file mode 100644 index d0449b23d..000000000 Binary files a/src/tools/scratch2jderobot/data/test_math_blocks_1.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_pose3d_blocks_1.sb2 b/src/tools/scratch2jderobot/data/test_pose3d_blocks_1.sb2 deleted file mode 100644 index b5c299ef2..000000000 Binary files a/src/tools/scratch2jderobot/data/test_pose3d_blocks_1.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_robot_blocks_2.sb2 b/src/tools/scratch2jderobot/data/test_robot_blocks_2.sb2 deleted file mode 100644 index 459c6102b..000000000 Binary files a/src/tools/scratch2jderobot/data/test_robot_blocks_2.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_robot_blocks_3.sb2 b/src/tools/scratch2jderobot/data/test_robot_blocks_3.sb2 deleted file mode 100644 index 65504eade..000000000 Binary files a/src/tools/scratch2jderobot/data/test_robot_blocks_3.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/data/test_robot_blocks_4.sb2 b/src/tools/scratch2jderobot/data/test_robot_blocks_4.sb2 deleted file mode 100644 index 12f59ff6a..000000000 Binary files a/src/tools/scratch2jderobot/data/test_robot_blocks_4.sb2 and /dev/null differ diff --git a/src/tools/scratch2jderobot/extension/ExtensionsDoc.HTTP-9-11.pdf b/src/tools/scratch2jderobot/extension/ExtensionsDoc.HTTP-9-11.pdf deleted file mode 100644 index 558f4f83c..000000000 Binary files a/src/tools/scratch2jderobot/extension/ExtensionsDoc.HTTP-9-11.pdf and /dev/null differ diff --git a/src/tools/scratch2jderobot/extension/scratch2robot.s2e b/src/tools/scratch2jderobot/extension/scratch2robot.s2e deleted file mode 100644 index b902e4497..000000000 --- a/src/tools/scratch2jderobot/extension/scratch2robot.s2e +++ /dev/null @@ -1,21 +0,0 @@ -{ - "extensionName": "Scratch2JdeRobot", - "extensionPort": 12345, - "blockSpecs": [ - ["", "stop robot-drone", "stop"], - ["", "move robot %n", "robot/move", "vx,vz"], - ["", "move drone %n", "drone/move", "vx,vz,vyaw"], - ["", "move robot %m.robotDirections speed %n", "robot/move/speed", "forward", 1], - ["", "turn robot %m.turnDirections speed %n", "turn/speed", "left", 1], - ["", "take off drone", "drone/takeoff"], - ["", "land drone", "drone/land"], - ["r", "frontal laser distance", "laser/frontal"], - ["r", "color detection %m.color", "camera/all","red"], - ["r", "get pose3D", "camera/pose3D"], - ], - "menus": { - "robotDirections": ["forward", "back"], - "turnDirections": ["left", "right"], - "color": ["red", "blue"] - } -} diff --git a/src/tools/scratch2jderobot/kurt/commands_src_extras.py b/src/tools/scratch2jderobot/kurt/commands_src_extras.py deleted file mode 100644 index 825061324..000000000 --- a/src/tools/scratch2jderobot/kurt/commands_src_extras.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# commands:Array -commands_extra = [ - # manually added - ['set %m.var to %s', ' ', 9, 'setVar:to:'], - ['change %m.var by %n', ' ', 9, 'changeVar:by:'], -] - -# extension:Array -extras = [] - -# robotics:ScratchExtensio -extras += [ - # add extensions code if not auto-generated - [' ', 'stop robot-drone', 'Scratch2JdeRobot/stop'], - [' ', 'move robot %n', 'Scratch2JdeRobot/robot/move', 'vx,vz'], - [' ', 'move drone %n', 'Scratch2JdeRobot/drone/move', 'vx,vz,vyaw'], - [' ', 'move robot %m.direction speed %n', 'Scratch2JdeRobot/robot/move/speed', 'forward', 1], - [' ', 'turn robot %m.turnDirections speed %n', 'Scratch2JdeRobot/turn/speed', 'left', 1], - [' ', 'take off drone', 'Scratch2JdeRobot/drone/takeoff'], - [' ', 'land drone', 'Scratch2JdeRobot/drone/land'], - ['r', 'frontal laser distance', 'Scratch2JdeRobot/laser/frontal'], - ['r', 'color detection %m.color', 'Scratch2JdeRobot/camera/all', 'red'], - ['r', 'get pose3D', 'Scratch2JdeRobot/camera/pose3D'], -] diff --git a/src/tools/scratch2jderobot/package.xml b/src/tools/scratch2jderobot/package.xml deleted file mode 100644 index da057d641..000000000 --- a/src/tools/scratch2jderobot/package.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - scratch2jderobot - 0.0.0 - - scratch2jderobot - - - - - Raul Perula-Martinez - - - - Raul Perula-Martinez - - - - GPL v3 - - - - - - - - - - - catkin - - - rospy - - - rosunit - rostest - - - - - - - - diff --git a/src/tools/scratch2jderobot/requirements.txt b/src/tools/scratch2jderobot/requirements.txt deleted file mode 100644 index b8deb5ea3..000000000 --- a/src/tools/scratch2jderobot/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -termcolor==1.1.0 -parse==1.8.2 -imutils==0.4.3 --e git+https://github.com/raulperula/kurt.git#egg=kurt diff --git a/src/tools/scratch2jderobot/rosdoc.yaml b/src/tools/scratch2jderobot/rosdoc.yaml deleted file mode 100644 index d21d73abc..000000000 --- a/src/tools/scratch2jderobot/rosdoc.yaml +++ /dev/null @@ -1,2 +0,0 @@ - - builder: sphinx - sphinx_root_dir: doc diff --git a/src/tools/scratch2jderobot/scripts/scratch2python.py b/src/tools/scratch2jderobot/scripts/scratch2python.py deleted file mode 100755 index 7784aa42e..000000000 --- a/src/tools/scratch2jderobot/scripts/scratch2python.py +++ /dev/null @@ -1,297 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -__author__ = "Raul Perula-Martinez" -__copyright__ = "JdeRobot project" -__credits__ = ["Raul Perula-Martinez"] -__license__ = "GPL v3" -__version__ = "0.0.0" -__maintainer__ = "Raul Perula-Martinez" -__email__ = "raules@gmail.com" -__status__ = "Development" - -import kurt -import os -import sys - -from difflib import SequenceMatcher -from parse import parse, compile -from termcolor import cprint - -MATH = [ - ['sqrt of {}', 'math.sqrt({l[0]})'], - ['sin of {}', 'math.sin({l[0]})'], - ['cos of {}', 'math.cos({l[0]})'], - ['tan of {}', 'math.tan({l[0]})'], - ['asin of {}', 'math.asin({l[0]})'], - ['acos of {}', 'math.acos({l[0]})'], - ['atan of {}', 'math.atan({l[0]})'], - ['log of {}', 'math.log10({l[0]})'], - ['ln of {}', 'math.log({l[0]})'], - ['floor of {}', 'math.floor({l[0]})'], - ['ceiling of {}', 'math.ceil({l[0]})'], - ['abs of {}', 'abs({l[0]})'], - ['{} mod of {}', '{l[0]}%{l[1]}'], - -] - -GENERAL = [ - ['end', ''], - ['forever', 'while True:'], - ['if {} then', 'if {l[0]}:'], - ['if {} > {} then', 'if {l[0]} > {l[1]}:'], - ['if {} < {} then', 'if {l[0]} < {l[1]}:'], - ['else', 'else:'], - ['repeat {}', 'for i in range({l[0]}):'], - ['say {}', 'print({l[0]})'], - ['set {} to {}', '{l[0]} = {l[1]}'], - ['wait {} secs', 'time.sleep({l[0]})'], - ['length of {}', 'len({l[0]})'], - ['insert {} at {} of {}', '{l[2]}.insert({l[1]}, {l[0]})'], - ['item {} of {}', '{l[1]}[0][{l[0]}]'], - ['add {} to {}', '{l[1]}.append({l[0]})'], - ['delete {} of {}', '{l[1]}.pop({l[0]})'], -] - -ROBOTICS = [ - ['move robot {}', 'robot.move_vector({l[0]})'], - ['move drone {}', 'robot.move_vector({l[0]})'], - ['move robot {} speed {}', 'robot.move("{l[0]}", {l[1]})'], - ['turn robot {} speed {}', 'robot.turn("{l[0]}", {l[1]})'], - ['stop robot-drone', 'robot.stop()'], - ['take off drone', 'robot.take_off()'], - ['land drone', 'robot.land()'], - ['frontal laser distance', 'robot.get_laser_distance()'], - ['color detection {}', 'robot.detect_object("{l[0]}")'], - ['get pose3D', 'robot.get_pose3d()'], - -] - -LISTNAMES = [] - -def is_conditional(sentence): - """ - Returns if a sentence is conditional or not. - - @param sentence: The sentence to check. - @return: True if it has a conditional, False otherwise. - """ - if "if" in sentence: - return True - - return False - - -def is_list(sentence): - """ - Returns if a sentence use list or not. - - @param sentence: The sentence to check. - @return: True if it has a list, False otherwise. - """ - if "insert" in sentence: - return True - if "add" in sentence: - return True - - return False - - -def similar(a, b): - """ - Returns the ratio value comparing two sentences. - - @param a: First sentence. - @param b: Second sentence. - @return: The ratio of the similarity. - """ - return SequenceMatcher(None, a, b).ratio() - - -def sentence_mapping(sentence, threshold=0.0): - """ - Maps a sentence and returns the original and the mapped. - - @param sentence: The sentence to map. - @return: The original sentence and the mapped sentence. - """ - - found = False - options = [] - original = None - translation = None - - # first look for general blocks - for elem in MATH: - if elem[0][:3] == sentence.replace(' ', '').replace('(', '')[:3]: - options.append(elem) - found = True - - if not found: - for elem in GENERAL: - if elem[0][:3] == sentence.replace(' ', '').replace('(', '')[:3]: - options.append(elem) - found = True - - # then look for robotics blocks - if not found: - for elem in ROBOTICS: - if elem[0][:3] == sentence.replace(' ', '').replace('(', '')[:3]: - options.append(elem) - found = True - - if found: - # select the option that better fits - l = [(m[0], m[1], similar(sentence, m[0])) for m in options] - original, translation, score = max(l, key=lambda item: item[2]) - - - - if score < threshold: - return None, None - - # clean sentence - s = sentence.replace(' ', '').replace('(', '').replace(')', '') - - # extract arguments - p = compile(original) - args = p.parse(s) - - if args: - args_aux = list(args) - - # look for more blocks - for idx in range(len(args_aux)): - new_ori, new_trans = sentence_mapping(args_aux[idx], 0.6) - - if new_trans != None: - # print "args: ",idx, args_aux[idx] - # print "trans: ",new_trans - args_aux[idx] = new_trans - - # print "trans: ",translation - # print "args: ",args_aux - translation = translation.format(l=args_aux) - - return original, translation - - -if __name__ == "__main__": - # get current working directory - path = os.getcwd() - open_path = path[:path.rfind('scripts')] + 'data/' - save_path = path[:path.rfind('scripts')] + 'src/scratch2jderobot/' - - if len(sys.argv) == 2: - # template creation - - template = "\ -#!/usr/bin/env python\n\ -# -*- coding: utf-8 -*-\n\n\ -import time\n\ -import config\n\ -import sys\n\ -import comm\n\ -import os\n\ -import yaml\n\ -import math\n\n\ -from drone import Drone\n\ -from robot import Robot\n\n\ -def execute(robot):\n\ -\ttry:\n\ -\t%s\ -except KeyboardInterrupt:\n\ -\t\traise\n\n\ -if __name__ == '__main__':\n\ -\tif len(sys.argv) == 2:\n\ -\t\tpath = os.getcwd()\n\ -\t\topen_path = path[:path.rfind('src')] + 'cfg/'\n\ -\t\tfilename = sys.argv[1]\n\n\ -\telse:\n\ -\t\tsys.exit(\"ERROR: Example:python my_generated_script.py cfgfile.yml\")\n\n\ -\t# loading the ICE and ROS parameters\n\ -\tcfg = config.load(open_path + filename)\n\ -\tstream = open(open_path + filename, \"r\")\n\ -\tyml_file = yaml.load(stream)\n\n\ -\tfor section in yml_file:\n\ -\t\tif section == 'drone':\n\ -\t\t\t#starting comm\n\ -\t\t\tjdrc = comm.init(cfg,'drone')\n\n\ -\t\t\t# creating the object\n\ -\t\t\trobot = Drone(jdrc)\n\n\ -\t\t\tbreak\n\ -\t\telif section == 'robot':\n\ -\t\t\t#starting comm\n\ -\t\t\tjdrc = comm.init(cfg,'robot')\n\n\ -\t\t\t# creating the object\n\ -\t\t\trobot = Robot(jdrc)\n\n\ -\t\t\tbreak\n\ -\t# executing the scratch program\n\ -\texecute(robot)\n\n\ -" - - # load the scratch project - p = kurt.Project.load(open_path + sys.argv[1]) - - # show the blocks included - for scriptable in p.sprites + [p.stage]: - for script in scriptable.scripts: - # exclude definition scripts - if "define" not in script.blocks[0].stringify(): - s = script - print("Stringify:") - sentences = [] - for b in s.blocks: - print(b.stringify()) - sentences += b.stringify().split('\n') - tab_seq = "\t" - python_program = "" - python_lists = "" - - for s in sentences: - # pre-processing if there is a condition (operators and types) - if is_conditional(s): - s = s.replace("'", "").replace("=", "==") - # mapping - original, translation = sentence_mapping(s) - - # count number of tabs - num_tabs = s.replace(' ', tab_seq).count(tab_seq) - - # check if there is list - - if is_list(s) and translation.split(".")[0] not in LISTNAMES : - newlistname = translation.split(".")[0] - LISTNAMES.append(newlistname) - python_lists += tab_seq - python_lists += translation.split(".")[0]+" = []\n\t" - - python_program += tab_seq * (num_tabs + 1) - - # set the code - if translation != None: - python_program += translation - else: - cprint("[WARN] Block <%s> not included yet" % s, 'yellow') - python_program += "\n" + tab_seq - - # join the template with the code and replace the tabs - python_lists += python_program - python_program = python_lists - file_text = template % python_program - file_text = file_text.replace(tab_seq, ' ' * 4) - - print("\n-------------------") - cprint(file_text, 'green') - print("-------------------\n") - - # save the code in a python file with the same name as sb2 file - file_name = sys.argv[1].replace('.sb2','.py') - f = open(save_path + file_name, "w") - os.chmod(save_path + file_name, 0775) - f.write(file_text) - f.close() - - else: - print( - "ERROR: Number of parameters incorrect. Example:\n\tpython scratch2python.py hello_world.sb2") diff --git a/src/tools/scratch2jderobot/setup.py b/src/tools/scratch2jderobot/setup.py deleted file mode 100644 index 8b38c1024..000000000 --- a/src/tools/scratch2jderobot/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from catkin_pkg.python_setup import generate_distutils_setup -from distutils.core import setup - - -d = generate_distutils_setup( - # don't do this unless you want a globally visible script - # scripts=['bin/myscript'], - packages=['scratch2jderobot'], - package_dir={'': 'src'} # , - # package_xml_path=pkg_path -) - -setup(**d) diff --git a/src/tools/scratch2jderobot/src/README.md b/src/tools/scratch2jderobot/src/README.md deleted file mode 100644 index 25bac1ea3..000000000 --- a/src/tools/scratch2jderobot/src/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# Execution steps - -1. Translate the Scratch program to Python - -``` -roscd scratch2ros/scripts -python scratch2python example.sb2 -``` - -2. Launch the ROBOT or the DRONE (simulation) - -**ROS specific**: - -* Kobuki robot (empty world): - -``` -roslaunch kobuki_gazebo kobuki_empty_world.launch --screen -``` - -* Turtlebot robot (with obstacles): - -``` -roslaunch turtlebot_gazebo turtlebot_world.launch -``` - -**ICE specific**: - -* Kobuki robot (laberinth): - -``` -gazebo kobuki-simple.world -``` - -* Parrot drone (empty world): - -``` -gazebo ArDrone.world -``` - -* Parrot drone (cat-mouse world): - -``` -gazebo ardrone-trees-simple.world -``` - -3. Execute the translated python program (depending on the type of robot) - -``` -python main_robot.py -``` - -or - -``` -python main_drone.py -``` diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/__init__.py b/src/tools/scratch2jderobot/src/scratch2jderobot/__init__.py deleted file mode 100755 index e69de29bb..000000000 diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/drone.py b/src/tools/scratch2jderobot/src/scratch2jderobot/drone.py deleted file mode 100755 index d93c9c77e..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/drone.py +++ /dev/null @@ -1,257 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import math -import time -import imutils -import cv2 - - -from parallelIce.cameraClient import CameraClient -from parallelIce.cmdvel import CMDVel -from parallelIce.extra import Extra -from parallelIce.navDataClient import NavDataClient -from parallelIce.pose3dClient import Pose3DClient - -# define the lower and upper boundaries of the basic colors -GREEN_RANGE = ((29, 86, 6), (64, 255, 255)) -RED_RANGE = ((139, 0, 0), (255, 160, 122)) -BLUE_RANGE = ((0, 128, 128), (65, 105, 225)) - -import math -import time -import imutils -import cv2 -import comm -import numpy as np - -from jderobotTypes import CMDVel -from jderobotTypes import Pose3d -from jderobotTypes import Image - -# define the lower and upper boundaries of the basic colors -GREEN_RANGE = ((29, 86, 6), (64, 255, 255)) -RED_RANGE = ((139, 0, 0), (255, 160, 122)) -BLUE_RANGE = ((0, 128, 128), (65, 105, 225)) - - -class Drone(): - - """ - Drone class. - """ - - def __init__(self, jdrc): - """ - Init method. - @param jdrc: - """ - - #variables - self.frontalCamera = False - - #get clients - self.__pose3d_client = jdrc.getPose3dClient("drone.Pose3D") - self.__camera_client = jdrc.getCameraClient("drone.Camera1") - self.__cmdvel_client = jdrc.getCMDVelClient("drone.CMDVel") - self.__extra_client = jdrc.getArDroneExtraClient("drone.Extra") - self.__navdata_client = jdrc.getNavdataClient("drone.Navdata") - - def close(self): - """ - Close communications with servers. - """ - - self.__camera_client.stop() - self.__navdata_client.stop() - self.__pose3d_client.stop() - - - - def get_pose3d(self): - """ - Get the value of odometry sensor. - - @return: return the asked value. - """ - - return self.__pose3d_client.getPose3d() - - - def toggleCam(self): - self.frontalCamera = True - self.__extra_client.toggleCam() - - - def detect_object(self, color): - """ - Detect an object using the camera. - - @param color: color to detect - - @return: size and center of the object detected in the frame - """ - - if not self.frontalCamera: - self.toggleCam() - # define the lower and upper boundaries of the basic colors - GREEN_RANGE = ((29, 86, 6), (64, 255, 255)) - RED_RANGE = ((139, 0, 0), (255, 160, 122)) - BLUE_RANGE = ((0, 128, 128), (65, 105, 225)) - - # initialize the values in case there is no object - x_position = 0 - y_position = 0 - size = 0 - - # chose the color to find - if color == "red": - color_range = RED_RANGE - if color == "green": - color_range = GREEN_RANGE - if color == "blue": - color_range = BLUE_RANGE - - # get image type from camera - image = self.__camera_client.getImage() - - # apply color filters to the image - filtered_image = cv2.inRange(image.data, color_range[0], color_range[1]) - rgb = cv2.cvtColor(image.data, cv2.COLOR_BGR2RGB) - - - # Apply threshold to the masked image - ret,thresh = cv2.threshold(filtered_image,127,255,0) - im,contours,hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) - # Find the index of the largest contour - for c in contours: - if c.any != 0: - areas = [cv2.contourArea(c) for c in contours] - max_index = np.argmax(areas) - cnt=contours[max_index] - if max(areas) > 0.0: - x,y,w,h = cv2.boundingRect(cnt) - cv2.rectangle(rgb,(x,y),(x+w,y+h),(0,255,0),2) - x_position = (w/2)+x - y_position = (h/2)+y - size = w*h - - # show the frame to our screen - cv2.imshow("Frame", rgb) - key = cv2.waitKey(1) & 0xFF - - return size, x_position, y_position - - - def go_up_down(self, direction): - """ - Set the vertical movement of the drone. - - @param direction: direction of the move. Options: forward (default), back. - """ - - # set default velocity (m/s) - vz = 2.0 - - if direction == "down": - vz = -vz - - # assign velocity - self.__cmdvel_client.setVZ(vz) - - # publish movement - self.__cmdvel_client.sendVelocities() - - def move_vector(self, velocities): - """ - Set the movements of the drone. - - @param velocities: a scratch list [x,z,yaw] with the velocities in m/s. - """ - vx = float(velocities[0]) - vz = float(velocities[1]) - vyaw = float(velocities[2]) - print "velocities vector:","x:",vx,"z:",vz,"yaw:",vyaw - self.__cmdvel_client.setVX(vx) - self.__cmdvel_client.setVZ(vz) - self.__cmdvel_client.setYaw(vyaw) - - # publish movement - self.__cmdvel_client.sendVelocities() - # - # def move(self, direction, vel=None): - # """ - # Set the horizontal movement of the drone. - # - # @param direction: direction of the move. Options: forward (default), back. - # @param vel: a number with the velocity in m/s. Default: 1 m/s. - # """ - # - # if vel == None: - # vel = 1 - # # set different direction - # if direction == "back": - # self.__cmdvel_client.setVX(-vel) - # elif direction == "forward": - # self.__cmdvel_client.setVX(vel) - # elif direction == "left": - # self.__cmdvel_client.setVY(vel) - # elif direction == "right": - # self.__cmdvel_client.setVY(-vel) - # elif direction == "down": - # self.__cmdvel_client.setVZ(-vel) - # elif direction == "up": - # self.__cmdvel_client.setVZ(vel) - # print direction - # - # # publish movement - # self.__cmdvel_client.sendVelocities() - # - # def turn(self, direction, vel=None): - # """ - # Set the angular velocity. - # - # @param direction: direction of the move. Options: left (default), right. - # @param vel: a number with the velocity in m/s. Default: 1 m/s. - # """ - # if vel == None: - # vel = 0.5 - # # set default velocity (m/s) - # yaw = vel * math.pi - # - # if direction == "right": - # yaw = -yaw - # - # # assign velocity - # self.__cmdvel_client.setYaw(yaw) - # - # # publish movement - # self.__cmdvel_client.sendVelocities() - - def stop(self): - """ - Set all velocities to zero. - """ - - self.__cmdvel_client.setVX(0) - self.__cmdvel_client.setVY(0) - self.__cmdvel_client.setVZ(0) - self.__cmdvel_client.setYaw(0) - - self.__cmdvel_client.sendVelocities() - - def take_off(self): - """ - Send the take off command. - """ - - self.__extra_client.takeoff() - time.sleep(1) - - def land(self): - """ - Send the land command. - """ - - self.__extra_client.land() - time.sleep(1) diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py b/src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py deleted file mode 100755 index f2d6723e8..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - robot.take_off() - time.sleep(1) - robot.move("forward") - time.sleep(3) - robot.stop() - time.sleep(1) - robot.move("left") - time.sleep(3) - robot.stop() - time.sleep(1) - robot.move("back") - time.sleep(3) - robot.stop() - time.sleep(1) - robot.move("right") - time.sleep(3) - robot.stop() - time.sleep(1) - robot.land() - time.sleep(1) - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/robot.py b/src/tools/scratch2jderobot/src/scratch2jderobot/robot.py deleted file mode 100755 index a080f3d47..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/robot.py +++ /dev/null @@ -1,244 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -__author__ = "Raul Perula-Martinez" -__copyright__ = "JdeRobot project" -__credits__ = ["Raul Perula-Martinez"] -__license__ = "GPL v3" -__version__ = "0.0.0" -__maintainer__ = "Raul Perula-Martinez" -__email__ = "raules@gmail.com" -__status__ = "Development" - - -import comm -import time - -from jderobotTypes import CMDVel - - -class Robot(): - - """ - Robot class. - """ - - def __init__(self, jdrc): - """ - Init method. - - @param jdrc: - """ - - # variables - - self.__vel = CMDVel() - - # get clients - self.__pose3d_client = jdrc.getPose3dClient("robot.Pose3D") - self.__motors_client = jdrc.getMotorsClient("robot.Motors") - self.__laser_client = jdrc.getLaserClient("robot.Laser") - - - def __publish(self, vel): - """ - . - - @param vel: - """ - - self.__motors_client.sendVelocities(vel) - time.sleep(1) - - def __reset(self): - """ - Reset the values to zero. - """ - - # reset velocities (m/s) - self.__vel.vx = 0.0 - self.__vel.vy = 0.0 - self.__vel.vz = 0.0 - self.__vel.ax = 0.0 - self.__vel.ay = 0.0 - self.__vel.az = 0.0 - - def get_pose3d(self): - """ - Get the value of odometry sensor. - - @return: return the asked value. - """ - - return self.__pose3d_client.getPose3d() - - - def detect_object(self, position, color): - """ - Detect an object using the camera. - - @param position: data to return - @param color: color to detect - - @return: size and center of the object detected in the frame - """ - # define the lower and upper boundaries of the basic colors - GREEN_RANGE = ((29, 86, 6), (64, 255, 255)) - RED_RANGE = ((139, 0, 0), (255, 160, 122)) - BLUE_RANGE = ((0, 128, 128), (65, 105, 225)) - - # initialize the values in case there is no object - x_position = 0 - y_position = 0 - size = 0 - - # chose the color to find - if color == "red": - color_range = RED_RANGE - if color == "green": - color_range = GREEN_RANGE - if color == "blue": - color_range = BLUE_RANGE - - # get image type from camera - image = self.__camera_client.getImage() - - # apply color filters to the image - filtered_image = cv2.inRange(image.data, color_range[0], color_range[1]) - rgb = cv2.cvtColor(image.data, cv2.COLOR_BGR2RGB) - - - # Apply threshold to the masked image - ret,thresh = cv2.threshold(filtered_image,127,255,0) - im,contours,hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) - # Find the index of the largest contour - for c in contours: - if c.any != 0: - areas = [cv2.contourArea(c) for c in contours] - max_index = np.argmax(areas) - cnt=contours[max_index] - if max(areas) > 0.0: - x,y,w,h = cv2.boundingRect(cnt) - cv2.rectangle(rgb,(x,y),(x+w,y+h),(0,255,0),2) - x_position = (w/2)+x - y_position = (h/2)+y - size = w*h - - # show the frame to our screen - cv2.imshow("Frame", rgb) - key = cv2.waitKey(1) & 0xFF - - print x_position, y_position, size - - if position == "x position": - return x_position - if position == "y position": - return y_position - else: - return size - - def get_laser_distance(self): - """ - Get the average value for the values of the frontal laser. - - @return: the average measure of the frontal laser data. - """ - - # get laser values - laser = self.__laser_client.getLaserData() - - # clean data (unranged values, e.g. nan) - l = [x for x in laser.values if str(x) != 'nan' and x < 10] - - try: - avg = sum(l) / len(l) - except ZeroDivisionError: - avg = 0 - - return avg - - - def move_vector(self, velocities): - """ - Set the vector movement of the robot. - - @param velocities: a vector with velocities (vx,vz) in m/s. - """ - - vx = float(velocities[0]) - vz = float(velocities[1]) - print "velocities:",vx,vz - # reset values - self.__reset() - - self.__vel.vx = vx - self.__vel.vz = vz - if vz>0: - self.turn("left",vz) - if vz<0: - self.turn("right",vz) - - self.__publish(self.__vel) - - - - def move(self, direction, vel=None): - """ - Set the straight movement of the robot. - - @param direction: direction of the move. Options: forward (default), back. - @param vel: a number with the velocity in m/s. Default: 0.2 m/s. - """ - - # reset values - self.__reset() - - # set default velocity (m/s) - self.__vel.vx = 0.2 - - # set different velocity than default - if vel != None: - self.__vel.vx = vel - - # set different direction - if direction == "back": - self.__vel.vx = -self.__vel.vx - - # publish movement - self.__publish(self.__vel) - - def turn(self, direction, vel=None): - """ - Set the angular movement of the robot. - - @param direction: direction of the move. Options: left (default), right. - @param vel: a number with the velocity in m/s. Default: 0.2 m/s. - """ - - # reset values - # self.__reset() - - # set default velocity (m/s) - self.__vel.az = 0.2 - - # set different velocity - if vel != None: - self.__vel.az = vel - - # set different direction - if direction == "right": - self.__vel.az = -self.__vel.az - - # publish movement - self.__publish(self.__vel) - - def stop(self): - """ - Set all velocities to zero in order to stop any move. - """ - - # reset values - self.__reset() - - # publish movement - self.__publish(self.__vel) diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/scratch.py b/src/tools/scratch2jderobot/src/scratch2jderobot/scratch.py deleted file mode 100755 index b5dd76184..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/scratch.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time - -def execute(robot): - try: - while True: - robot.move("%s", %s) - time.sleep(5) - robot.stop() - time.sleep(1) - robot.move("%s", %s) - time.sleep(5) - robot.stop() - time.sleep(1) - robot.turn("%s", %s) - time.sleep(2) - robot.stop() - time.sleep(1) - robot.turn("%s", %s) - time.sleep(2) - robot.stop() - time.sleep(1) - - except KeyboardInterrupt: - raise diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py deleted file mode 100755 index fb3908498..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - mylist = [] - myvelocity = [] - robot.take_off() - while True: - mylist.insert(0, robot.detect_object("red")) - size = mylist[0][0] - x = mylist[0][1] - y = mylist[0][2] - if size > 0: - if size > 700: - velx = '-2' - else: - velx = '2' - - if x > 165: - velyaw = '-2' - else: - velyaw = '2' - - if y > 110: - velz = '-1' - else: - velz = '1' - - else: - robot.stop() - velx = '0' - velz = '0' - velyaw = '2' - - myvelocity.insert(0, velx) - myvelocity.insert(1, velz) - myvelocity.insert(2, velyaw) - robot.move_vector(myvelocity) - - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_1.py deleted file mode 100755 index 6f506b7a0..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_1.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - mylist = [] - robot.take_off() - velx = '2' - velz = '1' - velyaw = '-3' - mylist.append(velx) - mylist.append(velz) - mylist.append(velyaw) - robot.move_vector(mylist) - time.sleep(4) - robot.stop() - robot.land() - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_2.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_2.py deleted file mode 100755 index da442ca4e..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_2.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - mylist2 = [] - mylist = [] - mylist2.append('0') - mylist2.append('0') - mylist2.append('-2') - mylist.append('0') - mylist.append('0') - mylist.append('2') - robot.take_off() - time.sleep(1) - robot.move_vector(mylist) - time.sleep(3) - robot.stop() - time.sleep(1) - robot.move_vector(mylist2) - time.sleep(3) - robot.stop() - time.sleep(1) - robot.land() - time.sleep(1) - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_3.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_3.py deleted file mode 100755 index d7884527e..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_3.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - mylist = [] - robot.take_off() - time.sleep(1) - mylist.append('1') - mylist.append('0') - mylist.append('0') - robot.move_vector(mylist) - time.sleep(3) - robot.stop() - time.sleep(1) - mylist.insert(0, '-1') - mylist.insert(1, '0') - mylist.insert(2, '0') - robot.move_vector(mylist) - time.sleep(3) - robot.stop() - time.sleep(1) - mylist.insert(0, '0') - mylist.insert(1, '1') - mylist.insert(2, '0') - robot.move_vector(mylist) - time.sleep(3) - robot.stop() - time.sleep(1) - mylist.insert(0, '0') - mylist.insert(1, '-1') - mylist.insert(2, '0') - robot.move_vector(mylist) - time.sleep(3) - robot.stop() - time.sleep(1) - robot.land() - time.sleep(1) - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_general_blocks.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_general_blocks.py deleted file mode 100755 index a15e31ec7..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_general_blocks.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - while True: - boolean = '0' - if ((boolean) == "Hello"): - for i in range(10): - print('Hello World') - time.sleep(1) - - - if ((boolean) > 0): - print('Hello World') - else: - print('Hello World') - - if ((boolean) == 1): - print('Hello World') - - - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_math_blocks_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_math_blocks_1.py deleted file mode 100755 index 8355544f4..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_math_blocks_1.py +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml - -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - if 2 == 2 and 3 > 2: - x = math.sqrt(9) - x = math.sin(9) - x = math.cos(9) - x = math.tan(9) - x = math.asin(9) - x = math.acos(9) - x = math.atan(9) - x = math.log(9) - x = math.log10(9) - x = abs(9) - x = math.floor(9) - x = math.ceil(9) - - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_pose3d_blocks_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_pose3d_blocks_1.py deleted file mode 100755 index 441b728bc..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_pose3d_blocks_1.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - myList = [] - myList.append(robot.get_pose3d()) - posex = myList[0][0] - posey = myList[0][1] - posez = myList[0][2] - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_2.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_2.py deleted file mode 100755 index 839715a0d..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_2.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - while True: - robot.turn("left", 1) - time.sleep(5) - robot.stop() - time.sleep(1) - robot.turn("right", 2) - time.sleep(5) - robot.stop() - time.sleep(1) - - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_3.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_3.py deleted file mode 100755 index 5eae3dfef..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_3.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - while True: - robot.move("forward", 2) - time.sleep(5) - robot.stop() - time.sleep(1) - robot.move("back", 2) - time.sleep(5) - robot.stop() - time.sleep(1) - robot.turn("left", 0.5) - time.sleep(2) - robot.stop() - time.sleep(1) - robot.turn("right", 0.5) - time.sleep(2) - robot.stop() - time.sleep(1) - - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) - diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_4.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_4.py deleted file mode 100755 index 317c78251..000000000 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_4.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import time -import config -import sys -import comm -import os -import yaml -import math - -from drone import Drone -from robot import Robot - -def execute(robot): - try: - mylist = [] - mylist2 = [] - mylist.append('0') - mylist.append('1') - mylist2.append('0.5') - mylist2.append('0') - while True: - lasedata = robot.get_laser_distance() - if lasedata < 2.5: - robot.move_vector(mylist) - else: - robot.move_vector(mylist2) - - - except KeyboardInterrupt: - raise - -if __name__ == '__main__': - if len(sys.argv) == 2: - path = os.getcwd() - open_path = path[:path.rfind('src')] + 'cfg/' - filename = sys.argv[1] - - else: - sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml") - - # loading the ICE and ROS parameters - cfg = config.load(open_path + filename) - stream = open(open_path + filename, "r") - yml_file = yaml.load(stream) - - for section in yml_file: - if section == 'drone': - #starting comm - jdrc = comm.init(cfg,'drone') - - # creating the object - robot = Drone(jdrc) - - break - elif section == 'robot': - #starting comm - jdrc = comm.init(cfg,'robot') - - # creating the object - robot = Robot(jdrc) - - break - # executing the scratch program - execute(robot) -