Closed whynpt closed 2 years ago
I find what is the exact cause of problem. To control jaco2 with mujoco, I run
robot_config = jaco2.Config() interface = Mujoco(robot_config) interface.connect()
,
but jaco2.Config()
object has no attribute '_connect' where MujocoConfig
has. So i did some change in jaco2.Config()
. I make jaco2.Config()
child class ofMujocoConfig
, but _g shows both in Baseconfig
and MujocoConfig
. Baseconfig._g
is None, and MujocoConfig_g
is np.zeros(6)
. so i want to know how to connect jaco2 with mujoco, simultaneously add gravity to robot.
The problem is that you are using the abr_control.arms.jaco2
config with the Mujoco
interface. Mujoco has it's own xml format it expects for arm configs, so instead of using the jaco2.py
config in the arms
folder, you need to load the xml into the MujocoConfig
, which subclasses the base config. I've added an item to the backlog to update the README to explain the differences between backends.
I've updated your script and it should run for you now. I've tested it on my machine and it runs fine. Note, if you go to abr_control/docs/examples/Mujoco
there are many examples showing how to use the various controllers and path planners.
Cheers
import traceback
import glfw
import numpy as np
from abr_control.arms.mujoco_config import MujocoConfig as arm
from abr_control.controllers import OSC
from abr_control.interfaces.mujoco import Mujoco
robot_config = arm('jaco2')
interface = Mujoco(robot_config, dt=0.001)
interface.connect()
ctrlr = OSC(robot_config,
kp=200,
# control (x, y, z) out of [x, y, z, alpha, beta, gamma]
# NOTE due to the angles of the jaco2 wrist joints, there
# are cases where we hit a singularity that reduces the arm
# to less than 6 controllable degrees of freedom, so control
# of 6 degrees does not work well in some cases
ctrlr_dof=[True, True, True, False, False, False])
target_xyz = [.2, .2, .5] # in metres
target_orientation = [0, 0, 0] # Euler angles, relevant when controlled
for ii in range(1000):
# NOTE look into abr_control path planners to filter your path to target
# using a single, unfiltered target will results in worse peformance and
# more jerk
feedback = interface.get_feedback() # returns a dictionary with q, dq
u = ctrlr.generate(
q=feedback['q'],
dq=feedback['dq'],
target=np.hstack([target_xyz, target_orientation]))
# add gripper joint angles (not force controllable)
# these are the steady state positions, but can be changed
u = np.hstack((u, np.zeros(robot_config.N_GRIPPER_JOINTS)))
interface.send_forces(u) # send forces and step CoppeliaSim sim forward
interface.disconnect()
Note that if you want 6DOF control (position and orientation) you'll need to change ctrlr_dof
to be True for all 6 degrees of freedom. The performance of the jaco2 in this case will not be great as it has singularities that get introduced due to the ~60deg wrist joints.
my code is demo in readme:
an error occured at line 224 of
basic_config.g()
. The traceback is:the problem is caused by
self._g(*parameters)
, where self._g is a np.ndarray [0. 0. 0. 0. 0. 0.], the parameters is joint angle that's a tuple. Doesself._g(*parameters)
mean self._g plus parameters?