如何使一个revoluteJoint振荡

如何使一个revoluteJoint振荡

本文介绍了如何使一个revoluteJoint振荡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个电机和低级放一个revoluteJoint;上限。我想知道如何使revoluteJoint的低级放大器之间振荡;上限。目前主体从下到上限值摆动,然后停止。任何帮助将AP preciated。这是code

I have created a revoluteJoint with a motor and lower & upper limits. I would like to know how to make the revoluteJoint oscillate between the lower & upper limits. Currently the body swings from the lower to the upper limit and then stops. Any help will be appreciated. This is the code

   final RevoluteJointDef revoluteJointDef2 = new RevoluteJointDef();
   revoluteJointDef2.initialize(legBody, circleBody1, circleBody1.getWorldCenter());
   revoluteJointDef2.enableMotor = true;
   revoluteJointDef2.enableLimit = true;
   rj2 = (RevoluteJoint) this.mPhysicsWorld.createJoint(revoluteJointDef2);
   rj2.setMotorSpeed(2);
   rj2.setMaxMotorTorque(10);
   rj2.setLimits((float)(30 * (Math.PI)/180), (float)(270 * (Math.PI)/180));

我如何联合反方向,并再次重申?

How do I make the joint reverse direction and repeat again?

推荐答案

我能够通过实现计时器任务创建oscilatting revoluteJoint。每次定时器触发我扭转电机的转速,使revoluteJoint低级放大器之间振荡;上限。

I was able to create an oscilatting revoluteJoint by implementing a timer task. Every time the timer fires I reverse the motor speed and make the revoluteJoint oscillate between lower & upper limits.

    class RemindTask extends TimerTask {
       RevoluteJoint rj1;;
        RemindTask(RevoluteJoint rj){
        rj1 = rj;
    }
    @Override
    public void run() {
        Log.d("x","x" +"Reversing motor");
        reverseMotor();
    }

    public void reverseMotor(){
        rj1.setMotorSpeed(-(rj1.getMotorSpeed()));
        rj1.setMaxMotorTorque(100);

    }
}

有关的链接,实现和code请看看我的博客文章的

For a link to implementation and code please take a look at my blog post http://gigadom.wordpress.com/2013/07/02/simulating-an-oscillating-revolutejoint-in-android/

这篇关于如何使一个revoluteJoint振荡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 19:59