petercorke / robotics-toolbox-python

Robotics Toolbox for Python
MIT License
2.12k stars 436 forks source link

Robot in Swift doesn't move #182

Closed BartlomiejKulecki closed 3 years ago

BartlomiejKulecki commented 3 years ago

Hello, I am using Robotic Toolbox in Pycharm on Windows 10. When I run this example code:

import roboticstoolbox as rtb
import spatialmath as sm
import numpy as np

# Make and instance of the Swift simulator and open it
env = rtb.backends.Swift()
env.launch()

# Make a panda model and set its joint angles to the ready joint configuration
panda = rtb.models.Panda()
panda.q = panda.qr

# Set a desired and effector pose an an offset from the current end-effector pose
Tep = panda.fkine(panda.q) * sm.SE3.Tx(0.2) * sm.SE3.Ty(0.2) * sm.SE3.Tz(0.45)

# Add the robot to the simulator
env.add(panda)

# Simulate the robot while it has not arrived at the goal
arrived = False
while not arrived:
    # Work out the required end-effector velocity to go towards the goal
    v, arrived = rtb.p_servo(panda.fkine(panda.q), Tep, 1)

    # Set the Panda's joint velocities
    panda.qd = np.linalg.pinv(panda.jacobe(panda.q)) @ v

    # Step the simulator by 50 milliseconds
    env.step(0.05)

the browser window opens, the robot renders correctly but it doesn't move.

jhavl commented 3 years ago

Which version of the toolbox and Swift are you ruunning? Are you installed off PyPI or from Github? Whats your Python version? Any error messages in your terminal or browser console? (Open browser console with control+shift+i)

BartlomiejKulecki commented 3 years ago

I just reinstalled toolbox with the commands:

pip3 uninstall roboticstoolbox-python 
pip3 install git+https://github.com/petercorke/robotics-toolbox-python

Python version 3.7 In terminal no errors. In browser console there is one error:

error
mfkenson commented 3 years ago

@jhavl I could reproduce the issue with latest commit 448247e in master branch here, and latest commit f2c8b98 in your swift repo. (UPDATE its not about source code. its the browser caching old version of swift javascript code causing function code mismatch. Clear the browser cache does the job!)

I tried to identify which section causing the issue and found self.process_events()==>events = self._send_socket('check_elements') ==> return self.inq.get() is blocking.

If I comment out this line 158. The robot moves as expected. https://github.com/petercorke/robotics-toolbox-python/blob/448247e40e0b1225b77de70b8a6cf1f299c8a5b9/roboticstoolbox/backends/Swift/Swift.py#L158 https://github.com/petercorke/robotics-toolbox-python/blob/448247e40e0b1225b77de70b8a6cf1f299c8a5b9/roboticstoolbox/backends/Swift/Swift.py#L502

It seems the queue.get is blocking by default and waits forever until an item arrives. I can see that the communication between swift backend and the python script is heavily depends on the in/out queues. I can't simply fix this buy adding a little timeout or make it non-blocking.

----- UPDATE -----

Finally! I found that it is google chrome caching the old index.js of swift-sim after inspecting the js code in google chrome and compare with swift-sim latest commit.

screenshot

Clear the browser cache does the job!

steps for google chrome users:

  1. Enter chrome://settings/clearBrowserData in address bar
  2. Time range: All time
  3. Select only the "Cached images and files" for minimal impact
chrome

@jhavl BTW thanks for bringing the swift-sim.

jhavl commented 3 years ago

@mfkenson thanks for this, browser cache is a common issue I run into. Setting no-cache is probably the best solution at least while Swift is under rapid development. I also added some basic troubleshooting tips to the common issues wiki page.

wanglong06 commented 1 year ago

Issue When I run the test code from the tutorial (attached in the end), the 'pyplot' version works fine. But I run into the same problem as in the original issue:

@BartlomiejKulecki the browser window opens, the robot renders correctly but it doesn't move.

I have tried clearing the cache in the browser and using firefox, but the issue persists. Would greatly appreciate any tips on how I can further investigate this.

My environment OS = Ubuntu 18.04 Browser = Chrome Packages versions in pip list:

Code that I ran

import roboticstoolbox as rtb
robot = rtb.models.Panda()
print(robot)

Te = robot.fkine(robot.qr)  # forward kinematics
print(Te)

from spatialmath import SE3

Tep = SE3.Trans(0.6, -0.3, 0.1) * SE3.OA([0, 1, 0], [0, 0, -1])
sol = robot.ik_LM(Tep)         # solve IK
print(sol)

q_pickup = sol[0]
print(robot.fkine(q_pickup))

qt = rtb.jtraj(robot.qr, q_pickup, 50)
robot.plot(qt.q, backend='pyplot', movie='panda1.gif')

robot.plot(qt.q)

@jhavl