From 8e96bb865f41c4859fa5072abc8a32425b5b426d Mon Sep 17 00:00:00 2001 From: globotix Date: Fri, 1 Oct 2021 03:03:34 +0800 Subject: [PATCH 1/3] removing extra files --- CMakeLists.txt~ | 163 ---------------------------------------- package.xml~ | 56 -------------- src/main_cloud_ros.py~ | 132 -------------------------------- src/roscommands.py~ | 80 -------------------- src/rosrun.py~ | 69 ----------------- src/rosservice.py~ | 152 ------------------------------------- src/rostopic.py~ | 166 ----------------------------------------- srv/Comando.srv~ | 3 - 8 files changed, 821 deletions(-) delete mode 100644 CMakeLists.txt~ delete mode 100644 package.xml~ delete mode 100755 src/main_cloud_ros.py~ delete mode 100644 src/roscommands.py~ delete mode 100644 src/rosrun.py~ delete mode 100644 src/rosservice.py~ delete mode 100644 src/rostopic.py~ delete mode 100755 srv/Comando.srv~ diff --git a/CMakeLists.txt~ b/CMakeLists.txt~ deleted file mode 100644 index 84d87a0..0000000 --- a/CMakeLists.txt~ +++ /dev/null @@ -1,163 +0,0 @@ -cmake_minimum_required(VERSION 2.8.3) -project(cloudRos) - -## Find catkin macros and libraries -## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) -## is used, also find other catkin packages -find_package(catkin REQUIRED COMPONENTS - roscpp - rospy - std_msgs - message_generation -) - -## System dependencies are found with CMake's conventions -# find_package(Boost REQUIRED COMPONENTS system) - - -## 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 ## -################################################ - -## To declare and build messages, services or actions from within this -## package, follow these steps: -## * Let MSG_DEP_SET be the set of packages whose message types you use in -## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...). -## * In the file package.xml: -## * add a build_depend and a run_depend tag for each package in MSG_DEP_SET -## * If MSG_DEP_SET isn't empty the following dependencies might have been -## pulled in transitively but can be declared for certainty nonetheless: -## * add a build_depend tag for "message_generation" -## * add a run_depend tag for "message_runtime" -## * In this file (CMakeLists.txt): -## * add "message_generation" and every package in MSG_DEP_SET to -## find_package(catkin REQUIRED COMPONENTS ...) -## * add "message_runtime" and every package in MSG_DEP_SET to -## catkin_package(CATKIN_DEPENDS ...) -## * uncomment the add_*_files sections below as needed -## and list every .msg/.srv/.action file to be processed -## * uncomment the generate_messages entry below -## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...) - -## Generate messages in the 'msg' folder -# add_message_files( -# FILES -# Message1.msg -# Message2.msg -# ) - -## Generate services in the 'srv' folder - add_service_files( - FILES - Comando.srv - ) - -## Generate actions in the 'action' folder -# add_action_files( -# FILES -# Action1.action -# Action2.action -# ) - -## Generate added messages and services with any dependencies listed here - generate_messages( - DEPENDENCIES - std_msgs - ) - -################################### -## catkin specific configuration ## -################################### -## The catkin_package macro generates cmake config files for your package -## Declare things to be passed to dependent projects -## INCLUDE_DIRS: uncomment this if you package contains header files -## LIBRARIES: libraries you create in this project that dependent projects also need -## CATKIN_DEPENDS: catkin_packages dependent projects also need -## DEPENDS: system dependencies of this project that dependent projects also need -catkin_package( -# INCLUDE_DIRS include -# LIBRARIES space_ros - CATKIN_DEPENDS roscpp rospy std_msgs message_runtime -# DEPENDS system_lib -) - -########### -## Build ## -########### - -## Specify additional locations of header files -## Your package locations should be listed before other locations -# include_directories(include) -include_directories( - ${catkin_INCLUDE_DIRS} -) - -## Declare a cpp library -# add_library(space_ros -# src/${PROJECT_NAME}/space_ros.cpp -# ) - -## Declare a cpp executable -# add_executable(space_ros_node src/space_ros_node.cpp) - -## Add cmake target dependencies of the executable/library -## as an example, message headers may need to be generated before nodes -# add_dependencies(space_ros_node space_ros_generate_messages_cpp) - -## Specify libraries to link a library or executable target against -# target_link_libraries(space_ros_node -# ${catkin_LIBRARIES} -# ) - -############# -## Install ## -############# - -# all install targets should use catkin DESTINATION variables -# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html - -## Mark executable scripts (Python etc.) for installation -## in contrast to setup.py, you can choose the destination -# install(PROGRAMS -# scripts/my_python_script -# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -# ) - -## Mark executables and/or libraries for installation -# install(TARGETS space_ros space_ros_node -# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} -# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -# ) - -## Mark cpp header files for installation -# install(DIRECTORY include/${PROJECT_NAME}/ -# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} -# FILES_MATCHING PATTERN "*.h" -# PATTERN ".svn" EXCLUDE -# ) - -## Mark other files for installation (e.g. launch and bag files, etc.) -# install(FILES -# # myfile1 -# # myfile2 -# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} -# ) - -############# -## Testing ## -############# - -## Add gtest based cpp test target and link libraries -# catkin_add_gtest(${PROJECT_NAME}-test test/test_space_ros.cpp) -# if(TARGET ${PROJECT_NAME}-test) -# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}) -# endif() - -## Add folders to be run by python nosetests -# catkin_add_nosetests(test) diff --git a/package.xml~ b/package.xml~ deleted file mode 100644 index d79dec3..0000000 --- a/package.xml~ +++ /dev/null @@ -1,56 +0,0 @@ - - - cloud_ros - 0.0.0 - The cloud_ros package - - - - - alyson - - - - - - TODO - - - - - - - - - - - - - - - - - - - message_generation - - - - message_runtime - - - catkin - roscpp - rospy - std_msgs - roscpp - rospy - std_msgs - - - - - - - - diff --git a/src/main_cloud_ros.py~ b/src/main_cloud_ros.py~ deleted file mode 100755 index b4fb82a..0000000 --- a/src/main_cloud_ros.py~ +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/env python - -import roslib; roslib.load_manifest('cloud_ros') -import rospy -from cloud_ros.srv import Comando -from std_msgs.msg import String -from pySpacebrew.spacebrew import Spacebrew -import rosgraph.masterapi - -import rostopic -from rostopic import rostopicFunctions - -import rosservice -from rosservice import rosserviceFunctions - -import rosrun -from rosrun import rosrunFunctions - -import roscommands -from roscommands import rosCommandsFunctions - -<<<<<<< HEAD -import sensor -from sensor import rosSensors - -======= ->>>>>>> 76550579ceb2a72361e7c3e8cea62b2a3fd5cd65 -import subprocess -import threading - -import sys, tty, termios - -import json -import time - -def send(req): - - global brew - - comando = req.command.split(" ") - - if(comando[0] == "rostopic"): - rostopicFunctions(req.command, brew) - elif(comando[0] == "rosservice"): - rosserviceFunctions(req.command, brew) - elif(comando[0] == "rosrun"): - rosrunFunctions(req.command, brew) - elif(comando[0] == "roscommands"): - rosCommandsFunctions(req.command, brew) - else: - rospy.logwarn("Incorrect command syntax") - -def received(data): - global brew - global start_time - - if data['action']=="send" and data['commandRos']=='rostopic': - method = getattr(rostopic, data['function']) - result = method(brew, data['topic'], data['freq'], data['ip']) - elif data['action']=="send" and data['commandRos']=='rosservice': - method = getattr(rosservice, data['function']) - result = method(brew, data['service'], data['args']) - elif data['action']=="send" and data['commandRos']=='rosrun': - method = getattr(rosrun, data['function']) - result = method(brew, data['package'], data['executable'], data['parameters']) - elif data['action']=="send" and data['commandRos']=='roscommands': - method = getattr(roscommands, data['function']) - result = method(brew, data['commands']) - else: - rospy.logwarn(data['title']+"\n"+data['datum']) - -class myThread (threading.Thread): - def __init__(self, threadID, name, counter): - threading.Thread.__init__(self) - self.threadID = threadID - self.name = name - self.counter = counter - - def run(self): - - global brew - - while(True): - orig_settings = termios.tcgetattr(sys.stdin) - tty.setcbreak(sys.stdin) - #tty.setraw(sys.stdin) - ch=sys.stdin.read(1)[0] - - if(ch == 'A'): - comm = "up" - elif(ch == 'B'): - comm = "down" - elif(ch == 'C'): - comm = "right" - elif(ch == 'D'): - comm = "left" - else: - comm = "" - - if(comm != ""): - rosCommandsFunctions(comm, brew) - -def cloud_ros(): - name = "rosPy Example" - - server = "localhost" - #server = "sandbox.spacebrew.cc" - - global brew - - brew = Spacebrew(name=name, server=server) - brew.addPublisher("Publisher") - brew.addSubscriber("Subscriber") - - try: - # start-up spacebrew - brew.start() - brew.subscribe("Subscriber", received) - - thread2 = myThread(1, "Thread-2", 1) - thread2.start() - finally: - rospy.init_node('cloud_ros_node') - rospy.loginfo("cloud_ros node is up and running!!!") - - s = rospy.Service('send_data', Comando, send) - - rospy.spin() - -if __name__ == '__main__': - cloud_ros() - diff --git a/src/roscommands.py~ b/src/roscommands.py~ deleted file mode 100644 index 0e0cc2e..0000000 --- a/src/roscommands.py~ +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python - -import roslib; roslib.load_manifest('cloud_ros') -import rospy -from cloud_ros.srv import * -from pySpacebrew.spacebrew import Spacebrew -from std_msgs.msg import String -import rosgraph.masterapi -import time -import os -import subprocess -import threading -from geometry_msgs.msg import Twist -from geometry_msgs.msg import Vector3 - -def rosCommandsFunctions(command, brew): - - commandSplit = command.split(" ") - if len(commandSplit) == 1: - data = {'commandRos':'roscommands', 'function':'roscommands', 'action':'send', 'commands':commandSplit[0]} - brew.publish("Publisher", data) - rospy.logwarn("Command sent = "+command) - elif (comandoSplit[1] == "set_robot"): - data = {'commandRos':'roscommands', 'function':'set_robot', 'action':'send', 'commands':commandSplit[2]} - brew.publish("Publisher", data) - rospy.logwarn("Command sent = "+command) - else: - rospy.logwarn("Incorrect command syntax") - -'''INICIO ROSCOMMANDS''' -def set_robot(brew, commands): - global robot - robot = commands - -def roscommands(brew, commands): - global robot - rospy.logwarn(robot) - - vel = Twist() - global proc - - vel.linear.x = 0 - vel.linear.y = 0 - vel.linear.z = 0 - - vel.angular.x = 0 - vel.angular.y = 0 - vel.angular.z = 0 - - if(commands == "up"): - vel.linear.x = 2 - elif(commands == "down"): - vel.linear.x = -2 - elif(commands == "right"): - vel.angular.z = -2 - elif(commands == "left"): - vel.angular.z = 2 - - robots = robot.split(":") - - for rob in robots: - pub = rospy.Publisher(rob+'/cmd_vel', Twist, queue_size=10) - pub.publish(vel) - - vel.linear.x = 0 - vel.linear.y = 0 - vel.linear.z = 0 - - vel.angular.x = 0 - vel.angular.y = 0 - vel.angular.z = 0 - - time.sleep(0.5) - - pub = rospy.Publisher(rob+'/cmd_vel', Twist, queue_size=10) - pub.publish(vel) - -'''FIM ROSCOMMANDS''' - - diff --git a/src/rosrun.py~ b/src/rosrun.py~ deleted file mode 100644 index cacdf70..0000000 --- a/src/rosrun.py~ +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env python - -import roslib; roslib.load_manifest('cloud_ros') -import rospy -from cloud_ros.srv import * -from pySpacebrew.spacebrew import Spacebrew -from std_msgs.msg import String -import rosgraph.masterapi -import time -import os -import subprocess -import threading - -def rosrunFunctions(command, brew): - global stop_ - stop_ = False - - commandSplit = command.split(" ") - - if len(commandSplit) == 3: - data = {'commandRos':'rosrun', 'function':'rosrun', 'action':'send', 'package':commandSplit[1], 'executable':commandSplit[2], 'parameters':''} - brew.publish("Publisher", data) - rospy.logwarn("Command sent = "+command) - elif len(comandoSplit) == 4: - data = {'commandRos':'rosrun', 'function':'rosrun', 'action':'send', 'package':commandSplit[1], 'executable':commandSplit[2], 'parameters':commandSplit[3]} - brew.publish("Publisher", data) - rospy.logwarn("Command sent = "+command) - else: - rospy.logwarn("Incorrect command syntax") - -'''INICIO ROSRUN''' - -def rosrun(brew, package, executable, parameters): - - aux = parameters.split("@") - parameters = aux[0] - for i in range(1, len(aux)-1): - parameters+=":="+aux[i] - - global proc - if(parameters != ''): - proc = subprocess.Popen(["rosrun " +package +" "+ executable+" "+parameters], stdout=subprocess.PIPE, shell=True) - else: - proc = subprocess.Popen(["rosrun " +package +" "+ executable], stdout=subprocess.PIPE, shell=True) - - data = {'datum':datum, 'title':'Package running ', 'action':'receive'} - - brew.publish("Publisher", data) - - thread1 = myThread(1, "Thread-1", 1) - thread1.start() - -'''FIM ROSRUN''' - -class myThread (threading.Thread): - def __init__(self, threadID, name, counter): - threading.Thread.__init__(self) - self.threadID = threadID - self.name = name - self.counter = counter - def run(self): - - global proc - - print "Starting " + self.name - (datum, err) = proc.communicate() - print "Exiting " + self.name - - diff --git a/src/rosservice.py~ b/src/rosservice.py~ deleted file mode 100644 index 137c2df..0000000 --- a/src/rosservice.py~ +++ /dev/null @@ -1,152 +0,0 @@ -#!/usr/bin/env python - -import roslib; roslib.load_manifest('cloud_ros') -import rospy -from cloud_ros.srv import * -from pySpacebrew.spacebrew import Spacebrew -from std_msgs.msg import String -import rosgraph.masterapi -import time -import os -import subprocess - -def rosserviceFunctions(command, brew): - global stop_ - stop_ = False - - commandSplit = command.split(" ") - if commandSplit[1] == "list": - data = {'commandRos':'rosservice', 'function':'rosserviceList', 'action':'send', 'service':'', 'args':''} - brew.publish("Publisher", data) -<<<<<<< HEAD - rospy.logwarn("Sent command = "+command) -======= - rospy.logwarn("sent command = "+command) ->>>>>>> 76550579ceb2a72361e7c3e8cea62b2a3fd5cd65 - - elif commandSplit[1] == "args": - if len(commandSplit) != 3: - rospy.logwarn("syntax = rosservice args /service") - else: - data = {'commandRos':'rosservice', 'function':'rosserviceArgs', 'action':'send', 'service':commandSplit[2], 'args':''} - brew.publish("Publisher", data) -<<<<<<< HEAD - rospy.logwarn("Sent command = "+command) -======= - rospy.logwarn("sent command = "+command) ->>>>>>> 76550579ceb2a72361e7c3e8cea62b2a3fd5cd65 - - elif commandSplit[1] == "call": - if len(commandSplit) < 3: - rospy.logwarn("syntax = rosservice call /service") - elif len(commandSplit) == 3: - data = {'commandRos':'rosservice', 'function':'rosserviceCall', 'action':'send', 'service':commandSplit[2], 'args':''} - brew.publish("Publisher", data) -<<<<<<< HEAD - rospy.logwarn("Sent command = "+command) -======= - rospy.logwarn("sent command = "+command) ->>>>>>> 76550579ceb2a72361e7c3e8cea62b2a3fd5cd65 - else: - argsSplit = command.split('"') - data = {'commandRos':'rosservice', 'function':'rosserviceCall', 'action':'send', 'service':commandSplit[2], 'args':argsSplit[1]} - brew.publish("Publisher", data) -<<<<<<< HEAD - rospy.logwarn("Sent command = "+command) -======= - rospy.logwarn("sent command = "+command) ->>>>>>> 76550579ceb2a72361e7c3e8cea62b2a3fd5cd65 - - elif commandSplit[1] == "node": - if len(commandSplit) != 3: - rospy.logwarn("syntax = rosservice node /service") - else: - data = {'commandRos':'rosservice', 'function':'rosserviceNode', 'action':'send', 'service':commandSplit[2], 'args':''} - brew.publish("Publisher", data) - - rospy.logwarn("Sent command = "+command) - - elif comandoSplit[1] == "type": - rospy.logwarn(command) - if len(commandSplit) < 3: - rospy.logwarn("syntax = rosservice node /service ( | rossrv (show | list | md5 | package | packages))") - elif len(comandoSplit) == 3: - data = {'commandRos':'rosservice', 'function':'rosserviceType', 'action':'send', 'service':commandSplit[2], 'args':''} - brew.publish("Publisher", data) - rospy.logwarn("Sent command = "+command) - else: - argsSplit = command.split('|') - rospy.logwarn('argssplit = '+argsSplit[1]) - data = {'commandRos':'rosservice', 'function':'rosserviceType', 'action':'send', 'service':commandSplit[2], 'args':argsSplit[1]} - brew.publish("Publisher", data) - rospy.logwarn("Sent command = "+command) - - elif commandSplit[1] == "stop": - stop_ = True - - else: - rospy.logwarn("Incorrect command syntax") - -'''ROSSERVICE LIST START''' -def rosserviceList(brew, service, args): - proc = subprocess.Popen(["rosservice list"], stdout=subprocess.PIPE, shell=True) - - (datum, err) = proc.communicate() - - data = {'datum':datum, 'title':"Rosservice list results from master "+brew.name, 'action':'receive'} - - brew.publish("Publisher", data) -'''ROSSERVICE LIST END''' - - -'''ROSSERVICE ARGS START''' -def rosserviceArgs(brew, service, args): - proc = subprocess.Popen(["rosservice args "+service], stdout=subprocess.PIPE, shell=True) - - (datum, err) = proc.communicate() - - data = {'datum':datum, 'title':"Rosservice args "+service+ " results from master "+brew.name, 'action':'receive'} - brew.publish("Publisher", data) -'''ROSSERVICE ARGS END''' - - -'''ROSSERVICE CALL START''' -def rosserviceCall(brew, service, args): - proc = subprocess.Popen(["rosservice call "+service+" '"+args+"'"], stdout=subprocess.PIPE, shell=True) - (dados, err) = proc.communicate() - - data = {'datum':datum, 'title':"Rosservice call "+service+" "+args+ " results from master "+brew.name, 'action':'receive'} - brew.publish("Publisher", data) -'''ROSSERVICE CALL END''' - - -'''ROSSERVICE NODE START''' -def rosserviceNode(brew, service, args): - proc = subprocess.Popen(["rosservice node "+service], stdout=subprocess.PIPE, shell=True) - (datum, err) = proc.communicate() - - data = {'datum':datum, 'title':"Rosservice node "+service+ " results from master "+brew.name, 'action':'receive'} - - brew.publish("Publisher", data) -'''ROSSERVICE NODE END''' - - -'''ROSSERVICE TYPE START''' -def rosserviceType(brew, service, args): - if args=="": - proc = subprocess.Popen(["rosservice type "+service], stdout=subprocess.PIPE, shell=True) - else: - proc = subprocess.Popen(["rosservice type "+service +" | "+ args], stdout=subprocess.PIPE, shell=True) - - (datum, err) = proc.communicate() - - data = {'datum':datum, 'title':"Rosservice type "+service+ " results from master "+brew.name, 'action':'receive'} - brew.publish("Publisher", data) -'''ROSSERVICE TYPE END''' - - - - - - - diff --git a/src/rostopic.py~ b/src/rostopic.py~ deleted file mode 100644 index 05db746..0000000 --- a/src/rostopic.py~ +++ /dev/null @@ -1,166 +0,0 @@ -#!/usr/bin/env python - -import roslib; roslib.load_manifest('cloud_ros') -import rospy -from cloud_ros.srv import * -from pySpacebrew.spacebrew import Spacebrew -from std_msgs.msg import String -from geometry_msgs.msg import Twist -import rosgraph.masterapi -import time -import os -import subprocess - -import importlib -import sys - -#from rosgraph_msgs.msg import Log -from geometry_msgs.msg import Twist - -#import std_msgs.msg -#import geometry_msgs.msg -#import rosgraph_msgs.msg - -def rostopicFunctions(command, brew): - - global stop_ - stop_ = False - global ip_ - - commandSplit = command.split(" ") - if commandSplit[1] == "list": - if(len(commandSplit) < 3): - ip = '' - else: - ip = commandSplit[2] - - data = {'commandRos':'rostopic', 'function':'rostopicList', 'action':'send', 'topic':'', 'freq':'0', 'ip':ip} - - brew.publish("Publisher", data) - rospy.logwarn("Sent command = "+command) - - elif commandSplit[1] == "echo": - if(len(commandSplit) < 5): - ip = '' - else: - ip = commandSplit[4] - - if len(commandSplit) < 4: - rospy.logwarn("syntax = rostopic echo /topic frequency") - else: - data = {'commandRos':'rostopic', 'function':'rostopicEcho', 'action':'send', 'topic':commandSplit[2][1:], 'freq':commandSplit[3], 'ip':ip} - brew.publish("Publisher", data) - rospy.logwarn("Sent command = "+command) - - elif commandSplit[1] == "info": - if(len(commandSplit) < 4): - ip = '' - else: - ip = commandSplit[3] - - data = {'commandRos':'rostopic', 'function':'rostopicInfo', 'action':'send', 'topic':commandSplit[2], 'freq':'0', 'ip':ip} - brew.publish("Publisher", data) - rospy.logwarn("Sent command = "+command) - - elif commandSplit[1] == "stop": - stop_ = True - else: - rospy.logwarn("Incorrect command syntax") - -'''INICIO ROSTOPIC LIST''' -def rostopicList(brew, topic, freq, ip): - - datum = "" - - master = rosgraph.masterapi.Master('/rostopic') - resp = master.getPublishedTopics('/') - - for i in range(0, len(resp)): - datum += "\n"+resp[i][0] - - data = {'datum':datum, 'title':"Rostopic list results from master "+brew.name, 'action':'receive'} - - brew.publish("Publisher", data) -'''ROSTOPIC LIST END''' - - -'''INICIO ROSTOPIC ECHO''' -def ros2xml(msg, name, depth=0): - xml = ""; - tabs = "\t"*depth - - if hasattr(msg, "_type"): - type = msg._type - xml = xml + tabs + "<" + name + " type=\"" + type + "\">\n" - - try: - for slot in msg.__slots__: - xml = xml + ros2xml(getattr(msg, slot), slot, depth=depth+1) - except: - xml = xml + tabs + str(msg) - xml = xml + tabs + "\n" - else: - xml = xml + tabs + "<" + name + ">" + str(msg) + "\n" - return xml - -def callback(resp): - - global brew_ - global stop_ - global freq_ - - #dados = resp.data - while(stop_ == False): - xml = ros2xml(resp, "") - data = {'datum':xml, 'title':"Rostopic echo results from master "+brew_.name, 'action':'receive'} - brew_.publish("Publisher", data) - time.sleep(float(freq_)) - - return - -def rostopicEcho(brew, topic, freq, ip): - global brew_ - brew_ = brew - - global freq_ - global stop_ - global ip_ - - freq_ = freq - stop_ = False - - datum = "" - - if(ip == '' or ip == ip_): - proc = subprocess.Popen(["rostopic type "+topic], stdout=subprocess.PIPE, shell=True) - (datum, err) = proc.communicate() - - dado = datum.split("/") - dado[0] += ".msg" - - mod = __import__(dado[0], fromlist=[dado[1]]) - - klass = getattr(mod, dado[1].strip()) - - rospy.Subscriber(topic, klass, callback) - else: - data = {'datum':datum, 'title':"IP = " +ip+ " does not correspond to the requested", 'action':'receive'} - brew.publish("Publisher", data) -'''FIM ROSTOPIC ECHO''' - - -'''ROSTOPIC INFO START''' -def rostopicInfo(brew, topic, freq, ip): - datum = "" - - if(ip == '' or ip == ip_): - proc = subprocess.Popen(["rostopic info "+topic], stdout=subprocess.PIPE, shell=True) - (datum, err) = proc.communicate() - - data = {'datum':datum, 'title':"Rostopic info "+topic+ " results from master "+brew.name, 'action':'receive'} - else: - data = {'datum':datum, 'title':"IP = " +ip+ " does not correspond to the requested", 'action':'receive'} - - brew.publish("Publisher", data) - -'''ROSTOPIC INFO END''' diff --git a/srv/Comando.srv~ b/srv/Comando.srv~ deleted file mode 100755 index 671f33d..0000000 --- a/srv/Comando.srv~ +++ /dev/null @@ -1,3 +0,0 @@ -string comando ---- -string resp From 96232ed88f9d17134739e1417f11c18205953177 Mon Sep 17 00:00:00 2001 From: globotix Date: Fri, 1 Oct 2021 03:04:01 +0800 Subject: [PATCH 2/3] added python3-websocket as a dependency --- package.xml | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/package.xml b/package.xml index 52deb4d..56c459c 100644 --- a/package.xml +++ b/package.xml @@ -15,22 +15,6 @@ TODO - - - - - - - - - - - - - - - - message_generation @@ -43,6 +27,7 @@ roscpp rospy std_msgs + python3-websocket roscpp rospy std_msgs From 5f57318a9cb040b921c4a19df2d5d0a516e5c20b Mon Sep 17 00:00:00 2001 From: globotix Date: Fri, 1 Oct 2021 03:04:57 +0800 Subject: [PATCH 3/3] Updated code compatibility to python3 and made map type expolicly a list --- src/__pycache__/roscommands.cpython-38.pyc | Bin 0 -> 1789 bytes src/__pycache__/rosrun.cpython-38.pyc | Bin 0 -> 2152 bytes src/__pycache__/rosservice.cpython-38.pyc | Bin 0 -> 3387 bytes src/__pycache__/rostopic.cpython-38.pyc | Bin 0 -> 3637 bytes src/boolean_client.py | 94 +++++ src/main_cloud_ros.py | 211 ++++++------ .../__pycache__/__init__.cpython-38.pyc | Bin 0 -> 207 bytes .../__pycache__/spacebrew.cpython-38.pyc | Bin 0 -> 7717 bytes src/pySpacebrew/spacebrew.py | 320 +++++++++++------- src/roscommands.py | 123 +++---- src/rosrun.py | 97 +++--- src/rosservice.py | 4 + src/rostopic.py | 257 +++++++------- src/trial.py | 100 ++++++ srv/Comando.srv | 0 15 files changed, 765 insertions(+), 441 deletions(-) create mode 100644 src/__pycache__/roscommands.cpython-38.pyc create mode 100644 src/__pycache__/rosrun.cpython-38.pyc create mode 100644 src/__pycache__/rosservice.cpython-38.pyc create mode 100644 src/__pycache__/rostopic.cpython-38.pyc create mode 100644 src/boolean_client.py create mode 100644 src/pySpacebrew/__pycache__/__init__.cpython-38.pyc create mode 100644 src/pySpacebrew/__pycache__/spacebrew.cpython-38.pyc create mode 100755 src/trial.py mode change 100755 => 100644 srv/Comando.srv diff --git a/src/__pycache__/roscommands.cpython-38.pyc b/src/__pycache__/roscommands.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..af35356b7cfca0c70a9a5e7ff74349b3e4c9589a GIT binary patch literal 1789 zcmb6Z%Wfn!uxPadNV zmqnc5hB$GU9Qg%4#TSq`P|M-xFP0T~fK^&Jjq;BZJoha(yT_C->rG<7(ma-MVn=E53zz-PN^SY}S;G5S)Cia<+|#nCMnENdlYGbzBtHfQy=9W2sHbcoYc<5y!t(P02e6*NQa=D_ zyg3AZj?S<~4SswsZ6 zmw@KCpqDt!^gn2(&eDoYf(OB7JC~?)fxs=ZVm+_RGOw62zTy>=R^IhZx)kr$%EX7$ zYN(64GGV^J@r_dQ#q>ZFYRu(q?a9JY2khw1haHnBt|2!EwZ5>~nZ5j3HLRtC40o3L z9d%mi{G=P2KutuU4H3LD(PU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(jN&scyI7cBsLZY~2JL+Scq&^|?DG^G*XF~H4reC9LiV>?bgHO(# z27m4JoIauFw2>EQo{*mgxlzKKWp;%6X`HDzW_U_C|OIOl|D@P;2L?q>S?v1p;{* zH@coh;3!N8Tr-M>g&b$Zx1#9&IL_)FMKMuVh&&Be#dTo1+yEcq9ZY3V2HauOkEo56X)C0W+q6l2}{OI894P4Wwuc4x7 z+xFROxTe(uwL)w3kYwq$ZD&OcU2&f7B-&I3t%9(+45`ZI|8mBLU(_-9k`B-pLEzEs OYaxI&-xT3;c<~=UVhF1M literal 0 HcmV?d00001 diff --git a/src/__pycache__/rosservice.cpython-38.pyc b/src/__pycache__/rosservice.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ad4d3d5116253574fd850016a15ec11c4be6cd6f GIT binary patch literal 3387 zcmcIm&2Jk;6yKTs^u~4^HzjE(WgAtrE;JFKman#gA}T6XZb$+`1~uAvHqJKdU2A5Y z593?_aX^52LL4fT9P97f9_h`cz7<&*}u=Bj?IHm3S~Ezc}wf3MXF%waj`i_B$X(2uh`D?ndjMK%uo1S_!# z=*x^OX_fLJ*rZiut{x?Aw!#xpA(C7Ll3Qx|^EOS_cm=fIT>%0Fc$8V81fX-~{uy-W5ebG!OJC0eTQ8EmYpO=$?mV;bMj zcIIK{@2T0P-w{^W(0QaJizpS(fyQxWgJcQLc(zs&|C?!@*r1OIf7sWn@jsQ`veNr& ze;uVLoO0&*Pl>-&-cRn6T?2GlJ?l`fni+@(&W5#i)#@`*A@PmO{V$LZgr8C~wbh;Aj@Q7OnHM;(sxW#v z!^mLgdkFMye^}S^AroK7aCt@9|0BELYq6`WeN|ztL6CdZyGO)3BoL_5h(eJ{7Xn=b zd^4;EvN#yuN1h>qm`SZ-O1GXgn|{m|6Cs_oc3e-xB$k%n>+NF&hR+*9<`&wkpnE;w zo$;k0PQ7ficgy1waPlFRfzCy-6Q}+*F7_?(aKATytZvAjkAQKAIVX*}A4Q{gBWL99 zkAZPSW~C7)E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--git a/src/__pycache__/rostopic.cpython-38.pyc b/src/__pycache__/rostopic.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7a3735c8a2af0c6cdc7ec54a71108702e199c688 GIT binary patch literal 3637 zcma)9&2JmW6`z^??oFqB~U;q(2IediXL*Hjs}YU0X^rhm_si;>E4qLb$@S`q-4WEyTrcvdh=#>-tYb1 z@U!XZh~XLRej4vBF!nEMTz(uh?&2-}1|gZ`DQi|GZ*tofO<_x?>Dbb3y0-M1K1z`W z-LM&Qn&YIkZq$ry-A$*u^=94Hy>xo3vN_Y7v2$mev&rmmPWq=D8i5SIVa<72lM%`V zc|}gi`Zv6JMNZ2Z^eoC*IfwG9oR_NO&dKP$^h@L@fJ;v6W}o`*^o296AA=hBx`r6cR#`UAJ*Lq|@R?y2BRyF*XTlx&&Nw`Tty z*_?&Ve~xUSUGw=d0crSzfZ1Ka$Ha%Obn)Yu3XI{#to>|C~3@aLCNKDI9i2 z*fZ>m9AZMaM(4dw+tkOkkDz1RBFUuTKVI`q)XuxzIFpa_!h}1ASzCAV%=mFtdev-q zMG>SyU}!$_FjHQ-am68`tKCSnU0SzG+w+x8jTHW zv_UoxldOGwvAKH~Hf|@|$uIgIP|Kyy*y>+>A)f)H^k5pPHdTB=+CrvUF z^s3Do4;$zmn;^}1pT;U%^Gq<>w{Z#1rao$J(qy$nXXnaT$IqF%fyVi#8+&;-+1O3< z?Ob<`Hrla1=wz*(G&zbl3f11Qwf7VaSM`?8^R(D_{K@9yq?_x+YK_lf9h;dSH|~!P zy;#9Y#TEo}Tqojn{Cp7#mkVZpFMOxY=ft=lrSSO-^O<XjY>&Oylf+Lf;MO8#`ycs`G&IiI&?tWr(%VB7axKy**Q_ z=Ec2^@jtdE%))M>$2gW-6dwg35@)+GkLkwE;%=heBuh2*77DdU;wlNkhT4EIer4FW z*k#Y~j(UfN2riXaquLC_L%apeW5R`>BC)`i;8pj9;P9Mdb=nlR7m3c;e&zGzX=`kSYzOqj&`(LGI&wIbD&vh zh0h$)dvf=4mR;wJew96Vo1MVk!1y_uv zdChn&ecVgV`K^A?pxW)#zO#BKQX#&TQjbh}dao~TZS=*R=$zj{cn5oN5o@i~FQ8*; ztyYodx@ffkhrIadQ8zUKyh<9zDYRM(jMFW4)z6`=ZqpQpbX*;87m!#JoB|84`sC~P%K)g2$PTB7;1E_X~AzgUDNP!GI20jYkXAZl?bd7qD!ofc)uppynVi4-6 z46B~u)G32kYPvq0E_qqgGp7!&5)E(|k~4f%$BU~H{1k!3X60-dO;~Jh?3bA_i&-2u zww?>)7h2|rI8J2AG*v&sms)=7yX%C=5ynH}G$Ofk@4+La$n&=vGEa&|mQ!v+jw^b3 zCL20$=)D9)h*Sysldn2?PCX#|ACn+=8>fRL7!`-xJ(ahU0>t(x?;#huj~+a_XQn96 z9cCTmuSETj^rKd*)9vL-w_55~)PX#zIz6>&2R9G5i?-@)C(8P>;>4-%=R}uQH4fBq zpN(aXAk3xl4$`^)J9dSDMC_`UJb`&rEWh?d@NEZJN8}=uOO0bT6pl zI#8cc{kJ4OC-DV|FG*OoqxfD6zt>0VE7JTuiPuE8x{iUr<1OgE00Ml)6_o?3)D=1t zcQ|(58n-}STLuLm7p7JLEA4FC%^Hyx>NhZI77#QxIj>K0v-$}Q%;CF_Oyx`MKgHL(*j4XT5!IP2^npzN*4 zCSc2x703yb_IoZRha1#K8Qp}p0O`XtxkKA1-i8SI#g8s$^-(*D!k>jp(UovMd^?=~ EFU4JB2><{9 literal 0 HcmV?d00001 diff --git a/src/boolean_client.py b/src/boolean_client.py new file mode 100644 index 0000000..a158810 --- /dev/null +++ b/src/boolean_client.py @@ -0,0 +1,94 @@ +#!/usr/bin/python3 + +import time +import locale +import curses +import sys +from pySpacebrew.spacebrew import Spacebrew + +# set the encoding to use for the terminal string +locale.setlocale(locale.LC_ALL, '') +code = locale.getpreferredencoding() + +# initialize the terminal display +stdscr = curses.initscr() +stdscr.keypad(1) +curses.noecho() # turn off echo +curses.curs_set(0) # turn off cursor + +# set-up a variables to hold coordinates +pos_state = 15 +local_state = False +remote_state = False + +# get app name and server from query string +name = "pyBoolean Example" +# server = "sandbox.spacebrew.cc" +server = "forever-spacebrew.herokuapp.com/" + +for cur_ele in sys.argv: + if "name" in cur_ele: + name = cur_ele[5:] + if "server" in cur_ele: + server = cur_ele[7:] + + +# configure the spacebrew client +brew = Spacebrew(name=name, server=server) +brew.addPublisher("local state", "boolean") +brew.addSubscriber("remote state", "boolean") + + +def handleBoolean(value): + global code, stdscr + stdscr.addstr(pos_remote, pos_state, (str(value) + " ").encode(code)) + stdscr.refresh() + + +brew.subscribe("remote state", handleBoolean) + +try: + # start-up spacebrew + brew.start() + + # create and load info message at the top of the terminal window + info_msg = "This is the pySpacebrew library boolean example. It sends out a boolean message every time\n" + info_msg += "the enter or return key is pressed and displays the latest boolean value it has received.\n" + info_msg += "Connected to Spacebrew as: " + name + "\n" + info_msg += "IMPORTANT: don't shrink the Terminal window as it may cause app to crash (bug with curses lib)." + stdscr.addstr(0, 0, info_msg.encode(code)) + stdscr.refresh() + + # update the location for the remote and local dice state + pos_local = stdscr.getyx()[0] + 2 + pos_remote = pos_local + 2 + + # display the label for the remote and local boolean states + stdscr.addstr(pos_local, 0, "local state: ".encode(code), curses.A_BOLD) + stdscr.addstr(pos_remote, 0, "remote state: ".encode(code), curses.A_BOLD) + + # display the starting state for remote and local boolean states + stdscr.addstr(pos_local, pos_state, (str(local_state) + " ").encode(code)) + stdscr.addstr(pos_remote, pos_state, + (str(remote_state) + " ").encode(code)) + stdscr.refresh() + + # listen for keypresses and handle input + while 1: + c = stdscr.getch() + local_state = not local_state + brew.publish('local state', True) + + if (c == 10 or c == 13): + stdscr.addstr(pos_local, pos_state, + (str(local_state) + " ").encode(code)) + + stdscr.refresh() + +# closing out the app and returning terminal to old settings +finally: + brew.stop() + curses.nocbreak() + stdscr.keypad(0) + curses.echo() + curses.endwin() diff --git a/src/main_cloud_ros.py b/src/main_cloud_ros.py index 8b5195b..13c32bf 100755 --- a/src/main_cloud_ros.py +++ b/src/main_cloud_ros.py @@ -1,67 +1,68 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 -import roslib; roslib.load_manifest('cloud_ros') -import rospy -from cloud_ros.srv import Comando -from std_msgs.msg import String -from pySpacebrew.spacebrew import Spacebrew -import rosgraph.masterapi - -import rostopic -from rostopic import rostopicFunctions - -import rosservice -from rosservice import rosserviceFunctions - -import rosrun +import termios +import tty +import time +import json +import sys +import threading +import subprocess +from roscommands import rosCommandsFunctions +import roscommands from rosrun import rosrunFunctions +import rosrun +from rosservice import rosserviceFunctions +import rosservice +from rostopic import rostopicFunctions +import rostopic +import rosgraph.masterapi +from pySpacebrew.spacebrew import Spacebrew +from std_msgs.msg import String +from cloud_ros.srv import Comando +import rospy +import roslib +roslib.load_manifest('cloud_ros') -import roscommands -from roscommands import rosCommandsFunctions -import subprocess -import threading +def send(req): + global brew -import sys, tty, termios + comando = req.comando.split(" ") -import json -import time + if(comando[0] == "rostopic"): + rostopicFunctions(req.comando, brew) + elif(comando[0] == "rosservice"): + rosserviceFunctions(req.comando, brew) + elif(comando[0] == "rosrun"): + rosrunFunctions(req.comando, brew) + elif(comando[0] == "roscommands"): + rosCommandsFunctions(req.comando, brew) + else: + rospy.logwarn("Incorrect command syntax") + return True -def send(req): - - global brew - - comando = req.command.split(" ") - - if(comando[0] == "rostopic"): - rostopicFunctions(req.command, brew) - elif(comando[0] == "rosservice"): - rosserviceFunctions(req.command, brew) - elif(comando[0] == "rosrun"): - rosrunFunctions(req.command, brew) - elif(comando[0] == "roscommands"): - rosCommandsFunctions(req.command, brew) - else: - rospy.logwarn("Incorrect command syntax") def received(data): - global brew - global start_time - - if data['action']=="send" and data['commandRos']=='rostopic': - method = getattr(rostopic, data['function']) - result = method(brew, data['topic'], data['freq'], data['ip']) - elif data['action']=="send" and data['commandRos']=='rosservice': - method = getattr(rosservice, data['function']) - result = method(brew, data['service'], data['args']) - elif data['action']=="send" and data['commandRos']=='rosrun': - method = getattr(rosrun, data['function']) - result = method(brew, data['package'], data['executable'], data['parameters']) - elif data['action']=="send" and data['commandRos']=='roscommands': - method = getattr(roscommands, data['function']) - result = method(brew, data['commands']) - else: - rospy.logwarn(data['title']+"\n"+data['datum']) + print("recieving data via the websocket: " + data) + global brew + global start_time + + if data['action'] == "send" and data['commandRos'] == 'rostopic': + method = getattr(rostopic, data['function']) + result = method(brew, data['topic'], data['freq'], data['ip']) + elif data['action'] == "send" and data['commandRos'] == 'rosservice': + method = getattr(rosservice, data['function']) + result = method(brew, data['service'], data['args']) + elif data['action'] == "send" and data['commandRos'] == 'rosrun': + method = getattr(rosrun, data['function']) + result = method(brew, data['package'], + data['executable'], data['parameters']) + elif data['action'] == "send" and data['commandRos'] == 'roscommands': + method = getattr(roscommands, data['function']) + result = method(brew, data['commands']) + else: + rospy.logwarn(data['title']+"\n"+data['datum']) + class myThread (threading.Thread): def __init__(self, threadID, name, counter): @@ -71,56 +72,70 @@ def __init__(self, threadID, name, counter): self.counter = counter def run(self): - - global brew - - while(True): - orig_settings = termios.tcgetattr(sys.stdin) - tty.setcbreak(sys.stdin) - #tty.setraw(sys.stdin) - ch=sys.stdin.read(1)[0] - - if(ch == 'A'): - comm = "up" - elif(ch == 'B'): - comm = "down" - elif(ch == 'C'): - comm = "right" - elif(ch == 'D'): - comm = "left" - else: - comm = "" - - if(comm != ""): - rosCommandsFunctions(comm, brew) + + global brew + + while(True): + orig_settings = termios.tcgetattr(sys.stdin) + tty.setcbreak(sys.stdin) + # tty.setraw(sys.stdin) + ch = sys.stdin.read(1)[0] + + if(ch == 'A'): + comm = "up" + elif(ch == 'B'): + comm = "down" + elif(ch == 'C'): + comm = "right" + elif(ch == 'D'): + comm = "left" + else: + comm = "" + + if(comm != ""): + rosCommandsFunctions(comm, brew) + def cloud_ros(): - name = "rosPy Example" + name = "rosPy Example" - server = "localhost" - #server = "sandbox.spacebrew.cc" - - global brew + # server = "localhost" + server = "forever-spacebrew.herokuapp.com/" - brew = Spacebrew(name=name, server=server) - brew.addPublisher("Publisher") - brew.addSubscriber("Subscriber") + global brew - try: - # start-up spacebrew - brew.start() - brew.subscribe("Subscriber", received) + brew = Spacebrew(name=name, server=server) + brew.addPublisher("ROS_Publisher") + brew.addPublisher("ROS_Publisher_two", "boolean") + print('main_cloud_ros: adding publisher') + brew.addSubscriber("Subscriber", "string") - thread2 = myThread(1, "Thread-2", 1) - thread2.start() - finally: - rospy.init_node('cloud_ros_node') - rospy.loginfo("cloud_ros node is up and running!!!") + try: + pass + # start-up spacebrew + brew.start() + brew.subscribe("Subscriber", received) - s = rospy.Service('send_data', Comando, send) + # thread2 = myThread(1, "Thread-2", 1) + # thread2.start() + finally: + rospy.init_node('cloud_ros_node') + rospy.loginfo("cloud_ros node is up and running!!!") - rospy.spin() + rospy.loginfo('service has been started') + s = rospy.Service('send_data', Comando, send) + rospy.spin() -if __name__ == '__main__': - cloud_ros() +def myhook(): + global thread2 + brew.stop() + # thread2.raise_exception() + print ("shutdown time!") + +if __name__ == '__main__': + rospy.on_shutdown(myhook) + try: + cloud_ros() + except rospy.ROSInterruptException: + pass \ No newline at end of file diff --git a/src/pySpacebrew/__pycache__/__init__.cpython-38.pyc b/src/pySpacebrew/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f947ed8e429aae602a91a30f9f14daf94ec9f01e GIT binary patch literal 207 zcmWIL<>g`k0^O9rLK7L! z>w{UkMIdPiJH8}8Kc`qf$UitJH8;N`6|AbDG8kr+etdjpUS>&ryk0@&Ee@O9{FKt1 MR6CF(KLarX0Q-$N`2YX_ literal 0 HcmV?d00001 diff --git a/src/pySpacebrew/__pycache__/spacebrew.cpython-38.pyc b/src/pySpacebrew/__pycache__/spacebrew.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8ea71938b2c5b51f156f3074c36b3a9d4fa5f06f GIT binary patch literal 7717 zcmbtZ%WoseeeUWPo79V=(T--;JG-5IdAYVF$4=~IGFgl>-n9`Mob^bKZTdk_td>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bMT4}7LyWoe2Z3>=@W0~j*Rfi`%loVm-{u~QDW+u*ziL%W zH!Dk=)2jI*#{4^O*?!Vw3%}_q`?rBNZ?2PR76d?3CAtOK*HM`XVC)ozySR^)OzU+F zgiX#e@7K`Ls!7z9?frQg`N2b?Hgbku4 z$4*aqOg8tH?G#QP@14n^ly~H_B}W%Lr3<9ym$eFOI{2}RZ!7W+2k0LL_@>g9^0Z1U zi>hnQ%zK#J+TMPyZe`n(M2Nd2fV7OjTj8#GOtiz1PaHg|x55i{MGa8Rl9xWUPN4yK z4SRaVq0Be%64)2mODeL2jzYk)|Gb0df8rK{hSrhFXRpkhG>E#GD*f?Pw6Ma2irj${ zF_%#B^F=BysFSJ`R%xXLt7qkzu@WOjW+;qaGW##^k)&bpbCii8N%GMjyU=}p*kN(W zGXKSXW_yiV;bdnU%D?3+x~aVSFxpGv?t>_8Eq^20+mY%QhQoq*&fi*s;M+*4n7PfZ zBP)vDzK2mi!#xSLFRQw<8U(6lC1uZUcIrYe59iPK2NYEv@FAwK}6Qzk} zmD=2OYVXGiE%ab>A%0n~>^HL;5@rOdz%bL6kURKZH|k>E@?x^f)tEdc6ap1Un@AA{ zi=zse5&PQfJb0Tsyk#YcHHJv32AgO1$am1^!6U5F|?cbEngAxQ$tOgRUb;g`6l0mWW+eC7&kGnL33 z3reAgsF=I_@GTUKA^1@UPD@)4s^&%3PHhUUh$5v+v77I~?~`mn5E5(#bhD2RILRgs\n" - - try: - for slot in msg.__slots__: - xml = xml + ros2xml(getattr(msg, slot), slot, depth=depth+1) - except: - xml = xml + tabs + str(msg) - xml = xml + tabs + "\n" - else: - xml = xml + tabs + "<" + name + ">" + str(msg) + "\n" - return xml + xml = "" + tabs = "\t"*depth + + if hasattr(msg, "_type"): + type = msg._type + xml = xml + tabs + "<" + name + " type=\"" + type + "\">\n" + + try: + for slot in msg.__slots__: + xml = xml + ros2xml(getattr(msg, slot), slot, depth=depth+1) + except: + xml = xml + tabs + str(msg) + xml = xml + tabs + "\n" + else: + xml = xml + tabs + "<" + name + ">" + str(msg) + "\n" + return xml + def callback(resp): - global brew_ - global stop_ - global freq_ + global brew_ + global stop_ + global freq_ - #dados = resp.data - while(stop_ == False): - xml = ros2xml(resp, "") - data = {'datum':xml, 'title':"Rostopic echo results from master "+brew_.name, 'action':'receive'} - brew_.publish("Publisher", data) - time.sleep(float(freq_)) + #dados = resp.data + while(stop_ == False): + xml = ros2xml(resp, "") + data = {'datum': xml, 'title': "Rostopic echo results from master " + + brew_.name, 'action': 'receive'} + brew_.publish("Publisher", data) + time.sleep(float(freq_)) + + return - return def rostopicEcho(brew, topic, freq, ip): - global brew_ - brew_ = brew + global brew_ + brew_ = brew + + global freq_ + global stop_ + global ip_ - global freq_ - global stop_ - global ip_ + freq_ = freq + stop_ = False - freq_ = freq - stop_ = False + datum = "" - datum = "" + if(ip == '' or ip == ip_): + proc = subprocess.Popen( + ["rostopic type "+topic], stdout=subprocess.PIPE, shell=True) + (datum, err) = proc.communicate() - if(ip == '' or ip == ip_): - proc = subprocess.Popen(["rostopic type "+topic], stdout=subprocess.PIPE, shell=True) - (datum, err) = proc.communicate() + dado = datum.split("/") + dado[0] += ".msg" - dado = datum.split("/") - dado[0] += ".msg" + mod = __import__(dado[0], fromlist=[dado[1]]) - mod = __import__(dado[0], fromlist=[dado[1]]) + klass = getattr(mod, dado[1].strip()) + + rospy.Subscriber(topic, klass, callback) + else: + data = {'datum': datum, 'title': "IP = " + ip + + " does not correspond to the requested", 'action': 'receive'} + brew.publish("Publisher", data) - klass = getattr(mod, dado[1].strip()) - rospy.Subscriber(topic, klass, callback) - else: - data = {'datum':datum, 'title':"IP = " +ip+ " does not correspond to the requested", 'action':'receive'} - brew.publish("Publisher", data) '''FIM ROSTOPIC ECHO''' '''ROSTOPIC INFO START''' + + def rostopicInfo(brew, topic, freq, ip): - datum = "" + datum = "" + + if(ip == '' or ip == ip_): + proc = subprocess.Popen( + ["rostopic info "+topic], stdout=subprocess.PIPE, shell=True) + (datum, err) = proc.communicate() - if(ip == '' or ip == ip_): - proc = subprocess.Popen(["rostopic info "+topic], stdout=subprocess.PIPE, shell=True) - (datum, err) = proc.communicate() + data = {'datum': datum, 'title': "Rostopic info "+topic + + " results from master "+brew.name, 'action': 'receive'} + else: + data = {'datum': datum, 'title': "IP = " + ip + + " does not correspond to the requested", 'action': 'receive'} - data = {'datum':datum, 'title':"Rostopic info "+topic+ " results from master "+brew.name, 'action':'receive'} - else: - data = {'datum':datum, 'title':"IP = " +ip+ " does not correspond to the requested", 'action':'receive'} + brew.publish("Publisher", data) - brew.publish("Publisher", data) '''ROSTOPIC INFO END''' diff --git a/src/trial.py b/src/trial.py new file mode 100755 index 0000000..9cb74b2 --- /dev/null +++ b/src/trial.py @@ -0,0 +1,100 @@ +from websocket import create_connection +import json +import time +from cloudbrain.router.pySpacebrew.spacebrew import Spacebrew + +# add the shared settings file to namespace +import sys +from os.path import dirname, abspath +sys.path.insert(0, dirname(dirname(dirname(abspath(__file__))))) + + +class SpacebrewRouter(object): + def __init__(self, server='127.0.0.1', port=9000): + self.server = server + self.port = port + self.ws = create_connection("ws://%s" % (self.server, self.port)) + + self.ws.send(json.dumps({"admin": [{"admin": True, "no_msgs": False}]})) + + message = { + "config": { + "name": 'router', + "remoteAddress": self.server + } + } + + self.ws.send(json.dumps(message)) + + self.brew = Spacebrew("router", description="Spacebrew Router", server=server) + + # Add publishers for RFID connect and disconnect events + booth_number = 1 + self.brew.addPublisher("booth-{0}-connect".format(booth_number), "boolean") + self.brew.addPublisher("booth-{0}-disconnect".format(booth_number), "boolean") + + self.brew.start() + + def get_spacebrew_config(self): + message = { + "status": True + } + self.ws.send(json.dumps(message)) + return json.loads(self.ws.recv()) + + def link(self, pub_metric, sub_metric, publisher, subscriber, pub_ip, sub_ip): + message = { + "route": { + "type": "add", + "publisher": { + "clientName": publisher, + "name": pub_metric, + "type": "string", + "remoteAddress": pub_ip + }, + "subscriber": { + "clientName": subscriber, + "name": sub_metric, + "type": "string", + "remoteAddress": sub_ip + } + } + } + self.ws.send(json.dumps(message)) + return json.dumps(message) + + def unlink(self, pub_metric, sub_metric, publisher, subscriber, pub_ip, sub_ip): + message = { + "route": { + "type": "remove", + "publisher": { + "clientName": publisher, + "name": pub_metric, + "type": "string", + "remoteAddress": pub_ip + }, + "subscriber": { + "clientName": subscriber, + "name": sub_metric, + "type": "string", + "remoteAddress": sub_ip + } + }, + "targetType": "admin" + } + self.ws.send(json.dumps(message)) + return json.dumps(message) + + def connect_event(self, booth, muse): + self.brew.publish("{0}-connect".format(booth), muse) + + def disconnect_event(self, booth, muse): + self.brew.publish("{0}-disconnect".format(booth), muse) + + +if __name__ == "__main__": + router = SpacebrewRouter(server=forever-spacebrew.herokuapp.com) + router.link('eeg', 'eeg', 'muse-001', 'cloudbrain', '127.0.0.1', '127.0.0.1') + router.link('acc', 'acc', 'muse-001', 'cloudbrain', '127.0.0.1', '127.0.0.1') + time.sleep(1) + router.unlink("eeg", 'eeg', 'muse-001', 'cloudbrain', '127.0.0.1', '127.0.0.1') \ No newline at end of file diff --git a/srv/Comando.srv b/srv/Comando.srv old mode 100755 new mode 100644