找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 5620|回复: 8

做了个蛇形机器人但是动作不连续是怎么回事?

[复制链接]
发表于 2013-5-6 15:13:40 | 显示全部楼层 |阅读模式
悬赏5乐币未解决
本帖最后由 月影疾风1990 于 2013-5-6 20:25 编辑

http://v.youku.com/v_show/id_XNTUyODg2MDIw.html
新手一枚,想做一个乐高机器人模仿一下蛇的蜿蜒运动,但是上了程序以后动作老是一卡一卡的,不知道算法出错在哪儿?用JAVA写的控制程序控制思想如下:三个电机都是正弦变化,隔一个相位差。视频发上面了,求教高手啊。
  

如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
发表于 2013-5-7 11:26:15 | 显示全部楼层
哈哈哈,楼主的蛇扭的好痛苦!

把代码放回帖里,看一看
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2013-5-7 17:06:18 | 显示全部楼层
iRobot 发表于 2013-5-7 11:26
哈哈哈,楼主的蛇扭的好痛苦!

把代码放回帖里,看一看

package org.lejos.example;

import lejos.nxt.*;
import lejos.util.Delay;
import lejos.nxt.Button;


import java.lang.Math;

public class HelloWorld
{
    public static void main(String args[])
    {
   
            int a[]=new int[6];  
            int b[]=new int[6];  
            int c[]=new int[6];  
            int phase=30;
            float step=(float) 0.56;
            float range=50;
            float flag = 0;
            a[0]=(int)(range*Math.sin(flag/2*step));
            b[0]=(int)(range*Math.sin((flag/2*step)+phase));
            c[0]=(int)(range*Math.sin((flag/2*step)+phase+phase));
            a[1]=0;
            b[1]=0;
            c[1]=0;
           

        LCD.drawString("Setting speed=500", 0, 0);//display program name before running
        Motor.A.setSpeed(800);
        Motor.B.setSpeed(800);
        Motor.C.setSpeed(800);

        Motor.A.rotateTo(0);
        Motor.B.rotateTo(0);
        Motor.C.rotateTo(0);
        LCD.drawString("Press a button to start!", 0, 1);
        Button.waitForPress();
        for(flag=0;flag<=500;flag++)
        {
        if(Button.ENTER.isPressed()==false)
        {
            a[1]=(int)(range*Math.sin(flag/2*step));
            if(Math.abs(a[1]-a[0])>40)
             {
                     Motor.A.setPower(15);
                     a[0]=a[1];
                     Motor.A.rotateTo(a[0],true);
             }
             else
             {
                     Motor.A.setPower(30);
                     a[0]=a[1];
                     Motor.A.rotateTo(a[0],true);         
             }
             Delay.msDelay(4);
            
             b[1]=(int)(range*Math.sin((flag/2*step)+phase));
             if(Math.abs(b[1]-b[0])>40)
             {
                     Motor.B.setPower(15);
                     b[0]=b[1];
                     Motor.B.rotateTo(b[0],true);
             }
             else
             {
                     Motor.B.setPower(30);
                     b[0]=b[1];
                     Motor.B.rotateTo(b[0],true);         
             }
             Delay.msDelay(4);
            
             c[1]=(int)(range*Math.sin((flag/2*step)+phase+phase));
             if(Math.abs(c[1]-c[0])>40)
             {
                     Motor.C.setPower(15);
                     c[0]=c[1];
                     Motor.C.rotateTo(c[0],true);
             }
             else
             {
                     Motor.C.setPower(30);
                     c[0]=c[1];
                     Motor.C.rotateTo(c[0],true);         
             }
             Delay.msDelay(4);
/*                a[0]=(int)(range*Math.sin(flag/2*step));
                b[0]=(int)(range*Math.sin((flag/2*step)+phase));
                c[0]=(int)(range*Math.sin((flag/2*step)+phase+phase));
                a[1]=a[0]/6;
                b[1]=b[0]/6;
                c[1]=c[0]/6;
               
                a[2]=a[0]*2/6;
                b[2]=b[0]*2/6;
                c[2]=c[0]*2/6;
               
                a[3]=a[0]*3/6;
                b[3]=b[0]*3/6;
                c[3]=c[0]*3/6;
               
                 a[4]=a[0]*4/6;
                b[4]=b[0]*4/6;
                c[4]=c[0]*4/6;
               
                 a[5]=a[0]*5/6;
                b[5]=b[0]*5/6;
                c[5]=c[0]*5/6;
               
                Motor.A.rotateTo(a[1],true);
                Delay.usDelay(100);
                Motor.B.rotateTo(b[1],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[1],true);
                Delay.usDelay(100);
               
                   Motor.A.rotateTo(a[2],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[2],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[2],true);
        
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[3],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[3],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[3],true);      
               
            
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[4],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[4],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[4],true);  
               
            
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[5],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[5],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[5],true);  
                                             
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[0],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[0],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[0],true);
                Delay.usDelay(100);
  */             
               
               
               
        }
       else
         {
           Motor.A.rotateTo(0);
           Motor.B.rotateTo(0);
           Motor.C.rotateTo(0);
                  break;
           }
        }
}
    }
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2013-5-7 17:09:59 | 显示全部楼层
额,错了,是这个
package org.lejos.example;

import lejos.nxt.*;
import lejos.util.Delay;
import lejos.nxt.Button;


import java.lang.Math;

