The robot API &&How to add and use sensor.

本文介绍了机器人API的基础操作,包括状态获取与运动控制,并详细展示了如何利用RobotFactory类添加及使用声纳传感器进行环境感知。

The robot API

Robot的状态API

Robot的状态可以可通过访问以下继承于Agentclas的方法得到:

*boolean collisionDetected():如果agent碰撞到物体,返回true.

*int getCounter():返回模拟器已经执行难过的次数.

*double getOdometer():返回agents里程表的数据,agents走了多少米.

*double getLifeTime():返回agent的存在多少”虚拟秒”

*void getCoords(Point3d coord):返回坐标,米为单位.


Robot的运动API

可以通过指定旋转速度和平均速度来控制robot的运动.

* void setRotationalVelocity(double rv):设置旋转速度,单位是弧度/.

* void setTranslationalVelocity(double tv):设置平均速度,单位是米/.

*double getRotationalVelocity():获取旋转速度,单位是弧度/.

*double getTranslationalVelocity():获取平均速度,单位是米/.

*void moveToStartPosition():robot放置回它开始的位置


传感器

你能为robot装备以下传感器:

*声纳定位器(Sonars)

*缓冲器(Bumpers)

*摄像头(Camera)

*光线传感器(Lightsensor)


RobotFactoryclass提供的方法能容易地添加上述的传感器.


添加和使用缓冲器传感器

在使用缓冲器之前必须先添加进robot.可以在robot的构造函数里面使用RobotFactory类绑定RangeSensorBelt对象.下面的例子为robot添加8个声纳传感器.每个声纳传感器一定范围内的距离信息以及碰撞状态,当在声纳范围内检测到物体返回true.能通过方法hasHitgetMeasurement单独访问每个声纳传感器.下面的例子每20帧打印出所有声纳传感器的状态.


建立robot类MyRobot.java(也可是在之前的MyRobot基础上添加缓冲器)

代码如下:


public class MyRobot extends Agent {

     RangeSensorBelt sonars;

     public Robot(Vector3d position, String name) {
         super(position, name);
         sonars = RobotFactory.addSonarBeltSensor(this,8);  //添加8个声纳传感器
     }

    public void performBehavior() {
        //every 20 frames
        if (getCounter()%20==0){             //20帧输出声纳传感器的状态
            // print each sonars measurement
            for (int i=0;i< sonars.getNumSensors();i++) {
                double range = sonars.getMeasurement(i); 
                double angle = sonars.getSonarAngle(i);
                boolean hit = sonars.hasHit(i);
                System.out.println("Sonar at angle "+ angle +
                "measured range ="+range+ " has hit something:"+hit); 
            }
        }
    }
}
 
编译:javac -classpath simbad.jar  MyProg.java MyEnv.java  MyRobot
运行:java -classpath simbad.jar:. MyProg
截图如下:




                
# 3D ViTac: Learning Fine-Grained Manipulation with Visuo-Tactile Sensing #### Project Website: https://binghao-huang.github.io/3D-ViTac/ This codebase contains python code and ros package for flexible tactile sensor in 3D-ViTac. To build the tactile sensors, follow the instructions below: [[Hardware Assembly Tutorial]](https://docs.google.com/document/d/1XGyn-iV_wzRmcMIsyS3kwcrjxbnvblZAyigwbzDsX-E/edit?tab=t.0#heading=h.ny8zu0pq9mxy) ,[[Bills of Material]](https://docs.google.com/document/d/1auxwAbAnt88nG7HDqanr4JJreuAVkrhs1nK16VQaLpk/edit?tab=t.0#heading=h.ny8zu0pq9mxy) ## 1. Firmware (1) Load the [arduino code](/arduino_code/MatrixArray.ino) to the arduino. ## 2. PYTHON(option 1) (1) Setup environment pip install pyserial pip install opencv-python==4.6.0.66 pip install threading pip install scipy (2)Start python visualization cd python python3 multi_thread_contact.py ## 3. ROS(option 2) 1. compile ros package(Assuming you have already installed ROS1) cd ros/tactile_ws catkin_make 3. rosrun tactile_sensor tactile_sensor.py ## 4. Multi Sensors name setup (optional) 1. setup multi thread tactile board name(Optional): - One issue that arises is the port each robot binds to can change over time, e.g. a robot that is initially ``ttyUSB0`` might suddenly become ``ttyUSB5``. - Take ``right_robot_left_finger``: right master robot as an example: 1. Find the port that the right master robot is currently binding to, e.g. ``ttyUSB0`` 2. run ``udevadm info --name=/dev/ttyUSB0 --attribute-walk | grep serial`` to obtain the serial number. Use the first one that shows up, the format should look similar to ``FT6S4DSP``. 3. ``sudo vim /etc/udev/rules.d/99-tactile.rules`` and add the following line: SUBSYSTEM=="tty", ATTRS{serial}=="<serial number here>", ENV{ID_MM_DEVICE_IGNORE}="1", ATTR{device/latency_timer}="1", SYMLINK+="right_robot_left_finger" 4. This will make sure the tactile
07-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值