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

Mocap can not specify the manipulator's initial pose #125

Open
DuYi-angle opened this issue Dec 6, 2024 · 1 comment
Open

Mocap can not specify the manipulator's initial pose #125

DuYi-angle opened this issue Dec 6, 2024 · 1 comment

Comments

@DuYi-angle
Copy link

I am adding mocap to the end of a Kinova Gen3 in mujoco to control a robotic arm. When I initialize the robotic arm, it works fine. But when the simulation starts, the robotic arm immediately returns to zero and then moves under the control of the mocap. I want to know why this is happening.This is my running code:

import mujoco
import mujoco.viewer
import numpy as np
import time
from copy import deepcopy

class KinovaControl:
def init(self, filename, init_position='home', is_show=True):
self.model = mujoco.MjModel.from_xml_path(filename)
self.data = mujoco.MjData(self.model)

    self.is_show = is_show
    if is_show:
        self.viewer = mujoco.viewer.launch_passive(self.model, self.data, key_callback=self.keyboard_cb)
        self.viewer.opt.frame = mujoco.mjtFrame.mjFRAME_WORLD 
        self.viewer.opt.frame = mujoco.mjtFrame.mjFRAME_BODY

    self.set_init(init_position)

def set_init(self, init_position):
    self.cnt = 0
    self.init_qpos = np.array([0, 0.26179939, 3.14159265, -2.26892803, 0, 0.95993109, 1.57079633])
    self.data.qpos = self.init_qpos
    mujoco.mj_forward(self.model, self.data)

    mujoco.set_mjcb_control(self.controller)

def controller(self, model, data):
    tmp = deepcopy(self.init_qpos)
    tmp[-1] += 0.01 * self.cnt
    self.cnt += 1
    # self.data.ctrl = tmp
    self.data.mocap_pos[0][1] -= 0.0001
    self.data.mocap_quat[0] = [1, 0, 0, 0]
    # print(self.data.body('bracelet_link'))

def main(self):
    while True:
        mujoco.mj_step(self.model, self.data)
        if self.viewer.is_running():
            self.viewer.sync()
        time.sleep(0.01)

def keyboard_cb(self, keycode):
    if chr(keycode) == ' ':
        mujoco.mj_resetData(self.model, self.data)
        mujoco.mj_forward(self.model, self.data)
        self.set_init('home')

if name == "main":
xml_path = "/home/zhangsl/DualArmControl/kinova_gen3/scene.xml"
kinova_control = KinovaControl(xml_path, 'home')
kinova_control.main()

My xml is modified from mujoco_menagerie
kinova_gen3.zip

@DuYi-angle
Copy link
Author

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

1 participant