public class HelloWorld
{
    public static void main(String args[])
    {
   
            int a[]=new int[6];  
            int b[]=new int[6];  
            int c[]=new int[6];  
            int phase=30;
            float step=(float) 0.56;
            float range=50;
            float flag = 0;
            a[0]=(int)(range*Math.sin(flag/2*step));
            b[0]=(int)(range*Math.sin((flag/2*step)+phase));
            c[0]=(int)(range*Math.sin((flag/2*step)+phase+phase));
            a[1]=0;
            b[1]=0;
            c[1]=0;
           

        LCD.drawString("Setting speed=500", 0, 0);//display program name before running
        Motor.A.setSpeed(800);
        Motor.B.setSpeed(800);
        Motor.C.setSpeed(800);

        Motor.A.rotateTo(0);
        Motor.B.rotateTo(0);
        Motor.C.rotateTo(0);
        LCD.drawString("Press a button to start!", 0, 1);
        Button.waitForPress();
        for(flag=0;flag<=500;flag++)
        {
        if(Button.ENTER.isPressed()==false)
        {
            a[1]=(int)(range*Math.sin(flag/2*step));
            if(Math.abs(a[1]-a[0])>40)
             {
                     Motor.A.setPower(15);
                     a[0]=a[1];
                     Motor.A.rotateTo(a[0],true);
             }
             else
             {
                     Motor.A.setPower(30);
                     a[0]=a[1];
                     Motor.A.rotateTo(a[0],true);         
             }
             Delay.msDelay(4);
            
             b[1]=(int)(range*Math.sin((flag/2*step)+phase));
             if(Math.abs(b[1]-b[0])>40)
             {
                     Motor.B.setPower(15);
                     b[0]=b[1];
                     Motor.B.rotateTo(b[0],true);
             }
             else
             {
                     Motor.B.setPower(30);
                     b[0]=b[1];
                     Motor.B.rotateTo(b[0],true);         
             }
             Delay.msDelay(4);
            
             c[1]=(int)(range*Math.sin((flag/2*step)+phase+phase));
             if(Math.abs(c[1]-c[0])>40)
             {
                     Motor.C.setPower(15);
                     c[0]=c[1];
                     Motor.C.rotateTo(c[0],true);
             }
             else
             {
                     Motor.C.setPower(30);
                     c[0]=c[1];
                     Motor.C.rotateTo(c[0],true);         
             }
             Delay.msDelay(4);
/*                a[0]=(int)(range*Math.sin(flag/2*step));
                b[0]=(int)(range*Math.sin((flag/2*step)+phase));
                c[0]=(int)(range*Math.sin((flag/2*step)+phase+phase));
                a[1]=a[0]/6;
                b[1]=b[0]/6;
                c[1]=c[0]/6;
               
                a[2]=a[0]*2/6;
                b[2]=b[0]*2/6;
                c[2]=c[0]*2/6;
               
                a[3]=a[0]*3/6;
                b[3]=b[0]*3/6;
                c[3]=c[0]*3/6;
               
                 a[4]=a[0]*4/6;
                b[4]=b[0]*4/6;
                c[4]=c[0]*4/6;
               
                 a[5]=a[0]*5/6;
                b[5]=b[0]*5/6;
                c[5]=c[0]*5/6;
               
                Motor.A.rotateTo(a[1],true);
                Delay.usDelay(100);
                Motor.B.rotateTo(b[1],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[1],true);
                Delay.usDelay(100);
               
                   Motor.A.rotateTo(a[2],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[2],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[2],true);
        
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[3],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[3],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[3],true);      
               
            
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[4],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[4],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[4],true);  
               
            
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[5],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[5],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[5],true);  
                                             
                Delay.usDelay(100);
                   Motor.A.rotateTo(a[0],true);
                   Delay.usDelay(100);
                Motor.B.rotateTo(b[0],true);
                Delay.usDelay(100);
                Motor.C.rotateTo(c[0],true);
                Delay.usDelay(100);
  */             
               
               
               
        }
       else
         {
           Motor.A.rotateTo(0);
           Motor.B.rotateTo(0);
           Motor.C.rotateTo(0);
                  break;
           }
        }
}
    }
       }
       else
         {
           Motor.A.rotateTo(0);
           Motor.B.rotateTo(0);
           Motor.C.rotateTo(0);
                  break;
           }
        }
}
    }
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2013-5-8 11:07:13 | 显示全部楼层
同一马达上的两个轮子是用一根轴连接在一起的么?
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2013-5-8 13:18:33 | 显示全部楼层
好巧,我们机器人学校,正好来了位新老师,要做蛇形机器人
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2013-5-8 20:07:22 | 显示全部楼层
lwg7719 发表于 2013-5-8 11:07
同一马达上的两个轮子是用一根轴连接在一起的么?

肯定是的撒,但是动作不连续不知道是怎么回事啊
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

 楼主| 发表于 2013-5-8 20:07:51 | 显示全部楼层
吴轶哲 发表于 2013-5-8 13:18
好巧,我们机器人学校,正好来了位新老师,要做蛇形机器人

呵呵,那万一你们也遇到这个问题解决了记得给我说下哈,谢了
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

发表于 2013-5-9 09:41:18 | 显示全部楼层
月影疾风1990 发表于 2013-5-8 20:07
肯定是的撒,但是动作不连续不知道是怎么回事啊

建议改成用两根轴分别固定两个轮子。因为在转弯过程中,两个轮子的转速是不一样的,如果在同一根轴上的轮子的转速始终是一样的,而两根轴控制两个轮子,在转弯的过程中可以实现两个轮子的转速有差异。如果程序没有错误的话,LZ可以尝试更换一下改改硬件!
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

手机版|中文乐高 ( 桂ICP备13001575号-7 )

GMT+8, 2025-6-24 00:46 , Processed in 0.787346 second(s), 20 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表