Ask Your Question
1

Rviz for android

asked 2019-10-15 03:01:10 -0600

Crowdeal gravatar image

hello i am a new to ros

can't compile by python in raspberry pi3

following is my code

server.py

#! /usr/bin/python

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from os import path
import rospkg
import subprocess
import sys

# Set up dictionary to hold rosrun nodes
nodes = dict()    
rp = rospkg.RosPack()

class MyHandler(BaseHTTPRequestHandler):            
    def do_GET(self):
        print ("\nIncoming request!")
        try:
            if self.path.startswith("/PKG"):
                splitPath = self.path.split("/")
                if len(splitPath) > 2:
                    splitPath.remove('');
                    try:
                        pkg_path = rp.get_path(splitPath[1])
                    except rospkg.ResourceNotFound:
                        self.send_error(404, "Resource not found: %s" % splitPath[1])
                        return

                    subdir = self.path.replace('/PKG/' + splitPath[1], '')
                    filePath = pkg_path + subdir

                    try:
                        f = open(filePath) 
                    except:
                        self.send_error(404, 'Requested file not found: %s' % self.path)
                        return

                    self.send_response(200)
                    self.send_header('Content-Type', "type/html")
                    self.send_header('Content-Length', path.getsize(filePath))
                    self.end_headers()
                    self.wfile.write(f.read())
                    f.close()
                    return
                else:
                    self.send_error(404, 'Not enough information supplied: %s' % self.path)
            if self.path.startswith("/ROSRUN"):
                print ("Received ROSRUN request!")
                splitPath = self.path.split("/")
                # splitPath = "","ROSRUN",NODEHANDLE,A,B,C,...N
                nodeHandle = splitPath[2]
                del splitPath[0:3]

                # If a node with this handle was already running, stop it
                if nodes.has_key(nodeHandle):
                    print ("Already had a node with handle " + nodeHandle + ". Stopping old node and replacing it.")
                    nodes[nodeHandle].kill()

                # Create a new node, include it in the list
                splitPath.insert(0,"rosrun")
                newProc = subprocess.Popen(splitPath, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)                
                nodes[nodeHandle] = newProc

                self.send_error(204)
                return
            if self.path.startswith("/ROSSTOP"):
                # Stop the specified node
                splitPath = self.path.split("/")
                nodeHandle = splitPath[2]
                if nodes.has_key(nodeHandle):
                    print( "Stopping node " + nodeHandle)
                    nodes[nodeHandle].kill()

                self.send_error(204)    
                return
            return
        except IOError:
            self.send_error(404, 'File Not Found: %s' % self.path)

def main():
    # Begin TF throttle
    throttleTFProc = subprocess.Popen(["rosrun", "tf_throttle", "tf_throttle"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    # Begin clock throttle
    #throttleClockProc = subprocess.Popen(["rosrun", "topic_tools", "throttle", "messages", "/clock", "1", "/clock_throttled"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    try:
        server = HTTPServer(('', 44644), MyHandler)
        print ('\nStarted Rviz for Android resource server on port 44644')
        server.serve_forever()
    except KeyboardInterrupt:
        print( 'Control-C received, shutting down server')
        throttleTFProc.kill()
        #throttleClockProc.kill()

        # Shut down all roslaunched processes
        for node in nodes:
            nodes[node].kill()

        server.socket.close()

if __name__ == '__main__':
    main()

error message

Traceback (most recent call last):
  File "/home/pi/server.py", line 99, in <module>
    main()
  File "/home/pi/server.py", line 80, in main
    throttleTFProc = subprocess.Popen(["rosrun", "tf_throttle", "tf_throttle"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
edit retag flag offensive close merge delete

Comments

Can you provide a bit more information please like: Can you run tf_throttle outside the script? Are the Ros environment variables set up correctly (did you source the setup.bash file prior to running the above script)?

Also please update the title of your post as it seems to have no connection to the question.

Jari gravatar imageJari ( 2019-10-15 12:09:08 -0600 )edit

I source the setup.bash to run my code but i dont know what is tf_throttle

And I downloaded the code from https://bitbucket.org/zimmrmn3/rviz-f...

Crowdeal gravatar imageCrowdeal ( 2019-10-15 18:03:09 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-10-15 19:01:58 -0600

Jari gravatar image

It appears you're missing tf_throttle. It was discontinued after ros groovy. If you're somehow still running groovy then you can probably install ros-groovy-tf-throttle package using apt. If not, you can try to build it from the source code here https://github.com/ros-interactive-ma...

edit flag offensive delete link more

Comments

Can I build it on kinetic?

Crowdeal gravatar imageCrowdeal ( 2019-10-15 20:18:25 -0600 )edit

You should be able to but you'll need to isolate the package and probably make some changes to get it to build under catkin. This is the specific package https://github.com/ros-interactive-ma...

Jari gravatar imageJari ( 2019-10-15 22:01:21 -0600 )edit

i git clone it and catkin it in my workspace when i launch tf_throttled.launch it will have a error

ERROR: cannot launch node of type [tf_throttle/tf_throttle]: can't locate node [tf_throttle] in package [tf_throttle]

how can i solve it

Crowdeal gravatar imageCrowdeal ( 2019-10-16 08:03:31 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-10-15 03:01:10 -0600

Seen: 42 times

Last updated: Oct 15