Quick Guide

1.创建机器控制器

主要包括:主程序, 环境的描述类, 机器人类

(1)主程序MyProg.java

import simbad.gui.Simbad;
public class MyProg {
    public static void main(String[] args) {
        Simbad frame = new Simbad(new MyEnv() ,false);
    }
}

Simbad frmae = new Simbad(new MyEnv(),false)    主程序的只要作用是启动Simbad并加载环境描述 ,MyEnv是下面要创建的环境描述的类


(2)描述环境 MyEnv.java

import simbad.sim.*;
import javax.vecmath.Vector3d;
public class MyEnv extends EnvironmentDescription {
    public MyEnv(){
        add(new Arch(new Vector3d(3,0,-3),this));
        add(new MyRobot(new Vector3d(0, 0, 0),"my robot"));
    }
}
描述机器人运行的环境:
add(Arch(new Vectord3d(3,0,-3),this));  向环境中添加一个3D拱形.
add(new MyRobot(new Vector3d(0,0,0),"my robot"))  向环境中添加一个机器人.当中的MyRobot是下面要创建的机器人类

(3)机器人类MyRobot.java
import  simbad.sim.*;
import javax.vecmath.Vector3d;

public class MyRobot extends Agent {
    public MyRobot (Vector3d position, String name) {     
        super(position,name);
    }
    public void initBehavior() {}
    
    public void performBehavior() {
        if (collisionDetected()) {
            // stop the robot
            setTranslationalVelocity(0.0);
            setRotationalVelocity(0);
        } else {
            // progress at 0.5 m/s
            setTranslationalVelocity(0.5);
            // frequently change orientation 
            if ((getCounter() % 100)==0) 
               setRotationalVelocity(Math.PI/2 * (0.5 - Math.random()));
        }
    }
}

MyRobot类继承于Agent类,这里需要重写两个方法:initBehavior和performBehavior
InitBehavior: 在Agent生命开始的时候由模拟器调用,这里为空,什么也不做.
performBehavior:每次操作的时候又模拟器调用.

--------------------------------------------------------------------------------------------------------------
最后编译和运行:
(我把simbad.jar 与上面的类放在同一个文件夹内)
编译:    javac -classpath simbad.jar MyProg.java MyEnv.java MyRobot.java
运行:    java -classpath simbad.jar:. MyProg

运行截图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值