petercorke / robotics-toolbox-python

Robotics Toolbox for Python
MIT License
2.18k stars 454 forks source link

VPython bug #185

Closed BartlomiejKulecki closed 3 years ago

BartlomiejKulecki commented 3 years ago

Hello When I run the code:

import roboticstoolbox as rtb
from spatialmath import *

robot = rtb.models.DH.Panda()
T = SE3(0.7, 0.2, 0.1) * SE3.OA([0, 1, 0], [0, 0, -1])
sol = robot.ikine_LM(T)  # solve IK
q_pickup = sol.q
print(q_pickup)  # display joint angles
print(robot.fkine(q_pickup))
qt = jtraj(robot.qz, q_pickup, 50)

env = rtb.backends.VPython()
env.launch()
env.add(fig_num=0, dhrobot=robot)
for q in qt.y:
    time.sleep(1/50)
    env.step(dt=0.025, id=robot, q=q)

the browser opens, robot is rendering, but when it should start moving (it is not) there are errors:

File "D:/rtb/scripts/main.py", line 100, in traj_vpython
  env.step(dt=0.025, id=robot, q=q)
File "C:\Users\Y700\AppData\Local\Programs\Python\Python37\lib\site-packages\roboticstoolbox\backends\VPython\VPython.py", line 200, in step
  if robot is None:
UnboundLocalError: local variable 'robot' referenced before assignment
micah-huth commented 3 years ago

This should be fixable by replacing \roboticstoolbox\backends\VPython\VPython.py line 190 from "# robot = None" to "robot = id". This will allow following conditional statements to run correctly.

I can't test/implement this at the moment, but I can get to it (if no one else does) early next week.

petercorke commented 3 years ago

@micah-huth good to hear from you, be great if you could have a look at this. Few things is like to chat to you about if you have cycles...