robotlearn / pyrobolearn Goto Github PK
View Code? Open in Web Editor NEWPyRoboLearn: a Python framework for Robot Learning
License: Apache License 2.0
PyRoboLearn: a Python framework for Robot Learning
License: Apache License 2.0
I have recently started using PyRoboLearn. I used to load collision shape in Pybullet as:
import pybullet as p
p.createVisualShape(shape, radius=radius, length=length, rgbaColor=[0.8, 0.6, 0.4, 1], specularColor=specular_color, visualFramePosition=position_offset, visualFrameOrientation=orientation)
It has many arguments that are not available in PyRoboLearn. It only provides a few arguments.
sim = Bullet()
create_visual_shape(sim.GEOM_CAPSULE, radius=radius, length=height/2., rgba_color=color)
How can I use other arguments in PyRoboLearn which are available in PyBullet?
It seems that almost all dependencies, no matter if truly required or not, get included globally.
Example:
For instance, raisimLib should not be required to run examples that do not depend on and do not use raisim. However, when it is not installed on a user-machine, pyrobolearn immediately throws an error like: current_dir=/home/.../.local/lib/python2.7/site-packages/pybullet_envs/bullet No module named raisimpy HINT: you need to install
raisimLiband
raisimOgre, and build the Python wrappers that are located in the
raisim_wrapper folder.
Possible solutions:
Thanks in advance, and best regards!
I have got the urdf model of a hole from solidworks, and also a mesh file of the hole. But when i try to assemble the peg into the hole. I found the collision shape of the hole is cylinder which is solid not contain the hole of the cylinder.
Could you tell me how to confige this stl model or use which of software to config this property
this is that model stl
hole_f.STL.tar.gz
I need this capability for attaching different types of grippers or end-effectors to robot or change their position/orientation through code rather than changing the URDF.
I am testing it using the following code in reaching.py
# Test
if __name__ == "__main__":
from itertools import count
import pyrobolearn as prl
# create simulator
sim = prl.simulators.Bullet()
# create environment
env = ReachingManipulationEnv(sim, control_mode = 'torque')
action = env.action
action.data = np.array([1,0,0,20,0,0,0])
print("\nAction: {}".format(action))
# run simulation
for _ in count():
# print(action)
env.step(action, sleep_dt=1./240)
Please guide me on what I am missing here.
Thanks.
Recently, I often encountered the singular matrix for training the GMM using your provided GMM class. However, the same data can be successfully trained. Would you have any time to check it out?
File "../models/gaussian.py", line 421, in pdf
return mvn.pdf(x, self.mean, self.cov, allow_singular=False) # default
File "/home/user/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/stats/_multivariate.py", line 516, in pdf
psd = _PSD(cov, allow_singular=allow_singular)
File "/home/user/anaconda3/envs/py37/lib/python3.7/site-packages/scipy/stats/_multivariate.py", line 165, in init
raise np.linalg.LinAlgError('singular matrix')
numpy.linalg.LinAlgError: singular matrix
Currently, in every Python file, the following is written at the beginning:
# -*- coding: utf-8 -*-
#!/usr/bin/env python
This is incorrect, and should be replaced by:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
The shebang (#! line) must always be the first, because the kernel looks at the first two bytes of an executable, and if they happen to be #!, then the kernel interprets the rest of the line as the binary that actually needs to be run. See the following link for more information: https://www.python.org/dev/peps/pep-0263/
Solution:
find . -type f \( -name "*.py" ! -name "__init__.py" \) -exec sed -i '/# -\*- coding: utf-8 -\*-/d' {} +
find . -type f \( -name "*.py" ! -name "__init__.py" \) -exec sed -i '2 i\# -*- coding: utf-8 -*-' {} +
The first bash line will delete the encoding in every python file (except the __init__.py
files), then the second line will put the encoding at the second line of every python file (except the __init__.py
files).
I tried git clone and download zip multiple times and failed (network error)
Upon succeeding download a master zip, I realized the repo is almost 1GB in size.
Should it be offloaded to Releases? Or split to many sub-repos?
Hi,
Thanks for the great work. I tried to use it by building the image from the dockerfile. However, I found the dockerfile includes operations of downloading a lot of big files (such as cuda, cudnn tools, gazebo models), which costs a lot of time and is prone to throw errors because of the bad internet connection or any other problems (such cases happened to me). I think a more reasonable way might be downloading the necessary big files in advance and use COPY command to place them in the right place. Through this way, even the building process failed, you don't have to download the files again.
I am not very familiar with docker, so if I am wrong, please overlook the above concerns.
As discussed with @lrozo I document the following issue here:
I have another MuJoCo installation on my system, which I cannot touch for different reasons. I did not install MuJoCo via the provided pyrobolearn installation script.
In that case, pyrobolearn throws an error as follows when trying to run any example.
Traceback (most recent call last):
File "examples/imitation/trajectory_reproduction_kuka_dmp.py", line 12, in <module>
from pyrobolearn.simulators import Bullet
File "/home/gim2rng/pyrobolearn_ws/pyrobolearn/pyrobolearn/__init__.py", line 24, in <module>
from . import simulators
File "/home/gim2rng/pyrobolearn_ws/pyrobolearn/pyrobolearn/simulators/__init__.py", line 31, in <module>
import mujoco_py
File "/home/gim2rng/.virtualenvs/venv_py3/lib/python3.6/site-packages/mujoco_py/__init__.py", line 2, in <module>
init_config()
File "/home/gim2rng/.virtualenvs/venv_py3/lib/python3.6/site-packages/mujoco_py/config.py", line 37, in init_config
raise error.MujocoDependencyError('Found your MuJoCo license key but not binaries. Please put your binaries into ~/.mujoco/mjpro131 or set MUJOCO_PY_MJPRO_PATH. Follow the instructions on https://github.com/openai/mujoco-py for setup.')
mujoco_py.error.MujocoDependencyError: Found your MuJoCo license key but not binaries. Please put your binaries into ~/.mujoco/mjpro131 or set MUJOCO_PY_MJPRO_PATH. Follow the instructions on https://github.com/openai/mujoco-py for setup.
When I run this file, first I record the trajectory using ctrl+r and then by pressing shift+r, it fails to execute and gives the following error:
TypeError: Expecting an instance of `Action`, np.array, or a list of the previous ones, but got instead: <class 'numpy.ndarray'>
Please help.
Hi, would you add any demo for the trajectory modulation based on via-points using KMP?
When I run Force_control_example.py, robot initially runs for few iterations, while showing end-effector forces plot. After some time, robot stops, a new black window appears and terminal shows following error:
-3.9336459877590596e-05
-1.80323431312297e-05
5.969657570434706e-06
2.6458507806909837e-05
4.270999884258811e-05
5.0823149630967465e-05
5.153522232988297e-05
4.396127642365691e-05
3.070630143922923e-05
1.3182937457178667e-05
-5.113344854462901e-06
-2.2079177359950246e-05
-3.482887550450532e-05
WARNING: QApplication was not created in the main() thread.
Exception in thread manipulator task:
Traceback (most recent call last):
File "/home/deepakraina/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/home/deepakraina/anaconda3/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "force_control/Force_control_example.py", line 191, in manipulator_thread
plt.show()
File "/home/deepakraina/anaconda3/lib/python3.7/site-packages/matplotlib/pyplot.py", line 269, in show
return _show(*args, **kw)
File "/home/deepakraina/anaconda3/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py", line 413, in wrapper
return func(*args, **kwargs)
File "/home/deepakraina/anaconda3/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 3302, in show
cls.mainloop()
File "/home/deepakraina/anaconda3/lib/python3.7/site-packages/matplotlib/backends/backend_qt5.py", line 1094, in mainloop
signal.signal(signal.SIGINT, signal.SIG_DFL)
File "/home/deepakraina/anaconda3/lib/python3.7/signal.py", line 47, in signal
handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
Please help with this. Thanks
Calling the get_joint_acceleration()
method in robots/robot.py leads to an error when called twice due two an indexing error for the cached values here. Easy fix for this issue is to replace this line by ddq = self._state['ddq'][0]
. Happy to do a PR :)
When trying to run any example, for example:
pyrobolearn_ws/pyrobolearn/examples/kinematics/forward$ python fk.py pybullet build time: Sep 25 2019 10:28:00 current_dir .../.virtualenvs/venv_py2/local/lib/python2.7/site-packages/pybullet_envs/bullet Traceback (most recent call last): File "fk.py", line 11, in <module> from pyrobolearn.simulators import Bullet File "/packages/pyrobolearn/pyrobolearn/__init__.py", line 23, in <module> from . import simulators File "/packages/pyrobolearn/pyrobolearn/simulators/__init__.py", line 35, in <module> from .raisim import Raisim File "/packages/pyrobolearn/pyrobolearn/simulators/raisim.py", line 31 SyntaxError: Non-ASCII character '\xe2' in file /home/gim2rng/packages/pyrobolearn/pyrobolearn/simulators/raisim.py on line 32, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
I started tracing back the non-readable characters, however they are numerous. Possibly introduced by editing the documentation sections in an inappropriate text-editor.
The docs really need a section on frame conventions. Here is what I've discovered:
I think it would be really nice to have to_earth_frame and to_body_frame helper functions
I've been testing the quadcopter model as a backend for ArduPilot. I do have it flying now, but I had to change the mass of the propellers to be 1000x smaller than the current value in the urdf. The default mass of 0.005 seems reasonable, but I needed to change it to be 0.000005 to get reasonable yaw control. There is some gross mis-match between thrust and yaw torque on the propellers.
I suspect it is related to thrust for gazebo normally being on -1 to 1 scale, whereas for this model it is 0 to 1000 scale.
I hope to get the force and torque information reciving from Ati senors in the simulation environment. But in your package is hard to realize. But I have found a package which can measure the ft information, but the topic is published in gazebo.
So I want to know how could I let the robot model in your environment stay the same as the robot environment in gazebo meanwhile passing the force/torque measurement from gazebo into your environment to realize the force control.
I have seen Force_control_example.py with the Kuka-IIWa robot, which is working perfectly fine. But then I tried to implement the same with the UR5 robot, then it is not able to do the force tracking. Can you please let me know, what I am doing wrong here. Is it an issue with M/D/K parameter tunning?
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
The task is to track the force along z axis (vertical to the table) by employing admittance control, meanwhile tracking
a circle trajectory on the xy plane. And the end-effector's target position is visualized by a sphere.
Reference:
[1] SONG, Peng; YU, Yueqing; ZHANG, Xuping. A tutorial survey and comparison of impedance control on robotic manipulation
. Robotica, 2019, 37.5: 801-836.
"""
import numpy as np
from itertools import count
from pyrobolearn.simulators import Bullet
from pyrobolearn.worlds import BasicWorld
from pyrobolearn.robots import Body, sensors, UR10, UR5
from pyrobolearn.utils.transformation import *
from pyrobolearn.utils.plotting.end_effector_realtime_FT_plot import EeFtRealTimePlot
from threading import Thread
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
# Real-time plot the End-effector force and torque
def plotting_thread(plot):
if not isinstance(plot, EeFtRealTimePlot):
raise TypeError("Expecting to plot type is CartesianRealTimePlot, not ""{}".format(plot))
while True:
plot.update()
# Manipulate the whole process
# The sphere is used to visualize the reference trajectory, So I creat the sphere trajectory as the reference
def manipulator_thread(world, robot, sphere, FT_sensor):
"""
First step: is to arrive the initial position
"""
for t in count():
# move sphere
# sphere.position = np.array([0.36, 0, 0.8])
sphere.position = np.array([0.5, 0.1, 0.94])
# get current end-effector position and velocity in the task/operational space
x = robot.get_link_world_positions(link_id)
dx = robot.get_link_world_linear_velocities(link_id)
o = robot.get_link_world_orientations(link_id)
do = robot.get_link_world_angular_velocities(link_id)
# Get joint positions
q = robot.get_joint_positions()
# Get linear jacobian
if robot.has_floating_base():
J = robot.get_jacobian(link_id, q=q)[:, qIdx + 6]
else:
J = robot.get_jacobian(link_id, q=q)[:, qIdx]
# Pseudo-inverse: \hat{J} = J^T (JJ^T + k^2 I)^{-1}
Jp = robot.get_damped_least_squares_inverse(J, damping)
dv = kp * (sphere.position - x) - kd * dx
dw = kp * quaternion_error(sphere.orientation, o) - kd * do
# evaluate damped-least-squares IK
dq = Jp.dot(np.hstack((dv, dw)))
# set joint positions
q = q[qIdx] + dq * dt
robot.set_joint_positions(q, joint_ids=joint_ids)
if t > 1000:
break
# step in simulation
world.step(sleep_dt=dt)
"""
Second step: From the initial pose, Move vertically downward
until end-effector touches the desktop with a force of 10N
"""
for t in count():
Fz_desired = 5 # the threshold of the contact force with table
# move sphere
sphere.position = np.array([0.5, 0.1, 0.94-0.0005*t])
# get current end-effector position and velocity in the task/operational space
x = robot.get_link_world_positions(link_id)
dx = robot.get_link_world_linear_velocities(link_id)
o = robot.get_link_world_orientations(link_id)
do = robot.get_link_world_angular_velocities(link_id)
# Get joint positions
q = robot.get_joint_positions()
# Get linear jacobian
if robot.has_floating_base():
J = robot.get_jacobian(link_id, q=q)[:, qIdx + 6]
else:
J = robot.get_jacobian(link_id, q=q)[:, qIdx]
# Pseudo-inverse: \hat{J} = J^T (JJ^T + k^2 I)^{-1}
Jp = robot.get_damped_least_squares_inverse(J, damping)
dv = kp * (sphere.position - x) - kd * dx
dw = kp * quaternion_error(sphere.orientation, o) - kd * do
# evaluate damped-least-squares IK
dq = Jp.dot(np.hstack((dv, dw)))
# set joint positions
# robot.set_joint_velocities(dq, joint_ids=joint_ids)
q = q[qIdx] + dq * dt
robot.set_joint_positions(q, joint_ids=joint_ids)
print('force:', FT_sensor.sense()[2])
if FT_sensor.sense() is not None:
if FT_sensor.sense()[2] > Fz_desired:
print('reached desired F')
break
# step in simulation
world.step(sleep_dt=dt)
sp_z = []
num = []
detx = np.array([0.0, 0.0, 0.0])
"""
Third step to keep the target force along z axis(vertical to the table),
and complete circular motion trajectory on plane xy
"""
circle_center = np.array([0.5, 0.1]) # the center of the trajectory
for t in count():
Fz_desired = 5 # desired force
# move sphere
if t == 0:
z = robot.get_link_world_positions(link_id)[2]
sphere.position = np.array([circle_center[0] - r * np.sin(w * t + np.pi / 2), circle_center[1] + r * np.cos(w * t + np.pi / 2), z])
# get current end-effector position and velocity in the task/operational space
x = robot.get_link_world_positions(link_id)
dx = robot.get_link_world_linear_velocities(link_id)
o = robot.get_link_world_orientations(link_id)
do = robot.get_link_world_angular_velocities(link_id)
# Get joint positions
q = robot.get_joint_positions()
# Get linear jacobian
if robot.has_floating_base():
J = robot.get_jacobian(link_id, q=q)[:, qIdx + 6]
else:
J = robot.get_jacobian(link_id, q=q)[:, qIdx]
# Pseudo-inverse: \hat{J} = J^T (JJ^T + k^2 I)^{-1}
Jp = robot.get_damped_least_squares_inverse(J, damping)
# Apply the admittance control
Fz_current = FT_sensor.sense()[2] # record the current Fz
print('Fz: ', Fz_current)
Fz_error = Fz_current - Fz_desired # record the current error
# set the M\D\K parameters by heuristic method, these parameters may have a good result
# M = 1
# D = 9500
# K = 500000
M = 0.2
D = 4250
K = 100000
# Refer the formula (33) in this article [1]
# the formula is theta_x(k) = Fc(k)*Ts^2+Bd*Ts*theta_x(k-1)+Md*(2*theta_x(k-1)-theta_x(k-2))/(Md+Bd*Ts+Kd*Ts^2)
numerator = Fz_error * np.square(dt) + D * dt * detx[1] + M * (2 * detx[1] - detx[2])
denominator = M + D*dt + K*np.square(dt)
detx_ = numerator / denominator
print (detx_)
detx[2] = detx[1]
detx[1] = detx[0]
detx[0] = detx_
zzz = sphere.position[2] + detx[0]
# circle_center the the centre of the circle trajectory on the table
sphere.position = np.array([circle_center[0] - r * np.sin(w * t + np.pi / 2), circle_center[1] + r * np.cos(w * t + np.pi / 2), zzz])
dv = kp * (sphere.position - x) - kd * dx # compute the other direction tracking error term
sp_z.append(sphere.position[2])
num.append(t)
dw = kp * quaternion_error(sphere.orientation, o) - kd * do
# evaluate damped-least-squares IK
dq = Jp.dot(np.hstack((dv, dw)))
# set joint positions
q = q[qIdx] + dq * dt
robot.set_joint_positions(q, joint_ids=joint_ids)
# print(Fz_error, dv[2])
if t == 2000:
break
# step in simulation
world.step(sleep_dt=dt)
plt.plot(num, sp_z) # plot the position on the z axis
plt.xlabel("timesteps")
plt.ylabel("vertical position")
plt.title("The z axis position during the task")
plt.show()
if __name__=='__main__':
# Create simulator
sim = Bullet()
# create world
world = BasicWorld(sim)
# flag : 0 # PI control
flag = 0
# create robot
robot = UR5(sim, position=[0,0,0.5])
# robot = 'ur5'
robot.print_info()
world.load_robot(robot)
world.load_table(position=np.array([1, 0., 0.]), orientation=np.array([0.0, 0.0, 0.0, 1.0]))
# define useful variables for IK
dt = 1. / 240
link_id = robot.get_end_effector_ids(end_effector=0)
print('link_id:',link_id)
joint_ids = robot.joints # actuated joint
damping = 0.01 # for damped-least-squares IK
wrt_link_id = -1 # robot.get_link_ids('iiwa_link_1')
qIdx = robot.get_q_indices(joint_ids)
print('qidx:', qIdx)
# define gains
kp = 500 # 5 if velocity control, 50 if position control
kd = 5 # 2*np.sqrt(kp)
# create sphere to follow
sphere = world.load_visual_sphere(position=np.array([0.5, 0., 0.5]), radius=0.05, color=(1, 0, 0, 0.5))
sphere = Body(sim, body_id=sphere)
# set initial joint p
# Positions (based on the position of the sphere at [0.5, 0, 1])
robot.reset_joint_states(q=[0.0, -1.57, 1.57, -1.57, -1.57, -1.57])
# define amplitude and angular velocity when moving the sphere
w = 0.01
r = 0.1
# I set the reference orientation to a constant
sphere.orientation = np.array([-0.49940256, 0.5001992, 0.50019888, 0.50019888])
FT_sensor = sensors.JointForceTorqueSensor(sim, body_id=robot.id, joint_ids=5)
# The plotting handle
plot = EeFtRealTimePlot(robot, sensor=FT_sensor, forcex=True, forcey=True, forcez=True,
torquex=True, torquey=True, torquez=True, num_point=1000, ticks=24)
# FT_ = np.zeros(6)
plot_t = Thread(target=plotting_thread, args=[plot], name='plotting task')
manipulator_t = Thread(target=manipulator_thread, args=(world, robot, sphere, FT_sensor), name='manipulator task')
thread_pools = [plot_t, manipulator_t]
for thread in thread_pools:
thread.start()
for thread in thread_pools:
thread.join()
When I run $ pip install -e .
ERROR: Command errored out with exit status 1:
command: /home/wq/env/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/wq/pyrobolearn/setup.py'"'"'; file='"'"'/home/wq/pyrobolearn/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-31a3tcbj
cwd: /home/wq/pyrobolearn/
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "/home/wq/pyrobolearn/setup.py", line 21, in
reqs = [str(ir.req) for ir in install_requires]
File "/home/wq/pyrobolearn/setup.py", line 21, in
reqs = [str(ir.req) for ir in install_requires]
AttributeError: 'ParsedRequirement' object has no attribute 'req'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
The same error occurs in the python 3.5/3.6 environment.
Hi! when i was preparing the env for the package, i have follow the instruction in the readme text, Everything is ok no error! But when i ran the pyrobolearn/examples/kinematics/forward it pull the error like that!
Some ROS packages were not found... Skipping prl.simulators.middlewares.ROS...
pybullet build time: Nov 17 2019 13:30:40
current_dir=/home/tiboy/py3.5/lib/python3.5/site-packages/pybullet_envs/bullet
Dart could not be found on this system... Skipping prl.simulators.Dart...
MuJoCo could not be found on this system... Skipping prl.simulators.Mujoco...
Raisim could not be found on this system... Skipping prl.simulators.Raisim...
RBDL could not be found on this system... Skipping priorities.RBDLModelInterface...
Traceback (most recent call last):
File "/home/tiboy/simulation/pyrobolearn/pyrobolearn/optimizers/nlopt_optimizer.py", line 15, in
import nlopt
File "/home/tiboy/py3.5/lib/python3.5/site-packages/nlopt.py", line 35, in
_nlopt = swig_import_helper()
File "/home/tiboy/py3.5/lib/python3.5/site-packages/nlopt.py", line 31, in swig_import_helper
_mod = imp.load_module('_nlopt', fp, pathname, description)
File "/home/tiboy/py3.5/lib/python3.5/imp.py", line 242, in load_module
return load_dynamic(name, filename, file)
File "/home/tiboy/py3.5/lib/python3.5/imp.py", line 342, in load_dynamic
return _load(spec)
ImportError: libnlopt.so.0: cannot open shared object file: No such file or directory
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tiboy/simulation/pyrobolearn/examples/kinematics/inverse/ik.py", line 14, in
from pyrobolearn.simulators import Bullet
File "/home/tiboy/simulation/pyrobolearn/pyrobolearn/init.py", line 98, in
from . import priorities
File "/home/tiboy/simulation/pyrobolearn/pyrobolearn/priorities/init.py", line 13, in
from . import solvers
File "/home/tiboy/simulation/pyrobolearn/pyrobolearn/priorities/solvers/init.py", line 10, in
from .nlp_task_solver import NLPTaskSolver
File "/home/tiboy/simulation/pyrobolearn/pyrobolearn/priorities/solvers/nlp_task_solver.py", line 15, in
from pyrobolearn.optimizers.nlopt_optimizer import NLopt
File "/home/tiboy/simulation/pyrobolearn/pyrobolearn/optimizers/nlopt_optimizer.py", line 17, in
raise ImportError(e.str() + "\n HINT: you can install nlopt via pip install nlopt
.")
ImportError: libnlopt.so.0: cannot open shared object file: No such file or directory
HINT: you can install nlopt via pip install nlopt
.
But i have pip the nlopt its version is 2.4.2.post2. So can you help me fix these problem
The imitation example given is only for the reproduction of demonstrated trajectory. What if I would like to change the goal location during reproduction? Is this possible with the same example?
After installation, when import pyrobolearn, get the following error:
Failed to load python extension for lz4 support. lz4 compression will not be available. pybullet build time: Oct 8 2020 00:10:04 Dart could not be found on this system... SKipping prl.simulators.Dart... ERROR: Expired activation key
Hi! Thanks for your contribution~
Recently I have try to exploit some code about force control using UR in your simulation framework. But I found the detected force is too high to tracking the reference force, could you attach some force control code using robot arm like kuka or other robots to be referred.
I am getting the following error when I run the pendulum.py file:
ImportError: cannot import name 'robot_names_to_classes' from partially initialized module 'pyrobolearn.robots' (most likely due to a circular import) (/home/$USER/$DIRECTORY/pyrobolearn-master/pyrobolearn/robots/__init__.py)
Our requirements file indicates that the torch library can be any >=1.1.0, however, it seems there were some relevant changes in recent versions (>1.1.0) that produces the following error when using GPR models (for example, when running gpr.py in the examples folder)
Traceback (most recent call last): File "/home/rol2rng/Code/IIT/pyrobolearn_fork/examples/models/gpr.py", line 41, in <module> f = model.sample(x, num_samples=10, to_numpy=True)
File "/home/rol2rng/Code/IIT/pyrobolearn_fork/pyrobolearn/models/gp/gp.py", line 665, in sample return self._convert_to_numpy(f.sample(num_samples))
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/gpytorch/distributions/multivariate_normal.py", line 167, in sample return self.rsample(sample_shape=sample_shape, base_samples=base_samples)
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/gpytorch/distributions/multivariate_normal.py", line 136, in rsample res = covar.zero_mean_mvn_samples(num_samples) + self.loc.unsqueeze(0)
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/gpytorch/lazy/lazy_tensor.py", line 1112, in zero_mean_mvn_samples covar_root = self.root_decomposition()
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/gpytorch/lazy/lazy_tensor.py", line 901, in root_decomposition )(*self.representation())
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/gpytorch/functions/_root_decomposition.py", line 64, in forward eigenvalues, eigenvectors = lanczos_tridiag_to_diag(t_mat)
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/gpytorch/utils/lanczos.py", line 166, in lanczos_tridiag_to_diag return batch_symeig(t_mat)
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/gpytorch/utils/eig.py", line 28, in batch_symeig eigenvalues[i] = evals.masked_fill_(1 - mask, 1)
File "/home/rol2rng/Code/IIT/pyrobolearn_official/venv35/lib/python3.5/site-packages/torch/tensor.py", line 362, in __rsub__ return _C._VariableFunctions.rsub(self, other)
RuntimeError: Subtraction, the
-operator, with a bool tensor is not supported. If you are trying to invert a mask, use the
~or
logical_not() operator instead.
This does not happen when installing specifically torch 1.1.0. However, note that the latest torch version requires Python >=3.6.
So, short-term solution: Fix the torch version in requirements to be == 1.1.0. Long-term solution, identify the required change in the sampling function of GP according to the latest Torch version.
I have try the track the orientation of the target sphere not just the position.
dv = kp_x * (sphere.position - x) + kd_x * dx I try to use this function to get the position control. It has a good performance. but when I add the orientation tracking using dw=kp_o* error_quaternion(sphere.orientation, quaternion_endeffector) + kd_o * do_d[0:3]
dq = Jp.dot(np.hstack((dv, dw))) but the performance of the tracking is not good.
the error_quaternion is
def error_quaternion(a, b):
q = a.copy()
p = b.copy()
x = q[0] * p[1] - q[1] * p[0] - q[2] * p[3] + q[3] * p[2]
y = q[0] * p[2] + q[1] * p[3] - q[2] * p[0] - q[3] * p[1]
z = q[0] * p[3] - q[1] * p[2] + q[2] * p[1] - q[3] * p[0]
return np.array([x, y, z])
do is error_quaternion_q(quaternion_endeffector, sphere.orientation) / dt
error_quaternion_q is
def error_quaternion_q(a, b):
q = a.copy()
p = b.copy()
w = q[0] * p[0] - q[1] * p[1] - q[2] * p[2] - q[3] * p[3]
x = q[0] * p[1] - q[1] * p[0] - q[2] * p[3] + q[3] * p[2]
y = q[0] * p[2] + q[1] * p[3] - q[2] * p[0] - q[3] * p[1]
z = q[0] * p[3] - q[1] * p[2] + q[2] * p[1] - q[3] * p[0]
return np.array([x, y, z, w])
Hello,
Thanks for the repo, it is fantastic what you have done here ! I come from UCL in Belgium and try to use Pyrobolearn for the first time for a course : the objective is to simulate just one leg of Pleurobot (imposed by our teacher) with a custom path.
It is very easy to compute the path we want and looking to the example of invert kinematics, we tried to make one leg following our path. But it isn't working very well !
Entire code is findable here : https://github.com/nicolascolsoul/biorobotics/blob/master/pleurobot_lmeca.py
But it looks very similar of the invert kinematics example except this line,
link_id = robot.get_end_effector_ids(end_effector=5)
To choose the right rear leg. But the end effector isn't following our curve and I don't understand.
Is the end effector (in Pleurobot model ?) the last joint or the output of the last joint ?
I want to the A point follow my path but it seems that it is the B point.
How can we achieve that ? I'm not very skilled in robotics/simulation so, if this question looks stupid, please tell me. Thank you so much.
As the installation instructions suggest to have either 2.7 or 3.5, the Mujoco installation fails as Mujoco 2.0 is supposed for python >=3.6 . Therefore, we need to mention this when installing Mujoco as an alternative simulator. Another solution would be to force the pip install
with 3.6 version.
Before you go online with Pyrobolearn at CoRL, you might want to consider adding a slim CI-pipeline, e.g. using travis, which is free for open-source projects.
In that context, you may also consider switching to a pull-request driven development, since pushing to master is not ideal, and will certainly scare potential users away. See e.g. the following discussion.
When detaching two bodies, the corresponding world.detach()
method does not work as documented.
In particular, consider the following three cases in the code example at the bottom (from worlds/samples/sports.basketball.py).
world.detach(body1=robot.id, body2=world.ball, link1=robot.end_effectors[0], link2=-1)
: This results in a KeyError, as the constraint dictionary is not properly addressed here. Easy fix, replace the indexing by self.constraints[(body1, body2)][(link1, link2)]
world.detach(body1=robot, body2=world.ball)
: This does not throw any error but fails silently. The reason is that only body IDs and not the Body instances are checked for being in the constraints here. Two fixes: either check if body1/2 instances of Body
and get their corresponding IDs, or change the docstring that this method only works for IDs.world.detach(body1=robot.id, body2=world.ball)
: Just specifying the body IDs and no link IDs works just fine :)Happy to do a PR fixing this issue.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""Provide the basketball world.
"""
import os
import numpy as np
from pyrobolearn.worlds import BasicWorld
__author__ = "Brian Delhaisse"
__copyright__ = "Copyright 2019, PyRoboLearn"
__credits__ = ["Brian Delhaisse"]
__license__ = "GNU GPLv3"
__version__ = "1.0.0"
__maintainer__ = "Brian Delhaisse"
__email__ = "[email protected]"
__status__ = "Development"
# TODO: finish to implement the world, create corresponding environment (in `envs` folder) with state and reward.
class BasketBallWorld(BasicWorld):
r"""Basketball world
"""
def __init__(self, simulator, position=(3., 0., 2.), scale=(1., 1., 1.)):
"""
Initialize the basketball world.
Args:
simulator (Simulator): the simulator instance.
position (tuple/list of 3 float, np.array[3]): position of the basketball hoop.
scale (tuple/list of 3 float): scale of the basket hoop.
"""
super(BasketBallWorld, self).__init__(simulator)
mesh_path = os.path.dirname(os.path.abspath(__file__)) + '/../../meshes/sports/basketball/'
position = np.asarray(position)
# load basket hoop position
self.hoop = self.load_mesh(mesh_path + 'basketball.obj', position=position, scale=scale, mass=0, flags=1)
# load ball
# self.ball = self.load_sphere(position=[0., 0., 1.], radius=0.1193, mass=0.625)
# self.apply_texture(texture=mesh_path + 'Basketball-ColorMap.jpg', body_id=self.ball)
self.ball = self.load_mesh(mesh_path + 'ball.obj', position=[0., 0., 2.], scale=(1., 1., 1.), mass=0.625,
flags=0)
self.ball_radius = 0.1193
# set the restitution coefficient for the ball
# Ref: "Measure the coefficient of restitution for sports balls", Persson, 2012
self.change_dynamics(self.ball, restitution=0.87)
self.change_dynamics(restitution=1.)
def reset(self, world_state=None):
super(BasketBallWorld, self).reset(world_state)
def step(self, sleep_dt=None):
super(BasketBallWorld, self).step(sleep_dt)
# Test
if __name__ == '__main__':
from itertools import count
import pyrobolearn as prl
# create simulator
sim = prl.simulators.Bullet()
# create world
world = BasketBallWorld(sim)
# create manipulator
robot = world.load_robot('kuka_iiwa')
# attach ball to robot end effector
world.attach(body1=robot, body2=world.ball, link1=robot.end_effectors[0], link2=-1, joint_axis=[0., 0., 0.],
parent_frame_position=[0., 0., world.ball_radius], child_frame_position=[0., 0., 0.],
parent_frame_orientation=[0, 0., 0., 1.])
# run simulation
for t in count():
if t % 100 == 0:
print(f"Timestep {t}")
if t == 500:
# Using PyBullet
# works after fixing (see comment above): specifying both body IDs and link IDs
# world.detach(body1=robot.id, body2=world.ball, link1=robot.end_effectors[0], link2=-1)
# does not work: specifying body1 as object and body2 by ID
# world.detach(body1=robot, body2=world.ball)
# works: specifying just body IDs
world.detach(body1=robot.id, body2=world.ball)
world.step(sim.dt)
Hello! I need to use two camera sensors but there aren't examples of how to put it in the simulation. I suggest creating a camera like a robot to load easily "world_load_camera" and the same thing to other sensors like IMU. Thanks a lot!
When I try to run the file pyrobolearn/examples/middlewares/bullet_ros_publisher.py, some errors occur, File "/pyrobolearn/pyrobolearn/utils/parsers/robots/urdf_parser.py", line 39, in init
super().init(filename)
TypeError: super() takes at least 1 argument (0 given)
so I have changed to super(URDFParser, self).init(filename)
another error occurs when I try to load the kuka_iiwa model in bullet_ros_publisher.py
in file /pyrobolearn/pyrobolearn/simulators/middlewares/robots/iiwa14.py
if self.is_publishing: q = self.subscriber.get_joint_positions() dq = self.subscriber.get_joint_velocities() tau = self.subscriber.get_joint_torques() if q is None: # +++++ return 0 # +++++ if len(q) > 0: q_indices = None if joint_ids is None else self.q_indices[joint_ids] if q_indices is not None: q[q_indices] = positions if velocities is not None: dq[q_indices] = velocities
the symbol '+++++' part is added to solve the problem of if q is None, the NoneType has no len()
File: robot.py
Function: get_link_world_velocities(self, link_ids=None, flatten=True):
Issue: When adding np.array(lin_vel + ang_vel)
in line 1407, this "addition" operation may, in fact, add both velocity vectors instead of concatenating (which basically depends on the type of data structure returned by the simulator, e.g. list or array).
Notes: This problem may replicate in line 1413
Some install scripts ask the user for a path where to install a certain package, although it is in fact not required, as the packages are being built and subsequently globally installed to /usr/local* anway.
As a user-friendly improvement, you can set a default download directory, e.g. to something like /tmp, which gets routinely deleted at startup!
Also, there is an inconsistency w.r.t. the install location in the scripts.
Some scripts automatically install libraries and headers to /usr/local*, otheres explicitly ask for setting the $CMAKE_PREFIX_PATH path implicitly via $LOCAL_BUILD
I'd suggest to replace LOCAL_BUILD entirely by CMAKE_PREFIX_PATH since it makes it clear to the user what the variable means, and default the latter to /usr/local*
If the user is behind a proxy/firewall, this line may throw an error:
Cloning into 'dart'... fatal: unable to connect to github.com: github.com: Name or service not known
Better try cloning via https whenever possible. This also applies to other installation scripts using the same git-clone as this.
Hello!! Is there some way to perform an inverse kinematics considering a gripper or other thing attached to the end link of the robot using pyrobolearn? Because I just can do IK considering the end link of the robot, but I'm using a gripper. So, I would like to do it by sending a position referring to the gripper. Thanks!
Hi, and first and foremost, thanks for the great work!
I checked out the repo and noted that the robots/urdf* folder is roughly 900 MB. This seems to be the case because of extremely high-resolution meshes.
Would it be an option to downsample the meshes a bit? For users, that would mean a more lean repo, faster collision checking in classical motion planning, faster rendering in visualization, etc.!
When I try to change the scale of the mesh (ellipsoid.obj), it is not working actually. I think is these two functions problem. when I use the function of pybullet, p.createVisualShape and p.createMultiBody is working.
How can we implement the trajectory visualization of robot end-effector as shown in your paper?
Hi, would you add any demo for the trajectory modulation based on via-points using KMP?
This line throws an error:
Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package libeigen-dev
Do we need to install libeigen3-dev instead?
Line 45 executes cmake in a folder that was just created without any CMakeLists.txt. Do we need first to git-clone something here?
I did not keep executing lines as these two issues arised.
When I run gmr.py and gmr_letter.py, the initialization of GMM is different, I don't understand the initialization of gaussians= (mean,cov);
gmm = GMM(gaussians=[Gaussian(mean=np.random.uniform(-1., 1., size=dim),
covariance=0.1np.identity(dim)) for _ in range(num_components)])
gmm = GMM(gaussians=[Gaussian(mean=np.concatenate((np.random.uniform(0, 2., size=1),
np.random.uniform(-8., 8., size=dim-1))),
covariance=0.1np.identity(dim)) for _ in range(num_components)])
When I tried to train the position data of the end-effector with gmm, the output result was completely wrong. If possible, I hope you can write an example, thank you!
Hi, thanks you for your effort to making good implementations of pyRobolearn.
I would like to know the usage of humanoid IK(for example, robot standing or robot horizontal walking).
I try to load humanoid and apply inverse kinematics code which you publish on github, but I got some errors and did not work well.
Please make some tutorials about humanoid version!!
setJointMotorControl is obsolete and replaced by setJointMotorControl2 API , but this is not yet reflected in pyrobolearn
If the user is behind a proxy/firewall, this line may throw an error:
Cloning into 'dart'... fatal: unable to connect to github.com: github.com: Name or service not known
Better try cloning via https whenever possible. This also applies to other installation scripts using the same git-clone as this.
Typing make -j4 dartpy
throws the error:
make: *** No rule to make target 'dartpy'. Stop.
I guess it is first needed to move to the python folder and then run the line above.
I want to confirm that whether the package has the function to get the robot end-effector pose in the coordinate of object B (B is not the world or the robot link). If it has, i will be convinent.
When running/using Mujoco, we need to first install patchelf:
sudo apt install patchelf
We also need to add these dependencies:
pip install pymesh pyassimp
When running examples where Mujoco is the simulator (from Pycharm), I got this error:
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.