Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't start simulator on Windows. #4

Closed
abhayraw1 opened this issue Feb 22, 2021 · 21 comments
Closed

Can't start simulator on Windows. #4

abhayraw1 opened this issue Feb 22, 2021 · 21 comments

Comments

@abhayraw1
Copy link

abhayraw1 commented Feb 22, 2021

I am trying to launch the swift simulator with the Panda manipulator.
I have a simple jupyter notebook with the following code (as mentioned in the readme):

import roboticstoolbox as rp

panda = rp.models.Panda()
panda.plot(q=panda.qr)

On execution, a new tab opens up in my browser with a small box on the top right corner displaying the timestamp and FPS and nothing happens after this. On the notebook side I get an excpetion, about 5-10 seconds after executing the cell.
Here is the stacktrace for that:

Could not connect to the Swift simulator 

---------------------------------------------------------------------------
Empty                                     Traceback (most recent call last)
<ipython-input-9-7e648cf58e0e> in <module>
      2 
      3 panda = rp.models.Panda()
----> 4 panda.plot(q=panda.qr)

~\Miniconda3\lib\site-packages\roboticstoolbox\robot\Robot.py in plot(self, q, backend, block, dt, limits, vellipse, fellipse, jointaxes, eeframe, shadow, name, movie)
    795         if backend.lower() == 'swift':  # pragma nocover
    796             if isinstance(self, rtb.ERobot):
