From 82931f75f6b96cf0a71b365f99e39bab9605a057 Mon Sep 17 00:00:00 2001 From: Santiago Carrion Date: Thu, 1 Feb 2018 19:56:53 +0100 Subject: [PATCH] small bug fix --- src/tools/scratch2jderobot/cfg/drone.yml | 16 ++--- .../scripts/scratch2python.py | 3 +- .../src/scratch2jderobot/drone.py | 4 +- .../src/scratch2jderobot/drone_move.py | 72 +++++++++++++++++++ .../src/scratch2jderobot/test_cat_mouse_1.py | 2 - .../scratch2jderobot/test_drone_blocks_1.py | 2 - .../scratch2jderobot/test_drone_blocks_2.py | 2 - .../scratch2jderobot/test_drone_blocks_3.py | 2 - .../scratch2jderobot/test_drone_blocks_4.py | 0 .../scratch2jderobot/test_general_blocks.py | 0 .../scratch2jderobot/test_list_blocks_1.py | 0 .../scratch2jderobot/test_robot_blocks_1.py | 3 - .../scratch2jderobot/test_robot_blocks_2.py | 2 - .../scratch2jderobot/test_robot_blocks_3.py | 2 - .../scratch2jderobot/test_robot_blocks_4.py | 2 - 15 files changed, 84 insertions(+), 28 deletions(-) create mode 100755 src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py mode change 100644 => 100755 src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py mode change 100644 => 100755 src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_4.py mode change 100644 => 100755 src/tools/scratch2jderobot/src/scratch2jderobot/test_general_blocks.py mode change 100644 => 100755 src/tools/scratch2jderobot/src/scratch2jderobot/test_list_blocks_1.py diff --git a/src/tools/scratch2jderobot/cfg/drone.yml b/src/tools/scratch2jderobot/cfg/drone.yml index 70c535902..57fc7906c 100644 --- a/src/tools/scratch2jderobot/cfg/drone.yml +++ b/src/tools/scratch2jderobot/cfg/drone.yml @@ -1,7 +1,7 @@ drone: Motors: Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS - Proxy: "Motors:default -h 0.0.0.0 -p 9001" + Proxy: "Motors:default -h localhost -p 9000" Topic: "/cmd_vel_mux/input/teleop" Name: Motors maxV: 3 @@ -9,38 +9,38 @@ drone: Camera1: Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS - Proxy: "Camera:default -h 0.0.0.0 -p 9000" + Proxy: "Camera:default -h localhost -p 9000" Format: RGB8 Topic: "/camera/rgb/image_raw" Name: Camera1 Pose3D: Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS - Proxy: "Pose3D:default -h 0.0.0.0 -p 9001" + Proxy: "Pose3D:default -h localhost -p 9000" Topic: "/odom" Name: Pose3d Laser: Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS - Proxy: "Laser:default -h 0.0.0.0 -p 9001" + Proxy: "Laser:default -h localhost -p 9000" Topic: "/scan" Name: Laser CMDVel: Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS - Proxy: "CMDVel:default -h 0.0.0.0 -p 9001" + Proxy: "CMDVel:default -h localhost -p 9000" Name: CMDVel Navdata: Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS - Proxy: "Navdata:default -h 0.0.0.0 -p 9001" + Proxy: "Navdata:default -h localhost -p 9000" Name: Navdata Extra: Server: 1 # 0 -> Deactivate, 1 -> Ice , 2 -> ROS - Proxy: "Extra:default -h 0.0.0.0 -p 9001" + Proxy: "Extra:default -h localhost -p 9000" Name: Extra - + Vmax: 3 Wmax: 0.7 diff --git a/src/tools/scratch2jderobot/scripts/scratch2python.py b/src/tools/scratch2jderobot/scripts/scratch2python.py index f108076d6..91d26bd07 100755 --- a/src/tools/scratch2jderobot/scripts/scratch2python.py +++ b/src/tools/scratch2jderobot/scripts/scratch2python.py @@ -158,7 +158,7 @@ def sentence_mapping(sentence, threshold=0.0): import os\n\ import yaml\n\n\ from drone import Drone\n\ -from robot import Robot\n\ +from robot import Robot\n\n\ def execute(robot):\n\ \ttry:\n\ \t%s\ @@ -239,6 +239,7 @@ def execute(robot):\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() diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/drone.py b/src/tools/scratch2jderobot/src/scratch2jderobot/drone.py index 3a51ec2e8..2d3d9acd9 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/drone.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/drone.py @@ -130,12 +130,12 @@ def detect_object(self, color): def get_size_object(self): - size, _, _ = self.detect_object(red") + size, _, _ = self.detect_object("red") return size def get_x_position(self): - _, x_position, _ = self.detect_object(red") + _, x_position, _ = self.detect_object("red") return x_position def get_y_position(self): diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py b/src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py new file mode 100755 index 000000000..f2d6723e8 --- /dev/null +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py @@ -0,0 +1,72 @@ +#!/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/test_cat_mouse_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py old mode 100644 new mode 100755 index eaf20cf9c..ef209ff0c --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py @@ -10,7 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList def execute(robot): try: @@ -44,7 +43,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/' diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_1.py index 6e88f15bf..dc0f865cd 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_1.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_1.py @@ -10,7 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList def execute(robot): try: @@ -38,7 +37,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/' diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_2.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_2.py index 285bd979c..3fe7453f7 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_2.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_2.py @@ -10,7 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList def execute(robot): try: @@ -30,7 +29,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/' diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_3.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_3.py index d658862ac..d9166b91e 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_3.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_3.py @@ -10,7 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList def execute(robot): try: @@ -33,7 +32,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/' diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_4.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_drone_blocks_4.py old mode 100644 new mode 100755 diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_general_blocks.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_general_blocks.py old mode 100644 new mode 100755 diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_list_blocks_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_list_blocks_1.py old mode 100644 new mode 100755 diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_1.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_1.py index 537ab7824..ff53cc197 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_1.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_1.py @@ -10,8 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList - def execute(robot): try: robot.move("forward") @@ -26,7 +24,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/' diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_2.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_2.py index 958c16940..bbd642d6d 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_2.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_2.py @@ -10,7 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList def execute(robot): try: @@ -28,7 +27,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/' diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_3.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_3.py index d4b3a87ca..f5334d528 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_3.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_3.py @@ -10,7 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList def execute(robot): try: @@ -36,7 +35,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/' diff --git a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_4.py b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_4.py index fdfd8a265..3f58f6e22 100755 --- a/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_4.py +++ b/src/tools/scratch2jderobot/src/scratch2jderobot/test_robot_blocks_4.py @@ -10,7 +10,6 @@ from drone import Drone from robot import Robot -from mylist import MyList def execute(robot): try: @@ -26,7 +25,6 @@ def execute(robot): raise if __name__ == '__main__': - mylist=MyList() if len(sys.argv) == 2: path = os.getcwd() open_path = path[:path.rfind('src')] + 'cfg/'