Skip to content
This repository was archived by the owner on Feb 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/tools/scratch2jderobot/cfg/drone.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
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
maxW: 0.7

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

Expand Down
3 changes: 2 additions & 1 deletion src/tools/scratch2jderobot/scripts/scratch2python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions src/tools/scratch2jderobot/src/scratch2jderobot/drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
72 changes: 72 additions & 0 deletions src/tools/scratch2jderobot/src/scratch2jderobot/drone_move.py
Original file line number Diff line number Diff line change
@@ -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)

2 changes: 0 additions & 2 deletions src/tools/scratch2jderobot/src/scratch2jderobot/test_cat_mouse_1.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
Expand Down Expand Up @@ -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/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
Expand Down Expand Up @@ -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/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
Expand All @@ -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/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
Expand All @@ -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/'
Expand Down
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
robot.move("forward")
Expand All @@ -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/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
Expand All @@ -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/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
Expand All @@ -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/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
try:
Expand All @@ -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/'
Expand Down