--> 797                 env = self._plot_swift(q=q, block=block)
    798             elif isinstance(self, rtb.DHRobot):
    799                 raise NotImplementedError(

~\Miniconda3\lib\site-packages\roboticstoolbox\robot\Robot.py in _plot_swift(self, q, block)
    886 
    887         # Add the self to the figure in readonly mode
--> 888         env.launch()
    889 
    890         env.add(

~\Miniconda3\lib\site-packages\roboticstoolbox\backends\Swift\Swift.py in launch(self, browser)
    103 
    104         if self.display:
--> 105             sw.start_servers(self.outq, self.inq, browser=browser)
    106             self.last_time = time.time()
    107 

~\Miniconda3\lib\site-packages\swift\Swift.py in start_servers(outq, inq, open_tab, browser)
     58 
     59         try:
---> 60             inq.get(timeout=10)
     61         except Empty:
     62             print('\nCould not connect to the Swift simulator \n')

~\Miniconda3\lib\queue.py in get(self, block, timeout)
    176                     remaining = endtime - time()
    177                     if remaining <= 0.0:
--> 178                         raise Empty
    179                     self.not_empty.wait(remaining)
    180             item = self._get()

Empty: 

Browser Window:
image

I'm running this on a conda environment in Windows 10 with python 3.7.7

PS: I tried disabling the firewall but that didn't help either.

@adv4ncr
Copy link

adv4ncr commented Feb 26, 2021

same question here

@jhavl
Copy link
Owner

jhavl commented Mar 1, 2021

Which version of the toolbox and Swift are you ruunning? Are you installed off PyPI or from Github? Also try deleting the browser cache.

@adv4ncr
Copy link

adv4ncr commented Mar 1, 2021

For me: using python 3.9.2 64-bit. Swift is directly built from Github.

called by:

import roboticstoolbox as rtb 
env = rtb.backends.Swift()  
env.launch()

From swift\Swift.py:

Could not connect to the Swift simulator

From my browser Firefox instantly:

Error code: 404  
Message: File not found.  
Error code explanation: HTTPStatus.NOT_FOUND - Nothing matches the given URI.

Tried with firewall off, different browser, PyPI version - nothing changes.

@jhavl
Copy link
Owner

jhavl commented Mar 3, 2021

Can you please try this:

  • Pull latest changes from the Swift repo
  • Install roboticstoolbox-python using the github version (if you are already using this then pull latest changes and reinstall)
  • Install spatialmath-python using the github version (if you are already using this then pull latest changes and reinstall)
  • Clear browser cache

@adv4ncr
Copy link

adv4ncr commented Mar 4, 2021

Found the bug for my case.

os.chdir(Path.home().anchor)

As I run the code from a different partition, changing the cwd makes it impossible to find the files.
Therefore it should be more something like:

os.chdir(root_dir.anchor)

By the way: big thanks for your work 😃

@pkoscik
Copy link

pkoscik commented Mar 21, 2021

Having the same issue, tried things posted in this thread but to no avail.

Browser console shows:
Loading module from “http://localhost:52000/js/index.js” was blocked because of a disallowed MIME type (“text/plain”).

Python Python 3.9.0 64-bit
Swift installed via pip
Runtime console error: Could not connect to the Swift simulator
screenshot of the browser

@asmwarrior
Copy link

I have the same issue here, I'm on Windows 7 64bit, WinPython 3.8.8.0 and the latest Official "obotics-toolbox-python" 0.9.1.

I can't start the Swift, see my issue report here:

Can't open the Swift simulator in the browser (Windows 7, Python 3.8)

Also, I can't start the vpython backend. I can only show a vpython window in Firefox tab by such command mentioned here vpython · PyPI

from vpython import *
sphere()

So, I guess it is a socket/server error under Windows OS.

Any one has find the solution?

@asmwarrior
Copy link

Found the bug for my case.

os.chdir(Path.home().anchor)

As I run the code from a different partition, changing the cwd makes it impossible to find the files.
Therefore it should be more something like:

os.chdir(root_dir.anchor)

By the way: big thanks for your work smiley

Hi, by using this changes, I can view the 3D arm in Swift Simulator(inside Firefox) now. Thanks!

@asmwarrior
Copy link

This is the patch to apply the changes to the latest git version:

 swift/SwiftRoute.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/swift/SwiftRoute.py b/swift/SwiftRoute.py
index d2f0c28..c826e14 100644
--- a/swift/SwiftRoute.py
+++ b/swift/SwiftRoute.py
@@ -147,7 +147,8 @@ class SwiftServer:
 
         root_dir = Path(sw.__file__).parent / 'out'
         # os.chdir(Path.home())
-        os.chdir(Path.home().anchor)
+        # os.chdir(Path.home().anchor)
+        os.chdir(root_dir.anchor)
 
         class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
             def log_message(self, format, *args):

@asmwarrior
Copy link

When I try to use the git version of roboticstoolbox-python and swift-sim, I notice that I can't run the swift simulator.

See my report here:

petercorke/robotics-toolbox-python#209 (comment)

It looks like when using the git version, the package are pointed by roboticstoolbox-python.egg-link and swift-sim.egg-link. Which has the contents like:

E:\code\robotics\robotics-toolbox-python
.

and

E:\code\robotics\swift
.

Which means the packages are points to my local git clone of the packages.

But I see that: E:\code\robotics\robotics-toolbox-python\roboticstoolbox\backends\swift, in this folder, I only have a single file named __init__.py, do I have to copy some code to here?

@asmwarrior
Copy link

When I try to use the git version of roboticstoolbox-python and swift-sim, I notice that I can't run the swift simulator.

See my report here:

petercorke/robotics-toolbox-python#209 (comment)

It looks like when using the git version, the package are pointed by roboticstoolbox-python.egg-link and swift-sim.egg-link. Which has the contents like:

E:\code\robotics\robotics-toolbox-python
.

and

E:\code\robotics\swift
.

Which means the packages are points to my local git clone of the packages.

But I see that: E:\code\robotics\robotics-toolbox-python\roboticstoolbox\backends\swift, in this folder, I only have a single file named __init__.py, do I have to copy some code to here?

OK, I found the solution of this issue now.

When I clone the repo in Windows, the folder name is E:\code\robotics\robotics-toolbox-python\roboticstoolbox\backends\swift, and the swift should be changed to Swift, then the Swift backend works now.

Question:

I see that from the github web address, https://github.com/petercorke/robotics-toolbox-python/tree/master/roboticstoolbox/backends/swift
It also use the wrong folder name, can you fix it?

Thanks.

@jhavl
Copy link
Owner

jhavl commented Apr 14, 2021

Sorry for the radio silence on this one.
Regarding the most recent comment: the Swift component of RTB was extracted from that repo and put into this one to make it possible for Swift to run standalone. So now it can be usedlike this:

import swift
env = swift.Swift()

For backwards compatibility and symmetry with other backends, it can be also used like this:

from roboticstoolbox.backends import swift
env = swift.Swift()

Where in the latter the folder was renamed to swift from Swift to match the first use case and to make the syntax for both uses the same. Hope that makes sense - I'm also trying to remove bugs resulting from the name switch.

@jhavl
Copy link
Owner

jhavl commented Apr 14, 2021

@adv4ncr: Regarding the first issue about the directory being wrong since you run code from a different partition. This is especially tricky. On the Python side of things, there is a HTTP server which provides files to the browser to display the robot/whatever meshes need to be displayed. The HTTP server can only serve files in or above where it is rooted. I think I'll have to add an optional keyword argument to Swift to specify where to launch the server for cases such as yours. Any thoughts on this?

@asmwarrior
Copy link

Sorry for the radio silence on this one.
Regarding the most recent comment: the Swift component of RTB was extracted from that repo and put into this one to make it possible for Swift to run standalone. So now it can be usedlike this:

import swift
env = swift.Swift()

For backwards compatibility and symmetry with other backends, it can be also used like this:

from roboticstoolbox.backends import swift
env = swift.Swift()

Where in the latter the folder was renamed to swift from Swift to match the first use case and to make the syntax for both uses the same. Hope that makes sense - I'm also trying to remove bugs resulting from the name switch.

Hi, thanks for your explanation, now you have to fix this line:

https://github.com/petercorke/robotics-toolbox-python/blob/71183f3221cf9ced69420f07ade06f4514c256ba/roboticstoolbox/robot/Robot.py#L1204

from roboticstoolbox.backends.Swift import Swift

This still exist in the latest github master.

@asmwarrior
Copy link

Sorry for the radio silence on this one.
Regarding the most recent comment: the Swift component of RTB was extracted from that repo and put into this one to make it possible for Swift to run standalone. So now it can be usedlike this:

import swift
env = swift.Swift()

For backwards compatibility and symmetry with other backends, it can be also used like this:

from roboticstoolbox.backends import swift
env = swift.Swift()

Where in the latter the folder was renamed to swift from Swift to match the first use case and to make the syntax for both uses the same. Hope that makes sense - I'm also trying to remove bugs resulting from the name switch.

Hi, thanks for your explanation, now you have to fix this line:

https://github.com/petercorke/robotics-toolbox-python/blob/71183f3221cf9ced69420f07ade06f4514c256ba/roboticstoolbox/robot/Robot.py#L1204

from roboticstoolbox.backends.Swift import Swift

This still exist in the latest github master.

I change the line to:

 roboticstoolbox/robot/Robot.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/roboticstoolbox/robot/Robot.py b/roboticstoolbox/robot/Robot.py
index e47a159e..924359eb 100644
--- a/roboticstoolbox/robot/Robot.py
+++ b/roboticstoolbox/robot/Robot.py
@@ -1201,7 +1201,7 @@ class Robot(ABC, DynamicsMixin, IKMixin):
                 raise NotImplementedError(
                     'Plotting in Swift is not implemented for DHRobots yet')
 
-            from roboticstoolbox.backends.Swift import Swift
+            from roboticstoolbox.backends.swift import Swift
             env = Swift()
 
         elif backend.lower() == 'pyplot':
@@ -1304,9 +1304,9 @@ class Robot(ABC, DynamicsMixin, IKMixin):
         # Add the self to the figure in readonly mode
         # Add the self to the figure in readonly mode
         if q.shape[0] == 1:
-            env.launch(self.name + ' Plot', limits=limits, fig=fig)
+            env.launch(name = self.name + ' Plot', limits=limits, fig=fig)
         else:
-            env.launch(self.name + ' Trajectory Plot', limits=limits, fig=fig)
+            env.launch(name = self.name + ' Trajectory Plot', limits=limits, fig=fig)
 
         env.add(
             self, readonly=True, jointaxes=jointaxes, jointlabels=jointlabels,

But I still can't run the simple test program:

import roboticstoolbox as rp

panda = rp.models.Panda()
panda.plot(q=panda.qr)

I got such error:

runfile('E:/code/robotics/robotics-toolbox-python/roboticstoolbox/examples/mytest.py', wdir='E:/code/robotics/robotics-toolbox-python/roboticstoolbox/examples')
Traceback (most recent call last):

  File "E:\code\robotics\robotics-toolbox-python\roboticstoolbox\examples\mytest.py", line 4, in <module>
    panda.plot(q=panda.qr)

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\robot\Robot.py", line 1311, in plot
    env.add(

TypeError: add() got an unexpected keyword argument 'jointaxes'


I'm a bit sad, because I got running errors here or there.

@asmwarrior
Copy link

But I still can't run the simple test program:

import roboticstoolbox as rp

panda = rp.models.Panda()
panda.plot(q=panda.qr)

I got such error:

runfile('E:/code/robotics/robotics-toolbox-python/roboticstoolbox/examples/mytest.py', wdir='E:/code/robotics/robotics-toolbox-python/roboticstoolbox/examples')
Traceback (most recent call last):

  File "E:\code\robotics\robotics-toolbox-python\roboticstoolbox\examples\mytest.py", line 4, in <module>
    panda.plot(q=panda.qr)

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\robot\Robot.py", line 1311, in plot
    env.add(

TypeError: add() got an unexpected keyword argument 'jointaxes'

I'm a bit sad, because I got running errors here or there.

I take some time to track down this error, it looks like the commit:

consolidate all plot/teach in robot class · petercorke/robotics-toolbox-python@8bb9ac5

I see that the the backend PyPlot has changed the add() function prototype, but not the other backends, currently, the vPython backend still has the function definition like:

    def add(self, dhrobot, fig_num=0, name=None, **kwargs):

https://github.com/petercorke/robotics-toolbox-python/blob/3455429f64a4a49c63422d69e62102e8bbb09801/roboticstoolbox/backends/VPython/VPython.py#L285-L300

@jhavl
Copy link
Owner

jhavl commented Apr 19, 2021

Hey @asmwarrior, on the latest commits for robotics toolbox and swift (you will need to re-install swift) I can run:

import roboticstoolbox as rp

panda = rp.models.Panda()
panda.plot(q=panda.qr)

@jhavl
Copy link
Owner

jhavl commented Apr 19, 2021

Hey @adv4ncr, @asmwarrior,

I've experimented with the recommended change to the server root. It turns out that using root_dir doesn't break other paths like I expected. Thanks for this recommendation! This change has been pushed to Github and will be in the next PyPI release.

@jhavl jhavl closed this as completed Apr 19, 2021
@asmwarrior
Copy link

Hey @asmwarrior, on the latest commits for robotics toolbox and swift (you will need to re-install swift) I can run:

import roboticstoolbox as rp

panda = rp.models.Panda()
panda.plot(q=panda.qr)

I just updated to the latest github version of swift, robotictoolbox, spatial-math, and running this code still gives me errors:

In [1]: runfile('E:/code/robotics/robotics-toolbox-python/roboticstoolbox/examples/mytest2.py', wdir='E:/code/robotics/robotics-toolbox-python/roboticstoolbox/examples')
error parsing URDF file E:\download\sci\Winpython64-3.8.8.0\WPy64-3880\python-3.8.8.amd64\Lib\site-packages\rtbdata\xacro\franka_description\robots\panda_arm_hand.urdf.xacro
Traceback (most recent call last):

  File "E:\code\robotics\robotics-toolbox-python\roboticstoolbox\examples\mytest2.py", line 3, in <module>
    panda = rp.models.Panda()

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\models\URDF\Panda.py", line 33, in __init__
    links, name = self.URDF_read(

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\robot\ERobot.py", line 1213, in URDF_read
    raise e

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\robot\ERobot.py", line 1210, in URDF_read
    urdf = URDF.loadstr(urdf_string, file_path)

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\tools\urdf\urdf.py", line 1952, in loadstr
    return URDF._from_xml(node, path)

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\tools\urdf\urdf.py", line 1980, in _from_xml
    return URDF(**kwargs)

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\tools\urdf\urdf.py", line 1767, in __init__
    childlink.v = var

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\robot\ELink.py", line 92, in v
    self._update_fknm()

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\robot\ELink.py", line 484, in _update_fknm
    shape_base, shape_wT, shape_sT, shape_sq = self._get_fknm()

  File "e:\code\robotics\robotics-toolbox-python\roboticstoolbox\robot\ELink.py", line 448, in _get_fknm
    shape_sq.append(shap._sq)

AttributeError: 'Mesh' object has no attribute '_sq'


In [2]: 

Can you have a look?
Thanks.

@jhavl
Copy link
Owner

jhavl commented Apr 19, 2021

This sounds like you need to be running the github version of spatialgeometry

@asmwarrior
Copy link

asmwarrior commented Apr 19, 2021

This sounds like you need to be running the github version of spatialgeometry

Good, this solved the problem.
I think I have 4 github version of the repo: "robotics-toolbox-python, spatialgeometry, spatialmath-python and swift".
I think this should be stated in some document/front page, so other guys can't meet the same issue as mine. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants